KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.enterprise.deploy.model.DDBean JavaDoc;
21
22 import org.apache.geronimo.deployment.plugin.DConfigBeanSupport;
23 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
24 import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
25 import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
26 import org.apache.xmlbeans.SchemaTypeLoader;
27
28 /**
29  *
30  *
31  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
32  *
33  **/

34 public class ConnectionDefinitionDConfigBean extends DConfigBeanSupport {
35
36     private ConnectionDefinitionInstance[] instances = new ConnectionDefinitionInstance[0];
37
38     public ConnectionDefinitionDConfigBean(DDBean JavaDoc ddBean, GerConnectionDefinitionType connectionDefinition) {
39         super(ddBean, connectionDefinition);
40         String JavaDoc connectionfactoryInterface = ddBean.getText("connectionfactory-interface")[0];
41         if (connectionDefinition.getConnectionfactoryInterface() == null) {
42             connectionDefinition.setConnectionfactoryInterface(connectionfactoryInterface);
43         } else {
44             assert connectionfactoryInterface.equals(connectionDefinition.getConnectionfactoryInterface());
45         }
46         // Get initial list of instances
47
instances = new ConnectionDefinitionInstance[getConnectionDefinition().getConnectiondefinitionInstanceArray().length];
48         for (int i = 0; i < instances.length; i++) {
49             instances[i] = new ConnectionDefinitionInstance();
50             instances[i].initialize(getConnectionDefinition().getConnectiondefinitionInstanceArray(i), this);
51         }
52     }
53
54     GerConnectionDefinitionType getConnectionDefinition() {
55         return (GerConnectionDefinitionType) getXmlObject();
56     }
57
58     public ConnectionDefinitionInstance[] getConnectionDefinitionInstance() {
59         return instances;
60     }
61
62     public void setConnectionDefinitionInstance(ConnectionDefinitionInstance[] instances) {
63         ConnectionDefinitionInstance[] old = getConnectionDefinitionInstance();
64         this.instances = instances;
65         for (int i = 0; i < instances.length; i++) { // catch additions
66
ConnectionDefinitionInstance instance = instances[i];
67             if (!instance.hasParent()) {
68                 GerConnectiondefinitionInstanceType xmlObject = getConnectionDefinition().addNewConnectiondefinitionInstance();
69                 xmlObject.setConnectionmanager(GerConnectionmanagerType.Factory.newInstance());
70                 instance.initialize(xmlObject, this);
71             }
72         }
73         for (int i = 0; i < old.length; i++) { // catch removals
74
ConnectionDefinitionInstance instance = old[i];
75             boolean found = false;
76             for (int j = 0; j < instances.length; j++) {
77                 if (instances[j] == instance) {
78                     found = true;
79                     break;
80                 }
81             }
82             if (!found) {
83                 // remove the XmlBean
84
for (int j = 0; j < getConnectionDefinition().getConnectiondefinitionInstanceArray().length; j++) {
85                     GerConnectiondefinitionInstanceType test = getConnectionDefinition().getConnectiondefinitionInstanceArray(j);
86                     if (test == instance.getConnectiondefinitionInstance()) {
87                         getConnectionDefinition().removeConnectiondefinitionInstance(j);
88                         break;
89                     }
90                 }
91                 // clean up the removed JavaBean
92
instance.dispose();
93             }
94         }
95         pcs.firePropertyChange("connectionDefinitionInstance", old, instances);
96     }
97
98     protected SchemaTypeLoader getSchemaTypeLoader() {
99         return ResourceAdapterDConfigRoot.SCHEMA_TYPE_LOADER;
100     }
101
102 }
103
Popular Tags