KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > deployment > dconfigbean > ConfigPropertySettings


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
18 package org.apache.geronimo.connector.deployment.dconfigbean;
19
20 import javax.enterprise.deploy.model.DDBean JavaDoc;
21 import javax.enterprise.deploy.model.XpathEvent JavaDoc;
22 import javax.enterprise.deploy.model.XpathListener JavaDoc;
23
24 import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
25 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
26 import org.apache.xmlbeans.SchemaTypeLoader;
27 import org.apache.xmlbeans.XmlBeans;
28
29 /**
30  * @version $Revision 1.0$ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
31  */

32 public class ConfigPropertySettings extends XmlBeanSupport {
33     private final static SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.getContextTypeLoader();
34     private String JavaDoc type;
35     private DDBean JavaDoc ddBean;
36     private XpathListener JavaDoc typeListener;
37     private XpathListener JavaDoc nameListener;
38
39     public ConfigPropertySettings() {
40         super(null);
41     }
42
43     void initialize(GerConfigPropertySettingType xmlObject, DDBean JavaDoc configPropertyBean) {
44         setXmlObject(xmlObject);
45         ddBean = configPropertyBean;
46         DDBean JavaDoc[] child = configPropertyBean.getChildBean("config-property-type");
47         if (child.length == 1) {
48             setConfigPropertyType(child[0]);
49         }
50         child = configPropertyBean.getChildBean("config-property-name");
51         if (child.length == 1) {
52             setConfigPropertyName(child[0]);
53         }
54         configPropertyBean.addXpathListener("config-property-type", typeListener = new XpathListener JavaDoc() {
55             public void fireXpathEvent(XpathEvent JavaDoc xpe) {
56                 if (xpe.isChangeEvent() || xpe.isAddEvent()) {
57                     setConfigPropertyType(xpe.getBean());
58                 } else if (xpe.isRemoveEvent()) {
59                     setConfigPropertyType((String JavaDoc) null);
60                 }
61             }
62         });
63         configPropertyBean.addXpathListener("config-property-name", nameListener = new XpathListener JavaDoc() {
64             public void fireXpathEvent(XpathEvent JavaDoc xpe) {
65                 if (xpe.isChangeEvent() || xpe.isAddEvent()) {
66                     setConfigPropertyName(xpe.getBean());
67                 } else if (xpe.isRemoveEvent()) {
68                     setConfigPropertyName((String JavaDoc) null);
69                 }
70             }
71         });
72     }
73
74     boolean matches(DDBean JavaDoc target) {
75         return target.equals(ddBean);
76     }
77
78     void dispose() {
79         if (ddBean != null) {
80             ddBean.removeXpathListener("config-property-type", typeListener);
81             ddBean.removeXpathListener("config-property-name", nameListener);
82         }
83         nameListener = null;
84         typeListener = null;
85         ddBean = null;
86     }
87
88     GerConfigPropertySettingType getConfigPropertySetting() {
89         return (GerConfigPropertySettingType) getXmlObject();
90     }
91
92     public String JavaDoc getConfigPropertyName() {
93         return getConfigPropertySetting().getName();
94     }
95
96     private void setConfigPropertyName(DDBean JavaDoc configPropertyBean) {
97         if (configPropertyBean == null) {
98             setConfigPropertyName((String JavaDoc) null);
99         } else {
100             setConfigPropertyName(configPropertyBean.getText());
101         }
102     }
103
104     private void setConfigPropertyName(String JavaDoc name) {
105         String JavaDoc old = getConfigPropertyName();
106         getConfigPropertySetting().setName(name);
107         pcs.firePropertyChange("configPropertyName", old, name);
108     }
109
110     public String JavaDoc getConfigPropertyType() {
111         return type;
112     }
113
114     private void setConfigPropertyType(DDBean JavaDoc configPropertyBean) {
115         if (configPropertyBean == null) {
116             setConfigPropertyType((String JavaDoc) null);
117         } else {
118             setConfigPropertyType(configPropertyBean.getText());
119         }
120     }
121
122     private void setConfigPropertyType(String JavaDoc type) {
123         String JavaDoc old = getConfigPropertyType();
124         this.type = type;
125         pcs.firePropertyChange("configPropertyType", old, type);
126     }
127
128     public String JavaDoc getConfigPropertyValue() {
129         return getConfigPropertySetting().getStringValue();
130     }
131
132     public void setConfigPropertyValue(String JavaDoc configPropertyValue) {
133         String JavaDoc old = getConfigPropertyValue();
134         getConfigPropertySetting().setStringValue(configPropertyValue);
135         pcs.firePropertyChange("configPropertyValue", old, configPropertyValue);
136     }
137
138     public String JavaDoc toString() {
139         return "Property "+getConfigPropertyName();
140     }
141 }
142
Popular Tags