1 17 18 package org.apache.geronimo.deployment.plugin; 19 20 import java.beans.PropertyChangeListener ; 21 import java.beans.PropertyChangeSupport ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.OutputStream ; 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 36 public abstract class XmlBeanSupport { protected final PropertyChangeSupport pcs = new PropertyChangeSupport (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 pcl) { 53 pcs.addPropertyChangeListener(pcl); 54 } 55 56 public void removePropertyChangeListener(PropertyChangeListener pcl) { 57 pcs.removePropertyChangeListener(pcl); 58 } 59 60 public void toXML(OutputStream outputStream) throws IOException { 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 inputStream) throws XmlException, IOException { 69 xmlObject = getSchemaTypeLoader().parse(inputStream, null, null); 70 } 71 72 protected SchemaTypeLoader getSchemaTypeLoader() { 75 return null; 76 } 77 78 public boolean configured() { 80 return getXmlObject() != null; 81 } 82 83 protected static boolean isEmpty(String s) { 84 return s == null || s.trim().equals(""); 85 } 86 } 87 | Popular Tags |