KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > cmi > compiler > MethodConf


1 /*
2  * Copyright (C) 2002-2003, Simon Nieuviarts
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA
18  */

19 package org.objectweb.carol.cmi.compiler;
20
21 import java.lang.reflect.Method JavaDoc;
22
23
24 public class MethodConf {
25     private MethodProto methodProto;
26     private ClassConf ccc;
27     private String JavaDoc balancer;
28     private Method JavaDoc method = null;
29
30     public MethodConf(ClassConf ccc, MethodProto mp, String JavaDoc balancerName) {
31         this.ccc = ccc;
32         methodProto = mp;
33         if (balancerName == null) {
34             balancerName = ccc.getBalancer();
35         }
36         this.balancer = balancerName;
37     }
38
39     public ClassConf getClassConf() {
40         return ccc;
41     }
42
43     public MethodProto getMethodProto() {
44         return methodProto;
45     }
46
47     public String JavaDoc getBalancer() {
48         return balancer;
49     }
50
51     public Method JavaDoc getMethod() {
52         return method;
53     }
54
55     public String JavaDoc getMthName() {
56         return method.getName();
57     }
58
59     public String JavaDoc getReturnTypeName() {
60         return MethodProto.getName(method.getReturnType());
61     }
62
63     private String JavaDoc paramString;
64
65     public String JavaDoc getParamString() {
66         if (paramString != null) {
67             return paramString;
68         }
69         Class JavaDoc[] params = method.getParameterTypes();
70         String JavaDoc s = "";
71         for (int i=0; i<params.length; i++) {
72             if (s.equals("")) {
73                 s = MethodProto.getName(params[i]) + " param" + (i + 1);
74             } else {
75                 s += ", " + MethodProto.getName(params[i]) + " param" + (i + 1);
76             }
77         }
78         paramString = s;
79         return s;
80     }
81
82     private String JavaDoc paramNamesString;
83
84     public String JavaDoc getParamNamesString() {
85         if (paramNamesString != null) {
86             return paramNamesString;
87         }
88         int len = method.getParameterTypes().length;
89         String JavaDoc s = "";
90         for (int i=0; i<len; i++) {
91             if (s.equals("")) {
92                 s = "param" + (i + 1);
93             } else {
94                 s += ", param" + (i + 1);
95             }
96         }
97         paramNamesString = s;
98         return s;
99     }
100
101     private String JavaDoc throwsString;
102
103     public String JavaDoc getThrowsString() {
104         if (throwsString != null) {
105             return throwsString;
106         }
107         Class JavaDoc[] ex = method.getExceptionTypes();
108         String JavaDoc s = "";
109         for (int i=0; i<ex.length; i++) {
110             if (s.equals("")) {
111                 s = MethodProto.getName(ex[i]);
112             } else {
113                 s += ", " + MethodProto.getName(ex[i]);
114             }
115         }
116         throwsString = s;
117         return s;
118     }
119
120     public String JavaDoc getDeclItfName() {
121         return MethodProto.getName(method.getDeclaringClass());
122     }
123
124     public boolean returnsVoid() {
125         return method.getReturnType().equals(void.class);
126     }
127
128     public void setMethod(Method JavaDoc method) throws CompilerException {
129         if (this.method == null) {
130             this.method = method;
131         } else {
132             throw new CompilerException("internal error");
133         }
134     }
135 }
136
Popular Tags