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: import javax.ejb.RemoveException;
22:
23: public class StatefulEJBHomeHandler extends EJBHomeHandler {
24:
25: public StatefulEJBHomeHandler() {
26: }
27:
28: public StatefulEJBHomeHandler(EJBMetaDataImpl ejb,
29: ServerMetaData server, ClientMetaData client) {
30: super (ejb, server, client);
31: }
32:
33: protected Object findX(Method method, Object[] args, Object proxy)
34: throws Throwable {
35: throw new SystemException(new UnsupportedOperationException(
36: "Stateful beans may not have find methods"));
37: }
38:
39: protected Object removeByPrimaryKey(Method method, Object[] args,
40: Object proxy) throws Throwable {
41: throw new ApplicationException(
42: new RemoveException(
43: "Session objects are private resources and do not have primary keys"));
44: }
45:
46: protected Object removeWithHandle(Method method, Object[] args,
47: Object proxy) throws Throwable {
48:
49: EJBObjectHandle handle = (EJBObjectHandle) args[0];
50:
51: if (handle == null)
52: throw new NullPointerException("The handle is null");
53:
54: EJBObjectHandler handler = handle.handler;
55: Object primKey = handler.primaryKey;
56:
57: if (!handler.ejb.deploymentID.equals(this .ejb.deploymentID)) {
58: throw new SystemException(new IllegalArgumentException(
59: "The handle is not from the same deployment"));
60: }
61:
62: EJBRequest req = new EJBRequest(
63: RequestMethodConstants.EJB_HOME_REMOVE_BY_HANDLE, ejb,
64: method, args, primKey);
65:
66: EJBResponse res = request(req);
67:
68: switch (res.getResponseCode()) {
69: case ResponseCodes.EJB_ERROR:
70: throw new SystemError((ThrowableArtifact) res.getResult());
71: case ResponseCodes.EJB_SYS_EXCEPTION:
72: throw new SystemException((ThrowableArtifact) res
73: .getResult());
74: case ResponseCodes.EJB_APP_EXCEPTION:
75: throw new ApplicationException((ThrowableArtifact) res
76: .getResult());
77: case ResponseCodes.EJB_OK:
78: invalidateAllHandlers(handler.getRegistryId());
79: handler.invalidateReference();
80: return null;
81: default:
82: throw new RemoteException(
83: "Received invalid response code from server: "
84: + res.getResponseCode());
85: }
86:
87: }
88: }
|