1 21 package org.jacorb.collection; 22 23 24 25 import org.jacorb.util.ObjectUtil; 26 27 import org.omg.CosCollection.*; 28 29 30 31 public class SequenceFactoryImpl extends SequenceFactoryPOA implements IteratorFactory { 32 33 public final static String IMPL_CATEGORY = "ArrayBased"; 34 35 private org.omg.PortableServer.POA poa; 36 37 public SequenceFactoryImpl( org.omg.PortableServer.POA poa ){ 38 39 this.poa = poa; 40 41 try { 42 43 poa.servant_to_reference(this); 44 45 } catch( Exception e ){ 46 47 System.out.println( "Internal error: Can not activate factory" ); 48 49 e.printStackTrace(); 50 51 throw new org.omg.CORBA.INTERNAL (); 52 53 } 54 55 }; 56 57 public CSequence create( Operations ops, int expected_size ){ 58 59 return create( ops, expected_size, poa ); 60 61 }; 62 63 public CSequence create( String ops_class, int expected_size ){ 64 65 OperationsOperations ops = null; 66 67 try { 68 69 Class operation_class = ObjectUtil.classForName( ops_class ); 70 71 ops = (OperationsOperations)operation_class.newInstance(); 72 73 } catch ( Exception e ){ 74 75 System.out.println( "Internal error: Can not instantiate object of class \""+ops_class+"\"" ); 76 77 throw new org.omg.CORBA.INTERNAL (); 78 79 }; 80 81 return create( ops, expected_size, poa ); 82 83 }; 84 85 public CSequence create( OperationsOperations ops, int expected_size, org.omg.PortableServer.POA poa ){ 86 87 SequenceImpl collection = new SequenceImpl( ops, poa, this, expected_size ); 88 89 CSequence collection_ref = null; 90 91 CSequencePOATie srvnt = new CSequencePOATie( collection ); 92 93 try { 94 95 collection_ref = CSequenceHelper.narrow(poa.servant_to_reference(srvnt)); 96 97 collection.set_servant( srvnt ); 98 99 } catch(Exception e) { 100 101 System.out.println("Internal error: Can not Activate collection"); 102 103 e.printStackTrace(); 104 105 throw new org.omg.CORBA.INTERNAL (); 106 107 } 108 109 return collection_ref; 110 111 }; 112 113 public Collection generic_create( NVPair[] parameters) throws ParameterInvalid{ 114 115 NVPairManager pm = new NVPairManager( parameters ); 116 117 String collection_interface = pm.find_string_param( CollectionService.COL_INTRF ); 118 119 String implementation_interface = pm.find_string_param( CollectionService.IMPL_INTRF ); 120 121 String implementation_category = pm.find_string_param( CollectionService.IMPL_CAT ); 122 123 if( implementation_category != null && !implementation_category.equals( IMPL_CATEGORY ) ) { 124 125 throw new ParameterInvalid( pm.find_param_idx( CollectionService.IMPL_CAT ), "CollectionFactory : not support implementation category "+implementation_category ); 126 127 } 128 129 Integer size = pm.find_ulong_param( CollectionService.EXP_SIZE ); 130 131 if ( size == null ) { 132 133 size = new Integer (10); 134 135 } 136 137 Operations ops = pm.find_operations_param( CollectionService.OPERATIONS ); 138 139 if ( ops == null ) { 140 141 String ops_class = pm.find_string_param( CollectionService.OPERATIONS_CLASS ); 142 143 if( ops_class == null ){ 144 145 throw new ParameterInvalid( pm.find_param_idx(CollectionService.OPERATIONS), "CollectionFactory: OPERATION object not defined" ); 146 147 } 148 149 return create( ops_class, size.intValue() ); 150 151 } else { 152 153 return create( ops, size.intValue() ); 154 155 } 156 157 }; 158 159 public PositionalIteratorImpl create_iterator( CollectionImpl collection, boolean read_only ){ 160 161 return create_iterator( collection, read_only, false ); 162 163 }; 164 165 public PositionalIteratorImpl create_iterator( CollectionImpl collection, boolean read_only, boolean reverse ){ 166 167 return new SequentialIteratorImpl( (SequentialCollectionImpl)collection, read_only, reverse ); 168 169 }; 170 171 } 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | Popular Tags |