protected Loader selectLoader(UnmarshallingContext.State state, TagName ea) throws SAXException { int idx = ea.atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"nil"); if (idx!=-1) { Boolean b = DatatypeConverterImpl._parseBoolean(ea.atts.getValue(idx)); if (b != null && b) { onNil(state); boolean hasOtherAttributes = (ea.atts.getLength() - 1) > 0; // see issues 6759703 and 565 - need to preserve attributes even if the element is nil; only when the type is stored in JAXBElement if (!(hasOtherAttributes && (state.getPrev().getTarget() instanceof JAXBElement))) { return Discarder.INSTANCE; } } } return defaultLoader; }
@Override public void leaveElement(UnmarshallingContext.State state, TagName ea) { Object[] keyValue = (Object[])state.getTarget(); Map map = (Map) state.getPrev().getTarget(); map.put(keyValue[0],keyValue[1]); }
@Override public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { // create or obtain the Map object try { BeanT target = (BeanT) state.getPrev().getTarget(); ValueT mapValue = acc.get(target); if(mapValue == null) mapValue = ClassFactory.create(mapImplClass); else mapValue.clear(); Stack.push(this.target, target); Stack.push(map, mapValue); state.setTarget(mapValue); } catch (AccessorException e) { // recover from error by setting a dummy Map that receives and discards the values handleGenericException(e,true); state.setTarget(new HashMap()); } }
public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException { try { xacc.parse(state.getTarget(),text); } catch (AccessorException e) { handleGenericException(e,true); } catch (RuntimeException e) { if(state.getPrev() != null) { if (!(state.getPrev().getTarget() instanceof JAXBElement)) handleParseConversionException(state,e); // else // do nothing - issue 601 - don't report exceptions like // NumberFormatException when unmarshalling "nillable" element // (I suppose JAXBElement indicates this } else { handleParseConversionException(state,e); } } } }
/** * 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()); } } }
protected Loader selectLoader(UnmarshallingContext.State state, TagName ea) throws SAXException { int idx = ea.atts.getIndex(WellKnownNamespace.XML_SCHEMA_INSTANCE,"nil"); if (idx!=-1) { Boolean b = DatatypeConverterImpl._parseBoolean(ea.atts.getValue(idx)); if (b != null && b) { onNil(state); boolean hasOtherAttributes = (ea.atts.getLength() - 1) > 0; // see issues 6759703 and 565 - need to preserve attributes even if the element is nil; only when the type is stored in JAXBElement if (!(hasOtherAttributes && (state.getPrev().getTarget() instanceof JAXBElement))) { return Discarder.INSTANCE; } } } return defaultLoader; }
public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException { try { xacc.parse(state.getPrev().getTarget(), text); } catch (AccessorException e) { handleGenericException(e,true); } catch (RuntimeException e) { handleParseConversionException(state,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) { Object[] keyValue = (Object[])state.getTarget(); Map map = (Map) state.getPrev().getTarget(); map.put(keyValue[0],keyValue[1]); }
@Override public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { state.setLoader(this); State s = (State) state.getPrev().getTarget(); s.depth++; state.setTarget(s); }
@Override public void leaveElement(UnmarshallingContext.State state, TagName ea) throws SAXException { state.getContext().endScope(frameSize); fireAfterUnmarshal(beanInfo, state.getTarget(), state.getPrev()); }
@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 void text(UnmarshallingContext.State state, CharSequence text) throws SAXException { try { xacc.parse(state.getTarget(),text); } catch (AccessorException e) { handleGenericException(e,true); } catch (RuntimeException e) { if(state.getPrev() != null) { if (!(state.getPrev().getTarget() instanceof JAXBElement)) handleParseConversionException(state,e); // else // do nothing - issue 601 - don't report exceptions like // NumberFormatException when unmarshalling "nillable" element // (I suppose JAXBElement indicates this } else { handleParseConversionException(state,e); } } } }
/** * 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()); } } }
@Override public void leaveElement(UnmarshallingContext.State state, TagName ea) throws SAXException { state.getContext().endScope(frameSize); fireAfterUnmarshal(beanInfo, state.getTarget(), state.getPrev()); }
public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException { try { xacc.parse(state.getPrev().getTarget(), text); } catch (AccessorException e) { handleGenericException(e,true); } catch (RuntimeException e) { handleParseConversionException(state,e); } } }
@Override public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { state.setLoader(this); State s = (State) state.getPrev().getTarget(); s.depth++; state.setTarget(s); }
@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); }