Home » geronimo-2.2-source-release » org.apache.geronimo.deployment.plugin » [javadoc | source]

    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;
   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   /**
   32    *
   33    *
   34    * @version $Rev: 697438 $ $Date: 2008-09-20 17:45:30 -0700 (Sat, 20 Sep 2008) $
   35    */
   36   public abstract class XmlBeanSupport { // should implement Serializable or Externalizable
   37       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       //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 s) {
   84           return s == null || s.trim().equals("");
   85       }
   86   }

Home » geronimo-2.2-source-release » org.apache.geronimo.deployment.plugin » [javadoc | source]