KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > ir > gui > remoteobject > ObjectRepresentantFactory


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

21 package org.jacorb.ir.gui.remoteobject;
22
23 import org.jacorb.ir.gui.typesystem.*;
24 import org.jacorb.ir.gui.typesystem.remote.*;
25 import org.omg.CORBA.*;
26 import javax.swing.tree.*;
27
28 /**
29  * This class was generated by a SmartGuide.
30  *
31  */

32 public class ObjectRepresentantFactory
33 {
34     private static ORB orb = ORB.init();
35
36     /**
37      * This method was created by a SmartGuide.
38      * @return org.jacorb.ir;.gui.remoteobject.ObjectRepresentant
39      * @param counterPart java.lang.Object
40      * @param type TypeSystemNode
41      * @param referencedBy TypeAssociator: das Attribut, das das Objekt enthält (darf null sein)
42      */

43     public static ObjectRepresentant create(java.lang.Object JavaDoc counterPart,
44                                             TypeSystemNode type,
45                                             TypeAssociator referencedBy)
46     {
47         // referencedBy wird benötigt, falls wir den Inhalt eines Attributes darstellen sollen.
48
// Wenn wir this sind, dann gibt es kein referencedBy, aber immer noch einen type (den wir auch brauchen)
49
String JavaDoc name = null;
50         if (referencedBy!=null) {
51             name = ((TypeSystemNode)referencedBy).getName();
52         }
53
54         if (type instanceof IRInterface) {
55             return new RemoteObject((org.omg.CORBA.Object JavaDoc)counterPart, type, name);
56         }
57         if (type instanceof IRStruct) {
58             return new Struct(counterPart, (IRStruct)type, name);
59         }
60         /* if (counterPart instanceof TypeCode) {
61             return new Struct(counterPart, null, name);
62             }
63         */

64         return new ObjectRepresentant(counterPart, type, name);
65     }
66     /**
67      * This method was created by a SmartGuide.
68      * @param counterPart org.omg.CORBA.Object
69      */

70     public static ObjectRepresentant create(org.omg.CORBA.Object JavaDoc counterPart) {
71         TypeSystemNode typeSystemNode =
72             (IRInterface)RemoteTypeSystem.createTypeSystemNode(
73                 InterfaceDefHelper.narrow( counterPart._get_interface_def()));
74         return create(counterPart,typeSystemNode,null);
75     }
76     /**
77      * This method was created by a SmartGuide.
78      * @param ior java.lang.String
79      */

80     public static ObjectRepresentant createFromIOR (String JavaDoc ior) {
81         org.omg.CORBA.Object JavaDoc obj = orb.string_to_object(ior);
82         return create(obj);
83     }
84     /**
85      * This method was created by a SmartGuide.
86      * @return java.lang.Object
87      * @param any org.omg.CORBA.Any
88      */

89     protected static void insertFromString (Any result, String JavaDoc value, TCKind kind ) {
90         switch (kind.value()) {
91             case TCKind._tk_null:
92             case TCKind._tk_void:
93             case TCKind._tk_short:
94             result.insert_short(Short.parseShort(value));
95             break;
96             case TCKind._tk_long:
97             result.insert_long(Integer.parseInt(value));
98             break;
99             case TCKind._tk_ushort:
100             result.insert_ushort(Short.parseShort(value));
101             break;
102             case TCKind._tk_ulong:
103             result.insert_ulong(Integer.parseInt(value));
104             break;
105             case TCKind._tk_float:
106             result.insert_float(new Float JavaDoc(value).floatValue());
107             break;
108             case TCKind._tk_double:
109             result.insert_double(new Double JavaDoc(value).doubleValue());
110             break;
111             case TCKind._tk_boolean:
112             result.insert_boolean(new Boolean JavaDoc(value).booleanValue());
113             break;
114             case TCKind._tk_char:
115             result.insert_char(value.charAt(0));
116             break;
117             case TCKind._tk_octet:
118             result.insert_octet(new Byte JavaDoc(value).byteValue());
119             break;
120             /* case TCKind._tk_any:
121                 return any.insert_any();
122                 case TCKind._tk_TypeCode:
123                 return any.insert_TypeCode();
124                 case TCKind._tk_Principal:
125                 return any.insert_Principal();
126             */

127             case TCKind._tk_objref:
128             result.insert_Object(orb.string_to_object(value));
129             break;
130             /* case TCKind._tk_struct:
131                 return any.insert_struct(); // gibt's nicht im Standard-Mapping
132             */

133             /* case TCKind._tk_union:
134                 return any.insert_union(); // gibt's nicht im Standard-Mapping
135             */

136             case TCKind._tk_enum:
137             result.insert_long(Integer.parseInt(value)); // ob das wohl konform ist?
138
break;
139             case TCKind._tk_string:
140             result.insert_string(value);
141             break;
142             /* case TCKind._tk_sequence:
143                 return any.insert_sequence(); // gibt's nicht im Standard-Mapping
144             */

145             /* case TCKind._tk_array:
146                 return any.insert_array(); // gibt's nicht im Standard-Mapping
147             */

148             /* case TCKind._tk_except:
149                 return any.insert_except(); // gibt's nicht im Standard-Mapping
150             */

151             case TCKind._tk_longlong:
152             result.insert_longlong(Long.parseLong(value));
153             break;
154             case TCKind._tk_ulonglong:
155             result.insert_ulonglong(Long.parseLong(value));
156             break;
157             case TCKind._tk_wchar:
158             result.insert_wchar(value.charAt(0));
159             break;
160             case TCKind._tk_wstring:
161             result.insert_wstring(value);
162             break;
163             default:
164         }
165     }
166     /**
167      * This method was created by a SmartGuide.
168      * @param args java.lang.String[]
169      */

170     public static void main(String JavaDoc args[]) {
171         try {
172             String JavaDoc[] initialServices = orb.list_initial_services();
173             org.omg.CORBA.Object JavaDoc orep = orb.resolve_initial_references("InterfaceRepository");
174             Repository rep = RepositoryHelper.narrow( orb.resolve_initial_references("InterfaceRepository"));
175             PrimitiveDef prim = rep.get_primitive(PrimitiveKind.pk_short);
176
177             InterfaceDef intf = InterfaceDefHelper.narrow( prim._get_interface_def());
178             ObjectRepresentant objr = ObjectRepresentantFactory.create(prim,RemoteTypeSystem.createTypeSystemNode(intf),null);
179             ModelBuilder.getSingleton().buildTreeModelAsync(objr);
180         }
181         catch (Exception JavaDoc e) {
182             e.printStackTrace();
183         }
184         return;
185     }
186     /**
187      * This method was created by a SmartGuide.
188      * @return java.lang.Object
189      * @param any org.omg.CORBA.Any
190      */

191     public static java.lang.Object JavaDoc objectFromAny (Any any ) {
192         switch (any.type().kind().value()) {
193             case TCKind._tk_null:
194             return null;
195             case TCKind._tk_void:
196             System.out.println("DII returned an Any of kind void?");
197             return null;
198             case TCKind._tk_short:
199             return new Short JavaDoc(any.extract_short());
200             case TCKind._tk_long:
201             return new Integer JavaDoc(any.extract_long());
202             case TCKind._tk_ushort:
203             return new Short JavaDoc(any.extract_ushort());
204             case TCKind._tk_ulong:
205             return new Integer JavaDoc(any.extract_ulong());
206             case TCKind._tk_float:
207             return new Float JavaDoc(any.extract_float());
208             case TCKind._tk_double:
209             return new Double JavaDoc(any.extract_double());
210             case TCKind._tk_boolean:
211             return new Boolean JavaDoc(any.extract_boolean());
212             case TCKind._tk_char:
213             return new Character JavaDoc(any.extract_char());
214             case TCKind._tk_octet:
215             return new Byte JavaDoc(any.extract_octet());
216             case TCKind._tk_any:
217             return any.extract_any();
218             case TCKind._tk_TypeCode:
219             return any.extract_TypeCode();
220             case TCKind._tk_Principal:
221             return any.extract_Principal();
222             case TCKind._tk_objref:
223             return any.extract_Object();
224             /* case TCKind._tk_struct:
225                 return any.extract_struct(); // gibt's nicht im Standard-Mapping
226             */

227             /* case TCKind._tk_union:
228                 return any.extract_union(); // gibt's nicht im Standard-Mapping
229             */

230             /* case TCKind._tk_enum:
231                 return any.extract_enum(); // gibt's nicht im Standard-Mapping
232             */

233             case TCKind._tk_string:
234             return any.extract_string();
235             /* case TCKind._tk_sequence:
236                 return any.extract_sequence(); // gibt's nicht im Standard-Mapping
237                 case TCKind._tk_array:
238                 return any.extract_array(); // gibt's nicht im Standard-Mapping case TCKind._tk_except:
239                 return any.extract_except(); // gibt's nicht im Standard-Mapping
240             */

241             case TCKind._tk_longlong:
242             return new Long JavaDoc(any.extract_longlong());
243             case TCKind._tk_ulonglong:
244             return new Long JavaDoc(any.extract_ulonglong());
245             case TCKind._tk_wchar:
246             return new Character JavaDoc(any.extract_wchar());
247             case TCKind._tk_wstring:
248             return new String JavaDoc(any.extract_wstring());
249         }
250         return null;
251     }
252 }
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
Popular Tags