001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.iiop.rmi;
023:
024: import org.omg.CORBA.AttributeMode;
025:
026: import java.lang.reflect.Method;
027:
028: import java.rmi.Remote;
029:
030: /**
031: * Attribute analysis.
032: *
033: * Routines here are conforming to the "Java(TM) Language to IDL Mapping
034: * Specification", version 1.1 (01-06-07).
035: *
036: * @author <a href="mailto:osh@sparre.dk">Ole Husgaard</a>
037: * @version $Revision: 57194 $
038: */
039: public class AttributeAnalysis extends AbstractAnalysis {
040: // Constants -----------------------------------------------------
041:
042: // Attributes ----------------------------------------------------
043:
044: // Static --------------------------------------------------------
045:
046: // Constructors --------------------------------------------------
047:
048: /**
049: * Create an attribute analysis.
050: */
051: private AttributeAnalysis(String javaName, AttributeMode mode,
052: Method accessor, Method mutator)
053: throws RMIIIOPViolationException {
054: super (Util.javaToIDLName(javaName), javaName);
055:
056: this .mode = mode;
057: this .cls = accessor.getReturnType();
058: this .accessor = accessor;
059: this .mutator = mutator;
060:
061: // Only do operation analysis if the attribute is in a remote interface.
062: if (accessor.getDeclaringClass().isInterface()
063: && Remote.class.isAssignableFrom(accessor
064: .getDeclaringClass())) {
065: accessorAnalysis = new OperationAnalysis(accessor);
066: if (mutator != null)
067: mutatorAnalysis = new OperationAnalysis(mutator);
068:
069: setIDLName(getIDLName()); // Fixup operation names
070: }
071: }
072:
073: /**
074: * Create an attribute analysis for a read-only attribute.
075: */
076: AttributeAnalysis(String javaName, Method accessor)
077: throws RMIIIOPViolationException {
078: this (javaName, AttributeMode.ATTR_READONLY, accessor, null);
079: }
080:
081: /**
082: * Create an attribute analysis for a read-write attribute.
083: */
084: AttributeAnalysis(String javaName, Method accessor, Method mutator)
085: throws RMIIIOPViolationException {
086: this (javaName, AttributeMode.ATTR_NORMAL, accessor, mutator);
087: }
088:
089: // Public --------------------------------------------------------
090:
091: /**
092: * Return my attribute mode.
093: */
094: public AttributeMode getMode() {
095: return mode;
096: }
097:
098: /**
099: * Return my Java type.
100: */
101: public Class getCls() {
102: return cls;
103: }
104:
105: /**
106: * Return my accessor method
107: */
108: public Method getAccessor() {
109: return accessor;
110: }
111:
112: /**
113: * Return my mutator method
114: */
115: public Method getMutator() {
116: return mutator;
117: }
118:
119: /**
120: * Return my accessor operation analysis
121: */
122: public OperationAnalysis getAccessorAnalysis() {
123: return accessorAnalysis;
124: }
125:
126: /**
127: * Return my mutator operation analysis
128: */
129: public OperationAnalysis getMutatorAnalysis() {
130: return mutatorAnalysis;
131: }
132:
133: // Protected -----------------------------------------------------
134:
135: // Package protected ---------------------------------------------
136:
137: /**
138: * Set my unqualified IDL name.
139: * This also sets the names of the associated operations.
140: */
141: void setIDLName(String idlName) {
142: super .setIDLName(idlName);
143:
144: // If the first char is an uppercase letter and the second char is not
145: // an uppercase letter, then convert the first char to lowercase.
146: if (idlName.charAt(0) >= 0x41
147: && idlName.charAt(0) <= 0x5a
148: && (idlName.length() <= 1 || idlName.charAt(1) < 0x41 || idlName
149: .charAt(1) > 0x5a)) {
150: idlName = idlName.substring(0, 1).toLowerCase()
151: + idlName.substring(1);
152: }
153:
154: if (accessorAnalysis != null)
155: accessorAnalysis.setIDLName("_get_" + idlName);
156: if (mutatorAnalysis != null)
157: mutatorAnalysis.setIDLName("_set_" + idlName);
158: }
159:
160: // Private -------------------------------------------------------
161:
162: /**
163: * Attribute mode.
164: */
165: private AttributeMode mode;
166:
167: /**
168: * Java type.
169: */
170: private Class cls;
171:
172: /**
173: * Accessor Method.
174: */
175: private Method accessor = null;
176:
177: /**
178: * Mutator Method.
179: * This is null for read-only attributes.
180: */
181: private Method mutator = null;
182:
183: /**
184: * Accessor method analysis.
185: */
186: private OperationAnalysis accessorAnalysis = null;
187:
188: /**
189: * Mutator method analysis.
190: * This is null for read-only attributes.
191: */
192: private OperationAnalysis mutatorAnalysis = null;
193:
194: }
|