KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.omg.CORBA.AttributeMode JavaDoc;
25
26 import java.lang.reflect.Method JavaDoc;
27
28 import java.rmi.Remote JavaDoc;
29
30 /**
31  * Attribute analysis.
32  *
33  * Routines here are conforming to the "Java(TM) Language to IDL Mapping
34  * Specification", version 1.1 (01-06-07).
35  *
36  * @author <a HREF="mailto:osh@sparre.dk">Ole Husgaard</a>
37  * @version $Revision: 37459 $
38  */

39 public class AttributeAnalysis
40    extends AbstractAnalysis
41 {
42    // Constants -----------------------------------------------------
43

44    // Attributes ----------------------------------------------------
45

46    // Static --------------------------------------------------------
47

48    // Constructors --------------------------------------------------
49

50    /**
51     * Create an attribute analysis.
52     */

53    private AttributeAnalysis(String JavaDoc javaName, AttributeMode JavaDoc mode,
54                              Method JavaDoc accessor, Method JavaDoc mutator)
55       throws RMIIIOPViolationException
56    {
57       super(Util.javaToIDLName(javaName), javaName);
58
59       this.mode = mode;
60       this.cls = accessor.getReturnType();
61       this.accessor = accessor;
62       this.mutator = mutator;
63
64       // Only do operation analysis if the attribute is in a remote interface.
65
if (accessor.getDeclaringClass().isInterface() &&
66           Remote JavaDoc.class.isAssignableFrom(accessor.getDeclaringClass())) {
67          accessorAnalysis = new OperationAnalysis(accessor);
68          if (mutator != null)
69             mutatorAnalysis = new OperationAnalysis(mutator);
70
71          setIDLName(getIDLName()); // Fixup operation names
72
}
73    }
74
75
76    /**
77     * Create an attribute analysis for a read-only attribute.
78     */

79    AttributeAnalysis(String JavaDoc javaName, Method JavaDoc accessor)
80       throws RMIIIOPViolationException
81    {
82       this(javaName, AttributeMode.ATTR_READONLY, accessor, null);
83    }
84
85    /**
86     * Create an attribute analysis for a read-write attribute.
87     */

88    AttributeAnalysis(String JavaDoc javaName, Method JavaDoc accessor, Method JavaDoc mutator)
89       throws RMIIIOPViolationException
90    {
91       this(javaName, AttributeMode.ATTR_NORMAL, accessor, mutator);
92    }
93
94    // Public --------------------------------------------------------
95

96    /**
97     * Return my attribute mode.
98     */

99    public AttributeMode JavaDoc getMode()
100    {
101       return mode;
102    }
103    
104    /**
105     * Return my Java type.
106     */

107    public Class JavaDoc getCls()
108    {
109       return cls;
110    }
111    
112    /**
113     * Return my accessor method
114     */

115    public Method JavaDoc getAccessor()
116    {
117       return accessor;
118    }
119    
120    /**
121     * Return my mutator method
122     */

123    public Method JavaDoc getMutator()
124    {
125       return mutator;
126    }
127    
128    /**
129     * Return my accessor operation analysis
130     */

131    public OperationAnalysis getAccessorAnalysis()
132    {
133       return accessorAnalysis;
134    }
135    
136    /**
137     * Return my mutator operation analysis
138     */

139    public OperationAnalysis getMutatorAnalysis()
140    {
141       return mutatorAnalysis;
142    }
143    
144    // Protected -----------------------------------------------------
145

146    // Package protected ---------------------------------------------
147

148    /**
149     * Set my unqualified IDL name.
150     * This also sets the names of the associated operations.
151     */

152    void setIDLName(String JavaDoc idlName)
153    {
154       super.setIDLName(idlName);
155
156       // If the first char is an uppercase letter and the second char is not
157
// an uppercase letter, then convert the first char to lowercase.
158
if (idlName.charAt(0) >= 0x41 && idlName.charAt(0) <= 0x5a
159           && (idlName.length() <= 1
160               || idlName.charAt(1) < 0x41 || idlName.charAt(1) > 0x5a)) {
161          idlName =
162             idlName.substring(0, 1).toLowerCase() + idlName.substring(1);
163       }
164
165       if (accessorAnalysis != null)
166          accessorAnalysis.setIDLName("_get_" + idlName);
167       if (mutatorAnalysis != null)
168          mutatorAnalysis.setIDLName("_set_" + idlName);
169    }
170
171    // Private -------------------------------------------------------
172

173    /**
174     * Attribute mode.
175     */

176    private AttributeMode JavaDoc mode;
177
178    /**
179     * Java type.
180     */

181    private Class JavaDoc cls;
182
183    /**
184     * Accessor Method.
185     */

186    private Method JavaDoc accessor = null;
187
188    /**
189     * Mutator Method.
190     * This is null for read-only attributes.
191     */

192    private Method JavaDoc mutator = null;
193
194    /**
195     * Accessor method analysis.
196     */

197    private OperationAnalysis accessorAnalysis = null;
198
199    /**
200     * Mutator method analysis.
201     * This is null for read-only attributes.
202     */

203    private OperationAnalysis mutatorAnalysis = null;
204
205 }
206
207
Popular Tags