KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > connector > AbstractInvocation


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ioc.connector;
8
9 import java.io.IOException JavaDoc;
10 import java.lang.reflect.Method JavaDoc;
11 import java.rmi.MarshalledObject JavaDoc;
12
13 import org.jfox.ioc.util.Marshaller;
14
15 /**
16  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
17  */

18
19 public abstract class AbstractInvocation implements Invocation {
20     private ObjectId objectId = null;
21
22     private String JavaDoc methodHash = null;
23     private Object JavaDoc[] args = null;
24
25     /**
26      * 远程调用的方法
27      * 远程调用的时候,传过去的时候只是 methodHash,在服务端通过解析methodHash才得到真正的Method
28      */

29     private transient Method JavaDoc method = null;
30
31     /**
32      * 用来存储执行对象,主要是EJB Bean
33      * //TODO: 需要处理集群复制的问题
34      */

35     private transient Object JavaDoc targetObject = null;
36
37     private boolean clustable = false;
38
39     public AbstractInvocation(ObjectId objectId, String JavaDoc methodHash, Object JavaDoc[] args) {
40         this.objectId = objectId;
41         this.methodHash = methodHash;
42         this.args = args;
43     }
44
45     public ObjectId getObjectId() {
46         return objectId;
47     }
48
49     public String JavaDoc getMethodHash() {
50         return methodHash;
51     }
52
53     public Object JavaDoc[] getArgs() {
54         return args;
55     }
56
57     public void setMethod(Method JavaDoc method) {
58         this.method = method;
59     }
60
61     public Method JavaDoc getMethod() {
62         return method;
63     }
64
65     public String JavaDoc toString() {
66         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
67         sb.append("Invocation {type=");
68         sb.append(this.getClass().getName());
69         sb.append(",objectId=");
70         sb.append(objectId);
71         if(method != null){
72             sb.append(", method=");
73             sb.append(method.getName());
74         }
75         sb.append(", methodHash=");
76         sb.append(methodHash);
77         sb.append("}");
78         return sb.toString();
79     }
80
81     public synchronized Object JavaDoc getTargetObject() {
82         if(( targetObject != null) && (targetObject instanceof MarshalledObject JavaDoc)) {
83             targetObject = Marshaller.unmarshall(targetObject);
84         }
85         return targetObject;
86     }
87
88     public void setTargetObject(Object JavaDoc targetObject) {
89         this.targetObject = targetObject;
90     }
91
92     public boolean isClustable() {
93         return clustable;
94     }
95
96     public void setClustable(boolean clustable) {
97         this.clustable = clustable;
98     }
99
100     private void writeObject(java.io.ObjectOutputStream JavaDoc out)
101             throws IOException JavaDoc {
102         out.defaultWriteObject();
103         out.writeObject(Marshaller.marshall(targetObject));
104     }
105
106     private void readObject(java.io.ObjectInputStream JavaDoc in)
107             throws IOException JavaDoc, ClassNotFoundException JavaDoc {
108         in.defaultReadObject();
109         targetObject = in.readObject();
110     }
111
112
113     public static void main(String JavaDoc[] args) {
114
115     }
116 }
117
Popular Tags