Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / CORBA / typecodes / GeneralTypeCode.java
blob0a907844ad90380d6e1f28ea1ee0c72207d85de6
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)
9 any later version.
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
19 02110-1301 USA.
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
24 combination.
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. */
39 package gnu.CORBA.typecodes;
41 import gnu.CORBA.CDR.BufferedCdrOutput;
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;
50 /**
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
62 /**
63 * Use serialVersionUID for interoperability.
65 private static final long serialVersionUID = 1;
68 /**
69 * Indicates that the field value has not been previously set.
71 protected static int UNSET = Integer.MIN_VALUE;
73 /**
74 * The kinds for that the length() must return 0 even if it
75 * has not been previously set.
77 private static final BitSet lengthAllowed = new BitSet();
79 static
81 lengthAllowed.set(TCKind._tk_array);
82 lengthAllowed.set(TCKind._tk_sequence);
83 lengthAllowed.set(TCKind._tk_string);
84 lengthAllowed.set(TCKind._tk_wstring);
87 private String id;
88 private String name;
89 private TypeCode concrete_base_type;
90 private TypeCode content_type;
91 private int len;
92 private int type_modifier = UNSET;
94 /**
95 * Create a new instance, setting kind to the given kind.
96 * @param a_kind the kind of the typecode being created.
98 public GeneralTypeCode(TCKind a_kind)
100 super(a_kind);
101 if (!lengthAllowed.get(a_kind.value()))
102 len = UNSET;
106 * Set this property.
108 public void setConcreteBase_type(TypeCode a_concrete_base_type)
110 this.concrete_base_type = a_concrete_base_type;
114 * Set the component content type.
116 public void setContentType(TypeCode a_content_type)
118 this.content_type = a_content_type;
122 * Set this property.
124 public void setId(String an_id)
126 this.id = an_id;
130 * Set the length property.
131 * @param l
133 public void setLength(int l)
135 len = l;
139 * Set this property.
141 public void setName(String a_name)
143 this.name = a_name;
147 * Set the type modifier.
149 public void setTypeModifier(int a_type_modifier)
151 this.type_modifier = a_type_modifier;
154 /** {@inheritDoc} */
155 public TypeCode concrete_base_type()
156 throws BadKind
158 if (concrete_base_type != null)
159 return concrete_base_type;
160 throw new BadKind("concrete_base_type");
164 * Returns the content type that must be explicitly set
165 * for this class.
167 * @throws BadKind if the content type has not been set.
169 public TypeCode content_type()
170 throws BadKind
172 if (content_type != null)
173 return content_type;
174 throw new BadKind("content_type");
178 * Returns true if both typecodes, if written into CDR
179 * stream, would result the same stream content.
181 public boolean equal(TypeCode other)
183 if (this == other)
184 return true;
185 if (kind() != other.kind())
186 return false;
188 BufferedCdrOutput a = new BufferedCdrOutput(16);
189 BufferedCdrOutput b = new BufferedCdrOutput(16);
191 a.write_TypeCode(this);
192 b.write_TypeCode(other);
194 return Arrays.equals(a.buffer.toByteArray(), b.buffer.toByteArray());
198 * Delegates functionality to {@link #equal}.
200 public boolean equivalent(TypeCode other)
202 return equal(other);
205 /** {@inheritDoc} */
206 public String id()
207 throws BadKind
209 if (id != null)
210 return id;
211 throw new BadKind("id");
215 * Get the length. For sequences, arrays, strings and wstrings
216 * this method returns 0 rather than throwing a BadKind even
217 * if {@link setLength(int)} has not been previously called.
219 * @return the length of string, array or sequence.
221 * @throws BadKind if the method cannot be invoked for the
222 * given kind of typecode.
224 public int length()
225 throws BadKind
227 if (len != UNSET)
228 return len;
229 throw new BadKind("length");
232 /** {@inheritDoc} */
233 public String name()
234 throws BadKind
236 if (name != null)
237 return name;
238 throw new BadKind("name");
241 /** {@inheritDoc} */
242 public short type_modifier()
243 throws BadKind
245 if (type_modifier != UNSET)
246 return (short) type_modifier;
247 throw new BadKind("type_modifier");