/** * Returns the default (un)marshaller pool used by all methods in this class. * * <div class="note"><b>Implementation note:</b> * Current implementation uses the double-check idiom. This is usually a deprecated practice * (the recommended alterative is to use static class initialization), but in this particular * case the field may be reset to {@code null} if OSGi modules are loaded or unloaded, so static * class initialization would be a little bit too rigid.</div> */ @SuppressWarnings("DoubleCheckedLocking") private static MarshallerPool getPool() throws JAXBException { MarshallerPool pool = POOL; if (pool == null) { synchronized (XML.class) { pool = POOL; // Double-check idiom: see javadoc. if (pool == null) { POOL = pool = new MarshallerPool(null); } } } return pool; }
public static synchronized MarshallerPool getMarshallerPool() { if (POLL == null) { final java.util.List<Class> classes = new ArrayList<>(); classes.add(Math.class); try { POLL = new MarshallerPool(JAXBContext.newInstance(classes.toArray(new Class[classes.size()])), null); } catch (JAXBException ex) { throw new RuntimeException("Could not load jaxbcontext for MathML.",ex); } } return POLL; }
/** * Returns the default (un)marshaller pool used by all methods in this class. * * <div class="note"><b>Implementation note:</b> * Current implementation uses the double-check idiom. This is usually a deprecated practice * (the recommended alterative is to use static class initialization), but in this particular * case the field may be reset to {@code null} if OSGi modules are loaded or unloaded, so static * class initialization would be a little bit too rigid.</div> */ @SuppressWarnings("DoubleCheckedLocking") private static MarshallerPool getPool() throws JAXBException { MarshallerPool pool = POOL; if (pool == null) { synchronized (XML.class) { pool = POOL; // Double-check idiom: see javadoc. if (pool == null) { POOL = pool = new MarshallerPool(Collections.singletonMap(LENIENT_UNMARSHAL, Boolean.TRUE)); } } } return pool; }
/** * Returns the (un)marshaller pool, creating it when first needed. * If the subclass does not define a JAXB context, then this method returns {@code null}. */ final MarshallerPool getMarshallerPool() throws JAXBException { MarshallerPool pool = jaxb; if (pool == null) { synchronized (this) { pool = jaxb; if (pool == null) { final JAXBContext context = getJAXBContext(); if (context != null) { jaxb = pool = new MarshallerPool(context, null); } } } } return pool; } }
/** * Returns the XML (un)marshaller pool to be shared by all test methods. * This test uses its own pool instead of {@link #getMarshallerPool()} * in order to use {@link FeatureAttributeMock}. * * @return the marshaller pool for this test. * @throws JAXBException if an error occurred while creating the pool. */ @Override protected MarshallerPool getMarshallerPool() throws JAXBException { if (pool == null) { pool = new MarshallerPool(JAXBContext.newInstance(FeatureAttributeMock.class), Collections.singletonMap(XML.LENIENT_UNMARSHAL, Boolean.TRUE)); } return pool; }
@BeforeClass public static void setUpClass() throws Exception { pool = new MarshallerPool(JAXBContext.newInstance("org.geotoolkit.xsd.xml.v2001"), null); }
@BeforeClass public static void setUpClass() throws Exception { pool = new MarshallerPool(JAXBContext.newInstance("org.geotoolkit.mathml.xml"), null); }
@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(); }
/** * Creates the XML (un)marshaller pool to be shared by all test methods. * The (un)marshallers locale and timezone will be set to fixed values. * * @throws JAXBException if an error occurred while creating the pool. * * @see #disposeMarshallerPool() */ @BeforeClass public static void createMarshallerPool() throws JAXBException { final Map<String,Object> properties = new HashMap<>(4); assertNull(properties.put(XML.LOCALE, Locale.FRANCE)); assertNull(properties.put(XML.TIMEZONE, "CET")); pool = new MarshallerPool(JAXBContext.newInstance(TimeInstant.class, TimePeriod.class), properties); }
/** * Returns the XML representation of the given name, wrapped * in a mock {@code <gml:IO_IdentifiedObject>} element. */ private String marshal(final GenericName name) throws JAXBException { if (pool == null) { pool = new MarshallerPool(JAXBContext.newInstance(IdentifiedObjectMock.class), Collections.singletonMap(XML.LENIENT_UNMARSHAL, Boolean.TRUE)); } final Marshaller marshaller = pool.acquireMarshaller(); marshaller.setProperty(XML.METADATA_VERSION, VERSION_2007); final String xml = marshal(marshaller, new IdentifiedObjectMock(null, name)); pool.recycle(marshaller); return xml; }
/** * Creates the XML (un)marshaller pool to be shared by all test methods. * The (un)marshallers locale and timezone will be set to fixed values. * * <p>This test uses its own pool instead of {@link #getMarshallerPool()} because it uses * {@link MetadataMock} instead of {@link org.apache.sis.metadata.iso.DefaultMetadata}.</p> * * @throws JAXBException if an error occurred while creating the pool. * * @see #disposeMarshallerPool() */ @BeforeClass public static void createMarshallerPool() throws JAXBException { final Map<String,Object> properties = new HashMap<>(4); assertNull(properties.put(XML.LOCALE, Locale.UK)); assertNull(properties.put(XML.TIMEZONE, UTC)); assertNull(properties.put(XML.LENIENT_UNMARSHAL, Boolean.TRUE)); pool = new MarshallerPool(JAXBContext.newInstance(MetadataMock.class), properties); }
/** * Returns the XML (un)marshaller for the tests in this class. The default implementation * returns a XML (un)marshaller pool potentially shared by test methods in all sub-classes. * The (un)marshallers locale is set to {@link Locale#UK} (the language of ISO standards) * and their timezone is arbitrarily set to CET (<cite>Central European Time</cite>). * * <div class="note"><b>Note:</b> * We intentionally use a timezone different than UTC in order to have an error of one or two hours * if a code fails to take timezone offset in account.</div> * * @return the shared (un)marshaller pool. * @throws JAXBException if an error occurred while creating the JAXB marshaller. */ protected MarshallerPool getMarshallerPool() throws JAXBException { synchronized (TestCase.class) { if (defaultPool == null) { final Map<String,Object> properties = new HashMap<>(4); assertNull(properties.put(XML.LOCALE, Locale.UK)); assertNull(properties.put(XML.TIMEZONE, TIMEZONE)); assertNull(properties.put(XML.LENIENT_UNMARSHAL, Boolean.TRUE)); defaultPool = new MarshallerPool(properties); } return defaultPool; } }
final MarshallerPool pool = new MarshallerPool(null); final Marshaller marshaller = pool.acquireMarshaller(); marshaller.setProperty(XML.LOCALE, locale);
final MarshallerPool pool = new MarshallerPool(JAXBContext.newInstance(new Class<?>[0]), null); final Marshaller marshaller = pool.acquireMarshaller(); assertNotNull(marshaller);