KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > deployment > jsr88 > AdminObjectDCB


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 package org.apache.geronimo.connector.deployment.jsr88;
18
19 import org.apache.geronimo.deployment.plugin.DConfigBeanSupport;
20 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType;
21 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType;
22 import org.apache.xmlbeans.SchemaTypeLoader;
23
24 import javax.enterprise.deploy.model.DDBean JavaDoc;
25
26 /**
27  * Represents /connector/adminobject in a Geronimo Connector deployment plan.
28  * Corresponds to /connector/resourceadapter/adminobject in the J2EE deployment plan.
29  * Note that in an arbitrary Geronimo connector plan, there can be multiple
30  * adminobject entries per adminobject from the J2EE plan. When we load such
31  * a plan, we combine all the adminobject-instances from those adminobjects
32  * into a single Geronimo adminobject per J2EE adminobject, so if we write it
33  * out again it'll be a little different, but that way this can be a DConfigBean
34  * instead of a POJO (the loading code is in ConnectorDCB).
35  *
36  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
37  */

38 public class AdminObjectDCB extends DConfigBeanSupport {
39     private AdminObjectInstance[] adminObjectInstance = new AdminObjectInstance[0];
40
41     public AdminObjectDCB(DDBean JavaDoc adminobjectDDBean, final GerAdminobjectType adminobject) {
42         super(adminobjectDDBean, adminobject);
43         //todo: listen for property changes on the admin object
44
configure(adminobjectDDBean, adminobject);
45     }
46
47     private void configure(DDBean JavaDoc adminDDBean, GerAdminobjectType adminXml) {
48         adminXml.setAdminobjectClass(adminDDBean.getText("adminobject-class")[0]);
49         adminXml.setAdminobjectInterface(adminDDBean.getText("adminobject-interface")[0]);
50         GerAdminobjectInstanceType[] xmls = adminXml.getAdminobjectInstanceArray();
51         adminObjectInstance = new AdminObjectInstance[xmls.length];
52         for (int i = 0; i < xmls.length; i++) {
53             adminObjectInstance[i] = new AdminObjectInstance(adminDDBean, xmls[i]);
54         }
55     }
56
57     GerAdminobjectType getAdminObject() {
58         return (GerAdminobjectType) getXmlObject();
59     }
60
61     void addAdminObjectInstance(GerAdminobjectInstanceType xml) {
62         AdminObjectInstance instance = new AdminObjectInstance(getDDBean(), xml);
63         AdminObjectInstance[] result = new AdminObjectInstance[adminObjectInstance.length+1];
64         System.arraycopy(adminObjectInstance, 0, result, 0, adminObjectInstance.length);
65         result[adminObjectInstance.length] = instance;
66         setAdminObjectInstance(result);
67     }
68
69     // ----------------------- JavaBean Properties for /adminobject ----------------------
70

71     public String JavaDoc getAdminObjectInterface() {
72         return getAdminObject().getAdminobjectInterface();
73     }
74
75     public String JavaDoc getAdminObjectClass() {
76         return getAdminObject().getAdminobjectClass();
77     }
78
79     public AdminObjectInstance[] getAdminObjectInstance() {
80         return adminObjectInstance;
81     }
82
83     public void setAdminObjectInstance(AdminObjectInstance[] adminObjectInstance) {
84         AdminObjectInstance[] old = getAdminObjectInstance();
85         //todo: whack all the old ones
86
for (int i = 0; i < adminObjectInstance.length; i++) {
87             AdminObjectInstance instance = adminObjectInstance[i];
88             if(instance.getAdminInstance() == null) {
89                 instance.configure(getDDBean(), getAdminObject().addNewAdminobjectInstance());
90             }
91         }
92         this.adminObjectInstance = adminObjectInstance;
93         pcs.firePropertyChange("adminObjectInstance", old, adminObjectInstance);
94     }
95
96     public AdminObjectInstance getAdminObjectInstance(int index) {
97         return adminObjectInstance[index];
98     }
99
100     public void setAdminObjectInstance(int index, AdminObjectInstance adminObjectInstance) {
101         AdminObjectInstance[] old = getAdminObjectInstance();
102         //todo: whack the old one
103
if(adminObjectInstance.getAdminInstance() == null) {
104             adminObjectInstance.configure(getDDBean(), getAdminObject().addNewAdminobjectInstance());
105         }
106         this.adminObjectInstance[index] = adminObjectInstance;
107         //todo: deep copy of array for "old"
108
pcs.firePropertyChange("adminObjectInstance", old, adminObjectInstance);
109     }
110
111     // ----------------------- End of JavaBean Properties ----------------------
112

113     protected SchemaTypeLoader getSchemaTypeLoader() {
114         return Connector15DCBRoot.SCHEMA_TYPE_LOADER;
115     }
116 }
117
Popular Tags