001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.geronimo.corba;
021:
022: import java.io.Serializable;
023: import java.util.Map;
024: import java.util.HashMap;
025: import java.util.Iterator;
026: import java.lang.reflect.Method;
027:
028: import org.apache.geronimo.corba.util.Util;
029: import org.apache.geronimo.corba.transaction.ServerTransactionPolicyConfig;
030: import org.apache.geronimo.corba.transaction.OperationTxPolicy;
031: import org.apache.geronimo.corba.transaction.MappedServerTransactionPolicyConfig;
032: import org.apache.geronimo.corba.transaction.nodistributedtransactions.NoDTxServerTransactionPolicies;
033: import org.apache.geronimo.gbean.GBeanLifecycle;
034: import org.apache.geronimo.openejb.EjbDeployment;
035:
036: import org.omg.CORBA.Policy;
037:
038: /**
039: * @version $Rev: 497125 $ $Date: 2007-01-17 10:51:30 -0800 (Wed, 17 Jan 2007) $
040: */
041: public class TSSLink implements GBeanLifecycle {
042: private final TSSBean tssBean;
043: private final EjbDeployment ejb;
044: private final String[] jndiNames;
045:
046: public TSSLink() {
047: tssBean = null;
048: ejb = null;
049: jndiNames = null;
050: }
051:
052: public TSSLink(String[] jndiNames, TSSBean tssBean,
053: EjbDeployment ejb) {
054: if (tssBean == null) {
055: throw new NullPointerException("No TSSBean supplied");
056: }
057: if (ejb == null) {
058: throw new NullPointerException("No ejb supplied");
059: }
060: this .jndiNames = jndiNames;
061: this .tssBean = tssBean;
062: this .ejb = ejb;
063: }
064:
065: public void doStart() throws Exception {
066: if (tssBean != null) {
067: tssBean.registerContainer(this );
068: }
069: }
070:
071: public void doStop() throws Exception {
072: destroy();
073: }
074:
075: public void doFail() {
076: destroy();
077: }
078:
079: protected void destroy() {
080: if (tssBean != null) {
081: tssBean.unregisterContainer(this );
082: }
083: }
084:
085: public EjbDeployment getDeployment() {
086: return ejb;
087: }
088:
089: public String getContainerId() {
090: return ejb.getDeploymentId();
091: }
092:
093: public String[] getJndiNames() {
094: return jndiNames;
095: }
096:
097: /**
098: * CORBA home transaction import policy configuration
099: * @return home transaction import policy
100: */
101: public Serializable getHomeTxPolicyConfig() {
102: if (ejb.getHomeInterface() == null) {
103: return null;
104: }
105: Serializable policy = buildTransactionImportPolicy(ejb
106: .getHomeInterface());
107: return policy;
108: }
109:
110: /**
111: * CORBA remote transaction import policy configuration
112: * @return remote transaction import policy
113: */
114: public Serializable getRemoteTxPolicyConfig() {
115: if (ejb.getRemoteInterface() == null) {
116: return null;
117: }
118: Serializable policy = buildTransactionImportPolicy(ejb
119: .getRemoteInterface());
120: return policy;
121: }
122:
123: private Serializable buildTransactionImportPolicy(Class intf) {
124:
125: Map policies = new HashMap();
126:
127: Map methodToOperation = Util.mapMethodToOperation(intf);
128: for (Iterator iterator = methodToOperation.entrySet()
129: .iterator(); iterator.hasNext();) {
130: Map.Entry entry = (Map.Entry) iterator.next();
131: Method method = (Method) entry.getKey();
132: String operation = (String) entry.getValue();
133:
134: if (!ejb.isBeanManagedTransaction()) {
135: byte transactionAttribute = ejb
136: .getTransactionAttribute(method);
137: OperationTxPolicy operationTxPolicy = NoDTxServerTransactionPolicies
138: .getContainerTransactionPolicy(transactionAttribute);
139: policies.put(operation, operationTxPolicy);
140: } else {
141: OperationTxPolicy operationTxPolicy = NoDTxServerTransactionPolicies
142: .getBeanTransactionPolicy();
143: policies.put(operation, operationTxPolicy);
144: }
145: }
146: ServerTransactionPolicyConfig serverTransactionPolicyConfig = new MappedServerTransactionPolicyConfig(
147: policies);
148:
149: return serverTransactionPolicyConfig;
150: }
151:
152: /**
153: * Add the policy overrides (if any) to the list
154: * of policies used to create a POA instance.
155: *
156: * @param policies The base set of policies.
157: *
158: * @return A new Policy array with the overrides added. Returns
159: * the same array if no overrides are required.
160: */
161: public Policy[] addPolicyOverrides(Policy[] policies) {
162: return tssBean.addPolicyOverrides(policies);
163: }
164: }
|