@Override public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { if(ea.matches(entryTag)) { state.setLoader(entryLoader); } else { super.childElement(state,ea); } }
@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> getExpectedAttributes() { return defaultLoader.getExpectedAttributes(); } }
private void _startElement(TagName tagName) throws SAXException { // remember the current element if we are interested in it. // because the inner peer might not be found while we consume // the enter element token, we need to keep this information // longer than this callback. That's why we assign it to a field. if( assoc!=null ) currentElement = scanner.getCurrentElement(); Loader h = current.loader; current.push(); // tell the parent about the new child h.childElement(current,tagName); assert current.loader!=null; // the childElement should register this // and tell the new child that you are activated current.loader.startElement(current,tagName); }
public void receive(UnmarshallingContext.State state, Object o) throws SAXException { try { set((BeanT) state.getTarget(), (ValueT) o); } catch (AccessorException e) { Loader.handleGenericException(e, true); } catch (IllegalAccessError iae) { // throw UnmarshalException instead IllegalAccesssError | Issue 475 Loader.handleGenericError(iae); } }
@Override public Collection<QName> getExpectedChildElements() { return defaultLoader.getExpectedChildElements(); }
@Override public final void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { Loader loader = selectLoader(state,ea); state.setLoader(loader); loader.startElement(state,ea); }
protected static void reportError(String msg, boolean canRecover) throws SAXException { reportError(msg, null, canRecover ); }
/** * Last resort when something goes terribly wrong within the unmarshaller. */ protected static void handleGenericException(Exception e) throws SAXException { handleGenericException(e,false); }
@Override public void leaveElement(State state, TagName ea) throws SAXException { super.leaveElement(state, ea); try { acc.set(Stack.pop(target), Stack.pop(map)); } catch (AccessorException ex) { handleGenericException(ex,true); } }
/** * Called when this loaderis an active loaderand we see a new child start tag. * * <p> * The callee is expected to designate another loaderas a loaderthat processes * this element, then it should also register a {@link Receiver}. * The designated loaderwill become an active loader. * * <p> * The default implementation reports an error saying an element is unexpected. */ public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { // notify the error, then recover by ignoring the whole element. reportUnexpectedChildElement(ea, true); state.setLoader(Discarder.INSTANCE); state.setReceiver(null); }
public void receive(UnmarshallingContext.State state, Object o) throws SAXException { try { set((BeanT) state.getTarget(), (ValueT) o); } catch (AccessorException e) { Loader.handleGenericException(e, true); } catch (IllegalAccessError iae) { // throw UnmarshalException instead IllegalAccesssError | Issue 475 Loader.handleGenericError(iae); } }
@Override public Collection<QName> getExpectedChildElements() { return defaultLoader.getExpectedChildElements(); }
@Override public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { final Loader loader = selectLoader(state, ea); state.setLoader(loader); loader.startElement(state, ea); }
public static void handleGenericError(Error e) throws SAXException { reportError(e.getMessage(), false); }
/** * Starts the packing scope, without adding any item. * * This allows us to return an empty pack, thereby allowing the user * to distinguish empty array vs null array. */ public void start( Accessor<BeanT,PropT> acc, Lister<BeanT,PropT,ItemT,PackT> lister) throws SAXException{ try { if(!hasStarted()) { this.bean = (BeanT)context.getCurrentState().getTarget(); this.acc = acc; this.lister = lister; this.pack = lister.startPacking(bean,acc); } } catch (AccessorException e) { Loader.handleGenericException(e,true); // recover from this error by ignoring future items. this.lister = Lister.getErrorInstance(); this.acc = Accessor.getErrorInstance(); } } }
@Override public final void endElement(TagName tagName) throws SAXException { pushCoordinator(); try { State child = current; // tell the child that your time is up child.loader.leaveElement(child,tagName); // child.pop will erase them so store them now Object target = child.target; Receiver recv = child.receiver; Intercepter intercepter = child.intercepter; child.pop(); // then let the parent know if(intercepter!=null) target = intercepter.intercept(current,target); if(recv!=null) recv.receive(current,target); } finally { popCoordinator(); } }
private void _startElement(TagName tagName) throws SAXException { // remember the current element if we are interested in it. // because the inner peer might not be found while we consume // the enter element token, we need to keep this information // longer than this callback. That's why we assign it to a field. if( assoc!=null ) currentElement = scanner.getCurrentElement(); Loader h = current.loader; current.push(); // tell the parent about the new child h.childElement(current,tagName); assert current.loader!=null; // the childElement should register this // and tell the new child that you are activated current.loader.startElement(current,tagName); }
/** * Called when this loaderis an active loaderand we see a new child start tag. * * <p> * The callee is expected to designate another loaderas a loaderthat processes * this element, then it should also register a {@link Receiver}. * The designated loaderwill become an active loader. * * <p> * The default implementation reports an error saying an element is unexpected. */ public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { // notify the error, then recover by ignoring the whole element. reportUnexpectedChildElement(ea, true); state.setLoader(Discarder.INSTANCE); state.setReceiver(null); }
public void receive(UnmarshallingContext.State state, Object o) throws SAXException { try { set((BeanT) state.getTarget(), (ValueT) o); } catch (AccessorException e) { Loader.handleGenericException(e, true); } catch (IllegalAccessError iae) { // throw UnmarshalException instead IllegalAccesssError | Issue 475 Loader.handleGenericError(iae); } }