/** * Acquires a unmarshaller and set the properties to the given value, if non-null. */ final Unmarshaller acquireUnmarshaller(final Map<String,?> properties) throws JAXBException { final Unmarshaller unmarshaller = acquireUnmarshaller(); if (properties != null) { for (final Map.Entry<String,?> entry : properties.entrySet()) { unmarshaller.setProperty(entry.getKey(), entry.getValue()); } } return unmarshaller; }
/** * Acquires a unmarshaller and set the properties to the given value, if non-null. */ final Unmarshaller acquireUnmarshaller(final Map<String,?> properties) throws JAXBException { final Unmarshaller unmarshaller = acquireUnmarshaller(); if (properties != null) { for (final Map.Entry<String,?> entry : properties.entrySet()) { unmarshaller.setProperty(entry.getKey(), entry.getValue()); } } return unmarshaller; }
/** * Unmarshal an object from the given string. * Note that the given argument is the XML document itself, * <strong>not</strong> a URL to a XML document. * * @param xml the XML representation of an object. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final String xml) throws JAXBException { ensureNonNull("input", xml); final StringReader in = new StringReader(xml); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(in); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given string. * Note that the given argument is the XML document itself, * <strong>not</strong> a URL to a XML document. * * @param xml the XML representation of an object. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final String xml) throws JAXBException { ensureNonNull("input", xml); final StringReader in = new StringReader(xml); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(in); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given file. * * @param input the file from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final File input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given stream. * * @param input the stream from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final InputStream input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given URL. * * @param input the URL from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final URL input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given stream. * * @param input the stream from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final InputStream input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given URL. * * @param input the URL from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final URL input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given file. * * @param input the file from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final File input) throws JAXBException { ensureNonNull("input", input); final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(input); pool.recycle(unmarshaller); return object; }
/** * Unmarshal an object from the given path. * * @param input the path from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final Path input) throws JAXBException { ensureNonNull("input", input); final Object object; try (InputStream in = Files.newInputStream(input, StandardOpenOption.READ)) { final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); object = unmarshaller.unmarshal(in); pool.recycle(unmarshaller); } catch (IOException e) { throw new JAXBException(Errors.format(Errors.Keys.CanNotRead_1, input), e); } return object; }
/** * Unmarshal an object from the given path. * * @param input the path from which to read a XML representation. * @return the object unmarshalled from the given input. * @throws JAXBException if an error occurred during the unmarshalling. */ public static Object unmarshal(final Path input) throws JAXBException { ensureNonNull("input", input); final Object object; try (InputStream in = Files.newInputStream(input, StandardOpenOption.READ)) { final MarshallerPool pool = getPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); object = unmarshaller.unmarshal(in); pool.recycle(unmarshaller); } catch (IOException e) { throw new JAXBException(Errors.format(Errors.Keys.CanNotRead_1, input), e); } return object; }
@Before public void setUp() throws JAXBException { pool = new MarshallerPool(JAXBContext.newInstance( "org.geotoolkit.xacml.xml.policy:" + "org.geotoolkit.xacml.xml.policy:" + "org.geotoolkit.xacml.xml.context"), null); unmarshaller = pool.acquireUnmarshaller(); }
@Before public void setUp() throws Exception { unmarshaller = pool.acquireUnmarshaller(); marshaller = pool.acquireMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); }
@Before public void setUp() throws JAXBException { marshaller = pool.acquireMarshaller(); unmarshaller = pool.acquireUnmarshaller(); }
/** * Converse of {@link #marshal(GenericName)}. */ private GenericName unmarshal(final String xml) throws JAXBException { final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object value = unmarshal(unmarshaller, xml); pool.recycle(unmarshaller); return ((IdentifiedObjectMock) value).alias; }
@Before public void setUp() throws Exception { pool = JTSWrapperMarshallerPool.getInstance(); factory = new ObjectFactory(); un = pool.acquireUnmarshaller(); m = pool.acquireMarshaller(); File xsdDirectory = getDirectoryFromResource("org.geotoolkit.gml.311.base"); SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File(xsdDirectory, "gml.xsd")); un.setSchema(schema); //m.setSchema(schema); }
/** * Unmarshals the content of the given test file using the {@linkplain #getMarshallerPool() test marshaller pool}. * The resource is obtained by a call to {@code getClass().getResource(filename)}, which implies that the file * shall be in the same package than the subclass of {@code this}. * * @param <T> compile-time type of {@code type} argument. * @param type the expected type of the unmarshalled object. * @param filename the name of the XML file in the package of the final subclass of {@code this}. * @return the object unmarshalled from the given file. * @throws JAXBException if an error occurred during unmarshalling. * * @see #assertMarshalEqualsFile(String, Object, String...) */ protected final <T> T unmarshalFile(final Class<T> type, final String filename) throws JAXBException { final MarshallerPool pool = getMarshallerPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshaller.unmarshal(getResource(filename)); pool.recycle(unmarshaller); assertInstanceOf(filename, type, object); return type.cast(object); }
/** * Unmarshals the given object using the {@linkplain #getMarshallerPool() test marshaller pool}. * * @param <T> compile-time type of {@code type} argument. * @param type the expected type of the unmarshalled object. * @param xml the XML representation of the object to unmarshal. * @return the unmarshalled object. * @throws JAXBException if an error occurred while unmarshalling the XML. * * @see #marshal(Object) */ protected final <T> T unmarshal(final Class<T> type, final String xml) throws JAXBException { final MarshallerPool pool = getMarshallerPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object object = unmarshal(unmarshaller, xml); pool.recycle(unmarshaller); assertInstanceOf("unmarshal", type, object); return type.cast(object); }
/** * Tests marshalling in the GML 3.1 namespace. * * @throws JAXBException if an error occurred during unmarshalling. */ @Test @DependsOnMethod("testUnmarshall") public void testUnarshallGML31() throws JAXBException { final MarshallerPool pool = getMarshallerPool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); unmarshaller.setProperty(XML.GML_VERSION, LegacyNamespaces.VERSION_3_0); final DefaultPrimeMeridian pm = (DefaultPrimeMeridian) unmarshal(unmarshaller, getGreenwichXml(LegacyNamespaces.GML)); pool.recycle(unmarshaller); assertIsGreenwich(pm); }