private Object unmarshal0( XMLReader reader, InputSource source, JaxBeanInfo expectedType ) throws JAXBException { SAXConnector connector = getUnmarshallerHandler(needsInterning(reader),expectedType); } catch( SAXException e ) { coordinator.clearStates(); throw createUnmarshalException(e);
private UnmarshallerImpl getUnmarshaller() { if(unmarshaller==null) unmarshaller = new UnmarshallerImpl(context,assoc); return unmarshaller; }
public final Object unmarshal0( Node node, JaxBeanInfo expectedType ) throws JAXBException { try { final DOMScanner scanner = new DOMScanner(); InterningXmlVisitor handler = new InterningXmlVisitor(createUnmarshallerHandler(null,false,expectedType)); scanner.setContentHandler(new SAXConnector(handler,scanner)); if(node.getNodeType() == Node.ELEMENT_NODE) { scanner.scan((Element)node); } else if(node.getNodeType() == Node.DOCUMENT_NODE) { scanner.scan((Document)node); } else { throw new IllegalArgumentException("Unexpected node type: "+node); } Object retVal = handler.getContext().getResult(); handler.getContext().clearResult(); return retVal; } catch( SAXException e ) { throw createUnmarshalException(e); } }
@Override public <T> JAXBElement<T> unmarshal(Node node, Class<T> expectedType) throws JAXBException { if (expectedType == null) { throw new IllegalArgumentException(); } return (JAXBElement)unmarshal0(node,getBeanInfo(expectedType)); }
private Object unmarshal0(XMLEventReader reader,JaxBeanInfo expectedType) throws JAXBException { if (reader == null) { throw new IllegalArgumentException( Messages.format(Messages.NULL_READER)); } try { XMLEvent event = reader.peek(); if (!event.isStartElement() && !event.isStartDocument()) { // TODO: convert event into event name throw new IllegalStateException( Messages.format( Messages.ILLEGAL_READER_STATE,event.getEventType())); } // Quick hack until SJSXP fixes 6270116 boolean isZephyr = reader.getClass().getName().equals("com.sun.xml.stream.XMLReaderImpl"); XmlVisitor h = createUnmarshallerHandler(null,false,expectedType); if(!isZephyr) { h = new InterningXmlVisitor(h); } new StAXEventConnector(reader,h).bridge(); return h.getContext().getResult(); } catch (XMLStreamException e) { throw handleStreamException(e); } }
/** * Returns true if an event handler is installed. * <p> * The default handler ignores any errors, and for that this method returns false. */ public final boolean hasEventHandler() { return getEventHandler()!=this; }
public UnmarshallerHandler getUnmarshallerHandler() { return getUnmarshallerHandler(true,null); }
public AttachmentUnmarshaller getAttachmentUnmarshaller() { return unmarshaller.getAttachmentUnmarshaller(); } }
/** * Fires the afterUnmarshal event if necessary. * * @param state * state of the parent object */ protected final void fireAfterUnmarshal(JaxBeanInfo beanInfo, Object child, UnmarshallingContext.State state) throws SAXException { // fire the event callback if(beanInfo.lookForLifecycleMethods()) { UnmarshallingContext context = state.getContext(); Unmarshaller.Listener listener = context.parent.getListener(); if(beanInfo.hasAfterUnmarshalMethod()) { beanInfo.invokeAfterUnmarshalMethod(context.parent, child, state.getTarget()); } if(listener!=null) listener.afterUnmarshal(child, state.getTarget()); } }
private SAXConnector getUnmarshallerHandler( boolean intern, JaxBeanInfo expectedType ) { XmlVisitor h = createUnmarshallerHandler(null, false, expectedType); if (intern) { h = new InterningXmlVisitor(h); } return new SAXConnector(h,null); }
public Schema getSchema() { return getUnmarshaller().getSchema(); }
public Object getProperty(String name) throws PropertyException { if (name == null) throw new IllegalArgumentException(Messages.NULL_PROPERTY_NAME.format()); // exclude RI properties that don't make sense for Binder if (excludeProperty(name)) { throw new PropertyException(name); } Object prop = null; PropertyException pe = null; try { prop = getMarshaller().getProperty(name); return prop; } catch (PropertyException p) { pe = p; } try { prop = getUnmarshaller().getProperty(name); return prop; } catch (PropertyException p) { pe = p; } pe.setStackTrace(Thread.currentThread().getStackTrace()); throw pe; }
@Override public <T> JAXBElement<T> unmarshal(XMLEventReader reader, Class<T> expectedType) throws JAXBException { if(expectedType==null) { throw new IllegalArgumentException(); } return (JAXBElement)unmarshal0(reader,getBeanInfo(expectedType)); }
public Object unmarshal0(XMLStreamReader reader, JaxBeanInfo expectedType) throws JAXBException { if (reader == null) { throw new IllegalArgumentException( Messages.format(Messages.NULL_READER)); } int eventType = reader.getEventType(); if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.START_DOCUMENT) { // TODO: convert eventType into event name throw new IllegalStateException( Messages.format(Messages.ILLEGAL_READER_STATE,eventType)); } XmlVisitor h = createUnmarshallerHandler(null,false,expectedType); StAXConnector connector=StAXStreamConnector.create(reader,h); try { connector.bridge(); } catch (XMLStreamException e) { throw handleStreamException(e); } Object retVal = h.getContext().getResult(); h.getContext().clearResult(); return retVal; }
@Override public boolean handleEvent(ValidationEvent event) { try { // if the handler says "abort", we will not return the object. boolean recover = parent.getEventHandler().handleEvent(event); if(!recover) aborted = true; return recover; } catch( RuntimeException re ) { // if client event handler causes a runtime exception, then we // have to return false. return false; } }
public UnmarshallerHandler getUnmarshallerHandler() { return getUnmarshallerHandler(true,null); }
public DataHandler unmarshal(String cid) { AttachmentUnmarshaller au = UnmarshallingContext.getInstance().parent.getAttachmentUnmarshaller(); // TODO: error check return au.getAttachmentAsDataHandler(cid); }
/** * Fires the beforeUnmarshal event if necessary. * * @param state * state of the newly create child object. */ protected final void fireBeforeUnmarshal(JaxBeanInfo beanInfo, Object child, UnmarshallingContext.State state) throws SAXException { if(beanInfo.lookForLifecycleMethods()) { UnmarshallingContext context = state.getContext(); Unmarshaller.Listener listener = context.parent.getListener(); if(beanInfo.hasBeforeUnmarshalMethod()) { beanInfo.invokeBeforeUnmarshalMethod(context.parent, child, state.getPrev().getTarget()); } if(listener!=null) { listener.beforeUnmarshal(child, state.getPrev().getTarget()); } } }
private SAXConnector getUnmarshallerHandler( boolean intern, JaxBeanInfo expectedType ) { XmlVisitor h = createUnmarshallerHandler(null, false, expectedType); if (intern) { h = new InterningXmlVisitor(h); } return new SAXConnector(h,null); }
public Schema getSchema() { return getUnmarshaller().getSchema(); }