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: import javax.enterprise.deploy.model.XpathEvent;
020: import javax.enterprise.deploy.model.XpathListener;
021:
022: import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
023: import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
024: import org.apache.xmlbeans.SchemaTypeLoader;
025: import org.apache.xmlbeans.XmlBeans;
026:
027: /**
028: * @version $Revision 1.0$ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
029: */
030: public class ConfigPropertySettings extends XmlBeanSupport {
031: private final static SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans
032: .getContextTypeLoader();
033: private String type;
034: private DDBean ddBean;
035: private XpathListener typeListener;
036: private XpathListener nameListener;
037:
038: public ConfigPropertySettings() {
039: super (null);
040: }
041:
042: void initialize(GerConfigPropertySettingType xmlObject,
043: DDBean configPropertyBean) {
044: setXmlObject(xmlObject);
045: ddBean = configPropertyBean;
046: DDBean[] child = configPropertyBean
047: .getChildBean("config-property-type");
048: if (child.length == 1) {
049: setConfigPropertyType(child[0]);
050: }
051: child = configPropertyBean.getChildBean("config-property-name");
052: if (child.length == 1) {
053: setConfigPropertyName(child[0]);
054: }
055: configPropertyBean.addXpathListener("config-property-type",
056: typeListener = new XpathListener() {
057: public void fireXpathEvent(XpathEvent xpe) {
058: if (xpe.isChangeEvent() || xpe.isAddEvent()) {
059: setConfigPropertyType(xpe.getBean());
060: } else if (xpe.isRemoveEvent()) {
061: setConfigPropertyType((String) null);
062: }
063: }
064: });
065: configPropertyBean.addXpathListener("config-property-name",
066: nameListener = new XpathListener() {
067: public void fireXpathEvent(XpathEvent xpe) {
068: if (xpe.isChangeEvent() || xpe.isAddEvent()) {
069: setConfigPropertyName(xpe.getBean());
070: } else if (xpe.isRemoveEvent()) {
071: setConfigPropertyName((String) null);
072: }
073: }
074: });
075: }
076:
077: boolean matches(DDBean target) {
078: return target.equals(ddBean);
079: }
080:
081: void dispose() {
082: if (ddBean != null) {
083: ddBean.removeXpathListener("config-property-type",
084: typeListener);
085: ddBean.removeXpathListener("config-property-name",
086: nameListener);
087: }
088: nameListener = null;
089: typeListener = null;
090: ddBean = null;
091: }
092:
093: GerConfigPropertySettingType getConfigPropertySetting() {
094: return (GerConfigPropertySettingType) getXmlObject();
095: }
096:
097: public String getConfigPropertyName() {
098: return getConfigPropertySetting().getName();
099: }
100:
101: private void setConfigPropertyName(DDBean configPropertyBean) {
102: if (configPropertyBean == null) {
103: setConfigPropertyName((String) null);
104: } else {
105: setConfigPropertyName(configPropertyBean.getText());
106: }
107: }
108:
109: private void setConfigPropertyName(String name) {
110: String old = getConfigPropertyName();
111: getConfigPropertySetting().setName(name);
112: pcs.firePropertyChange("configPropertyName", old, name);
113: }
114:
115: public String getConfigPropertyType() {
116: return type;
117: }
118:
119: private void setConfigPropertyType(DDBean configPropertyBean) {
120: if (configPropertyBean == null) {
121: setConfigPropertyType((String) null);
122: } else {
123: setConfigPropertyType(configPropertyBean.getText());
124: }
125: }
126:
127: private void setConfigPropertyType(String type) {
128: String old = getConfigPropertyType();
129: this .type = type;
130: pcs.firePropertyChange("configPropertyType", old, type);
131: }
132:
133: public String getConfigPropertyValue() {
134: return getConfigPropertySetting().getStringValue();
135: }
136:
137: public void setConfigPropertyValue(String configPropertyValue) {
138: String old = getConfigPropertyValue();
139: getConfigPropertySetting().setStringValue(configPropertyValue);
140: pcs.firePropertyChange("configPropertyValue", old,
141: configPropertyValue);
142: }
143:
144: public String toString() {
145: return "Property " + getConfigPropertyName();
146: }
147: }
|