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 javax.enterprise.deploy.model.DDBean;
019:
020: import org.apache.geronimo.deployment.plugin.DConfigBeanSupport;
021: import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType;
022: import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType;
023: import org.apache.xmlbeans.SchemaTypeLoader;
024:
025: /**
026: *
027: *
028: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
029: *
030: * */
031: public class AdminObjectDConfigBean extends DConfigBeanSupport {
032: private AdminObjectInstance[] instances = new AdminObjectInstance[0];
033:
034: public AdminObjectDConfigBean(DDBean ddBean,
035: GerAdminobjectType adminObject) {
036: super (ddBean, adminObject);
037: String adminObjectInterface = ddBean
038: .getText("adminobject-interface")[0];
039: if (adminObject.getAdminobjectInterface() == null) {
040: adminObject.setAdminobjectInterface(adminObjectInterface);
041: } else {
042: assert adminObjectInterface.equals(adminObject
043: .getAdminobjectInterface());
044: }
045: String adminObjectClass = ddBean.getText("adminobject-class")[0];
046: if (adminObject.getAdminobjectClass() == null) {
047: adminObject.setAdminobjectClass(adminObjectClass);
048: } else {
049: assert adminObjectClass.equals(adminObject
050: .getAdminobjectClass());
051: }
052: // Get initial list of instances
053: GerAdminobjectInstanceType[] xmlInstances = getAdminObject()
054: .getAdminobjectInstanceArray();
055: instances = new AdminObjectInstance[xmlInstances.length];
056: for (int i = 0; i < instances.length; i++) {
057: instances[i] = new AdminObjectInstance();
058: instances[i].initialize(xmlInstances[i], this );
059: }
060: }
061:
062: GerAdminobjectType getAdminObject() {
063: return (GerAdminobjectType) getXmlObject();
064: }
065:
066: public AdminObjectInstance[] getAdminObjectInstance() {
067: return instances;
068: }
069:
070: public void setAdminObjectInstance(AdminObjectInstance[] instances) {
071: AdminObjectInstance[] old = getAdminObjectInstance();
072: this .instances = instances;
073: for (int i = 0; i < instances.length; i++) { // catch additions
074: AdminObjectInstance instance = instances[i];
075: if (!instance.hasParent()) {
076: GerAdminobjectInstanceType xmlObject = getAdminObject()
077: .addNewAdminobjectInstance();
078: instance.initialize(xmlObject, this );
079: }
080: }
081: for (int i = 0; i < old.length; i++) { // catch removals
082: AdminObjectInstance instance = old[i];
083: boolean found = false;
084: for (int j = 0; j < instances.length; j++) {
085: if (instances[j] == instance) {
086: found = true;
087: break;
088: }
089: }
090: if (!found) {
091: // remove the XmlBean
092: for (int j = 0; j < getAdminObject()
093: .getAdminobjectInstanceArray().length; j++) {
094: GerAdminobjectInstanceType test = getAdminObject()
095: .getAdminobjectInstanceArray(j);
096: if (test == instance.getAdminobjectInstance()) {
097: getAdminObject().removeAdminobjectInstance(j);
098: break;
099: }
100: }
101: // clean up the removed JavaBean
102: instance.dispose();
103: }
104: }
105: pcs.firePropertyChange("adminObjectInstance", old, instances);
106: }
107:
108: protected SchemaTypeLoader getSchemaTypeLoader() {
109: return ResourceAdapterDConfigRoot.SCHEMA_TYPE_LOADER;
110: }
111:
112: }
|