KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > CORBA > CorbaIORDecoderHandler


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy.
23 Contributor(s): Philippe Merle.
24
25 ====================================================================*/

26 package org.objectweb.openccm.explorer.CORBA;
27
28 /** To use the ORB class */
29 import org.objectweb.util.explorer.context.lib.AbstractDecoder;
30 import org.omg.CORBA.ORB JavaDoc;
31
32 /**
33  * This class allows to decode a CORBA stub and
34  * provide the associated object.
35  *
36  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
37  *
38  * @version 0.1
39  */

40 public class CorbaIORDecoderHandler
41      extends AbstractDecoder {
42
43     /** To object's class concern by the handler */
44     protected final Class JavaDoc class_ = org.omg.CORBA.Object JavaDoc.class;
45
46     /** The current ORB */
47     protected ORB JavaDoc orb_ = null;
48
49     /**
50      * Default Constructor
51      */

52     public CorbaIORDecoderHandler() {
53         orb_ = org.objectweb.openccm.corba.TheORB.getORB();
54     }
55
56     /**
57      * Uses to decode an object, for example if it's a CORBA Object
58      * @param node The object to decode
59      * @return the decoded object
60      */

61     public Object JavaDoc decode(Object JavaDoc node) {
62         //
63
// Related to Bug #300847.
64
// Contributor: Philippe Merle
65
//
66
// Deal with null CORBA Object References.
67
//
68
if(node == null)
69             return new String JavaDoc("NULL CORBA OBJECT REFERENCE");
70
71         if (class_.isAssignableFrom(node.getClass())) {
72             try {
73                 TypageCORBA typeCORBA = new TypageCORBA((org.omg.CORBA.Object JavaDoc) node, orb_);
74                 Class JavaDoc[] argsType = new Class JavaDoc[] { org.omg.CORBA.Object JavaDoc.class };
75                 Object JavaDoc[] args = new Object JavaDoc[] { node };
76                 Class JavaDoc c = typeCORBA.getJavaHelperClass();
77                 if (c != null) {
78                     Object JavaDoc o = c.getMethod("narrow", argsType).invoke(null, args);
79                     if (!node.getClass().getName().equals(o.getClass().getName()))
80                         return o;
81                 }
82             } catch (NoSuchMethodException JavaDoc e) {
83                 e.printStackTrace();
84             } catch (IllegalAccessException JavaDoc e) {
85                 e.printStackTrace();
86             } catch (java.lang.reflect.InvocationTargetException JavaDoc e) {
87                 e.printStackTrace();
88             } catch (ObjectToStringNotSupportedException e) {
89                 // Ignore
90
}
91         } else if (next_ != null) {
92             return next_.decode(node);
93         }
94         return node;
95     }
96
97 }
98
Popular Tags