001: package org.jacorb.orb.dynany;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
024:
025: import org.apache.avalon.framework.logger.Logger;
026: import org.jacorb.orb.TypeCode;
027:
028: /**
029: * @author Gerald Brose, FU Berlin
030: * @version $Id: DynAnyFactoryImpl.java,v 1.16 2006/05/19 22:23:31 alphonse.bendt Exp $
031: */
032:
033: public class DynAnyFactoryImpl extends org.omg.CORBA.LocalObject
034: implements org.omg.DynamicAny.DynAnyFactory {
035: private final org.jacorb.orb.ORB orb;
036: private final Logger logger;
037:
038: public DynAnyFactoryImpl(org.jacorb.orb.ORB orb) {
039: super ();
040: this .orb = orb;
041: logger = orb.getConfiguration().getNamedLogger("jacorb.orb");
042: }
043:
044: public org.omg.DynamicAny.DynAny create_dyn_any(
045: org.omg.CORBA.Any value) throws InconsistentTypeCode {
046: try {
047: org.omg.DynamicAny.DynAny dynAny = create_dyn_any_from_type_code(value
048: .type());
049: dynAny.from_any(value);
050: return dynAny;
051: } catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue iv) {
052: logger.error("unable to create DynAny", iv);
053: } catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch itc) {
054: logger.error("unable to create DynAny", itc);
055: }
056: throw new InconsistentTypeCode();
057: }
058:
059: public org.omg.DynamicAny.DynAny create_dyn_any_from_type_code(
060: org.omg.CORBA.TypeCode typeCode)
061: throws InconsistentTypeCode {
062: final org.omg.CORBA.TypeCode _type = TypeCode
063: .originalType(typeCode);
064:
065: try {
066: switch (_type.kind().value()) {
067: case org.omg.CORBA.TCKind._tk_null:
068: case org.omg.CORBA.TCKind._tk_void:
069: case org.omg.CORBA.TCKind._tk_short:
070: case org.omg.CORBA.TCKind._tk_long:
071: case org.omg.CORBA.TCKind._tk_ushort:
072: case org.omg.CORBA.TCKind._tk_ulong:
073: case org.omg.CORBA.TCKind._tk_float:
074: case org.omg.CORBA.TCKind._tk_double:
075: case org.omg.CORBA.TCKind._tk_boolean:
076: case org.omg.CORBA.TCKind._tk_char:
077: case org.omg.CORBA.TCKind._tk_octet:
078: case org.omg.CORBA.TCKind._tk_any:
079: case org.omg.CORBA.TCKind._tk_TypeCode:
080: case org.omg.CORBA.TCKind._tk_objref:
081: case org.omg.CORBA.TCKind._tk_string:
082: case org.omg.CORBA.TCKind._tk_longlong:
083: case org.omg.CORBA.TCKind._tk_ulonglong:
084: case org.omg.CORBA.TCKind._tk_wchar:
085: case org.omg.CORBA.TCKind._tk_wstring: {
086: return new DynAny(this , _type, orb, logger);
087: }
088: case org.omg.CORBA.TCKind._tk_fixed: {
089: return new DynFixed(this , _type, orb, logger);
090: }
091: case org.omg.CORBA.TCKind._tk_except:
092: case org.omg.CORBA.TCKind._tk_struct: {
093: return new DynStruct(this , _type, orb, logger);
094: }
095: case org.omg.CORBA.TCKind._tk_enum: {
096: return new DynEnum(this , _type, orb, logger);
097: }
098: case org.omg.CORBA.TCKind._tk_array: {
099: return new DynArray(this , _type, orb, logger);
100: }
101: case org.omg.CORBA.TCKind._tk_sequence: {
102: return new DynSequence(this , _type, orb, logger);
103: }
104: case org.omg.CORBA.TCKind._tk_union: {
105: return new DynUnion(this , _type, orb, logger);
106: }
107: case org.omg.CORBA.TCKind._tk_value: {
108: throw new org.omg.CORBA.NO_IMPLEMENT(
109: "DynValue is not yet implemented in Jacorb");
110: }
111: default:
112: throw new InconsistentTypeCode();
113: }
114: } catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch itc) {
115: throw new InconsistentTypeCode();
116: }
117: }
118: }
|