geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r575143 - in /geronimo/server/trunk: applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/car/ maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ maven-plugins/car-maven-pl...
Date Thu, 13 Sep 2007 02:12:12 GMT
Author: djencks
Date: Wed Sep 12 19:12:11 2007
New Revision: 575143

URL: http://svn.apache.org/viewvc?rev=575143&view=rev
Log:
GERONIMO-3453 Make installing xml attributes into configs.xml work.  Introduce a utility class for handling the jaxb details

Added:
    geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java   (with props)
Modified:
    geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/PluginMetadataTest.java
    geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java
    geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
    geronimo/server/trunk/modules/geronimo-system/src/main/xsd/attributes-1.2.xsd
    geronimo/server/trunk/modules/geronimo-system/src/test/java/org/apache/geronimo/system/plugin/CopyConfigTest.java

Modified: geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java?rev=575143&r1=575142&r2=575143&view=diff
==============================================================================
--- geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java (original)
+++ geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java Wed Sep 12 19:12:11 2007
@@ -58,7 +58,7 @@
 import org.apache.geronimo.kernel.repository.Version;
 import org.apache.geronimo.kernel.util.XmlUtil;
 import org.apache.geronimo.system.plugin.PluginInstaller;
-import org.apache.geronimo.system.plugin.PluginInstallerGBean;
+import org.apache.geronimo.system.plugin.PluginXmlUtil;
 import org.apache.geronimo.system.plugin.model.PluginListType;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -204,7 +204,7 @@
         ConfigurationManager mgr = ConfigurationUtil.getConfigurationManager(kernel);
         PluginInstaller installer = getInstaller(kernel);
         PluginListType pluginList = installer.createPluginListForRepositories(mgr, repo);
-        PluginInstallerGBean.writePluginList(pluginList, out);
+        PluginXmlUtil.writePluginList(pluginList, out);
     }
 
 

Modified: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java?rev=575143&r1=575142&r2=575143&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java (original)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java Wed Sep 12 19:12:11 2007
@@ -40,6 +40,7 @@
 import org.apache.geronimo.kernel.repository.ListableRepository;
 import org.apache.geronimo.kernel.repository.Maven2Repository;
 import org.apache.geronimo.system.plugin.PluginInstallerGBean;
+import org.apache.geronimo.system.plugin.PluginXmlUtil;
 import org.apache.geronimo.system.plugin.model.PluginListType;
 import org.apache.geronimo.system.plugin.model.PluginType;
 import org.xml.sax.SAXException;
@@ -64,7 +65,7 @@
         File outFile = new File(baseDir, "geronimo-plugins.xml");
         Writer out = new FileWriter(outFile, false);
         try {
-            PluginInstallerGBean.writePluginList(pluginList, out);
+            PluginXmlUtil.writePluginList(pluginList, out);
         } finally {
             out.close();
         }
