001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JEJBRequest.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.rpc;
025:
026: import static org.ow2.easybeans.util.marshalling.Serialization.loadObject;
027: import static org.ow2.easybeans.util.marshalling.Serialization.storeObject;
028:
029: import java.io.IOException;
030:
031: import org.ow2.easybeans.rpc.api.EJBRequest;
032: import org.ow2.easybeans.rpc.api.RPCException;
033:
034: /**
035: * Implementation of the EJBRequest interface.
036: * @author Florent Benoit
037: */
038: public class JEJBRequest implements EJBRequest {
039:
040: /**
041: * Id for serializable class.
042: */
043: private static final long serialVersionUID = -3588466669344863787L;
044:
045: /**
046: * Name of the method.
047: */
048: private String methodName = null;
049:
050: /**
051: * Hashing of the method.
052: * @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/rmi/spec/rmi-stubs24.html">Method hashing of RMI</a>
053: */
054: private long methodHash;
055:
056: /**
057: * Arguments of the method.
058: */
059: private byte[] byteArgs;
060:
061: /**
062: * Arguments of the method (not serializable).
063: */
064: private transient Object[] args = null;
065:
066: /**
067: * Id of the container that will be used on the remote side.
068: */
069: private String containerId = null;
070:
071: /**
072: * Name of the factory for which is dedicated this request.
073: */
074: private String factoryName = null;
075:
076: /**
077: * Id of the bean (ie, for stateful).
078: */
079: private Long beanId = null;
080:
081: /**
082: * Builds a new request that will be sent on remote side.
083: * @param methodName the name of the method.
084: * @param methodHash the hash of the method.
085: * @param args the arguments of the method.
086: * @param containerId id of the remote container.
087: * @param factoryName the name of the remote factory.
088: * @param beanId the bean identifier.
089: * @throws RPCException if the request cannot be built.
090: */
091: public JEJBRequest(final String methodName, final long methodHash,
092: final Object[] args, final String containerId,
093: final String factoryName, final Long beanId)
094: throws RPCException {
095: this .methodHash = methodHash;
096: this .methodName = methodName;
097:
098: try {
099: byteArgs = storeObject(args);
100: } catch (IOException e) {
101: throw new RPCException(
102: "Cannot serialize the arguments of the request.", e);
103: }
104: this .args = args;
105: this .containerId = containerId;
106: this .factoryName = factoryName;
107: this .beanId = beanId;
108: }
109:
110: /**
111: * @return name of the method
112: */
113: public String getMethodName() {
114: return methodName;
115: }
116:
117: /**
118: * @see <a
119: * href="http://java.sun.com/j2se/1.5.0/docs/guide/rmi/spec/rmi-stubs24.html">Method
120: * hashing of RMI</a>
121: * @return the hash of this method
122: */
123: public long getMethodHash() {
124: return methodHash;
125: }
126:
127: /**
128: * @return the argument of the request (send by the client).
129: * @throws IllegalStateException if arguments were serialized and not available.
130: */
131: public Object[] getMethodArgs() throws IllegalStateException {
132: // try to read object from array of bytes
133: try {
134: args = (Object[]) loadObject(byteArgs);
135: } catch (IOException e) {
136: throw new IllegalStateException(
137: "Cannot get arguments of the request", e);
138: } catch (ClassNotFoundException e) {
139: throw new IllegalStateException(
140: "Cannot get arguments of the request", e);
141: }
142: return args;
143: }
144:
145: /**
146: * @return the container id of this request. It will be used to know the
147: * container for which this request is sent.
148: */
149: public String getContainerId() {
150: return containerId;
151: }
152:
153: /**
154: * @return the factory name of the container.
155: */
156: public String getFactory() {
157: return factoryName;
158: }
159:
160: /**
161: * @return the id of the bean.
162: */
163: public Long getBeanId() {
164: return beanId;
165: }
166:
167: }
|