1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53:
54: import ;
55:
56: import ;
57:
58: public class gnuDynSequence
59: extends gnuDynArray
60: implements DynSequence, Serializable
61: {
62:
65: private static final long serialVersionUID = 1;
66:
67:
70: final int bound;
71:
72:
78: public gnuDynSequence(TypeCode oType, TypeCode aType,
79: gnuDynAnyFactory aFactory, ORB anOrb
80: )
81: throws BAD_PARAM
82: {
83: super(oType, aType, aFactory, anOrb, false);
84: array = new DynAny[ 0 ];
85: try
86: {
87: bound = final_type.length();
88: }
89: catch (BadKind ex)
90: {
91: throw new Unexpected(ex);
92: }
93: }
94:
95:
98: public int get_length()
99: {
100: return array.length;
101: }
102:
103:
106: public void set_length(int length)
107: throws InvalidValue
108: {
109: checkBound(length);
110: if (length == array.length)
111: return;
112: else if (length < array.length)
113: {
114:
115: DynAny[] d = new DynAny[ length ];
116: for (int i = 0; i < d.length; i++)
117: d [ i ] = array [ i ];
118: array = d;
119: }
120: else
121: {
122:
123: DynAny[] d = new DynAny[ length ];
124: for (int i = 0; i < array.length; i++)
125: d [ i ] = array [ i ];
126:
127: for (int i = array.length; i < d.length; i++)
128: {
129: try
130: {
131: d [ i ] =
132: factory.create_dyn_any_from_type_code(official_components);
133: }
134: catch (InconsistentTypeCode e)
135: {
136: throw new Unexpected(e);
137: }
138: }
139: array = d;
140: }
141: valueChanged();
142: }
143:
144:
147: public void assign(DynAny from)
148: throws TypeMismatch
149: {
150: checkType(official_type, from.type());
151: if (from instanceof DynSequence)
152: {
153: DynSequence dyn = (DynSequence) from;
154: array = dyn.get_elements_as_dyn_any();
155: }
156: else
157: throw new TypeMismatch();
158: }
159:
160:
163: public void set_elements_as_dyn_any(DynAny[] value)
164: throws InvalidValue, TypeMismatch
165: {
166: checkBound(value.length);
167: if (array.length != value.length)
168: set_length(value.length);
169:
170: for (int i = 0; i < value.length; i++)
171: {
172: checkType(official_components, value [ i ].type());
173: array [ i ].assign(value [ i ]);
174: }
175: valueChanged();
176: }
177:
178:
181: public void set_elements(Any[] value)
182: throws InvalidValue, TypeMismatch
183: {
184: checkBound(value.length);
185:
186: DynAny[] prev = array;
187:
188: array = new DynAny[ value.length ];
189: try
190: {
191: super.set_elements(value);
192:
193:
194: }
195:
196:
197: catch (TypeMismatch ex)
198: {
199: array = prev;
200: throw ex;
201: }
202: catch (InvalidValue ex)
203: {
204: array = prev;
205: throw ex;
206: }
207: catch (RuntimeException rex)
208: {
209: array = prev;
210: throw rex;
211: }
212: }
213:
214:
217: public DynAny copy()
218: {
219: DynAny[] c = new DynAny[ array.length ];
220: for (int i = 0; i < c.length; i++)
221: {
222: c [ i ] = array [ i ].copy();
223: }
224:
225: gnuDynSequence d =
226: new gnuDynSequence(official_type, final_type, factory, orb);
227: d.array = c;
228: return d;
229: }
230:
231:
236: void checkBound(int x)
237: throws InvalidValue
238: {
239: if (bound != 0)
240: if (x < 0 || x > bound)
241: throw new InvalidValue(x + " out of bounds, valid [0.." + bound + "]");
242: }
243:
244:
247: protected void checkArrayValid(Object members)
248: throws TypeMismatch, InvalidValue
249: {
250: checkBound(Array.getLength(members));
251: if (get_length() != Array.getLength(members))
252: set_length(Array.getLength(members));
253: }
254: }