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.geronimo.corba;
17:
18: import org.omg.CORBA.Any;
19: import org.omg.CORBA.ORB;
20: import org.omg.CORBA.Policy;
21: import org.omg.PortableServer.IdAssignmentPolicyValue;
22: import org.omg.PortableServer.ImplicitActivationPolicyValue;
23: import org.omg.PortableServer.POA;
24: import org.omg.PortableServer.POAPackage.ObjectNotActive;
25: import org.omg.PortableServer.POAPackage.WrongPolicy;
26: import org.omg.PortableServer.RequestProcessingPolicyValue;
27: import org.omg.PortableServer.ServantRetentionPolicyValue;
28: import org.apache.openejb.InterfaceType;
29: import org.apache.geronimo.corba.transaction.ServerTransactionPolicyFactory;
30:
31: /**
32: * @version $Revision: 497125 $ $Date: 2007-01-17 10:51:30 -0800 (Wed, 17 Jan 2007) $
33: */
34: public final class AdapterStateless extends Adapter {
35: private final POA poa;
36: private final byte[] object_id;
37: private final org.omg.CORBA.Object objectReference;
38:
39: public AdapterStateless(TSSLink tssLink, ORB orb, POA parentPOA,
40: Policy securityPolicy) throws CORBAException {
41: super (tssLink, orb, parentPOA, securityPolicy);
42: Any any = orb.create_any();
43: any.insert_Value(tssLink.getRemoteTxPolicyConfig());
44:
45: try {
46: Policy[] policies = new Policy[] {
47: securityPolicy,
48: orb.create_policy(
49: ServerTransactionPolicyFactory.POLICY_TYPE,
50: any),
51: // homePOA.create_lifespan_policy(LifespanPolicyValue.TRANSIENT),
52: homePOA
53: .create_request_processing_policy(RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY),
54: homePOA
55: .create_servant_retention_policy(ServantRetentionPolicyValue.RETAIN),
56: homePOA
57: .create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID),
58: homePOA
59: .create_implicit_activation_policy(ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION), };
60: // make sure we create this with the appropriate ORB-specific policies.
61: policies = tssLink.addPolicyOverrides(policies);
62: poa = homePOA.create_POA(tssLink.getContainerId(), homePOA
63: .the_POAManager(), policies);
64:
65: poa.the_POAManager().activate();
66:
67: StandardServant servant = new StandardServant(orb,
68: InterfaceType.EJB_OBJECT, tssLink.getDeployment());
69:
70: poa.activate_object_with_id(object_id = tssLink
71: .getContainerId().getBytes(), servant);
72: objectReference = poa.servant_to_reference(servant);
73: } catch (Exception e) {
74: throw new CORBAException("Unable to activate EJB "
75: + tssLink.getContainerId() + " as CORBA object", e);
76: }
77: }
78:
79: public void stop() throws CORBAException {
80: try {
81: poa.deactivate_object(object_id);
82: poa.destroy(true, true);
83: super .stop();
84: } catch (ObjectNotActive e) {
85: throw new CORBAException("Unable to activate EJB "
86: + tssLink.getContainerId() + " as CORBA object", e);
87: } catch (WrongPolicy e) {
88: throw new CORBAException("Unable to activate EJB "
89: + tssLink.getContainerId() + " as CORBA object", e);
90: }
91: }
92:
93: public org.omg.CORBA.Object genObjectReference(Object primaryKey) {
94: return objectReference;
95: }
96: }
|