01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.core.mdb;
18:
19: import org.apache.openejb.DeploymentInfo;
20: import org.apache.openejb.core.CoreDeploymentInfo;
21: import org.apache.geronimo.transaction.manager.NamedXAResource;
22: import org.apache.geronimo.transaction.manager.WrapperNamedXAResource;
23:
24: import javax.resource.spi.UnavailableException;
25: import javax.resource.spi.ActivationSpec;
26: import javax.resource.spi.endpoint.MessageEndpoint;
27: import javax.resource.spi.endpoint.MessageEndpointFactory;
28: import javax.transaction.xa.XAResource;
29: import java.lang.reflect.Method;
30: import java.lang.reflect.Proxy;
31:
32: public class EndpointFactory implements MessageEndpointFactory {
33: private final ActivationSpec activationSpec;
34: private final MdbContainer container;
35: private final CoreDeploymentInfo deploymentInfo;
36: private final MdbInstanceFactory instanceFactory;
37: private final ClassLoader classLoader;
38: private final Class[] interfaces;
39: private final boolean txRecovery;
40:
41: public EndpointFactory(ActivationSpec activationSpec,
42: MdbContainer container, CoreDeploymentInfo deploymentInfo,
43: MdbInstanceFactory instanceFactory, boolean txRecovery) {
44: this .activationSpec = activationSpec;
45: this .container = container;
46: this .deploymentInfo = deploymentInfo;
47: this .instanceFactory = instanceFactory;
48: classLoader = container.getMessageListenerInterface()
49: .getClassLoader();
50: interfaces = new Class[] {
51: container.getMessageListenerInterface(),
52: MessageEndpoint.class };
53: this .txRecovery = txRecovery;
54: }
55:
56: public ActivationSpec getActivationSpec() {
57: return activationSpec;
58: }
59:
60: public MdbInstanceFactory getInstanceFactory() {
61: return instanceFactory;
62: }
63:
64: public MessageEndpoint createEndpoint(XAResource xaResource)
65: throws UnavailableException {
66: if (txRecovery) {
67: xaResource = new WrapperNamedXAResource(xaResource,
68: container.getContainerID().toString());
69: }
70: EndpointHandler endpointHandler = new EndpointHandler(
71: container, deploymentInfo, instanceFactory, xaResource);
72: MessageEndpoint messageEndpoint = (MessageEndpoint) Proxy
73: .newProxyInstance(classLoader, interfaces,
74: endpointHandler);
75: return messageEndpoint;
76: }
77:
78: public boolean isDeliveryTransacted(Method method)
79: throws NoSuchMethodException {
80: byte transactionAttribute = deploymentInfo
81: .getTransactionAttribute(method);
82: return DeploymentInfo.TX_REQUIRED == transactionAttribute;
83: }
84: }
|