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: */package org.apache.geronimo.connector.deployment.dconfigbean;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020: import javax.enterprise.deploy.model.DDBean;
021: import javax.enterprise.deploy.spi.DConfigBean;
022: import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
023:
024: import org.apache.geronimo.deployment.plugin.DConfigBeanSupport;
025: import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
026: import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
027: import org.apache.geronimo.xbeans.geronimo.GerOutboundResourceadapterType;
028: import org.apache.geronimo.xbeans.geronimo.GerResourceadapterInstanceType;
029: import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
030: import org.apache.xmlbeans.SchemaTypeLoader;
031:
032: /**
033: *
034: *
035: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
036: *
037: * */
038: public class ResourceAdapterDConfigBean extends DConfigBeanSupport {
039:
040: private final static String[][] RESOURCE_ADAPTER_XPATHS = {
041: { "config-property" },
042: { "outbound-resourceadapter", "connection-definition" },
043: { "adminobject" } };
044: private Map configPropertiesMap = new HashMap();
045: private Map connectionDefinitionsMap = new HashMap();
046: private Map adminObjectsMap = new HashMap();
047:
048: public ResourceAdapterDConfigBean(DDBean ddBean,
049: final GerResourceadapterType resourceadapter) {
050: super (ddBean, resourceadapter);
051: if (getResourceadapterInstance() == null) {
052: resourceadapter.addNewResourceadapterInstance();
053: }
054: ConfigPropertiesHelper.initializeConfigSettings(
055: ddBean,
056: new ConfigPropertiesHelper.ConfigPropertiesSource() {
057: public GerConfigPropertySettingType[] getConfigPropertySettingArray() {
058: return getResourceadapterInstance()
059: .getConfigPropertySettingArray();
060: }
061:
062: public GerConfigPropertySettingType addNewConfigPropertySetting() {
063: return getResourceadapterInstance()
064: .addNewConfigPropertySetting();
065: }
066:
067: public void removeConfigPropertySetting(int j) {
068: }
069:
070: public ConfigPropertySettings[] getConfigPropertySettings() {
071: return new ConfigPropertySettings[0];
072: }
073:
074: public void setConfigPropertySettings(
075: ConfigPropertySettings[] configs) {
076: }
077:
078: }, configPropertiesMap, "config-property",
079: "config-property-name");
080: //initialize connection definitions
081: GerOutboundResourceadapterType outboundResourceadapter = resourceadapter
082: .getOutboundResourceadapter();
083: if (outboundResourceadapter == null) {
084: outboundResourceadapter = resourceadapter
085: .addNewOutboundResourceadapter();
086: }
087: DDBean[] connectionDefinitionDDBeans = ddBean
088: .getChildBean(getXpaths()[1]);
089: GerConnectionDefinitionType[] connectionDefinitions = outboundResourceadapter
090: .getConnectionDefinitionArray();
091:
092: if (connectionDefinitions.length == 0) {
093: //we are new
094: for (int i = 0; i < connectionDefinitionDDBeans.length; i++) {
095: DDBean connectionDefinitionDdBean = connectionDefinitionDDBeans[i];
096: GerConnectionDefinitionType connectionDefinition = outboundResourceadapter
097: .addNewConnectionDefinition();
098: String connectionfactoryInterface = connectionDefinitionDdBean
099: .getText("connectionfactory-interface")[0];
100: ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean = new ConnectionDefinitionDConfigBean(
101: connectionDefinitionDdBean,
102: connectionDefinition);
103: connectionDefinitionsMap.put(
104: connectionfactoryInterface,
105: connectionDefinitionDConfigBean);
106: }
107: } else {
108: //we are read in from xml. Check correct length
109: assert connectionDefinitionDDBeans.length == connectionDefinitions.length;
110: for (int i = 0; i < connectionDefinitionDDBeans.length; i++) {
111: DDBean connectionDefinitionDdBean = connectionDefinitionDDBeans[i];
112: GerConnectionDefinitionType connectionDefinition = connectionDefinitions[i];
113: String connectionfactoryInterface = connectionDefinitionDdBean
114: .getText("connectionfactory-interface")[0];
115: assert connectionfactoryInterface
116: .equals(connectionDefinition
117: .getConnectionfactoryInterface());
118: ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean = new ConnectionDefinitionDConfigBean(
119: connectionDefinitionDdBean,
120: connectionDefinition);
121: connectionDefinitionsMap.put(
122: connectionfactoryInterface,
123: connectionDefinitionDConfigBean);
124: }
125: }
126:
127: //admin objects
128: // DDBean[] adminObjecDdBeans = ddBean.getChildBean(getXpaths()[2]);
129: // GerAdminobjectType[] adminobjectTypes = getResourceadapter().getAdminobjectArray();
130: //
131: // if (adminobjectTypes.length == 0) {
132: // //we are new
133: // for (int i = 0; i < adminObjecDdBeans.length; i++) {
134: // DDBean adminObjectDdBean = adminObjecDdBeans[i];
135: // GerAdminobjectType adminobjectType = getResourceadapter().addNewAdminobject();
136: // String adminObjectInterface = adminObjectDdBean.getText("adminobject-interface")[0];
137: // String adminObjectClass = adminObjectDdBean.getText("adminobject-class")[0];
138: // AdminObjectDConfigBean adminObjectDConfigBean = new AdminObjectDConfigBean(adminObjectDdBean, adminobjectType);
139: // adminObjectsMap.put(new Key(adminObjectInterface, adminObjectClass), adminObjectDConfigBean);
140: // }
141: // } else {
142: // //we are read in from xml. Check correct length
143: // assert adminObjecDdBeans.length == adminobjectTypes.length;
144: // for (int i = 0; i < adminObjecDdBeans.length; i++) {
145: // DDBean adminObjectDdBean = adminObjecDdBeans[i];
146: // GerAdminobjectType adminobjectType = adminobjectTypes[i];
147: // String adminObjectInterface = adminObjectDdBean.getText("adminobject-interface")[0];
148: // assert(adminObjectInterface.equals(adminobjectType.getAdminobjectInterface().getStringValue()));
149: // String adminObjectClass = adminObjectDdBean.getText("adminobject-class")[0];
150: // assert(adminObjectClass.equals(adminobjectType.getAdminobjectClass().getStringValue()));
151: // AdminObjectDConfigBean adminObjectDConfigBean = new AdminObjectDConfigBean(adminObjectDdBean, adminobjectType);
152: // adminObjectsMap.put(new Key(adminObjectInterface, adminObjectClass), adminObjectDConfigBean);
153: //
154: // }
155: // }
156:
157: }
158:
159: GerResourceadapterType getResourceadapter() {
160: return (GerResourceadapterType) getXmlObject();
161: }
162:
163: private GerResourceadapterInstanceType getResourceadapterInstance() {
164: return getResourceadapter().getResourceadapterInstance();
165: }
166:
167: public String getResourceAdapterName() {
168: return getResourceadapterInstance().getResourceadapterName();
169: }
170:
171: public void setResourceAdapterName(String resourceAdapterName) {
172: getResourceadapterInstance().setResourceadapterName(
173: resourceAdapterName);
174: }
175:
176: public String getWorkManager() {
177: if (getResourceadapterInstance() == null
178: || getResourceadapterInstance().getWorkmanager() == null) {
179: return null;
180: }
181: return getResourceadapterInstance().getWorkmanager()
182: .getGbeanLink();
183: }
184:
185: public void setWorkManager(String workManager) {
186: if (getResourceadapterInstance() == null) {
187: getResourceadapter().addNewResourceadapterInstance();
188: }
189: if (getResourceadapterInstance().getWorkmanager() == null) {
190: getResourceadapterInstance().addNewWorkmanager();
191: }
192: getResourceadapterInstance().getWorkmanager().setGbeanLink(
193: workManager);
194: }
195:
196: public DConfigBean getDConfigBean(DDBean bean)
197: throws ConfigurationException {
198: String xpath = bean.getXpath();
199: String[] xpaths = getXpaths();
200: if (xpath.equals(xpaths[0])) {
201: //resource adapter config property
202: String configPropertyName = bean
203: .getText("config-property-name")[0];
204: ConfigPropertySettingDConfigBean configPropertySetting = (ConfigPropertySettingDConfigBean) configPropertiesMap
205: .get(configPropertyName);
206: assert configPropertySetting != null;
207: return configPropertySetting;
208: }
209: if (xpath.equals(xpaths[1])) {
210: //connection definition
211: String connectionFactoryInterface = bean
212: .getText("connectionfactory-interface")[0];
213: ConnectionDefinitionDConfigBean connectionDefinition = (ConnectionDefinitionDConfigBean) connectionDefinitionsMap
214: .get(connectionFactoryInterface);
215: assert connectionDefinition != null;
216: return connectionDefinition;
217: }
218: if (xpath.equals(xpaths[2])) {
219: //admin objects
220: String adminObjectInterface = bean
221: .getText("adminobject-interface")[0];
222: String adminObjectClass = bean.getText("adminobject-class")[0];
223: AdminObjectDConfigBean adminObject = (AdminObjectDConfigBean) adminObjectsMap
224: .get(new Key(adminObjectInterface, adminObjectClass));
225: assert adminObject != null;
226: return adminObject;
227: }
228: return null;
229: }
230:
231: public String[] getXpaths() {
232: return getXPathsForJ2ee_1_4(RESOURCE_ADAPTER_XPATHS);
233: }
234:
235: protected SchemaTypeLoader getSchemaTypeLoader() {
236: return ResourceAdapterDConfigRoot.SCHEMA_TYPE_LOADER;
237: }
238:
239: //from doubleKeyedHashMap, currently in transaction module
240: private final static class Key {
241: private final Object part1;
242: private final Object part2;
243:
244: public Key(Object part1, Object part2) {
245: this .part1 = part1;
246: this .part2 = part2;
247: }
248:
249: public int hashCode() {
250: return part1.hashCode() ^ part2.hashCode();
251: }
252:
253: public boolean equals(Object obj) {
254: if (obj instanceof Key) {
255: Key other = (Key) obj;
256: return this .part1.equals(other.part1)
257: && this .part2.equals(other.part2);
258: } else {
259: return false;
260: }
261: }
262: }
263: }
|