@@ -110,7 +111,7 @@
                 }
                 InputStream in = jar.getInputStream(entry);
                 try {
-                    PluginType pluginType = PluginInstallerGBean.loadPluginMetadata(in);
+                    PluginType pluginType = PluginXmlUtil.loadPluginMetadata(in);
                     if (pluginType.getPluginArtifact().isEmpty()) {
                         return null;
                     }

Modified: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java?rev=575143&r1=575142&r2=575143&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java (original)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java Wed Sep 12 19:12:11 2007
@@ -26,7 +26,7 @@
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.geronimo.system.plugin.PluginInstallerGBean;
+import org.apache.geronimo.system.plugin.PluginXmlUtil;
 import org.apache.geronimo.system.plugin.model.ArtifactType;
 import org.apache.geronimo.system.plugin.model.DependencyType;
 import org.apache.geronimo.system.plugin.model.LicenseType;
@@ -140,10 +140,10 @@
             instance = new PluginArtifactType();
         } else {
             String instanceString = instanceDom.getChild("plugin-artifact").toString();
-            instance = PluginInstallerGBean.loadPluginArtifactMetadata(new StringReader(instanceString.replace("#{", "${")));
+            instance = PluginXmlUtil.loadPluginArtifactMetadata(new StringReader(instanceString.replace("#{", "${")));
         }
         if (this.commonInstance != null && this.commonInstance.getChild("plugin-artifact") != null) {
-            PluginArtifactType commonInstance = PluginInstallerGBean.loadPluginArtifactMetadata(new StringReader(this.commonInstance.getChild("plugin-artifact").toString().replace("#{", "${")));
+            PluginArtifactType commonInstance = PluginXmlUtil.loadPluginArtifactMetadata(new StringReader(this.commonInstance.getChild("plugin-artifact").toString().replace("#{", "${")));
             //merge
             if (instance.getArtifactAlias().isEmpty()) {
                 instance.getArtifactAlias().addAll(commonInstance.getArtifactAlias());
@@ -190,7 +190,7 @@
         targetDir.mkdirs();
         FileOutputStream out = new FileOutputStream(targetFile);
         try {
-            PluginInstallerGBean.writePluginMetadata(metadata, out);
+            PluginXmlUtil.writePluginMetadata(metadata, out);
         } finally {
             out.close();
         }

Modified: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java?rev=575143&r1=575142&r2=575143&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java (original)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java Wed Sep 12 19:12:11 2007
@@ -30,10 +30,10 @@
 import org.apache.geronimo.kernel.config.NoSuchStoreException;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.system.plugin.PluginInstallerGBean;
-import org.apache.geronimo.system.plugin.model.ArtifactType;
+import org.apache.geronimo.system.plugin.PluginXmlUtil;
+import org.apache.geronimo.system.plugin.model.PluginArtifactType;
 import org.apache.geronimo.system.plugin.model.PluginListType;
 import org.apache.geronimo.system.plugin.model.PluginType;
-import org.apache.geronimo.system.plugin.model.PluginArtifactType;
 
 /**
  * Maintain the geronimo-plugins.xml catalog in the local maven repository by merging in the geronimo-plugin.xml from the current project.
@@ -56,7 +56,7 @@
         InputStream min = new FileInputStream(targetFile);
         PluginType plugin;
         try {
-            plugin = PluginInstallerGBean.loadPluginMetadata(min);
+            plugin = PluginXmlUtil.loadPluginMetadata(min);
         } finally {
             min.close();
         }
@@ -69,7 +69,7 @@
         if (outFile.exists()) {
             InputStream in = new FileInputStream(outFile);
             try {
-                pluginList = PluginInstallerGBean.loadPluginList(in);
+                pluginList = PluginXmlUtil.loadPluginList(in);
             } finally {
                 in.close();
             }
@@ -81,7 +81,7 @@
         updatePluginList(plugin, pluginList);
         Writer out = new FileWriter(outFile, false);
         try {
-            PluginInstallerGBean.writePluginList(pluginList, out);
+            PluginXmlUtil.writePluginList(pluginList, out);
         } finally {
             out.close();
         }

Modified: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/PluginMetadataTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/PluginMetadataTest.java?rev=575143&r1=575142&r2=575143&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/PluginMetadataTest.java (original)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/PluginMetadataTest.java Wed Sep 12 19:12:11 2007
@@ -21,10 +21,9 @@
 package org.apache.geronimo.mavenplugins.car;
 
 import java.io.StringReader;
-import java.io.ByteArrayInputStream;
 
 import junit.framework.TestCase;
-import org.apache.geronimo.system.plugin.PluginInstallerGBean;
+import org.apache.geronimo.system.plugin.PluginXmlUtil;
 import org.apache.geronimo.system.plugin.model.PluginArtifactType;
 
 /**
@@ -59,7 +58,7 @@
 
     //TODO test #{ to ${ replacement
     public void testReadInstance() throws Exception {
-        PluginArtifactType instance = PluginInstallerGBean.loadPluginArtifactMetadata(new StringReader(INSTANCE1));
+        PluginArtifactType instance = PluginXmlUtil.loadPluginArtifactMetadata(new StringReader(INSTANCE1));
         assertEquals(2, instance.getConfigSubstitution().size());
     }
 }

Modified: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java?rev=575143&r1=575142&r2=575143&view=diff
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java (original)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java Wed Sep 12 19:12:11 2007
@@ -29,12 +29,13 @@
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.xml.bind.JAXBException;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLStreamException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -51,6 +52,7 @@
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.util.XmlUtil;
 import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
+import org.apache.geronimo.system.plugin.PluginXmlUtil;
 import org.apache.geronimo.system.plugin.model.AttributeType;
 import org.apache.geronimo.system.plugin.model.GbeanType;
 import org.apache.geronimo.system.plugin.model.ReferenceType;
@@ -182,19 +184,14 @@
                 if (attr.isNull()) {
                     getNullAttributes().add(attr.getName());
                 } else {
-                    List<Object> content = attr.getContent();
-                    StringBuffer buf = new StringBuffer();
-                    for (Object o2 : content) {
-                        if (o2 instanceof String) {
-                            buf.append((String) o2);
-                        } else if (o2 instanceof Node) {
-                            buf.append(getContentsAsText((Node)o2));
-                        } else {
-                            buf.append("===============").append(o2.getClass()).append("===========");
-                            buf.append(o2);
-                        }
+                    String value;
+                    try {
+                        value = PluginXmlUtil.extractAttributeValue(attr);
+                    } catch (JAXBException e) {
+                        throw new InvalidGBeanException("Could not extract attribute value from gbean override", e);
+                    } catch (XMLStreamException e) {
+                        throw new InvalidGBeanException("Could not extract attribute value from gbean override", e);
                     }
-                    String value = buf.toString();
                     if (value.length() == 0) {
                         setClearAttribute(attr.getName());
                     } else {

Modified: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java?rev=575143&r1=575142&r2=575143&view=diff
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java (original)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java Wed Sep 12 19:12:11 2007
@@ -23,9 +23,6 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -52,18 +49,12 @@
 
 import javax.security.auth.login.FailedLoginException;
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.sax.SAXSource;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -94,7 +85,6 @@
 import org.apache.geronimo.system.plugin.model.DependencyType;
 import org.apache.geronimo.system.plugin.model.HashType;
 import org.apache.geronimo.system.plugin.model.LicenseType;
-import org.apache.geronimo.system.plugin.model.ObjectFactory;
 import org.apache.geronimo.system.plugin.model.PluginArtifactType;
 import org.apache.geronimo.system.plugin.model.PluginListType;
 import org.apache.geronimo.system.plugin.model.PluginType;
@@ -109,11 +99,8 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.DefaultHandler;
-import org.xml.sax.helpers.XMLFilterImpl;
 
 /**
  * A GBean that knows how to download configurations from a Maven repository.
@@ -123,20 +110,6 @@
 public class PluginInstallerGBean implements PluginInstaller {
     private final static Log log = LogFactory.getLog(PluginInstallerGBean.class);
 
-    public static final XMLInputFactory XMLINPUT_FACTORY = XMLInputFactory.newInstance();
-    private static final JAXBContext PLUGIN_CONTEXT;
-    private static final JAXBContext PLUGIN_LIST_CONTEXT;
-    private static final JAXBContext PLUGIN_ARTIFACT_CONTEXT;
-
-    static {
-        try {
-            PLUGIN_CONTEXT = JAXBContext.newInstance(PluginType.class);
-            PLUGIN_LIST_CONTEXT = JAXBContext.newInstance(PluginListType.class);
-            PLUGIN_ARTIFACT_CONTEXT = JAXBContext.newInstance(PluginArtifactType.class);
-        } catch (JAXBException e) {
-            throw new RuntimeException("Could not create jaxb contexts for plugin types");
-        }
-    }
 
     private static int counter;
     private final ConfigurationManager configManager;
@@ -263,7 +236,7 @@
             }
             PluginType result;
             try {
-                result = loadPluginMetadata(in);
+                result = PluginXmlUtil.loadPluginMetadata(in);
             } finally {
                 in.close();
             }
@@ -313,7 +286,7 @@
                     if (entry.getName().equals("META-INF/geronimo-plugin.xml")) {
                         entry = new JarEntry(entry.getName());
                         out.putNextEntry(entry);
-                        writePluginMetadata(metadata, out);
+                        PluginXmlUtil.writePluginMetadata(metadata, out);
                     } else if (entry.getName().equals("META-INF/MANIFEST.MF")) {
                         // do nothing, already passed in a manifest
                     } else {
@@ -358,7 +331,7 @@
                     }
                 }
                 fos = new FileOutputStream(xml);
-                writePluginMetadata(metadata, fos);
+                PluginXmlUtil.writePluginMetadata(metadata, fos);
             } catch (Exception e) {
                 log.error("Unable to save plugin metadata for " + artifact, e);
             } finally {
@@ -373,20 +346,6 @@
         }
     }
 
-    public static void writePluginMetadata(PluginType metadata, OutputStream out) throws XMLStreamException, JAXBException {
-        Marshaller marshaller = PLUGIN_CONTEXT.createMarshaller();
-        marshaller.setProperty("jaxb.formatted.output", true);
-        JAXBElement<PluginType> element = new ObjectFactory().createGeronimoPlugin(metadata);
-        marshaller.marshal(element, out);
-    }
-
-    public static void writePluginList(PluginListType metadata, Writer out) throws XMLStreamException, JAXBException {
-        Marshaller marshaller = PLUGIN_LIST_CONTEXT.createMarshaller();
-        marshaller.setProperty("jaxb.formatted.output", true);
-        JAXBElement<PluginListType> element = new ObjectFactory().createGeronimoPluginList(metadata);
-        marshaller.marshal(element, out);
-    }
-
     /**
      * Lists the plugins available for download in a particular Geronimo repository.
      *
@@ -407,7 +366,7 @@
         try {
             //todo: use a progress monitor
             InputStream in = openStream(null, Collections.singletonList(url), username, password, null).getStream();
-            return loadPluginList(in);
+            return PluginXmlUtil.loadPluginList(in);
         } catch (MissingDependencyException e) {
             log.error("Cannot find plugin index at site " + url);
             return null;
@@ -1441,99 +1400,13 @@
             }
             InputStream in = jar.getInputStream(entry);
             try {
-                return loadPluginMetadata(in);
+                return PluginXmlUtil.loadPluginMetadata(in);
             } finally {
                 in.close();
             }
         } finally {
             jar.close();
         }
-    }
-
-    /**
-     * Read a set of plugin metadata from a DOM document.
-     */
-    public static PluginType loadPluginMetadata(InputStream in) throws SAXException, MalformedURLException, JAXBException, XMLStreamException {
-        XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
-        Unmarshaller unmarshaller = PLUGIN_CONTEXT.createUnmarshaller();
-        JAXBElement<PluginType> element = unmarshaller.unmarshal(xmlStream, PluginType.class);
-        PluginType plugin = element.getValue();
-        return plugin;
-    }
-
-    public static PluginArtifactType loadPluginArtifactMetadata(Reader in) throws SAXException, MalformedURLException, JAXBException, XMLStreamException, ParserConfigurationException {
-        InputSource inputSource = new InputSource(in);
-
-        SAXParserFactory factory = SAXParserFactory.newInstance();
-        factory.setNamespaceAware(true);
-        factory.setValidating(false);
-        SAXParser parser = factory.newSAXParser();
-
-        Unmarshaller unmarshaller = PLUGIN_ARTIFACT_CONTEXT.createUnmarshaller();
-//        unmarshaller.setEventHandler(new ValidationEventHandler(){
-//            public boolean handleEvent(ValidationEvent validationEvent) {
-//                System.out.println(validationEvent);
-//                return false;
-//            }
-//        });
-
-
-        NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
-        xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
-
-        SAXSource source = new SAXSource(xmlFilter, inputSource);
-//        XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
-        JAXBElement<PluginArtifactType> element = unmarshaller.unmarshal(source, PluginArtifactType.class);
-        PluginArtifactType plugin = element.getValue();
-        return plugin;
-    }
-
-    public static class NamespaceFilter extends XMLFilterImpl {
-        private static String PLUGIN_NS = "http://geronimo.apache.org/xml/ns/plugins-1.3";
-        private static String GBEAN_NS = "http://geronimo.apache.org/xml/ns/attributes-1.2";
-        private static String ENVIRONMENT_NS = "http://geronimo.apache.org/xml/ns/deployment-1.2";
-
-        private String namespace;
-
-        public NamespaceFilter(XMLReader xmlReader) {
-            super(xmlReader);
-        }
-
-        @Override
-        public void startElement(String uri, String localName, String qname, Attributes atts) throws SAXException {
-            if ("plugin-artifact".equals(localName)) {
-                namespace = PLUGIN_NS;
-            } else if ("gbean".equals(localName)) {
-                namespace = GBEAN_NS;
-            } else if ("environment".equals(localName)) {
-                namespace = ENVIRONMENT_NS;
-            }
-            super.startElement(namespace, localName, qname, atts);
-        }
-
-        @Override
-        public void endElement(String uri, String localName, String qName) throws SAXException {
-            super.endElement(namespace, localName, qName);
-            if ("plugin-artifact".equals(localName)) {
-                namespace = null;
-            } else if ("gbean".equals(localName)) {
-                namespace = PLUGIN_NS;
-            } else if ("environment".equals(localName)) {
-                namespace = GBEAN_NS;
-            }
-        }
-    }
-
-    /**
-     * Loads the list of all available plugins from the specified stream
-     * (representing geronimo-plugins.xml at the specified repository).
-     */
-    public static PluginListType loadPluginList(InputStream in) throws ParserConfigurationException, IOException, SAXException, JAXBException, XMLStreamException {
-        Unmarshaller unmarshaller = PLUGIN_LIST_CONTEXT.createUnmarshaller();
-        XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
-        JAXBElement<PluginListType> element = unmarshaller.unmarshal(xmlStream, PluginListType.class);
-        PluginListType pluginList = element.getValue();
-        return pluginList;
     }
 
     /**

Added: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java?rev=575143&view=auto
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java (added)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java Wed Sep 12 19:12:11 2007
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.system.plugin;
+
+import java.io.OutputStream;
+import java.io.Writer;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.SAXParser;
+import javax.xml.transform.sax.SAXSource;
+
+import org.xml.sax.helpers.XMLFilterImpl;
+import org.xml.sax.XMLReader;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
+import org.apache.geronimo.system.plugin.model.PluginType;
+import org.apache.geronimo.system.plugin.model.ObjectFactory;
+import org.apache.geronimo.system.plugin.model.PluginListType;
+import org.apache.geronimo.system.plugin.model.PluginArtifactType;
+import org.apache.geronimo.system.plugin.model.AttributeType;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class PluginXmlUtil {
+    public static final XMLInputFactory XMLINPUT_FACTORY = XMLInputFactory.newInstance();
+    public static final JAXBContext PLUGIN_CONTEXT;
+    public static final JAXBContext PLUGIN_LIST_CONTEXT;
+    public static final JAXBContext PLUGIN_ARTIFACT_CONTEXT;
+
+    static {
+        try {
+            PLUGIN_CONTEXT = JAXBContext.newInstance(PluginType.class);
+            PLUGIN_LIST_CONTEXT = JAXBContext.newInstance(PluginListType.class);
+            PLUGIN_ARTIFACT_CONTEXT = JAXBContext.newInstance(PluginArtifactType.class);
+        } catch (JAXBException e) {
+            throw new RuntimeException("Could not create jaxb contexts for plugin types");
+        }
+    }
+
+    public static void writePluginMetadata(PluginType metadata, OutputStream out) throws XMLStreamException, JAXBException {
+        Marshaller marshaller = PLUGIN_CONTEXT.createMarshaller();
+        marshaller.setProperty("jaxb.formatted.output", true);
+        JAXBElement<PluginType> element = new ObjectFactory().createGeronimoPlugin(metadata);
+        marshaller.marshal(element, out);
+    }
+
+    public static void writePluginList(PluginListType metadata, Writer out) throws XMLStreamException, JAXBException {
+        Marshaller marshaller = PLUGIN_LIST_CONTEXT.createMarshaller();
+        marshaller.setProperty("jaxb.formatted.output", true);
+        JAXBElement<PluginListType> element = new ObjectFactory().createGeronimoPluginList(metadata);
+        marshaller.marshal(element, out);
+    }
+
+    public static void writeAttribute(AttributeType metadata, Writer out) throws XMLStreamException, JAXBException {
+        Marshaller marshaller = PLUGIN_LIST_CONTEXT.createMarshaller();
+        marshaller.setProperty("jaxb.formatted.output", true);
+        JAXBElement<AttributeType> element = new ObjectFactory().createAttribute(metadata);
+        marshaller.marshal(element, out);
+    }
+
+    public static String extractAttributeValue(AttributeType attr) throws JAXBException, XMLStreamException {
+        StringWriter sw = new StringWriter();
+        PluginXmlUtil.writeAttribute(attr, sw);
+        String s = sw.toString();
+        int start = s.indexOf('>');
+        start = s.indexOf('>', start + 1);
+        int end = s.lastIndexOf('<');
+        return s.substring(start + 1, end).trim();
+    }
+
+    /**
+     * Read a set of plugin metadata from a DOM document.
+     */
+    public static PluginType loadPluginMetadata(InputStream in) throws SAXException, MalformedURLException, JAXBException, XMLStreamException {
+        XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
+        Unmarshaller unmarshaller = PLUGIN_CONTEXT.createUnmarshaller();
+        JAXBElement<PluginType> element = unmarshaller.unmarshal(xmlStream, PluginType.class);
+        PluginType plugin = element.getValue();
+        return plugin;
+    }
+
+    public static PluginArtifactType loadPluginArtifactMetadata(Reader in) throws SAXException, MalformedURLException, JAXBException, XMLStreamException, ParserConfigurationException {
+        InputSource inputSource = new InputSource(in);
+
+        SAXParserFactory factory = SAXParserFactory.newInstance();
+        factory.setNamespaceAware(true);
+        factory.setValidating(false);
+        SAXParser parser = factory.newSAXParser();
+
+        Unmarshaller unmarshaller = PLUGIN_ARTIFACT_CONTEXT.createUnmarshaller();
+//        unmarshaller.setEventHandler(new ValidationEventHandler(){
+//            public boolean handleEvent(ValidationEvent validationEvent) {
+//                System.out.println(validationEvent);
+//                return false;
+//            }
+//        });
+
+
+        NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
+        xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
+
+        SAXSource source = new SAXSource(xmlFilter, inputSource);
+//        XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
+        JAXBElement<PluginArtifactType> element = unmarshaller.unmarshal(source, PluginArtifactType.class);
+        PluginArtifactType plugin = element.getValue();
+        return plugin;
+    }
+
+    /**
+     * Loads the list of all available plugins from the specified stream
+     * (representing geronimo-plugins.xml at the specified repository).
+     */
+    public static PluginListType loadPluginList(InputStream in) throws ParserConfigurationException, IOException, SAXException, JAXBException, XMLStreamException {
+        Unmarshaller unmarshaller = PLUGIN_LIST_CONTEXT.createUnmarshaller();
+        XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
+        JAXBElement<PluginListType> element = unmarshaller.unmarshal(xmlStream, PluginListType.class);
+        PluginListType pluginList = element.getValue();
+        return pluginList;
+    }
+
+    public static class NamespaceFilter extends XMLFilterImpl {
+        private static String PLUGIN_NS = "http://geronimo.apache.org/xml/ns/plugins-1.3";
+        private static String GBEAN_NS = "http://geronimo.apache.org/xml/ns/attributes-1.2";
+        private static String ENVIRONMENT_NS = "http://geronimo.apache.org/xml/ns/deployment-1.2";
+
+        private String namespace;
+
+        public NamespaceFilter(XMLReader xmlReader) {
+            super(xmlReader);
+        }
+
+        @Override
+        public void startElement(String uri, String localName, String qname, Attributes atts) throws SAXException {
+            if ("plugin-artifact".equals(localName)) {
+                namespace = PLUGIN_NS;
+            } else if ("gbean".equals(localName)) {
+                namespace = GBEAN_NS;
+            } else if ("environment".equals(localName)) {
+                namespace = ENVIRONMENT_NS;
+            }
+            super.startElement(namespace, localName, qname, atts);
+        }
+
+        @Override
+        public void endElement(String uri, String localName, String qName) throws SAXException {
+            super.endElement(namespace, localName, qName);
+            if ("plugin-artifact".equals(localName)) {
+                namespace = null;
+            } else if ("gbean".equals(localName)) {
+                namespace = PLUGIN_NS;
+            } else if ("environment".equals(localName)) {
+                namespace = GBEAN_NS;
+            }
+        }
+    }
+}

Propchange: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/modules/geronimo-system/src/main/xsd/attributes-1.2.xsd
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/xsd/attributes-1.2.xsd?rev=575143&r1=575142&r2=575143&view=diff
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/xsd/attributes-1.2.xsd (original)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/xsd/attributes-1.2.xsd Wed Sep 12 19:12:11 2007
@@ -71,6 +71,13 @@
             </xsd:documentation>
         </xsd:annotation>
     </xsd:element>
+    <xsd:element name="attribute" type="atts:attributeType">
+        <xsd:annotation>
+            <xsd:documentation>
+                gbean attribute as an element for ease in jaxb serialization to string.
+            </xsd:documentation>
+        </xsd:annotation>
+    </xsd:element>
 
     <xsd:complexType name="attributesType">
         <xsd:sequence>
@@ -116,7 +123,7 @@
             <xsd:element name="comment" type="xsd:string" minOccurs="0"
                 maxOccurs="1" />
             <xsd:choice minOccurs="0" maxOccurs="unbounded">
-                <xsd:element name="attribute" type="atts:attributeType" />
+                <xsd:element ref="atts:attribute" />
                 <xsd:element name="reference" type="atts:referenceType" />
             </xsd:choice>
         </xsd:sequence>

Modified: geronimo/server/trunk/modules/geronimo-system/src/test/java/org/apache/geronimo/system/plugin/CopyConfigTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/test/java/org/apache/geronimo/system/plugin/CopyConfigTest.java?rev=575143&r1=575142&r2=575143&view=diff
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/test/java/org/apache/geronimo/system/plugin/CopyConfigTest.java (original)
+++ geronimo/server/trunk/modules/geronimo-system/src/test/java/org/apache/geronimo/system/plugin/CopyConfigTest.java Wed Sep 12 19:12:11 2007
@@ -24,12 +24,15 @@
 import java.io.ByteArrayInputStream;
 import java.io.Reader;
 import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Serializable;
 import java.util.List;
 
 import junit.framework.TestCase;
 import org.apache.geronimo.system.plugin.model.PluginType;
 import org.apache.geronimo.system.plugin.model.GbeanType;
 import org.apache.geronimo.system.plugin.model.PluginArtifactType;
+import org.apache.geronimo.system.plugin.model.AttributeType;
 import org.apache.geronimo.system.configuration.GBeanOverride;
 import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
 
@@ -114,12 +117,51 @@
             "        </config-xml-content>\n" +
             "    </plugin-artifact>\n" +
             "</geronimo-plugin>";
-    private static final String ATTRIBUTE_VALUE = "<dependencies><dependency><groupId>org.apache.geronimo.cts</groupId><artifactId>server-security</artifactId><version>${version}</version><type>car</type>                         </dependency><dependency><groupId>org.apache.geronimo.cts</groupId><artifactId>database</artifactId><version>${version}</version><type>car</type>                         </dependency><dependency><groupId>org.apache.geronimo.cts</groupId><artifactId>jms</artifactId><version>${version}</version><type>car</type>                         </dependency><dependency><groupId>org.apache.geronimo.configs</groupId><artifactId>j2ee-server</artifactId><version>${geronimo.version}</version><type>car</type>                         </dependency><dependency><groupId>org.apache.geronimo.cts</groupId><artifactId>server-ior</artifactId><version>${version}</version><type>car</type>                         </dependency><dependency><groupId>org.apache.geronimo.configs</grou
 pId><artifactId>uddi-jetty6</artifactId><version>${geronimo.version}</version><type>car</type>                         </dependency>                     </dependencies>\n" +
-            "            ";
+    private static final String ATTRIBUTE_VALUE =
+            "<environment:environment xmlns:environment=\"http://geronimo.apache.org/xml/ns/deployment-1.2\">\n" +
+            "        <environment:dependencies>\n" +
+            "            <environment:dependency>\n" +
+            "                <environment:groupId>org.apache.geronimo.cts</environment:groupId>\n" +
+            "                <environment:artifactId>server-security</environment:artifactId>\n" +
+            "                <environment:version>${version}</environment:version>\n" +
+            "                <environment:type>car</environment:type>\n" +
+            "                        </environment:dependency>\n" +
+            "            <environment:dependency>\n" +
+            "                <environment:groupId>org.apache.geronimo.cts</environment:groupId>\n" +
+            "                <environment:artifactId>database</environment:artifactId>\n" +
+            "                <environment:version>${version}</environment:version>\n" +
+            "                <environment:type>car</environment:type>\n" +
+            "                        </environment:dependency>\n" +
+            "            <environment:dependency>\n" +
+            "                <environment:groupId>org.apache.geronimo.cts</environment:groupId>\n" +
+            "                <environment:artifactId>jms</environment:artifactId>\n" +
+            "                <environment:version>${version}</environment:version>\n" +
+            "                <environment:type>car</environment:type>\n" +
+            "                        </environment:dependency>\n" +
+            "            <environment:dependency>\n" +
+            "                <environment:groupId>org.apache.geronimo.configs</environment:groupId>\n" +
+            "                <environment:artifactId>j2ee-server</environment:artifactId>\n" +
+            "                <environment:version>${geronimo.version}</environment:version>\n" +
+            "                <environment:type>car</environment:type>\n" +
+            "                        </environment:dependency>\n" +
+            "            <environment:dependency>\n" +
+            "                <environment:groupId>org.apache.geronimo.cts</environment:groupId>\n" +
+            "                <environment:artifactId>server-ior</environment:artifactId>\n" +
+            "                <environment:version>${version}</environment:version>\n" +
+            "                <environment:type>car</environment:type>\n" +
+            "                        </environment:dependency>\n" +
+            "            <environment:dependency>\n" +
+            "                <environment:groupId>org.apache.geronimo.configs</environment:groupId>\n" +
+            "                <environment:artifactId>uddi-jetty6</environment:artifactId>\n" +
+            "                <environment:version>${geronimo.version}</environment:version>\n" +
+            "                <environment:type>car</environment:type>\n" +
+            "                        </environment:dependency>\n" +
+            "                    </environment:dependencies>\n" +
+            "                </environment:environment>";
 
     public void testCopyConfig() throws Exception {
         InputStream in = new ByteArrayInputStream(CONFIG.getBytes());
-        PluginType pluginType = PluginInstallerGBean.loadPluginMetadata(in);
+        PluginType pluginType = PluginXmlUtil.loadPluginMetadata(in);
         List<GbeanType> gbeans = pluginType.getPluginArtifact().get(0).getConfigXmlContent().getGbean();
         assertEquals(2, gbeans.size());
         GBeanOverride override = new GBeanOverride(gbeans.get(0), new JexlExpressionParser());
@@ -142,7 +184,81 @@
     
     public void testReadNoNS() throws Exception {
         Reader in = new StringReader(INSTANCE);
-        PluginArtifactType instance = PluginInstallerGBean.loadPluginArtifactMetadata(in);
+        PluginArtifactType instance = PluginXmlUtil.loadPluginArtifactMetadata(in);
         assertEquals("DirectoryService", instance.getConfigXmlContent().getGbean().get(0).getName());
+    }
+
+    private static final String INSTANCE2 = "                        <plugin-artifact>\n" +
+            "                            <config-xml-content>\n" +
+            "                                <gbean name=\"ResourceRefBuilder\">\n" +
+            "                                    <attribute name=\"eeNamespaces\">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute>\n" +
+            "                                    <attribute name=\"defaultEnvironment\">\n" +
+            "                                        <environment xmlns=\"http://geronimo.apache.org/xml/ns/deployment-1.2\">\n" +
+            "                                            <dependencies>\n" +
+            "                                                <dependency>\n" +
+            "                                                    <groupId>org.apache.geronimo.configs</groupId>\n" +
+            "                                                    <artifactId>j2ee-corba-yoko</artifactId>\n" +
+            "                                                    <type>car</type>\n" +
+            "                                                </dependency>\n" +
+            "                                            </dependencies>\n" +
+            "                                        </environment>\n" +
+            "                                    </attribute>\n" +
+            "                                </gbean>\n" +
+            "\n" +
+            "                                <gbean name=\"AdminObjectRefBuilder\">\n" +
+            "                                    <attribute name=\"eeNamespaces\">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute>\n" +
+            "                                </gbean>\n" +
+            "\n" +
+            "                                <gbean name=\"ClientResourceRefBuilder\">\n" +
+            "                                    <attribute name=\"eeNamespaces\">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute>\n" +
+            "                                    <attribute name=\"defaultEnvironment\">\n" +
+            "                                        <environment xmlns=\"http://geronimo.apache.org/xml/ns/deployment-1.2\">\n" +
+            "                                            <dependencies>\n" +
+            "                                                <dependency>\n" +
+            "                                                    <groupId>org.apache.geronimo.configs</groupId>\n" +
+            "                                                    <artifactId>client-corba-yoko</artifactId>\n" +
+            "                                                    <type>car</type>\n" +
+            "                                                </dependency>\n" +
+            "                                            </dependencies>\n" +
+            "                                        </environment>\n" +
+            "                                    </attribute>\n" +
+            "                                </gbean>\n" +
+            "                            </config-xml-content>\n" +
+            "                        </plugin-artifact>";
+
+    private static final String ATTR = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
+            "<ns2:attribute name=\"defaultEnvironment\" xmlns:ns2=\"http://geronimo.apache.org/xml/ns/attributes-1.2\" xmlns=\"http://geronimo.apache.org/xml/ns/plugins-1.3\">\n" +
+            "    <environment:environment xmlns:environment=\"http://geronimo.apache.org/xml/ns/deployment-1.2\">\n" +
+            "        <environment:dependencies>\n" +
+            "            <environment:dependency>\n" +
+            "                <environment:groupId>org.apache.geronimo.configs</environment:groupId>\n" +
+            "                <environment:artifactId>j2ee-corba-yoko</environment:artifactId>\n" +
+            "                <environment:type>car</environment:type>\n" +
+            "                                                </environment:dependency>\n" +
+            "                                            </environment:dependencies>\n" +
+            "                                        </environment:environment>\n" +
+            "                                    </ns2:attribute>";
+
+    private static final String VALUE =
+            "<environment:environment xmlns:environment=\"http://geronimo.apache.org/xml/ns/deployment-1.2\">\n" +
+            "        <environment:dependencies>\n" +
+            "            <environment:dependency>\n" +
+            "                <environment:groupId>org.apache.geronimo.configs</environment:groupId>\n" +
+            "                <environment:artifactId>j2ee-corba-yoko</environment:artifactId>\n" +
+            "                <environment:type>car</environment:type>\n" +
+            "                                                </environment:dependency>\n" +
+            "                                            </environment:dependencies>\n" +
+            "                                        </environment:environment>";
+    
+    public void testXmlAttribute() throws Exception {
+        Reader in = new StringReader(INSTANCE2);
+        PluginArtifactType instance = PluginXmlUtil.loadPluginArtifactMetadata(in);
+        List<GbeanType> gbeans = instance.getConfigXmlContent().getGbean();
+        assertEquals(3, gbeans.size());
+        List<Object> contents = gbeans.get(0).getAttributeOrReference();
+        assertEquals(2, contents.size());
+        AttributeType attr = (AttributeType) contents.get(1);
+        String value = PluginXmlUtil.extractAttributeValue(attr);
+        assertEquals(VALUE, value);
     }
 }



Mime
View raw message