KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > rpc > JEJBRequest


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JEJBRequest.java 357 2006-04-18 16:27:42Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.rpc;
27
28 import static org.objectweb.easybeans.util.marshalling.Serialization.loadObject;
29 import static org.objectweb.easybeans.util.marshalling.Serialization.storeObject;
30
31 import java.io.IOException JavaDoc;
32
33 import org.objectweb.easybeans.rpc.api.EJBRequest;
34 import org.objectweb.easybeans.rpc.api.RPCException;
35 /**
36  * Implementation of the EJBRequest interface.
37  * @author Florent Benoit
38  */

39 public class JEJBRequest implements EJBRequest {
40
41     /**
42      * Id for serializable class.
43      */

44     private static final long serialVersionUID = -3588466669344863787L;
45
46     /**
47      * Name of the method.
48      */

49     private String JavaDoc methodName = null;
50
51     /**
52      * Hashing of the method.
53       * @see <a HREF="http://java.sun.com/j2se/1.5.0/docs/guide/rmi/spec/rmi-stubs24.html">Method hashing of RMI</a>
54      */

55     private long methodHash;
56
57     /**
58      * Arguments of the method.
59      */

60     private byte[] byteArgs;
61
62     /**
63      * Arguments of the method (not serializable).
64      */

65     private transient Object JavaDoc[] args = null;
66
67     /**
68      * Id of the container that will be used on the remote side.
69      */

70     private String JavaDoc containerId = null;
71
72     /**
73      * Name of the factory for which is dedicated this request.
74      */

75     private String JavaDoc factoryName = null;
76
77     /**
78      * Id of the bean (ie, for stateful).
79      */

80     private Long JavaDoc beanId = null;
81
82     /**
83      * Builds a new request that will be sent on remote side.
84      * @param methodName the name of the method.
85      * @param methodHash the hash of the method.
86      * @param args the arguments of the method.
87      * @param containerId id of the remote container.
88      * @param factoryName the name of the remote factory.
89      * @param beanId the bean identifier.
90      * @throws RPCException if the request cannot be built.
91      */

92     public JEJBRequest(final String JavaDoc methodName, final long methodHash, final Object JavaDoc[] args, final String JavaDoc containerId,
93             final String JavaDoc factoryName, final Long JavaDoc beanId) throws RPCException {
94         this.methodHash = methodHash;
95         this.methodName = methodName;
96
97         try {
98             byteArgs = storeObject(args);
99         } catch (IOException JavaDoc e) {
100             throw new RPCException("Cannot serialize the arguments of the request.", e);
101         }
102         this.args = args;
103         this.containerId = containerId;
104         this.factoryName = factoryName;
105         this.beanId = beanId;
106     }
107
108     /**
109      * @return name of the method
110      */

111     public String JavaDoc getMethodName() {
112         return methodName;
113     }
114
115     /**
116      * @see <a
117      * HREF="http://java.sun.com/j2se/1.5.0/docs/guide/rmi/spec/rmi-stubs24.html">Method
118      * hashing of RMI</a>
119      * @return the hash of this method
120      */

121     public long getMethodHash() {
122         return methodHash;
123     }
124
125     /**
126      * @return the argument of the request (send by the client).
127      * @throws IllegalStateException if arguments were serialized and not available.
128      */

129     public Object JavaDoc[] getMethodArgs() throws IllegalStateException JavaDoc {
130         if (args == null) {
131             // try to read object from array of bytes
132
try {
133                 args = (Object JavaDoc[]) loadObject(byteArgs);
134             } catch (IOException JavaDoc e) {
135                 throw new IllegalStateException JavaDoc("Cannot get arguments of the request", e);
136             } catch (ClassNotFoundException JavaDoc e) {
137                 throw new IllegalStateException JavaDoc("Cannot get arguments of the request", e);
138             }
139         }
140         return args;
141     }
142
143     /**
144      * @return the container id of this request. It will be used to know the
145      * container for which this request is sent.
146      */

147     public String JavaDoc getContainerId() {
148         return containerId;
149     }
150
151     /**
152      * @return the factory name of the container.
153      */

154     public String JavaDoc getFactory() {
155         return factoryName;
156     }
157
158     /**
159      * @return the id of the bean.
160      */

161     public Long JavaDoc getBeanId() {
162         return beanId;
163     }
164
165 }
166
Popular Tags