KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > dynany > DynAnyFactoryImpl


1 package org.jacorb.orb.dynany;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import java.util.*;
24
25 import org.omg.DynamicAny.*;
26 import org.omg.CORBA.TCKind JavaDoc;
27 import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode JavaDoc;
28
29 import org.jacorb.orb.TypeCode;
30
31 /**
32  * @author Gerald Brose, FU Berlin
33  * @version $Id: DynAnyFactoryImpl.java,v 1.13 2005/03/25 13:15:55 andre.spiegel Exp $
34  *
35  */

36
37 public class DynAnyFactoryImpl
38     extends org.omg.CORBA.LocalObject JavaDoc
39     implements org.omg.DynamicAny.DynAnyFactory JavaDoc
40 {
41     org.omg.CORBA.ORB JavaDoc orb;
42
43     public DynAnyFactoryImpl( org.omg.CORBA.ORB JavaDoc orb )
44     {
45         this.orb = orb;
46         // _this_object( orb );
47
}
48
49     public org.omg.DynamicAny.DynAny JavaDoc create_dyn_any( org.omg.CORBA.Any JavaDoc value )
50        throws InconsistentTypeCode JavaDoc
51     {
52        try
53        {
54           org.omg.DynamicAny.DynAny JavaDoc dynAny =
55              create_dyn_any_from_type_code( value.type() );
56           dynAny.from_any( value );
57           return dynAny;
58        }
59        catch( org.omg.DynamicAny.DynAnyPackage.InvalidValue JavaDoc iv )
60        {
61           iv.printStackTrace();
62        }
63        catch( org.omg.DynamicAny.DynAnyPackage.TypeMismatch JavaDoc itc )
64        {
65           itc.printStackTrace();
66        }
67        throw new InconsistentTypeCode JavaDoc();
68     }
69
70
71     public org.omg.DynamicAny.DynAny JavaDoc create_dyn_any_from_type_code( org.omg.CORBA.TypeCode JavaDoc type )
72     throws InconsistentTypeCode JavaDoc
73     {
74         type = TypeCode.originalType( type );
75
76         try
77         {
78             switch( type.kind().value() )
79             {
80                 case org.omg.CORBA.TCKind._tk_null:
81                 case org.omg.CORBA.TCKind._tk_void:
82                 case org.omg.CORBA.TCKind._tk_short:
83                 case org.omg.CORBA.TCKind._tk_long:
84                 case org.omg.CORBA.TCKind._tk_ushort:
85                 case org.omg.CORBA.TCKind._tk_ulong:
86                 case org.omg.CORBA.TCKind._tk_float:
87                 case org.omg.CORBA.TCKind._tk_double:
88                 case org.omg.CORBA.TCKind._tk_boolean:
89                 case org.omg.CORBA.TCKind._tk_char:
90                 case org.omg.CORBA.TCKind._tk_octet:
91                 case org.omg.CORBA.TCKind._tk_any:
92                 case org.omg.CORBA.TCKind._tk_TypeCode:
93                 case org.omg.CORBA.TCKind._tk_objref:
94                 case org.omg.CORBA.TCKind._tk_string:
95                 case org.omg.CORBA.TCKind._tk_longlong:
96                 case org.omg.CORBA.TCKind._tk_ulonglong:
97                 case org.omg.CORBA.TCKind._tk_wchar:
98                 case org.omg.CORBA.TCKind._tk_wstring:
99                 {
100                    return new DynAny( this , type, orb ) ;
101                 }
102                 case org.omg.CORBA.TCKind._tk_fixed:
103                 {
104                     return new DynFixed( this , type ) ;
105                 }
106                 case org.omg.CORBA.TCKind._tk_except:
107                 case org.omg.CORBA.TCKind._tk_struct:
108                 {
109                     return new DynStruct( this , type, orb ) ;
110                 }
111                 case org.omg.CORBA.TCKind._tk_enum:
112                 {
113                     return new DynEnum( this , type, orb ) ;
114                 }
115                 case org.omg.CORBA.TCKind._tk_array:
116                 {
117                     return new DynArray( this , type, orb ) ;
118                 }
119                 case org.omg.CORBA.TCKind._tk_sequence:
120                 {
121                     return new DynSequence( this , type, orb ) ;
122                 }
123                 case org.omg.CORBA.TCKind._tk_union:
124                 {
125                     return new DynUnion( this , type, orb ) ;
126                 }
127                 default:
128                     throw new InconsistentTypeCode JavaDoc();
129             }
130         }
131         catch( org.omg.DynamicAny.DynAnyPackage.InvalidValue JavaDoc iv )
132         {
133             iv.printStackTrace();
134         }
135         catch( org.omg.DynamicAny.DynAnyPackage.TypeMismatch JavaDoc itc )
136         {
137             throw new InconsistentTypeCode JavaDoc();
138         }
139         return null;
140     }
141 }
142
143
144
145
146
147
Popular Tags