KickJava   Java API By Example, From Geeks To Geeks.

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


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 SequenceFactoryImpl extends SequenceFactoryPOA implements IteratorFactory {
32
33     public final static String JavaDoc IMPL_CATEGORY = "ArrayBased";
34
35     private org.omg.PortableServer.POA JavaDoc poa;
36
37     public SequenceFactoryImpl( org.omg.PortableServer.POA JavaDoc poa ){
38
39         this.poa = poa;
40
41         try {
42
43             poa.servant_to_reference(this);
44
45         } catch( Exception JavaDoc e ){
46
47             System.out.println( "Internal error: Can not activate factory" );
48
49             e.printStackTrace();
50
51             throw new org.omg.CORBA.INTERNAL JavaDoc();
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 JavaDoc ops_class, int expected_size ){
64
65         OperationsOperations ops = null;
66
67         try {
68
69             Class JavaDoc operation_class = ObjectUtil.classForName( ops_class );
70
71             ops = (OperationsOperations)operation_class.newInstance();
72
73         } catch ( Exception JavaDoc e ){
74
75             System.out.println( "Internal error: Can not instantiate object of class \""+ops_class+"\"" );
76
77             throw new org.omg.CORBA.INTERNAL JavaDoc();
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 JavaDoc 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 JavaDoc e) {
100
101             System.out.println("Internal error: Can not Activate collection");
102
103             e.printStackTrace();
104
105             throw new org.omg.CORBA.INTERNAL JavaDoc();
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 JavaDoc collection_interface = pm.find_string_param( CollectionService.COL_INTRF );
118
119         String JavaDoc implementation_interface = pm.find_string_param( CollectionService.IMPL_INTRF );
120
121         String JavaDoc 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 JavaDoc size = pm.find_ulong_param( CollectionService.EXP_SIZE );
130
131         if ( size == null ) {
132
133             size = new Integer JavaDoc(10);
134
135         }
136
137         Operations ops = pm.find_operations_param( CollectionService.OPERATIONS );
138
139         if ( ops == null ) {
140
141             String JavaDoc 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