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