01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.client;
17:
18: import java.lang.reflect.Method;
19: import java.rmi.RemoteException;
20:
21: public class StatefulEJBObjectHandler extends EJBObjectHandler {
22:
23: public StatefulEJBObjectHandler() {
24: }
25:
26: public StatefulEJBObjectHandler(EJBMetaDataImpl ejb,
27: ServerMetaData server, ClientMetaData client) {
28: super (ejb, server, client);
29: }
30:
31: public StatefulEJBObjectHandler(EJBMetaDataImpl ejb,
32: ServerMetaData server, ClientMetaData client,
33: Object primaryKey) {
34: super (ejb, server, client, primaryKey);
35: registerHandler(primaryKey, this );
36: }
37:
38: public Object getRegistryId() {
39: return primaryKey;
40: }
41:
42: protected Object getPrimaryKey(Method method, Object[] args,
43: Object proxy) throws Throwable {
44: throw new RemoteException(
45: "Session objects are private resources and do not have primary keys");
46: }
47:
48: protected Object isIdentical(Method method, Object[] args,
49: Object proxy) throws Throwable {
50: if (args[0] == null)
51: return Boolean.FALSE;
52:
53: EJBObjectProxy ejbObject = (EJBObjectProxy) args[0];
54: EJBObjectHandler that = ejbObject.getEJBObjectHandler();
55:
56: return new Boolean(this .primaryKey.equals(that.primaryKey));
57: }
58:
59: protected Object equals(Method method, Object[] args, Object proxy)
60: throws Throwable {
61: return isIdentical(method, args, proxy);
62: }
63:
64: protected Object remove(Method method, Object[] args, Object proxy)
65: throws Throwable {
66:
67: EJBRequest req = new EJBRequest(
68: RequestMethodConstants.EJB_OBJECT_REMOVE, ejb, method,
69: args, primaryKey);
70:
71: EJBResponse res = request(req);
72:
73: if (ResponseCodes.EJB_ERROR == res.getResponseCode()) {
74: throw (Throwable) res.getResult();
75: }
76:
77: invalidateAllHandlers(this.getRegistryId());
78: this.invalidateReference();
79: return null;
80: }
81:
82: }
|