KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > rmi > ClassAnalysis


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software 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 software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.iiop.rmi;
23
24
25 /**
26  * Analysis class for classes. These define IDL types.
27  *
28  * Routines here are conforming to the "Java(TM) Language to IDL Mapping
29  * Specification", version 1.1 (01-06-07).
30  *
31  * @author <a HREF="mailto:osh@sparre.dk">Ole Husgaard</a>
32  * @version $Revision: 37459 $
33  */

34 public class ClassAnalysis
35    extends AbstractAnalysis
36 {
37    // Constants -----------------------------------------------------
38

39    // Attributes ----------------------------------------------------
40

41    // Static --------------------------------------------------------
42

43    /**
44     * Analyze the given class, and return the analysis.
45    public static ClassAnalysis getClassAnalysis(Class cls)
46       throws RMIIIOPViolationException
47    {
48       if (cls == null)
49          throw new IllegalArgumentException("Cannot analyze NULL class.");
50       if (cls == java.lang.String.class || cls == java.lang.Object.class ||
51           cls == java.lang.Class.class || cls == java.io.Serializable.class ||
52           cls == java.io.Externalizable.class ||
53           cls == java.rmi.Remote.class)
54          throw new IllegalArgumentException("Cannot analyze special class: " +
55                                             cls.getName());
56  
57       if (cls.isPrimitive())
58          return PrimitiveAnalysis.getPrimitiveAnalysis(cls);
59
60
61       if (cls.isInterface() && java.rmi.Remote.class.isAssignableFrom(cls))
62          return InterfaceAnalysis.getInterfaceAnalysis(cls);
63 // TODO
64 throw new RuntimeException("ClassAnalysis.getClassAnalysis() TODO");
65    }
66     */

67
68    static private String JavaDoc javaNameOfClass(Class JavaDoc cls)
69    {
70       if (cls == null)
71          throw new IllegalArgumentException JavaDoc("Cannot analyze NULL class.");
72  
73       String JavaDoc s = cls.getName();
74  
75       return s.substring(s.lastIndexOf('.')+1);
76    }
77
78    // Constructors --------------------------------------------------
79

80    public ClassAnalysis(Class JavaDoc cls, String JavaDoc idlName, String JavaDoc javaName)
81    {
82       super(idlName, javaName);
83
84       this.cls = cls;
85    }
86
87    public ClassAnalysis(Class JavaDoc cls, String JavaDoc javaName)
88    {
89       this(cls, Util.javaToIDLName(javaName), javaName);
90    }
91
92    public ClassAnalysis(Class JavaDoc cls)
93    {
94       this(cls, javaNameOfClass(cls));
95    }
96
97    // Public --------------------------------------------------------
98

99    /**
100     * Return my java class.
101     */

102    public Class JavaDoc getCls()
103    {
104       return cls;
105    }
106
107    // Package protected ---------------------------------------------
108

109    // Protected -----------------------------------------------------
110

111    /**
112     * My java class.
113     */

114    protected Class JavaDoc cls;
115
116    // Private -------------------------------------------------------
117
}
118
119
Popular Tags