View Javadoc

1   /**
2    *
3    * Copyright 2003-2005 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     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   */
17  
18  package org.apache.geronimo.connector;
19  
20  import javax.resource.ResourceException;
21  import javax.resource.spi.ActivationSpec;
22  import javax.resource.spi.BootstrapContext;
23  import javax.resource.spi.ResourceAdapter;
24  import javax.resource.spi.ResourceAdapterAssociation;
25  import javax.resource.spi.ResourceAdapterInternalException;
26  import javax.resource.spi.endpoint.MessageEndpointFactory;
27  import javax.transaction.xa.XAResource;
28  
29  /**
30   * Dynamic GBean wrapper around a ResourceAdapter object, exposing the config-properties as
31   * GBean attributes.
32   *
33   * @version $Rev: 430508 $ $Date: 2006-08-10 12:56:47 -0700 (Thu, 10 Aug 2006) $
34   */
35  public class ResourceAdapterWrapper implements ResourceAdapter {
36  
37      private final String resourceAdapterClass;
38  
39      private final BootstrapContext bootstrapContext;
40  
41      protected final ResourceAdapter resourceAdapter;
42  
43  
44      /**
45       *  default constructor for enhancement proxy endpoint
46       */
47      public ResourceAdapterWrapper() {
48          this.resourceAdapterClass = null;
49          this.bootstrapContext = null;
50          this.resourceAdapter = null;
51      }
52  
53      public ResourceAdapterWrapper(String resourceAdapterClass,
54              BootstrapContext bootstrapContext,
55              ClassLoader cl) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
56          this.resourceAdapterClass = resourceAdapterClass;
57          this.bootstrapContext = bootstrapContext;
58          Class clazz = cl.loadClass(resourceAdapterClass);
59          resourceAdapter = (ResourceAdapter) clazz.newInstance();
60      }
61      
62      public ResourceAdapterWrapper(ResourceAdapter resourceAdapter, BootstrapContext bootstrapContext) {
63          this.resourceAdapterClass = resourceAdapter.getClass().getName();
64          this.bootstrapContext = bootstrapContext;
65          this.resourceAdapter = resourceAdapter;
66      }
67  
68      public String getResourceAdapterClass() {
69          return resourceAdapterClass;
70      }
71  
72      public void registerResourceAdapterAssociation(final ResourceAdapterAssociation resourceAdapterAssociation) throws ResourceException {
73          resourceAdapterAssociation.setResourceAdapter(resourceAdapter);
74      }
75  
76      public void start(BootstrapContext ctx) throws ResourceAdapterInternalException {
77          throw new IllegalStateException("Don't call this");
78      }
79  
80      public void stop() {
81          throw new IllegalStateException("Don't call this");
82      }
83  
84      //endpoint handling
85      public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
86          resourceAdapter.endpointActivation(messageEndpointFactory, activationSpec);
87      }
88  
89      public void endpointDeactivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) {
90          resourceAdapter.endpointDeactivation(messageEndpointFactory, activationSpec);
91      }
92  
93      public XAResource[] getXAResources(ActivationSpec[] specs) throws ResourceException {
94          return resourceAdapter.getXAResources(specs);
95      }
96  
97      public void doStart() throws Exception {
98          resourceAdapter.start(bootstrapContext);
99      }
100 
101     public void doStop() {
102         resourceAdapter.stop();
103     }
104 
105     public void doFail() {
106         resourceAdapter.stop();
107     }
108 
109 }