001    /**
002     *
003     * Copyright 2005 The Apache Software Foundation
004     *
005     *  Licensed under the Apache License, Version 2.0 (the "License");
006     *  you may not use this file except in compliance with the License.
007     *  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.connector;
019    
020    import org.apache.geronimo.gbean.DynamicGBean;
021    import org.apache.geronimo.gbean.DynamicGBeanDelegate;
022    import org.apache.geronimo.gbean.GBeanInfo;
023    import org.apache.geronimo.gbean.GBeanInfoBuilder;
024    import org.apache.geronimo.gbean.GBeanLifecycle;
025    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
026    import org.apache.geronimo.management.geronimo.JCAResourceAdapter;
027    
028    import javax.resource.spi.ResourceAdapter;
029    import javax.resource.spi.ResourceAdapterAssociation;
030    import javax.resource.spi.XATerminator;
031    import javax.resource.spi.work.WorkManager;
032    
033    /**
034     * 
035     * @version $Revision: 430508 $
036     */
037    public class ResourceAdapterWrapperGBean extends ResourceAdapterWrapper implements GBeanLifecycle, DynamicGBean, JCAResourceAdapter {
038    
039        private final DynamicGBeanDelegate delegate;
040        private final String objectName;
041    
042        public ResourceAdapterWrapperGBean() {
043            delegate=null;
044            objectName = null;
045        }
046    
047        public ResourceAdapterWrapperGBean(String resourceAdapterClass, WorkManager workManager, XATerminator xaTerminator, ClassLoader cl, String objectName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
048            super(resourceAdapterClass, new GeronimoBootstrapContext (workManager, xaTerminator), cl);
049            delegate = new DynamicGBeanDelegate();
050            delegate.addAll(resourceAdapter);
051            this.objectName = objectName;
052        }
053    
054        public Object getAttribute(String name) throws Exception {
055            return delegate.getAttribute(name);
056        }
057    
058        public void setAttribute(String name, Object value) throws Exception {
059            delegate.setAttribute(name, value);
060        }
061    
062        public Object invoke(String name, Object[] arguments, String[] types) throws Exception {
063            //we have no dynamic operations
064            return null;
065        }
066    
067        public String getObjectName() {
068            return objectName;
069        }
070    
071        public boolean isStateManageable() {
072            return false;
073        }
074    
075        public boolean isStatisticsProvider() {
076            return false;
077        }
078    
079        public boolean isEventProvider() {
080            return false;
081        }
082    
083        public static final GBeanInfo GBEAN_INFO;
084    
085        static {
086            GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(ResourceAdapterWrapperGBean.class, NameFactory.JCA_RESOURCE_ADAPTER);
087            infoBuilder.addAttribute("resourceAdapterClass", String.class, true);
088            infoBuilder.addAttribute("classLoader", ClassLoader.class, false);
089            infoBuilder.addAttribute("objectName", String.class, false);
090    
091            infoBuilder.addReference("WorkManager", WorkManager.class, NameFactory.JCA_WORK_MANAGER);
092            infoBuilder.addReference("XATerminator", XATerminator.class, NameFactory.JCA_WORK_MANAGER);
093    
094            infoBuilder.addOperation("registerResourceAdapterAssociation", new Class[]{ResourceAdapterAssociation.class});
095    
096            infoBuilder.addInterface(ResourceAdapter.class);
097            infoBuilder.addInterface(JCAResourceAdapter.class);
098    
099            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    }