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 package org.apache.geronimo.connector.deployment.jsr88;
018
019 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterInstanceType;
020 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
021 import org.apache.geronimo.naming.deployment.jsr88.GBeanLocator;
022 import org.apache.xmlbeans.SchemaTypeLoader;
023 import javax.enterprise.deploy.model.DDBean;
024
025 /**
026 * Represents /connector/resourceadapter/resourceadapter-instance in the
027 * Geronimo Connector deployment plan. The settings here correspond to
028 * /connector/resourceadapter in the J2EE plan, but since there can be
029 * several instances per resource adapter, it's not 1:1 and this is not
030 * a DConfigBean.
031 *
032 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
033 */
034 public class ResourceAdapterInstance extends ConfigHolder {
035 private DDBean resourceAdapter;
036 private GBeanLocator workManager;
037
038 /**
039 * Present so a tool can create a new one
040 */
041 public ResourceAdapterInstance() {
042 }
043
044 public ResourceAdapterInstance(DDBean resourceAdapter, GerResourceadapterInstanceType instance) {
045 configure(resourceAdapter, instance);
046 }
047
048 protected GerResourceadapterInstanceType getResourceAdapterInstance() {
049 return (GerResourceadapterInstanceType) getXmlObject();
050 }
051
052 public void reconfigure() {
053 configure(resourceAdapter, getResourceAdapterInstance());
054 }
055
056 void configure(DDBean resourceAdapter, GerResourceadapterInstanceType xml) {
057 this.resourceAdapter = resourceAdapter;
058 super.configure(resourceAdapter, xml);
059 }
060
061 protected GerConfigPropertySettingType createConfigProperty() {
062 return getResourceAdapterInstance().addNewConfigPropertySetting();
063 }
064
065 protected GerConfigPropertySettingType[] getConfigProperties() {
066 return getResourceAdapterInstance().getConfigPropertySettingArray();
067 }
068
069 protected void removeConfigProperty(int index) {
070 getResourceAdapterInstance().removeConfigPropertySetting(index);
071 }
072
073 // ----------------------- JavaBean Properties for /resourceadapter-instance ----------------------
074
075 public String getResourceAdapterName() {
076 return getResourceAdapterInstance().getResourceadapterName();
077 }
078
079 public void setResourceAdapterName(String name) {
080 String old = getResourceAdapterName();
081 getResourceAdapterInstance().setResourceadapterName(name);
082 pcs.firePropertyChange("resourceAdapterName", old, name);
083 }
084
085 public GBeanLocator getWorkManager() {
086 return workManager;
087 }
088
089 public void setWorkManager(GBeanLocator locator) {
090 GBeanLocator old = getWorkManager();
091 if(locator != null && !locator.configured()) {
092 if(getResourceAdapterInstance().getWorkmanager() != null) {
093 locator.configure(getResourceAdapterInstance().getWorkmanager());
094 } else {
095 locator.configure(getResourceAdapterInstance().addNewWorkmanager());
096 }
097 }
098 workManager = locator;
099 pcs.firePropertyChange("workManager", old, workManager);
100 }
101
102 // ----------------------- End of JavaBean Properties ----------------------
103
104 protected SchemaTypeLoader getSchemaTypeLoader() {
105 return Connector15DCBRoot.SCHEMA_TYPE_LOADER;
106 }
107 }