001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.collection;
022:
023: import org.jacorb.util.ObjectUtil;
024:
025: import org.omg.CosCollection.*;
026:
027: public class SequenceFactoryImpl extends SequenceFactoryPOA implements
028: IteratorFactory {
029:
030: public final static String IMPL_CATEGORY = "ArrayBased";
031:
032: private org.omg.PortableServer.POA poa;
033:
034: public SequenceFactoryImpl(org.omg.PortableServer.POA poa) {
035:
036: this .poa = poa;
037:
038: try {
039:
040: poa.servant_to_reference(this );
041:
042: } catch (Exception e) {
043:
044: System.out
045: .println("Internal error: Can not activate factory");
046:
047: e.printStackTrace();
048:
049: throw new org.omg.CORBA.INTERNAL();
050:
051: }
052:
053: };
054:
055: public CSequence create(Operations ops, int expected_size) {
056:
057: return create(ops, expected_size, poa);
058:
059: };
060:
061: public CSequence create(String ops_class, int expected_size) {
062:
063: OperationsOperations ops = null;
064:
065: try {
066:
067: Class operation_class = ObjectUtil.classForName(ops_class);
068:
069: ops = (OperationsOperations) operation_class.newInstance();
070:
071: } catch (Exception e) {
072:
073: System.out
074: .println("Internal error: Can not instantiate object of class \""
075: + ops_class + "\"");
076:
077: throw new org.omg.CORBA.INTERNAL();
078:
079: }
080: ;
081:
082: return create(ops, expected_size, poa);
083:
084: };
085:
086: public CSequence create(OperationsOperations ops,
087: int expected_size, org.omg.PortableServer.POA poa) {
088:
089: SequenceImpl collection = new SequenceImpl(ops, poa, this ,
090: expected_size);
091:
092: CSequence collection_ref = null;
093:
094: CSequencePOATie srvnt = new CSequencePOATie(collection);
095:
096: try {
097:
098: collection_ref = CSequenceHelper.narrow(poa
099: .servant_to_reference(srvnt));
100:
101: collection.set_servant(srvnt);
102:
103: } catch (Exception e) {
104:
105: System.out
106: .println("Internal error: Can not Activate collection");
107:
108: e.printStackTrace();
109:
110: throw new org.omg.CORBA.INTERNAL();
111:
112: }
113:
114: return collection_ref;
115:
116: };
117:
118: public Collection generic_create(NVPair[] parameters)
119: throws ParameterInvalid {
120:
121: NVPairManager pm = new NVPairManager(parameters);
122:
123: String collection_interface = pm
124: .find_string_param(CollectionService.COL_INTRF);
125:
126: String implementation_interface = pm
127: .find_string_param(CollectionService.IMPL_INTRF);
128:
129: String implementation_category = pm
130: .find_string_param(CollectionService.IMPL_CAT);
131:
132: if (implementation_category != null
133: && !implementation_category.equals(IMPL_CATEGORY)) {
134:
135: throw new ParameterInvalid(pm
136: .find_param_idx(CollectionService.IMPL_CAT),
137: "CollectionFactory : not support implementation category "
138: + implementation_category);
139:
140: }
141:
142: Integer size = pm.find_ulong_param(CollectionService.EXP_SIZE);
143:
144: if (size == null) {
145:
146: size = new Integer(10);
147:
148: }
149:
150: Operations ops = pm
151: .find_operations_param(CollectionService.OPERATIONS);
152:
153: if (ops == null) {
154:
155: String ops_class = pm
156: .find_string_param(CollectionService.OPERATIONS_CLASS);
157:
158: if (ops_class == null) {
159:
160: throw new ParameterInvalid(pm
161: .find_param_idx(CollectionService.OPERATIONS),
162: "CollectionFactory: OPERATION object not defined");
163:
164: }
165:
166: return create(ops_class, size.intValue());
167:
168: } else {
169:
170: return create(ops, size.intValue());
171:
172: }
173:
174: };
175:
176: public PositionalIteratorImpl create_iterator(
177: CollectionImpl collection, boolean read_only) {
178:
179: return create_iterator(collection, read_only, false);
180:
181: };
182:
183: public PositionalIteratorImpl create_iterator(
184: CollectionImpl collection, boolean read_only,
185: boolean reverse) {
186:
187: return new SequentialIteratorImpl(
188: (SequentialCollectionImpl) collection, read_only,
189: reverse);
190:
191: };
192:
193: }
|