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