@Override public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException { if(text.length()==0) return; // there's no point in creating an empty Text node in DOM. try { State s = (State) state.getTarget(); s.handler.characters(text.toString().toCharArray(),0,text.length()); } catch( SAXException e ) { state.getContext().handleError(e); throw e; } }
/** * Receives the root element and determines how to start * unmarshalling. */ @Override public void childElement(UnmarshallingContext.State state, TagName ea) { UnmarshallingContext context = state.getContext(); // unmarshals the specified type QName qn = new QName(ea.uri,ea.local); state.prev.target = new JAXBElement(qn,context.expectedType.jaxbType,null,null); state.receiver = this; // this is bit wasteful, as in theory we should have each expectedType keep // nillable version --- but that increases the combination from two to four, // which adds the resident memory footprint. Since XsiNilLoader is small, // I intentionally allocate a new instance freshly. state.loader = new XsiNilLoader(context.expectedType.getLoader(null,true)); }
@Override public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { UnmarshallingContext context = state.getContext();
protected Loader selectLoader(UnmarshallingContext.State state, TagName tag) throws SAXException { UnmarshallingContext context = state.getContext(); if(mode.allowTypedObject) { Loader l = context.selectRootLoader(state,tag); if(l!=null) return l; } if(mode.allowDom) return dom; // simply discard. return Discarder.INSTANCE; }
/*pacakge*/ static JaxBeanInfo parseXsiType(UnmarshallingContext.State state, TagName ea, @Nullable JaxBeanInfo defaultBeanInfo) throws SAXException { UnmarshallingContext context = state.getContext(); JaxBeanInfo beanInfo = null;
protected Loader selectLoader(UnmarshallingContext.State state, TagName ea) throws SAXException { UnmarshallingContext context = state.getContext(); JaxBeanInfo beanInfo = null; state.getContext().getJAXBContext(), cbii.getTransducer(), acc));
@Override public void childElement(UnmarshallingContext.State state, TagName arg) throws SAXException { ChildLoader child = childUnmarshallers.get(arg.uri,arg.local); if(child == null) { Boolean backupWithParentNamespace = ((JAXBContextImpl) state.getContext().getJAXBContext()).backupWithParentNamespace; backupWithParentNamespace = backupWithParentNamespace != null ? backupWithParentNamespace : Boolean.parseBoolean(Util.getSystemProperty(JAXBRIContext.BACKUP_WITH_PARENT_NAMESPACE)); if ((beanInfo != null) && (beanInfo.getTypeNames() != null) && backupWithParentNamespace) { Iterator<?> typeNamesIt = beanInfo.getTypeNames().iterator(); QName parentQName = null; if ((typeNamesIt != null) && (typeNamesIt.hasNext()) && (catchAll == null)) { parentQName = (QName) typeNamesIt.next(); String parentUri = parentQName.getNamespaceURI(); child = childUnmarshallers.get(parentUri, arg.local); } } if (child == null) { child = catchAll; if(child==null) { super.childElement(state,arg); return; } } } state.setLoader(child.loader); state.setReceiver(child.receiver); }
/** * Receives the root element and determines how to start * unmarshalling. */ @Override public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { Loader loader = state.getContext().selectRootLoader(state,ea); if(loader!=null) { state.loader = loader; state.receiver = this; return; } // the registry doesn't know about this element. // try its xsi:type JaxBeanInfo beanInfo = XsiTypeLoader.parseXsiType(state, ea, null); if(beanInfo==null) { // we don't even know its xsi:type reportUnexpectedChildElement(ea,false); return; } state.loader = beanInfo.getLoader(null,false); state.prev.backup = new JAXBElement<Object>(ea.createQName(),Object.class,null); state.receiver = this; }
@Override public void leaveElement(UnmarshallingContext.State state, TagName ea) throws SAXException { State s = (State) state.getTarget(); UnmarshallingContext context = state.getContext(); try { s.handler.endElement(ea.uri, ea.local, ea.getQname()); s.undeclarePrefixes(context.getNewlyDeclaredPrefixes()); } catch( SAXException e ) { context.handleError(e); throw e; } if((--s.depth)==0) { // emulate the end of the document try { s.undeclarePrefixes(context.getAllDeclaredPrefixes()); s.handler.endDocument(); } catch( SAXException e ) { context.handleError(e); throw e; } // we are done state.setTarget(s.getElement()); } }
@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); }
/** * 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()); } } }
/** * 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()); } }
@Override public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { UnmarshallingContext context = state.getContext(); if (state.getTarget() == null) state.setTarget(new State(context)); State s = (State) state.getTarget(); try { s.declarePrefixes(context, context.getNewlyDeclaredPrefixes()); s.handler.startElement(ea.uri, ea.local, ea.getQname(), ea.atts); } catch (SAXException e) { context.handleError(e); throw e; } }
@Override public void leaveElement(UnmarshallingContext.State state, TagName ea) throws SAXException { state.getContext().endScope(1); }
@Override public void receive(State state, Object o) { JAXBElement e = (JAXBElement)state.target; e.setValue(o); state.getContext().recordOuterPeer(e); state.getContext().result = e; } }
/** * This method is called by the generated derived class * when a datatype parse method throws an exception. */ protected static void handleParseConversionException(UnmarshallingContext.State state, Exception e) throws SAXException { // wrap it into a ParseConversionEvent and report it state.getContext().handleError(e); } }
@Override public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { UnmarshallingContext context = state.getContext(); context.startScope(1); // inherit the target so that our children can access its target state.setTarget(state.getPrev().getTarget()); // start it now, so that even if there's no children we can still return empty collection context.getScope(0).start(acc,lister); }
@Override public void leaveElement(UnmarshallingContext.State state, TagName ea) throws SAXException { state.getContext().endScope(frameSize); fireAfterUnmarshal(beanInfo, state.getTarget(), state.getPrev()); }
@Override public void receive(State state, Object o) { if(state.backup!=null) { ((JAXBElement<Object>)state.backup).setValue(o); o = state.backup; } if (state.nil) { ((JAXBElement<Object>)o).setNil(true); } state.getContext().result = o; } }
protected Loader selectLoader(UnmarshallingContext.State state, TagName tag) throws SAXException { UnmarshallingContext context = state.getContext(); if(mode.allowTypedObject) { Loader l = context.selectRootLoader(state,tag); if(l!=null) return l; } if(mode.allowDom) return dom; // simply discard. return Discarder.INSTANCE; }