KickJava   Java API By Example, From Geeks To Geeks.

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


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.GerAdminobjectInstanceType;
24 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType;
25 import org.apache.xmlbeans.SchemaTypeLoader;
26
27 /**
28  *
29  *
30  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
31  *
32  * */

33 public class AdminObjectDConfigBean extends DConfigBeanSupport {
34     private AdminObjectInstance[] instances = new AdminObjectInstance[0];
35
36     public AdminObjectDConfigBean(DDBean JavaDoc ddBean, GerAdminobjectType adminObject) {
37         super(ddBean, adminObject);
38         String JavaDoc adminObjectInterface = ddBean.getText("adminobject-interface")[0];
39         if (adminObject.getAdminobjectInterface() == null) {
40             adminObject.setAdminobjectInterface(adminObjectInterface);
41         } else {
42             assert adminObjectInterface.equals(adminObject.getAdminobjectInterface());
43         }
44         String JavaDoc adminObjectClass = ddBean.getText("adminobject-class")[0];
45         if (adminObject.getAdminobjectClass() == null) {
46             adminObject.setAdminobjectClass(adminObjectClass);
47         } else {
48             assert adminObjectClass.equals(adminObject.getAdminobjectClass());
49         }
50         // Get initial list of instances
51
GerAdminobjectInstanceType[] xmlInstances = getAdminObject().getAdminobjectInstanceArray();
52         instances = new AdminObjectInstance[xmlInstances.length];
53         for (int i = 0; i < instances.length; i++) {
54             instances[i] = new AdminObjectInstance();
55             instances[i].initialize(xmlInstances[i], this);
56         }
57     }
58
59     GerAdminobjectType getAdminObject() {
60         return (GerAdminobjectType) getXmlObject();
61     }
62
63     public AdminObjectInstance[] getAdminObjectInstance() {
64         return instances;
65     }
66
67     public void setAdminObjectInstance(AdminObjectInstance[] instances) {
68         AdminObjectInstance[] old = getAdminObjectInstance();
69         this.instances = instances;
70         for (int i = 0; i < instances.length; i++) { // catch additions
71
AdminObjectInstance instance = instances[i];
72             if (!instance.hasParent()) {
73                 GerAdminobjectInstanceType xmlObject = getAdminObject().addNewAdminobjectInstance();
74                 instance.initialize(xmlObject, this);
75             }
76         }
77         for (int i = 0; i < old.length; i++) { // catch removals
78
AdminObjectInstance instance = old[i];
79             boolean found = false;
80             for (int j = 0; j < instances.length; j++) {
81                 if (instances[j] == instance) {
82                     found = true;
83                     break;
84                 }
85             }
86             if (!found) {
87                 // remove the XmlBean
88
for (int j = 0; j < getAdminObject().getAdminobjectInstanceArray().length; j++) {
89                     GerAdminobjectInstanceType test = getAdminObject().getAdminobjectInstanceArray(j);
90                     if (test == instance.getAdminobjectInstance()) {
91                         getAdminObject().removeAdminobjectInstance(j);
92                         break;
93                     }
94                 }
95                 // clean up the removed JavaBean
96
instance.dispose();
97             }
98         }
99         pcs.firePropertyChange("adminObjectInstance", old, instances);
100     }
101
102     protected SchemaTypeLoader getSchemaTypeLoader() {
103         return ResourceAdapterDConfigRoot.SCHEMA_TYPE_LOADER;
104     }
105
106 }
107
Popular Tags