KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > collection > SortedRelationFactoryImpl


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

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 JavaDoc IMPL_CATEGORY = "ArrayBased";
40
41     private org.omg.PortableServer.POA JavaDoc poa;
42
43
44
45     public SortedRelationFactoryImpl( org.omg.PortableServer.POA JavaDoc poa )
46
47     {
48
49         this.poa = poa;
50
51         try {
52
53             poa.servant_to_reference(this);
54
55         } catch( Exception JavaDoc e ){
56
57             System.out.println( "Internal error: Can not activate factory" );
58
59             e.printStackTrace();
60
61             throw new org.omg.CORBA.INTERNAL JavaDoc();
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 JavaDoc ops_class, int expected_size )
78
79     {
80
81         OperationsOperations ops = null;
82
83         try {
84
85             Class JavaDoc operation_class = ObjectUtil.classForName( ops_class );
86
87             ops = (OperationsOperations)operation_class.newInstance();
88
89         } catch ( Exception JavaDoc e ){
90
91             System.out.println( "Internal error: Can not instantiate object of class \""+ops_class+"\"" );
92
93             throw new org.omg.CORBA.INTERNAL JavaDoc();
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 JavaDoc 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 JavaDoc e) {
116
117             System.out.println("Internal error: Can not Activate collection");
118
119             e.printStackTrace();
120
121             throw new org.omg.CORBA.INTERNAL JavaDoc();
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 JavaDoc collection_interface = pm.find_string_param( CollectionService.COL_INTRF );
134
135         String JavaDoc implementation_interface = pm.find_string_param( CollectionService.IMPL_INTRF );
136
137         String JavaDoc 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 JavaDoc size = pm.find_ulong_param( CollectionService.EXP_SIZE );
146
147         if ( size == null ) {
148
149             size = new Integer JavaDoc(10);
150
151         }
152
153         Operations ops = pm.find_operations_param( CollectionService.OPERATIONS );
154
155         if ( ops == null ) {
156
157             String JavaDoc 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