KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > bussinessproxy > remote > http > HttpRequest


1 /**
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6
7        http://www.apache.org/licenses/LICENSE-2.0
8
9   * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */

15
16 package com.jdon.bussinessproxy.remote.http;
17
18 import com.jdon.bussinessproxy.TargetMetaDef;
19 import java.io.Serializable JavaDoc;
20
21
22 public class HttpRequest implements Serializable JavaDoc {
23
24     private TargetMetaDef targetMetaDef;
25     private String JavaDoc methodName;
26     private String JavaDoc[] paramTypesName;
27     private Object JavaDoc[] args;
28
29     public HttpRequest(TargetMetaDef targetMetaDef, String JavaDoc methodToCall,
30                               Class JavaDoc[] paramTypes, Object JavaDoc[] args) {
31         this.targetMetaDef = targetMetaDef;
32         this.methodName = methodToCall;
33         setParamTypes(paramTypes);
34         this.args = args;
35     }
36
37
38     public boolean isStatefull() {
39         return true;
40     }
41
42
43     public TargetMetaDef getTargetMetaDef() {
44         return targetMetaDef;
45     }
46
47     public void setTargetMetaDef(TargetMetaDef targetMetaDef) {
48         this.targetMetaDef = targetMetaDef;
49     }
50
51     public String JavaDoc getMethodName() {
52         return methodName;
53     }
54
55     public void setMethodName(String JavaDoc methodName) {
56         this.methodName = methodName;
57     }
58
59     /**
60      * @return The array of params of the invoked method.
61      */

62     public Class JavaDoc[] getParamTypes() {
63         ClassLoader JavaDoc curClassLoader = this.getClass().getClassLoader();
64         Class JavaDoc[] result = new Class JavaDoc[paramTypesName.length];
65         for (int i = 0; i < paramTypesName.length; i++) {
66             String JavaDoc type = paramTypesName[i];
67             Class JavaDoc arg = null;
68             if (type == null)
69                 arg = null;
70             else if (type.equals("int"))
71                 arg = Integer.TYPE;
72             else if (type.equals("boolean"))
73                 arg = Boolean.TYPE;
74             else if (type.equals("float"))
75                 arg = Float.TYPE;
76             else if (type.equals("byte"))
77                 arg = Byte.TYPE;
78             else if (type.equals("short"))
79                 arg = Short.TYPE;
80             else if (type.equals("char"))
81                 arg = Character.TYPE;
82             else if (type.equals("long"))
83                 arg = Long.TYPE;
84             else if (type.equals("double"))
85                 arg = Double.TYPE;
86             else
87                 try {
88                     arg = Class.forName(type);
89                 } catch (ClassNotFoundException JavaDoc e) {
90                     throw new RuntimeException JavaDoc(e.getLocalizedMessage());
91                 }
92             result[i] = arg;
93         }
94         return result;
95     }
96
97     public void setParamTypes(Class JavaDoc[] paramTypes) {
98         paramTypesName = new String JavaDoc[paramTypes.length];
99         for (int i = 0; i < paramTypes.length; i++) {
100             Class JavaDoc type = paramTypes[i];
101             paramTypesName[i] = type.getName();
102         }
103     }
104
105     public Object JavaDoc[] getArgs() {
106         return args;
107     }
108
109     public void setArgs(Object JavaDoc[] args) {
110         this.args = args;
111     }
112
113 }
114
Popular Tags