public Object createInstance() throws SAXException { try { return method.invoke(factorInstance); } catch (IllegalAccessException e) { getInstance().handleError(e,false); } catch (InvocationTargetException e) { getInstance().handleError(e,false); } return null; // can never be executed } }
public UnmarshallerImpl( JAXBContextImpl context, AssociationMap assoc ) { this.context = context; this.coordinator = new UnmarshallingContext( this, assoc ); try { setEventHandler(this); } catch (JAXBException e) { throw new AssertionError(e); // impossible } }
@Override public void startElement(TagName tagName) throws SAXException { pushCoordinator(); try { _startElement(tagName); } finally { popCoordinator(); } }
@Override public <A extends XmlAdapter> A getAdapter(Class<A> type) { if(type==null) { throw new IllegalArgumentException(); } if(coordinator.containsAdapter(type)) { return coordinator.getAdapter(type); } else { return null; } }
public void parse(final BeanT bean, CharSequence lexical) throws AccessorException, SAXException { final String idref = WhiteSpaceProcessor.trim(lexical).toString(); final UnmarshallingContext context = UnmarshallingContext.getInstance(); final Callable callable = context.getObjectFromId(idref,acc.valueType); if(callable==null) { context.errorUnresolvedIDREF(bean,idref,context.getLocator()); return; } else { final LocatorEx loc = new LocatorEx.Snapshot(context.getLocator()); context.addPatcher(new Patcher() { public void run() throws SAXException { try {
child = context.getInnerPeer(); child = context.createInstance(beanInfo); context.recordInnerPeer(child); context.startScope(frameSize); context.handleError(Messages.UNABLE_TO_CREATE_MAP.format(attCatchAll.valueType)); return;
public static void reportError(String msg, Exception nested, boolean canRecover) throws SAXException { UnmarshallingContext context = UnmarshallingContext.getInstance(); context.handleEvent( new ValidationEventImpl( canRecover? ValidationEvent.ERROR : ValidationEvent.FATAL_ERROR, msg, context.getLocator().getLocation(), nested ), canRecover ); }
public Source parse(CharSequence text) throws SAXException { try { if(text instanceof Base64Data) return new DataSourceSource( ((Base64Data)text).getDataHandler() ); else return new DataSourceSource(new ByteArrayDataSource(decodeBase64(text), UnmarshallingContext.getInstance().getXMIMEContentType())); } catch (MimeTypeParseException e) { UnmarshallingContext.getInstance().handleError(e); return null; } }
@Override public final void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { state.setLoader(core); state.setIntercepter(this); // TODO: make sure there aren't too many duplicate of this code // create the object to unmarshal Object child; UnmarshallingContext context = state.getContext(); // let's see if we can reuse the existing peer object child = context.getOuterPeer(); if(child!=null && jaxbType!=child.getClass()) child = null; // unexpected type. if(child!=null) reset((JAXBElement)child,context); if(child==null) child = context.createInstance(ElementBeanInfoImpl.this); fireBeforeUnmarshal(ElementBeanInfoImpl.this, child, state); context.recordOuterPeer(child); UnmarshallingContext.State p = state.getPrev(); p.setBackup(p.getTarget()); p.setTarget(child); core.startElement(state,ea); }
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 ValueT parse(CharSequence lexical) throws AccessorException, SAXException { String value = WhiteSpaceProcessor.trim(lexical).toString(); UnmarshallingContext.getInstance().addToIdTable(value); return core.parse(value); } }
public BeanT parse(CharSequence lexical) throws AccessorException, SAXException { UnmarshallingContext ctxt = UnmarshallingContext.getInstance(); BeanT inst; if(ctxt!=null) inst = (BeanT)ctxt.createInstance(ownerClass); else // when this runs for parsing enum constants, // there's no UnmarshallingContext. inst = ClassFactory.create(ownerClass); xacc.parse(inst,lexical); return inst; }
public DataHandler parse(CharSequence text) { if(text instanceof Base64Data) return ((Base64Data)text).getDataHandler(); else return new DataHandler(new ByteArrayDataSource(decodeBase64(text), UnmarshallingContext.getInstance().getXMIMEContentType())); }
@Override public Collection<QName> getExpectedChildElements() { return getInstance().getJAXBContext().getValidRootNames(); }
@SuppressWarnings({"StringEquality"}) protected final void reportUnexpectedChildElement(TagName ea, boolean canRecover) throws SAXException { if (canRecover) { // this error happens particurly often (when input documents contain a lot of unexpected elements to be ignored), // so don't bother computing all the messages and etc if we know that // there's no event handler to receive the error in the end. See #286 UnmarshallingContext context = UnmarshallingContext.getInstance(); if (!context.parent.hasEventHandler() // is somebody listening? || !context.shouldErrorBeReported()) // should we report error? return; } if(ea.uri!=ea.uri.intern() || ea.local!=ea.local.intern()) reportError(Messages.UNINTERNED_STRINGS.format(), canRecover ); else reportError(Messages.UNEXPECTED_ELEMENT.format(ea.uri,ea.local,computeExpectedElements()), canRecover ); }
@Override public Collection<QName> getExpectedElements() { try { return UnmarshallingContext.getInstance().getCurrentExpectedElements(); } catch (NullPointerException npe) { // TODO: need to check what could be done in JAXB in order to prevent the npe // thrown from com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext#1206 } // something went wrong - return empty list return Collections.emptyList(); }
@Override public Collection<QName> getExpectedAttributes() { if (JSONHelper.isNaturalNotationEnabled()) { try { return UnmarshallingContext.getInstance().getCurrentExpectedAttributes(); } catch (NullPointerException npe) { // thrown from com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext } catch (NoSuchMethodError nsme) { // thrown when JAXB version is less than 2.1.12 Logger.getLogger(getClass().getName()) .log(Level.SEVERE, com.sun.jersey.json.impl.ImplMessages.ERROR_JAXB_RI_2_1_12_MISSING(), nsme); } } // something went wrong - return empty list return Collections.emptyList(); }
public DataHandler unmarshal(String cid) { AttachmentUnmarshaller au = UnmarshallingContext.getInstance().parent.getAttachmentUnmarshaller(); // TODO: error check return au.getAttachmentAsDataHandler(cid); }
public void setFactories(Object factoryInstances) { factories.clear(); if(factoryInstances==null) { return; } if(factoryInstances instanceof Object[]) { for( Object factory : (Object[])factoryInstances ) { // look for all the public methods inlcuding derived ones addFactory(factory); } } else { addFactory(factoryInstances); } }
reader.parse(source); } catch( IOException e ) { coordinator.clearStates(); throw new UnmarshalException(e); } catch( SAXException e ) { coordinator.clearStates(); throw createUnmarshalException(e);