/** * Ends the current packing scope. * * <p> * If any packing in progress will be finalized by this method. * * @param frameSize * The same size that gets passed to the {@link #startScope(int)} * method. */ public void endScope(int frameSize) throws SAXException { try { for( ; frameSize>0; frameSize--, scopeTop-- ) scopes[scopeTop].finish(); } catch (AccessorException e) { handleError(e); // the error might have left scopes in inconsistent state, // so replace them by fresh ones for( ; frameSize>0; frameSize-- ) scopes[scopeTop--] = new Scope(this); } }
/** * Finishes up the current packing in progress (if any) and * resets this object. */ public void finish() throws AccessorException { if(hasStarted()) { lister.endPacking(pack,bean,acc); reset(); } assert clean(); }
@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); }
/** * 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(); } } }
/** * Initializes all the fields to null. */ public void reset() { if(bean==null) { // already initialized assert clean(); return; } bean = null; acc = null; pack = null; lister = null; }
/** * Starts a new packing scope. * * <p> * This method allocates a specified number of fresh {@link Scope} objects. * They can be accessed by the {@link #getScope} method until the corresponding * {@link #endScope} method is invoked. * * <p> * A new scope will mask the currently active scope. Only one frame of {@link Scope}s * can be accessed at any given time. * * @param frameSize * The # of slots to be allocated. */ public void startScope(int frameSize) { scopeTop += frameSize; // reallocation if(scopeTop>=scopes.length) { Scope[] s = new Scope[Math.max(scopeTop+1,scopes.length*2)]; System.arraycopy(scopes,0,s,0,scopes.length); for( int i=scopes.length; i<s.length; i++ ) s[i] = new Scope(this); scopes = s; } }
/** * Adds a new item to this packing scope. */ public void add( Accessor<BeanT,PropT> acc, Lister<BeanT,PropT,ItemT,PackT> lister, ItemT value) throws SAXException{ try { if(!hasStarted()) { this.bean = (BeanT)context.getCurrentState().getTarget(); this.acc = acc; this.lister = lister; this.pack = lister.startPacking(bean,acc); } lister.addToPack(pack,value); } catch (AccessorException e) { Loader.handleGenericException(e,true); // recover from this error by ignoring future items. this.lister = Lister.getErrorInstance(); this.acc = Accessor.getErrorInstance(); } }
/** * Initializes all the fields to null. */ public void reset() { if(bean==null) { // already initialized assert clean(); return; } bean = null; acc = null; pack = null; lister = null; }
/** * Starts a new packing scope. * * <p> * This method allocates a specified number of fresh {@link Scope} objects. * They can be accessed by the {@link #getScope} method until the corresponding * {@link #endScope} method is invoked. * * <p> * A new scope will mask the currently active scope. Only one frame of {@link Scope}s * can be accessed at any given time. * * @param frameSize * The # of slots to be allocated. */ public void startScope(int frameSize) { scopeTop += frameSize; // reallocation if(scopeTop>=scopes.length) { Scope[] s = new Scope[Math.max(scopeTop+1,scopes.length*2)]; System.arraycopy(scopes,0,s,0,scopes.length); for( int i=scopes.length; i<s.length; i++ ) s[i] = new Scope(this); scopes = s; } }
/** * Finishes up the current packing in progress (if any) and * resets this object. */ public void finish() throws AccessorException { if(hasStarted()) { lister.endPacking(pack,bean,acc); reset(); } assert clean(); }
/** * Ends the current packing scope. * * <p> * If any packing in progress will be finalized by this method. * * @param frameSize * The same size that gets passed to the {@link #startScope(int)} * method. */ public void endScope(int frameSize) throws SAXException { try { for( ; frameSize>0; frameSize--, scopeTop-- ) scopes[scopeTop].finish(); } catch (AccessorException e) { handleError(e); // the error might have left scopes in inconsistent state, // so replace them by fresh ones for( ; frameSize>0; frameSize-- ) scopes[scopeTop--] = new Scope(this); } }
/** * 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 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); }
/** * Initializes all the fields to null. */ public void reset() { if(bean==null) { // already initialized assert clean(); return; } bean = null; acc = null; pack = null; lister = null; }
/** * Starts a new packing scope. * * <p> * This method allocates a specified number of fresh {@link Scope} objects. * They can be accessed by the {@link #getScope} method until the corresponding * {@link #endScope} method is invoked. * * <p> * A new scope will mask the currently active scope. Only one frame of {@link Scope}s * can be accessed at any given time. * * @param frameSize * The # of slots to be allocated. */ public void startScope(int frameSize) { scopeTop += frameSize; // reallocation if(scopeTop>=scopes.length) { Scope[] s = new Scope[Math.max(scopeTop+1,scopes.length*2)]; System.arraycopy(scopes,0,s,0,scopes.length); for( int i=scopes.length; i<s.length; i++ ) s[i] = new Scope(this); scopes = s; } }
/** * Finishes up the current packing in progress (if any) and * resets this object. */ public void finish() throws AccessorException { if(hasStarted()) { lister.endPacking(pack,bean,acc); reset(); } assert clean(); }
/** * Ends the current packing scope. * * <p> * If any packing in progress will be finalized by this method. * * @param frameSize * The same size that gets passed to the {@link #startScope(int)} * method. */ public void endScope(int frameSize) throws SAXException { try { for( ; frameSize>0; frameSize--, scopeTop-- ) scopes[scopeTop].finish(); } catch (AccessorException e) { handleError(e); // the error might have left scopes in inconsistent state, // so replace them by fresh ones for( ; frameSize>0; frameSize-- ) scopes[scopeTop--] = new Scope(this); } }
/** * Adds a new item to this packing scope. */ public void add( Accessor<BeanT,PropT> acc, Lister<BeanT,PropT,ItemT,PackT> lister, ItemT value) throws SAXException{ try { if(!hasStarted()) { this.bean = (BeanT)context.getCurrentState().getTarget(); this.acc = acc; this.lister = lister; this.pack = lister.startPacking(bean,acc); } lister.addToPack(pack,value); } 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 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); }
/** * Initializes all the fields to null. */ public void reset() { if(bean==null) { // already initialized assert clean(); return; } bean = null; acc = null; pack = null; lister = null; }