KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > deployment > dconfigbean > ResourceAdapterDConfigBean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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.deployment.dconfigbean;
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22 import javax.enterprise.deploy.model.DDBean JavaDoc;
23 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
24 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
25
26 import org.apache.geronimo.deployment.plugin.DConfigBeanSupport;
27 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
28 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
29 import org.apache.geronimo.xbeans.geronimo.GerOutboundResourceadapterType;
30 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterInstanceType;
31 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
32 import org.apache.xmlbeans.SchemaTypeLoader;
33
34 /**
35  *
36  *
37  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
38  *
39  * */

40 public class ResourceAdapterDConfigBean extends DConfigBeanSupport {
41
42     private final static String JavaDoc[][] RESOURCE_ADAPTER_XPATHS = {
43         {"config-property"},
44         {"outbound-resourceadapter", "connection-definition"},
45         {"adminobject"}};
46     private Map JavaDoc configPropertiesMap = new HashMap JavaDoc();
47     private Map JavaDoc connectionDefinitionsMap = new HashMap JavaDoc();
48     private Map JavaDoc adminObjectsMap = new HashMap JavaDoc();
49
50     public ResourceAdapterDConfigBean(DDBean JavaDoc ddBean, final GerResourceadapterType resourceadapter) {
51         super(ddBean, resourceadapter);
52         if (getResourceadapterInstance() == null) {
53             resourceadapter.addNewResourceadapterInstance();
54         }
55         ConfigPropertiesHelper.initializeConfigSettings(ddBean, new ConfigPropertiesHelper.ConfigPropertiesSource() {
56             public GerConfigPropertySettingType[] getConfigPropertySettingArray() {
57                 return getResourceadapterInstance().getConfigPropertySettingArray();
58             }
59
60             public GerConfigPropertySettingType addNewConfigPropertySetting() {
61                 return getResourceadapterInstance().addNewConfigPropertySetting();
62             }
63
64             public void removeConfigPropertySetting(int j) {
65             }
66
67             public ConfigPropertySettings[] getConfigPropertySettings() {
68                 return new ConfigPropertySettings[0];
69             }
70
71             public void setConfigPropertySettings(ConfigPropertySettings[] configs) {
72             }
73
74         }, configPropertiesMap, "config-property", "config-property-name");
75         //initialize connection definitions
76
GerOutboundResourceadapterType outboundResourceadapter = resourceadapter.getOutboundResourceadapter();
77         if (outboundResourceadapter == null) {
78             outboundResourceadapter = resourceadapter.addNewOutboundResourceadapter();
79         }
80         DDBean JavaDoc[] connectionDefinitionDDBeans = ddBean.getChildBean(getXpaths()[1]);
81         GerConnectionDefinitionType[] connectionDefinitions = outboundResourceadapter.getConnectionDefinitionArray();
82
83         if (connectionDefinitions.length == 0) {
84             //we are new
85
for (int i = 0; i < connectionDefinitionDDBeans.length; i++) {
86                 DDBean JavaDoc connectionDefinitionDdBean = connectionDefinitionDDBeans[i];
87                 GerConnectionDefinitionType connectionDefinition = outboundResourceadapter.addNewConnectionDefinition();
88                 String JavaDoc connectionfactoryInterface = connectionDefinitionDdBean.getText("connectionfactory-interface")[0];
89                 ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean = new ConnectionDefinitionDConfigBean(connectionDefinitionDdBean, connectionDefinition);
90                 connectionDefinitionsMap.put(connectionfactoryInterface, connectionDefinitionDConfigBean);
91             }
92         } else {
93             //we are read in from xml. Check correct length
94
assert connectionDefinitionDDBeans.length == connectionDefinitions.length;
95             for (int i = 0; i < connectionDefinitionDDBeans.length; i++) {
96                 DDBean JavaDoc connectionDefinitionDdBean = connectionDefinitionDDBeans[i];
97                 GerConnectionDefinitionType connectionDefinition = connectionDefinitions[i];
98                 String JavaDoc connectionfactoryInterface = connectionDefinitionDdBean.getText("connectionfactory-interface")[0];
99                 assert connectionfactoryInterface.equals(connectionDefinition.getConnectionfactoryInterface());
100                 ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean = new ConnectionDefinitionDConfigBean(connectionDefinitionDdBean, connectionDefinition);
101                 connectionDefinitionsMap.put(connectionfactoryInterface, connectionDefinitionDConfigBean);
102             }
103         }
104
105         //admin objects
106
// DDBean[] adminObjecDdBeans = ddBean.getChildBean(getXpaths()[2]);
107
// GerAdminobjectType[] adminobjectTypes = getResourceadapter().getAdminobjectArray();
108
//
109
// if (adminobjectTypes.length == 0) {
110
// //we are new
111
// for (int i = 0; i < adminObjecDdBeans.length; i++) {
112
// DDBean adminObjectDdBean = adminObjecDdBeans[i];
113
// GerAdminobjectType adminobjectType = getResourceadapter().addNewAdminobject();
114
// String adminObjectInterface = adminObjectDdBean.getText("adminobject-interface")[0];
115
// String adminObjectClass = adminObjectDdBean.getText("adminobject-class")[0];
116
// AdminObjectDConfigBean adminObjectDConfigBean = new AdminObjectDConfigBean(adminObjectDdBean, adminobjectType);
117
// adminObjectsMap.put(new Key(adminObjectInterface, adminObjectClass), adminObjectDConfigBean);
118
// }
119
// } else {
120
// //we are read in from xml. Check correct length
121
// assert adminObjecDdBeans.length == adminobjectTypes.length;
122
// for (int i = 0; i < adminObjecDdBeans.length; i++) {
123
// DDBean adminObjectDdBean = adminObjecDdBeans[i];
124
// GerAdminobjectType adminobjectType = adminobjectTypes[i];
125
// String adminObjectInterface = adminObjectDdBean.getText("adminobject-interface")[0];
126
// assert(adminObjectInterface.equals(adminobjectType.getAdminobjectInterface().getStringValue()));
127
// String adminObjectClass = adminObjectDdBean.getText("adminobject-class")[0];
128
// assert(adminObjectClass.equals(adminobjectType.getAdminobjectClass().getStringValue()));
129
// AdminObjectDConfigBean adminObjectDConfigBean = new AdminObjectDConfigBean(adminObjectDdBean, adminobjectType);
130
// adminObjectsMap.put(new Key(adminObjectInterface, adminObjectClass), adminObjectDConfigBean);
131
//
132
// }
133
// }
134

135     }
136
137     GerResourceadapterType getResourceadapter() {
138         return (GerResourceadapterType) getXmlObject();
139     }
140
141     private GerResourceadapterInstanceType getResourceadapterInstance() {
142         return getResourceadapter().getResourceadapterInstance();
143     }
144
145     public String JavaDoc getResourceAdapterName() {
146         return getResourceadapterInstance().getResourceadapterName();
147     }
148
149     public void setResourceAdapterName(String JavaDoc resourceAdapterName) {
150         getResourceadapterInstance().setResourceadapterName(resourceAdapterName);
151     }
152
153     public String JavaDoc getWorkManager() {
154         if(getResourceadapterInstance() == null || getResourceadapterInstance().getWorkmanager() == null) {
155             return null;
156         }
157         return getResourceadapterInstance().getWorkmanager().getGbeanLink();
158     }
159
160     public void setWorkManager(String JavaDoc workManager) {
161         if(getResourceadapterInstance() == null) {
162             getResourceadapter().addNewResourceadapterInstance();
163         }
164         if(getResourceadapterInstance().getWorkmanager() == null) {
165             getResourceadapterInstance().addNewWorkmanager();
166         }
167         getResourceadapterInstance().getWorkmanager().setGbeanLink(workManager);
168     }
169
170     public DConfigBean JavaDoc getDConfigBean(DDBean JavaDoc bean) throws ConfigurationException JavaDoc {
171         String JavaDoc xpath = bean.getXpath();
172         String JavaDoc[] xpaths = getXpaths();
173         if (xpath.equals(xpaths[0])) {
174             //resource adapter config property
175
String JavaDoc configPropertyName = bean.getText("config-property-name")[0];
176             ConfigPropertySettingDConfigBean configPropertySetting = (ConfigPropertySettingDConfigBean) configPropertiesMap.get(configPropertyName);
177             assert configPropertySetting != null;
178             return configPropertySetting;
179         }
180         if (xpath.equals(xpaths[1])) {
181             //connection definition
182
String JavaDoc connectionFactoryInterface = bean.getText("connectionfactory-interface")[0];
183             ConnectionDefinitionDConfigBean connectionDefinition = (ConnectionDefinitionDConfigBean) connectionDefinitionsMap.get(connectionFactoryInterface);
184             assert connectionDefinition != null;
185             return connectionDefinition;
186         }
187         if (xpath.equals(xpaths[2])) {
188             //admin objects
189
String JavaDoc adminObjectInterface = bean.getText("adminobject-interface")[0];
190             String JavaDoc adminObjectClass = bean.getText("adminobject-class")[0];
191             AdminObjectDConfigBean adminObject = (AdminObjectDConfigBean) adminObjectsMap.get(new Key(adminObjectInterface, adminObjectClass));
192             assert adminObject != null;
193             return adminObject;
194         }
195         return null;
196     }
197
198
199     public String JavaDoc[] getXpaths() {
200         return getXPathsForJ2ee_1_4(RESOURCE_ADAPTER_XPATHS);
201     }
202
203     protected SchemaTypeLoader getSchemaTypeLoader() {
204         return ResourceAdapterDConfigRoot.SCHEMA_TYPE_LOADER;
205     }
206
207
208     //from doubleKeyedHashMap, currently in transaction module
209
private final static class Key {
210         private final Object JavaDoc part1;
211         private final Object JavaDoc part2;
212
213         public Key(Object JavaDoc part1, Object JavaDoc part2) {
214             this.part1 = part1;
215             this.part2 = part2;
216         }
217
218         public int hashCode() {
219             return part1.hashCode() ^ part2.hashCode();
220         }
221
222         public boolean equals(Object JavaDoc obj) {
223             if (obj instanceof Key) {
224                 Key other = (Key) obj;
225                 return this.part1.equals(other.part1) && this.part2.equals(other.part2);
226             } else {
227                 return false;
228             }
229         }
230     }
231 }
232
Popular Tags