KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > plugin > XmlBeanSupport


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.deployment.plugin;
19
20 import java.beans.PropertyChangeListener JavaDoc;
21 import java.beans.PropertyChangeSupport JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.io.OutputStream JavaDoc;
25
26 import org.apache.xmlbeans.SchemaTypeLoader;
27 import org.apache.xmlbeans.XmlException;
28 import org.apache.xmlbeans.XmlObject;
29 import org.apache.xmlbeans.XmlOptions;
30
31 /**
32  *
33  *
34  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
35  */

36 public abstract class XmlBeanSupport { // should implement Serializable or Externalizable
37
protected final PropertyChangeSupport JavaDoc pcs = new PropertyChangeSupport JavaDoc(this);
38     private XmlObject xmlObject;
39
40     public XmlBeanSupport(XmlObject xmlObject) {
41         this.xmlObject = xmlObject;
42     }
43
44     protected void setXmlObject(XmlObject xmlObject) {
45         this.xmlObject = xmlObject;
46     }
47
48     protected XmlObject getXmlObject() {
49         return xmlObject;
50     }
51
52     public void addPropertyChangeListener(PropertyChangeListener JavaDoc pcl) {
53         pcs.addPropertyChangeListener(pcl);
54     }
55
56     public void removePropertyChangeListener(PropertyChangeListener JavaDoc pcl) {
57         pcs.removePropertyChangeListener(pcl);
58     }
59
60     public void toXML(OutputStream JavaDoc outputStream) throws IOException JavaDoc {
61         XmlOptions options = new XmlOptions();
62         options.setSavePrettyPrint();
63         options.setSavePrettyPrintIndent(4);
64         options.setUseDefaultNamespace();
65         xmlObject.save(outputStream, options);
66     }
67
68     public void fromXML(InputStream JavaDoc inputStream) throws XmlException, IOException JavaDoc {
69         xmlObject = getSchemaTypeLoader().parse(inputStream, null, null);
70     }
71
72     //override unless the particular object can never be read directly from xml, such as the
73
//connector ConnectionDefinitionInstance.
74
protected SchemaTypeLoader getSchemaTypeLoader() {
75         return null;
76     }
77
78     // Must be public but should not be a JavaBean property -- sigh
79
public boolean configured() {
80         return getXmlObject() != null;
81     }
82
83     protected static boolean isEmpty(String JavaDoc s) {
84         return s == null || s.trim().equals("");
85     }
86 }
87
Popular Tags