KickJava   Java API By Example, From Geeks To Geeks.

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


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

41 public class OperationAnalysis
42    extends AbstractAnalysis
43 {
44    // Constants -----------------------------------------------------
45

46    // Attributes ----------------------------------------------------
47

48    // Static --------------------------------------------------------
49

50    private static final org.jboss.logging.Logger logger =
51                org.jboss.logging.Logger.getLogger(OperationAnalysis.class);
52
53    // Constructors --------------------------------------------------
54

55    OperationAnalysis(Method JavaDoc method)
56       throws RMIIIOPViolationException
57    {
58       super(method.getName());
59       logger.debug("new OperationAnalysis: " + method.getName());
60       this.method = method;
61
62       // Check if valid return type, IF it is a remote interface.
63
Class JavaDoc retCls = method.getReturnType();
64       if (retCls.isInterface() && Remote JavaDoc.class.isAssignableFrom(retCls))
65          Util.isValidRMIIIOP(retCls);
66
67       // Analyze exceptions
68
Class JavaDoc[] ex = method.getExceptionTypes();
69       boolean gotRemoteException = false;
70       ArrayList JavaDoc a = new ArrayList JavaDoc();
71       for (int i = 0; i < ex.length; ++i) {
72          if (ex[i].isAssignableFrom(java.rmi.RemoteException JavaDoc.class))
73             gotRemoteException = true;
74          if (Exception JavaDoc.class.isAssignableFrom(ex[i]) &&
75              !RuntimeException JavaDoc.class.isAssignableFrom(ex[i]) &&
76              !RemoteException JavaDoc.class.isAssignableFrom(ex[i]) )
77            a.add(ExceptionAnalysis.getExceptionAnalysis(ex[i])); // map this
78
}
79       if (!gotRemoteException &&
80           Remote JavaDoc.class.isAssignableFrom(method.getDeclaringClass()))
81          throw new RMIIIOPViolationException(
82               "All interface methods must throw java.rmi.RemoteException, " +
83               "or a superclass of java.rmi.RemoteException, but method " +
84               getJavaName() + " of interface " +
85               method.getDeclaringClass().getName() + " does not.", "1.2.3");
86       mappedExceptions = new ExceptionAnalysis[a.size()];
87       mappedExceptions = (ExceptionAnalysis[])a.toArray(mappedExceptions);
88
89       // Analyze parameters
90
Class JavaDoc[] params = method.getParameterTypes();
91       parameters = new ParameterAnalysis[params.length];
92       for (int i = 0; i < params.length; ++i) {
93          logger.debug("OperationAnalysis: " + method.getName() +
94                       " has parameter [" + params[i].getName() + "]");
95          parameters[i] = new ParameterAnalysis("param" + (i+1), params[i]);
96       }
97    }
98
99    // Public --------------------------------------------------------
100

101    /**
102     * Return my Java return type.
103     */

104    public Class JavaDoc getReturnType()
105    {
106       return method.getReturnType();
107    }
108  
109    /**
110     * Return my mapped Method.
111     */

112    public Method JavaDoc getMethod()
113    {
114       return method;
115    }
116    
117    /**
118     * Return my mapped exceptions.
119     */

120    public ExceptionAnalysis[] getMappedExceptions()
121    {
122       return (ExceptionAnalysis[])mappedExceptions.clone();
123    }
124    
125    /**
126     * Return my parameters.
127     */

128    public ParameterAnalysis[] getParameters()
129    {
130       return (ParameterAnalysis[])parameters.clone();
131    }
132    
133    // Protected -----------------------------------------------------
134

135    // Private -------------------------------------------------------
136

137    /**
138     * The Method that this OperationAnalysis is mapping.
139     */

140    private Method JavaDoc method;
141
142    /**
143     * The mapped exceptions of this operation.
144     */

145    private ExceptionAnalysis[] mappedExceptions;
146
147    /**
148     * The parameters of this operation.
149     */

150    private ParameterAnalysis[] parameters;
151
152 }
153
Popular Tags