Source for gnu.CORBA.typecodes.RecordTypeCode

   1: /* RecordTypeCode.java --
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   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.
  10: 
  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.
  15: 
  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.
  20: 
  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.
  25: 
  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. */
  37: 
  38: 
  39: package gnu.CORBA.typecodes;
  40: 
  41: import gnu.CORBA.CorbaList;
  42: 
  43: import org.omg.CORBA.Any;
  44: import org.omg.CORBA.StructMember;
  45: import org.omg.CORBA.TCKind;
  46: import org.omg.CORBA.TypeCode;
  47: import org.omg.CORBA.TypeCodePackage.BadKind;
  48: import org.omg.CORBA.TypeCodePackage.Bounds;
  49: import org.omg.CORBA.UnionMember;
  50: import org.omg.CORBA.ValueMember;
  51: 
  52: /**
  53:  * The type code that also has the member property getters
  54:  * supported.
  55:  *
  56:  * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
  57:  */
  58: public class RecordTypeCode
  59:   extends GeneralTypeCode
  60: {
  61:   /**
  62:    * Use serialVersionUID for interoperability.
  63:    */
  64:   private static final long serialVersionUID = 1;
  65: 
  66:   /**
  67:    * The individual field of the record.
  68:    */
  69:   public static class Field
  70:   {
  71:     /**
  72:      * The record label.
  73:      */
  74:     public Any label;
  75: 
  76:     /**
  77:      * The record name.
  78:      */
  79:     public String name;
  80: 
  81:     /**
  82:      * The record type.
  83:      */
  84:     public TypeCode type;
  85: 
  86:     /**
  87:      * The record visibility.
  88:      */
  89:     public int visibility = UNSET;
  90:   }
  91: 
  92:   /**
  93:    * The members of this data structure.
  94:    */
  95:   protected CorbaList members = new CorbaList();
  96:   private TypeCode discriminator_type;
  97:   private int default_index = UNSET;
  98: 
  99:   /**
 100:    * Creates the type code of the given kind.
 101:    */
 102:   public RecordTypeCode(TCKind a_kind)
 103:   {
 104:     super(a_kind);
 105:   }
 106: 
 107:   /**
 108:    * Set the default index.
 109:    */
 110:   public void setDefaultIndex(int a_default_index)
 111:   {
 112:     this.default_index = a_default_index;
 113:   }
 114: 
 115:   /**
 116:    * Set the discriminator type.
 117:    */
 118:   public void setDiscriminator_type(TypeCode a_discriminator_type)
 119:   {
 120:     this.discriminator_type = a_discriminator_type;
 121:   }
 122: 
 123:   public Field getField(int p)
 124:   {
 125:     return (Field) members.get(p);
 126:   }
 127: 
 128:   public void add(Field field)
 129:   {
 130:     members.add(field);
 131:   }
 132: 
 133:   /**
 134:    * Adds a new field, taking values from the passed
 135:    * {@link StructMember}.
 136:    */
 137:   public void add(StructMember m)
 138:   {
 139:     Field f = field();
 140:     f.name = m.name;
 141:     f.type = m.type;
 142:   }
 143: 
 144:   /**
 145:    * Adds a new field, taking values from the passed
 146:    * {@link ValueMember}.
 147:    */
 148:   public void add(ValueMember m)
 149:   {
 150:     Field f = field();
 151:     f.name = m.name;
 152:     f.type = m.type;
 153:     f.visibility = m.access;
 154: 
 155:   }
 156: 
 157:   /**
 158:    * Adds a new field, taking values from the passed
 159:    * {@link UnionMember}.
 160:    */
 161:   public void add(UnionMember m)
 162:   {
 163:     Field f = field();
 164:     f.name = m.name;
 165:     f.type = m.type;
 166:     f.label = m.label;
 167:   }
 168: 
 169:   public int default_index()
 170:                     throws BadKind
 171:   {
 172:     if (default_index != UNSET)
 173:       return default_index;
 174:     throw new BadKind();
 175:   }
 176: 
 177:   public TypeCode discriminator_type()
 178:                               throws BadKind
 179:   {
 180:     if (discriminator_type != null)
 181:       return discriminator_type;
 182:     throw new BadKind();
 183:   }
 184: 
 185:   /**
 186:    * Creates, adds and returns new field.
 187:    */
 188:   public Field field()
 189:   {
 190:     Field f = new Field();
 191:     members.add(f);
 192:     return f;
 193:   }
 194: 
 195:   /** {@inheritDoc} */
 196:   public int member_count()
 197:   {
 198:     return members.size();
 199:   }
 200: 
 201:   /** {@inheritDoc} */
 202:   public Any member_label(int index)
 203:                    throws BadKind, Bounds
 204:   {
 205:     Field f = getField(index);
 206:     if (f.label != null)
 207:       {
 208:         return f.label;
 209:       }
 210:     else
 211:       throw new BadKind();
 212:   }
 213: 
 214:   /** {@inheritDoc} */
 215:   public String member_name(int index)
 216:                      throws BadKind
 217:   {
 218:     Field f = getField(index);
 219:     if (f.name != null)
 220:       {
 221:         return f.name;
 222:       }
 223:     else
 224:       throw new BadKind();
 225:   }
 226: 
 227:   /** {@inheritDoc} */
 228:   public TypeCode member_type(int index)
 229:                        throws BadKind, Bounds
 230:   {
 231:     Field f = getField(index);
 232:     if (f.type != null)
 233:       {
 234:         return f.type;
 235:       }
 236:     else
 237:       throw new BadKind();
 238:   }
 239: 
 240:   /** {@inheritDoc} */
 241:   public short member_visibility(int index)
 242:                           throws BadKind, Bounds
 243:   {
 244:     Field f = getField(index);
 245:     if (f.visibility != UNSET)
 246:       {
 247:         return (short) f.visibility;
 248:       }
 249:     else
 250:       throw new BadKind();
 251:   }
 252: }