/** * Creates a pooled unmarshaller wrapping the given one. * Callers shall invoke {@link #reset(Pooled)} after construction for completing the initialization. * * @param unmarshaller the unmarshaller to use for the actual work. * @param template the {@link PooledTemplate} from which to get the initial values. * @throws JAXBException if an error occurred while setting a property. */ PooledUnmarshaller(final Unmarshaller unmarshaller, final Pooled template) throws JAXBException { super(template); this.unmarshaller = unmarshaller; initialize(template); }
/** * Delegates to the wrapped unmarshaller. The initial state will be saved * if it was not already done, for future restoration by {@link #reset(Pooled)}. */ @Override public void setAttachmentUnmarshaller(final AttachmentUnmarshaller au) { if (!isPropertySaved(AttachmentUnmarshaller.class)) { saveProperty(AttachmentUnmarshaller.class, unmarshaller.getAttachmentUnmarshaller()); } unmarshaller.setAttachmentUnmarshaller(au); }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public Object unmarshal(final XMLStreamReader input) throws JAXBException { final TransformVersion version = getTransformVersion(); if (version != null) try { return unmarshal(InputFactory.createXMLEventReader(input), version); } catch (XMLStreamException e) { throw new JAXBException(e); } else { final Context context = begin(); try { return unmarshaller.unmarshal(input); } finally { context.finish(); } } }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public <T> JAXBElement<T> unmarshal(final Node input, final Class<T> declaredType) throws JAXBException { final FilterVersion version = getFilterVersion(); if (version != null) try { return unmarshal(InputFactory.createXMLStreamReader(input), version, declaredType); } catch (XMLStreamException e) { throw new JAXBException(e); } else { final Context context = begin(); try { return unmarshaller.unmarshal(input, declaredType); } finally { context.finish(); } } }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public Object unmarshal(XMLEventReader input) throws JAXBException { final TransformVersion version = getTransformVersion(); if (version != null) { input = new TransformingReader(input, version); } final Context context = begin(); try { return unmarshaller.unmarshal(input); } finally { context.finish(); } }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public Object unmarshal(XMLStreamReader input) throws JAXBException { final FilterVersion version = getFilterVersion(); if (version != null) { input = new FilteredStreamReader(input, version); } final Context context = begin(); try { return unmarshaller.unmarshal(input); } finally { context.finish(); } }
/** * Same as {@link #unmarshal(XMLStreamReader, FilterVersion)}, but delegating to the unmarshaller * methods returning a JAXB element instead than the one returning the object. */ private <T> JAXBElement<T> unmarshal(XMLStreamReader input, final FilterVersion version, final Class<T> declaredType) throws XMLStreamException, JAXBException { input = new FilteredStreamReader(input, version); final Context context = begin(); final JAXBElement<T> object; try { object = unmarshaller.unmarshal(input, declaredType); } finally { context.finish(); } input.close(); // Despite its name, this method does not close the underlying input stream. return object; }
/** * Returns a JAXB unmarshaller from the pool. If there is no unmarshaller currently available * in the pool, then this method will {@linkplain #createUnmarshaller() create} a new one. * * <p>This method shall be used as below:</p> * * {@preformat java * Unmarshaller unmarshaller = pool.acquireUnmarshaller(); * Unmarshaller.unmarchall(...); * pool.recycle(unmarshaller); * } * * Note that {@link #recycle(Unmarshaller)} shall not be invoked in case of exception, * since the unmarshaller may be in an invalid state. * * @return a unmarshaller configured for parsing OGC/ISO XML. * @throws JAXBException if an error occurred while creating and configuring the unmarshaller. */ public Unmarshaller acquireUnmarshaller() throws JAXBException { Unmarshaller unmarshaller = unmarshallers.poll(); if (unmarshaller == null) { unmarshaller = new PooledUnmarshaller(createUnmarshaller(), template); } return unmarshaller; }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public Object unmarshal(final Reader input) throws JAXBException { final TransformVersion version = getTransformVersion(); if (version != null) try { return unmarshal(InputFactory.createXMLEventReader(input), version); } catch (XMLStreamException e) { throw new JAXBException(e); } else { final Context context = begin(); try { return unmarshaller.unmarshal(input); } finally { context.finish(); } } }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public Object unmarshal(final XMLEventReader input) throws JAXBException { final FilterVersion version = getFilterVersion(); if (version != null) try { return unmarshal(InputFactory.createXMLStreamReader(input), version); } catch (XMLStreamException e) { throw new JAXBException(e); } else { final Context context = begin(); try { return unmarshaller.unmarshal(input); } finally { context.finish(); } } }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public <T> JAXBElement<T> unmarshal(XMLEventReader input, final Class<T> declaredType) throws JAXBException { final TransformVersion version = getTransformVersion(); if (version != null) { input = new TransformingReader(input, version); } final Context context = begin(); try { return unmarshaller.unmarshal(input, declaredType); } finally { context.finish(); } }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public <T> JAXBElement<T> unmarshal(XMLStreamReader input, final Class<T> declaredType) throws JAXBException { final FilterVersion version = getFilterVersion(); if (version != null) { input = new FilteredStreamReader(input, version); } final Context context = begin(); try { return unmarshaller.unmarshal(input, declaredType); } finally { context.finish(); } }
/** * Unmarshals to the given input with on-the-fly substitution of namespaces. * This method is invoked only when the user asked to marshal from a different GML version * than the one supported natively by SIS, i.e. when {@link #getFilterVersion()} returns a * non-null value. * * @param input the reader created by SIS (<b>not</b> the reader given by the user). * @param version identify the namespace substitutions to perform. * @return the unmarshalled object. */ private Object unmarshal(XMLStreamReader input, final FilterVersion version) throws XMLStreamException, JAXBException { input = new FilteredStreamReader(input, version); final Context context = begin(); final Object object; try { object = unmarshaller.unmarshal(input); } finally { context.finish(); } input.close(); // Despite its name, this method does not close the underlying input stream. return object; }
/** * Returns a JAXB unmarshaller from the pool. If there is no unmarshaller currently available * in the pool, then this method will {@linkplain #createUnmarshaller() create} a new one. * * <p>This method shall be used as below:</p> * * {@preformat java * Unmarshaller unmarshaller = pool.acquireUnmarshaller(); * Unmarshaller.unmarchall(...); * pool.recycle(unmarshaller); * } * * Note that {@link #recycle(Unmarshaller)} shall not be invoked in case of exception, * since the unmarshaller may be in an invalid state. * * @return a unmarshaller configured for parsing OGC/ISO XML. * @throws JAXBException if an error occurred while creating and configuring the unmarshaller. */ public Unmarshaller acquireUnmarshaller() throws JAXBException { Unmarshaller unmarshaller = unmarshallers.poll(); if (unmarshaller == null) { unmarshaller = new PooledUnmarshaller(createUnmarshaller(), template); } return unmarshaller; }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public <T> JAXBElement<T> unmarshal(final Source input, final Class<T> declaredType) throws JAXBException { final TransformVersion version = getTransformVersion(); if (version != null) try { return unmarshal(InputFactory.createXMLEventReader(input), version, declaredType); } catch (XMLStreamException e) { throw new JAXBException(e); } else { final Context context = begin(); try { return unmarshaller.unmarshal(input, declaredType); } finally { context.finish(); } } }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public Object unmarshal(final Reader input) throws JAXBException { final FilterVersion version = getFilterVersion(); if (version != null) try { return unmarshal(InputFactory.createXMLStreamReader(input), version); } catch (XMLStreamException e) { throw new JAXBException(e); } else { final Context context = begin(); try { return unmarshaller.unmarshal(input); } finally { context.finish(); } } }
/** * Delegates to the wrapped marshaller. The initial state will be saved * if it was not already done, for future restoration by {@link #reset(Pooled)}. */ @Override public void setListener(final Listener listener) { if (!isPropertySaved(Listener.class)) { saveProperty(Listener.class, unmarshaller.getListener()); } unmarshaller.setListener(listener); }
/** * Same as {@link #unmarshal(XMLEventReader, TransformVersion)}, but delegating to the unmarshaller * methods returning a JAXB element instead than the one returning the object. */ private <T> JAXBElement<T> unmarshal(XMLEventReader input, final TransformVersion version, final Class<T> declaredType) throws XMLStreamException, JAXBException { input = new TransformingReader(input, version); final Context context = begin(); final JAXBElement<T> object; try { object = unmarshaller.unmarshal(input, declaredType); } finally { context.finish(); } input.close(); // Despite its name, this method does not close the underlying input stream. return object; }
/** * Creates a pooled unmarshaller wrapping the given one. * Callers shall invoke {@link #reset(Pooled)} after construction for completing the initialization. * * @param unmarshaller the unmarshaller to use for the actual work. * @param template the {@link PooledTemplate} from which to get the initial values. * @throws JAXBException if an error occurred while setting a property. */ PooledUnmarshaller(final Unmarshaller unmarshaller, final Pooled template) throws JAXBException { super(template); this.unmarshaller = unmarshaller; initialize(template); }
/** * Delegates the unmarshalling to the wrapped unmarshaller. */ @Override public Object unmarshal(final File input) throws JAXBException { final TransformVersion version = getTransformVersion(); if (version != null) try { try (InputStream s = new BufferedInputStream(new FileInputStream(input))) { return unmarshal(InputFactory.createXMLEventReader(s), version); } } catch (IOException | XMLStreamException e) { throw new JAXBException(e); } else { final Context context = begin(); try { return unmarshaller.unmarshal(input); } finally { context.finish(); } } }