View Javadoc

1   /**
2    *
3    * Copyright 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 org.apache.geronimo.gbean.DynamicGBean;
21  import org.apache.geronimo.gbean.DynamicGBeanDelegate;
22  import org.apache.geronimo.gbean.GBeanInfo;
23  import org.apache.geronimo.gbean.GBeanInfoBuilder;
24  import org.apache.geronimo.gbean.GBeanLifecycle;
25  import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
26  import org.apache.geronimo.management.geronimo.JCAResourceAdapter;
27  
28  import javax.resource.spi.ResourceAdapter;
29  import javax.resource.spi.ResourceAdapterAssociation;
30  import javax.resource.spi.XATerminator;
31  import javax.resource.spi.work.WorkManager;
32  
33  /**
34   * 
35   * @version $Revision: 430508 $
36   */
37  public class ResourceAdapterWrapperGBean extends ResourceAdapterWrapper implements GBeanLifecycle, DynamicGBean, JCAResourceAdapter {
38  
39      private final DynamicGBeanDelegate delegate;
40      private final String objectName;
41  
42      public ResourceAdapterWrapperGBean() {
43          delegate=null;
44          objectName = null;
45      }
46  
47      public ResourceAdapterWrapperGBean(String resourceAdapterClass, WorkManager workManager, XATerminator xaTerminator, ClassLoader cl, String objectName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
48          super(resourceAdapterClass, new GeronimoBootstrapContext (workManager, xaTerminator), cl);
49          delegate = new DynamicGBeanDelegate();
50          delegate.addAll(resourceAdapter);
51          this.objectName = objectName;
52      }
53  
54      public Object getAttribute(String name) throws Exception {
55          return delegate.getAttribute(name);
56      }
57  
58      public void setAttribute(String name, Object value) throws Exception {
59          delegate.setAttribute(name, value);
60      }
61  
62      public Object invoke(String name, Object[] arguments, String[] types) throws Exception {
63          //we have no dynamic operations
64          return null;
65      }
66  
67      public String getObjectName() {
68          return objectName;
69      }
70  
71      public boolean isStateManageable() {
72          return false;
73      }
74  
75      public boolean isStatisticsProvider() {
76          return false;
77      }
78  
79      public boolean isEventProvider() {
80          return false;
81      }
82  
83      public static final GBeanInfo GBEAN_INFO;
84  
85      static {
86          GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(ResourceAdapterWrapperGBean.class, NameFactory.JCA_RESOURCE_ADAPTER);
87          infoBuilder.addAttribute("resourceAdapterClass", String.class, true);
88          infoBuilder.addAttribute("classLoader", ClassLoader.class, false);
89          infoBuilder.addAttribute("objectName", String.class, false);
90  
91          infoBuilder.addReference("WorkManager", WorkManager.class, NameFactory.JCA_WORK_MANAGER);
92          infoBuilder.addReference("XATerminator", XATerminator.class, NameFactory.JCA_WORK_MANAGER);
93  
94          infoBuilder.addOperation("registerResourceAdapterAssociation", new Class[]{ResourceAdapterAssociation.class});
95  
96          infoBuilder.addInterface(ResourceAdapter.class);
97          infoBuilder.addInterface(JCAResourceAdapter.class);
98  
99          infoBuilder.setConstructor(new String[]{"resourceAdapterClass", "WorkManager", "XATerminator", "classLoader", "objectName"});
100 
101         GBEAN_INFO = infoBuilder.getBeanInfo();
102     }
103 
104     public static GBeanInfo getGBeanInfo() {
105         return GBEAN_INFO;
106     }
107 
108 }