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 import javax.enterprise.deploy.model.XpathListener;
022
023 import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
024 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType;
025 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
026 import org.apache.xmlbeans.SchemaTypeLoader;
027 import org.apache.xmlbeans.XmlBeans;
028
029 /**
030 *
031 *
032 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
033 *
034 * */
035 public class AdminObjectInstance extends XmlBeanSupport {
036 private final static SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.getContextTypeLoader();
037 private AdminObjectDConfigBean parent;
038 private ConfigPropertySettings[] configs;
039 private XpathListener configListener;
040
041 public AdminObjectInstance() {
042 super(null);
043 }
044
045 void initialize(GerAdminobjectInstanceType xmlObject, AdminObjectDConfigBean parent) {
046 setXmlObject(xmlObject);
047 this.parent = parent;
048 DDBean parentDDBean = parent.getDDBean();
049 configListener = ConfigPropertiesHelper.initialize(parentDDBean, new ConfigPropertiesHelper.ConfigPropertiesSource() {
050 public GerConfigPropertySettingType[] getConfigPropertySettingArray() {
051 return getAdminobjectInstance().getConfigPropertySettingArray();
052 }
053
054 public GerConfigPropertySettingType addNewConfigPropertySetting() {
055 return getAdminobjectInstance().addNewConfigPropertySetting();
056 }
057
058 public void removeConfigPropertySetting(int j) {
059 getAdminobjectInstance().removeConfigPropertySetting(j);
060 }
061
062 public ConfigPropertySettings[] getConfigPropertySettings() {
063 return configs;
064 }
065
066 public void setConfigPropertySettings(ConfigPropertySettings[] configs) {
067 setConfigProperty(configs);
068 }
069
070 }, "config-property", "config-property-name");
071 }
072
073 boolean hasParent() {
074 return parent != null;
075 }
076
077 void dispose() {
078 if (configs != null) {
079 for (int i = 0; i < configs.length; i++) {
080 configs[i].dispose();
081 }
082 }
083 if (parent != null) {
084 parent.getDDBean().removeXpathListener("config-property", configListener);
085 }
086 configs = null;
087 configListener = null;
088 parent = null;
089 }
090
091 // JavaBean properties for this object (with a couple helper methods)
092 GerAdminobjectInstanceType getAdminobjectInstance() {
093 return (GerAdminobjectInstanceType) getXmlObject();
094 }
095
096 public ConfigPropertySettings[] getConfigProperty() {
097 return configs;
098 }
099
100 private void setConfigProperty(ConfigPropertySettings[] configs) { // can only be changed by adding a new DDBean
101 ConfigPropertySettings[] old = getConfigProperty();
102 this.configs = configs;
103 pcs.firePropertyChange("configProperty", old, configs);
104 }
105
106 public String getMessageDestinationName() {
107 return getAdminobjectInstance().getMessageDestinationName();
108 }
109
110 public void setMessageDestinationName(String messageDestinationName) {
111 getAdminobjectInstance().setMessageDestinationName(messageDestinationName);
112 }
113
114 }