1 16 package org.apache.commons.betwixt.io.read; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 21 34 public class BeanCreationList extends BeanCreationChain { 35 36 38 42 public static final BeanCreationList createStandardChain() { 43 BeanCreationList chain = new BeanCreationList(); 44 chain.addBeanCreator( ChainedBeanCreatorFactory.createIDREFBeanCreator() ); 45 chain.addBeanCreator( ChainedBeanCreatorFactory.createDerivedBeanCreator() ); 46 chain.addBeanCreator( ChainedBeanCreatorFactory.createElementTypeBeanCreator() ); 47 return chain; 48 } 49 50 51 52 54 private ArrayList beanCreators = new ArrayList (); 55 56 58 66 public Object create( ElementMapping elementMapping, ReadContext readContext ) { 67 ChainWorker worker = new ChainWorker(); 68 return worker.create( elementMapping, readContext ); 69 } 70 71 73 77 public int getSize() { 78 return beanCreators.size(); 79 } 80 81 91 public void insertBeanCreator( 92 int index, 93 ChainedBeanCreator beanCreator ) 94 throws IndexOutOfBoundsException { 95 beanCreators.add( index, beanCreator ); 96 } 97 98 102 public void addBeanCreator( ChainedBeanCreator beanCreator ) { 103 beanCreators.add( beanCreator ); 104 } 105 106 109 public void clearBeanCreators() { 110 beanCreators.clear(); 111 } 112 113 114 private class ChainWorker extends BeanCreationChain { 115 116 private Iterator iterator; 117 118 ChainWorker() { 119 iterator = beanCreators.iterator(); 120 } 121 122 125 public Object create( ElementMapping elementMapping, ReadContext readContext ) { 126 if ( iterator.hasNext() ) { 127 ChainedBeanCreator beanCreator = (ChainedBeanCreator) iterator.next(); 128 return beanCreator.create( elementMapping, readContext, this ); 129 } 130 131 return null; 132 } 133 } 134 } 135 | Popular Tags |