1 /* generalTypeCode.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import gnu.CORBA.CDR.cdrBufOutput;
43 import java.util.Arrays;
44 import java.util.BitSet;
46 import org.omg.CORBA.TCKind;
47 import org.omg.CORBA.TypeCode;
48 import org.omg.CORBA.TypeCodePackage.BadKind;
51 * A typecode for types, requiring to provide various additional
52 * properties but still not requiring to store the
53 * members of the structure. The property can be retrieved
54 * by the corresponding method if it has been previously assigned.
55 * Otherwise, a {@link BadKind} is thrown.
57 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
59 public class generalTypeCode
60 extends primitiveTypeCode
63 * Indicates that the field value has not been previously set.
65 protected static int UNSET = Integer.MIN_VALUE;
68 * The kinds for that the length() must return 0 even if it
69 * has not been previously set.
71 private static final BitSet lengthAllowed = new BitSet();
75 lengthAllowed.set(TCKind._tk_array);
76 lengthAllowed.set(TCKind._tk_sequence);
77 lengthAllowed.set(TCKind._tk_string);
78 lengthAllowed.set(TCKind._tk_wstring);
83 private TypeCode concrete_base_type;
84 private TypeCode content_type;
86 private int type_modifier = UNSET;
89 * Create a new instance, setting kind to the given kind.
92 public generalTypeCode(TCKind kind)
95 if (!lengthAllowed.get(kind.value()))
102 public void setConcreteBase_type(TypeCode concrete_base_type)
104 this.concrete_base_type = concrete_base_type;
108 * Set the component content type.
110 public void setContentType(TypeCode a_content_type)
112 this.content_type = a_content_type;
118 public void setId(String id)
124 * Set the length property.
127 public void setLength(int l)
135 public void setName(String name)
141 * Set the type modifier.
143 public void setTypeModifier(int a_type_modifier)
145 this.type_modifier = a_type_modifier;
149 public TypeCode concrete_base_type()
152 if (concrete_base_type != null)
153 return concrete_base_type;
154 throw new BadKind("concrete_base_type");
158 * Returns the content type that must be explicitly set
161 * @throws BadKind if the content type has not been set.
163 public TypeCode content_type()
166 if (content_type != null)
168 throw new BadKind("content_type");
172 * Returns true if both typecodes, if written into CDR
173 * stream, would result the same stream content.
175 public boolean equal(TypeCode other)
179 if (kind() != other.kind())
182 cdrBufOutput a = new cdrBufOutput(16);
183 cdrBufOutput b = new cdrBufOutput(16);
185 a.write_TypeCode(this);
186 b.write_TypeCode(other);
188 return Arrays.equals(a.buffer.toByteArray(), b.buffer.toByteArray());
192 * Delegates functionality to {@link #equal}.
194 public boolean equivalent(TypeCode other)
205 throw new BadKind("id");
209 * Get the length. For sequences, arrays, strings and wstrings
210 * this method returns 0 rather than throwing a BadKind even
211 * if {@link setLength(int)} has not been previously called.
213 * @return the length of string, array or sequence.
215 * @throws BadKind if the method cannot be invoked for the
216 * given kind of typecode.
223 throw new BadKind("length");
232 throw new BadKind("name");
236 public short type_modifier()
239 if (type_modifier != UNSET)
240 return (short) type_modifier;
241 throw new BadKind("type_modifier");