001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.iiop.rmi.ir;
023:
024: import org.omg.CORBA.TypeCode;
025: import org.omg.CORBA.TypeCodePackage.BadKind;
026: import org.omg.CORBA.TCKind;
027: import org.omg.CORBA.DefinitionKind;
028: import org.omg.CORBA.IDLType;
029: import org.omg.CORBA.IDLTypeHelper;
030: import org.omg.CORBA.IDLTypeOperations;
031:
032: import java.io.UnsupportedEncodingException;
033:
034: /**
035: * IDLType IR object.
036: *
037: * @author <a href="mailto:osh@sparre.dk">Ole Husgaard</a>
038: * @version $Revision: 57194 $
039: */
040: abstract class IDLTypeImpl extends IRObjectImpl implements LocalIDLType {
041: // Constants -----------------------------------------------------
042:
043: // Attributes ----------------------------------------------------
044:
045: // Static --------------------------------------------------------
046:
047: // Constructors --------------------------------------------------
048:
049: IDLTypeImpl(TypeCode typeCode, DefinitionKind def_kind,
050: RepositoryImpl repository) {
051: super (def_kind, repository);
052:
053: this .typeCode = typeCode;
054: }
055:
056: // Public --------------------------------------------------------
057:
058: // IDLTypeOperations implementation ---------------------------------
059:
060: public TypeCode type() {
061: return typeCode;
062: }
063:
064: // Package protected ---------------------------------------------
065:
066: /**
067: * Return the LocalIDLType for the given TypeCode.
068: */
069: static LocalIDLType getIDLType(TypeCode typeCode,
070: RepositoryImpl repository) {
071: TCKind tcKind = typeCode.kind();
072:
073: if (PrimitiveDefImpl.isPrimitiveTCKind(tcKind))
074: return new PrimitiveDefImpl(typeCode, repository);
075:
076: if (tcKind == TCKind.tk_sequence)
077: return repository.getSequenceImpl(typeCode);
078:
079: if (tcKind == TCKind.tk_value || tcKind == TCKind.tk_value_box
080: || tcKind == TCKind.tk_alias
081: || tcKind == TCKind.tk_struct
082: || tcKind == TCKind.tk_union
083: || tcKind == TCKind.tk_enum
084: || tcKind == TCKind.tk_objref) {
085: try {
086: return (LocalIDLType) repository._lookup_id(typeCode
087: .id());
088: } catch (BadKind ex) {
089: throw new RuntimeException("Bad kind for TypeCode.id()");
090: }
091: }
092:
093: throw new RuntimeException("TODO: tcKind=" + tcKind.value());
094: }
095:
096: // Protected -----------------------------------------------------
097:
098: /**
099: * Return the POA object ID of this IR object.
100: * We delegate to the IR to get a serial number ID.
101: */
102: protected byte[] getObjectId() {
103: return repository.getNextObjectId();
104: }
105:
106: // Private -------------------------------------------------------
107:
108: /**
109: * My TypeCode.
110: */
111: private TypeCode typeCode;
112:
113: }
|