001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. 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 javax.resource.ResourceException; 021 import javax.resource.spi.ActivationSpec; 022 import javax.resource.spi.ResourceAdapter; 023 import javax.resource.spi.endpoint.MessageEndpointFactory; 024 025 /** 026 * Wrapper for ActivationSpec instances. 027 * The framework assumes all RequiredConfigProperties are of type String, although it 028 * is unclear if this is required by the spec. 029 * 030 * @version $Rev: 550546 $ $Date: 2007-06-25 12:52:11 -0400 (Mon, 25 Jun 2007) $ 031 */ 032 public class ActivationSpecWrapper { 033 034 protected final ActivationSpec activationSpec; 035 036 private final ResourceAdapterWrapper resourceAdapterWrapper; 037 private final String containerId; 038 039 /** 040 * Default constructor required when a class is used as a GBean Endpoint. 041 */ 042 public ActivationSpecWrapper() { 043 activationSpec = null; 044 containerId = null; 045 resourceAdapterWrapper = null; 046 } 047 048 /** 049 * Normal managed constructor. 050 * 051 * @param activationSpecClass Class of admin object to be wrapped. 052 * @throws IllegalAccessException 053 * @throws InstantiationException 054 */ 055 public ActivationSpecWrapper(final String activationSpecClass, 056 final String containerId, 057 final ResourceAdapterWrapper resourceAdapterWrapper, 058 final ClassLoader cl) throws IllegalAccessException, InstantiationException, ClassNotFoundException { 059 Class clazz = cl.loadClass(activationSpecClass); 060 this.activationSpec = (ActivationSpec) clazz.newInstance(); 061 this.containerId = containerId; 062 this.resourceAdapterWrapper = resourceAdapterWrapper; 063 } 064 065 /** 066 */ 067 public ActivationSpecWrapper(ActivationSpec activationSpec, ResourceAdapterWrapper resourceAdapterWrapper) { 068 this.activationSpec = activationSpec; 069 this.resourceAdapterWrapper = resourceAdapterWrapper; 070 this.containerId = null; 071 } 072 073 /** 074 * Returns class of wrapped ActivationSpec. 075 * 076 * @return class of wrapped ActivationSpec 077 */ 078 // public String getActivationSpecClass() { 079 // return activationSpecClass; 080 // } 081 082 public String getContainerId() { 083 return containerId; 084 } 085 086 public ResourceAdapterWrapper getResourceAdapterWrapper() { 087 return resourceAdapterWrapper; 088 } 089 090 091 //GBeanLifecycle implementation 092 public void activate(final MessageEndpointFactory messageEndpointFactory) throws ResourceException { 093 ResourceAdapter resourceAdapter = activationSpec.getResourceAdapter(); 094 if (resourceAdapter == null) { 095 resourceAdapterWrapper.registerResourceAdapterAssociation(activationSpec); 096 } 097 resourceAdapterWrapper.endpointActivation(messageEndpointFactory, activationSpec); 098 resourceAdapterWrapper.doRecovery(activationSpec, containerId); 099 } 100 101 public void deactivate(final MessageEndpointFactory messageEndpointFactory) { 102 ResourceAdapter resourceAdapter = activationSpec.getResourceAdapter(); 103 if (resourceAdapter != null) { 104 resourceAdapterWrapper.endpointDeactivation(messageEndpointFactory, activationSpec); 105 } else { 106 //this should never happen, activation spec should have been registered with r.a. 107 throw new IllegalStateException("ActivationSpec was never registered with ResourceAdapter"); 108 } 109 } 110 111 }