geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject svn commit: r561989 - in /geronimo/server/trunk/modules/geronimo-system/src: main/java/org/apache/geronimo/system/configuration/ main/java/org/apache/geronimo/system/plugin/ main/resources/META-INF/schema/ test/java/org/apache/geronimo/system/configura...
Date Wed, 01 Aug 2007 23:30:03 GMT
Author: jaydm
Date: Wed Aug  1 16:29:59 2007
New Revision: 561989

URL: http://svn.apache.org/viewvc?view=rev&rev=561989
Log:
GERONIMO-1265 - Preserve comments added by users in config.xml file
   - Changes inspired by patch from Don Hill - Thanks Don!

Modified:
    geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java
    geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
    geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ServerOverride.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/resources/META-INF/schema/plugins-1.1.xsd
    geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/plugins-1.2.xsd
    geronimo/server/trunk/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java

Modified: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java?view=diff&rev=561989&r1=561988&r2=561989
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java
(original)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java
Wed Aug  1 16:29:59 2007
@@ -29,6 +29,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
 
 /**
  * @version $Rev$ $Date$
@@ -37,11 +38,12 @@
     private final Artifact name;
     private boolean load;
     private String condition;
+    private String comment;
     private final Map<Object, GBeanOverride> gbeans = new LinkedHashMap<Object,
GBeanOverride>();
 
     /**
      * Cached condition parser; lazy init on the first call to {@link #parseCondition()}
-     * whne {@link #condition} is non-null.
+     * when {@link #condition} is non-null.
      */
     private static ConditionParser parser;
 
@@ -59,6 +61,8 @@
         this.name = name;
         this.load = base.load;
         this.condition = base.condition;
+        this.comment = base.comment;
+
         for (GBeanOverride gbean : base.gbeans.values()) {
             GBeanOverride replacement = new GBeanOverride(gbean, base.name.toString(), name.toString());
             gbeans.put(replacement.getName(), replacement);
@@ -67,11 +71,12 @@
 
     public ConfigurationOverride(Element element, JexlExpressionParser expressionParser)
throws InvalidGBeanException {
         name = Artifact.create(element.getAttribute("name"));
-        
+
         condition = element.getAttribute("condition");
+        comment = getCommentText(element);
         
         String loadConfigString = element.getAttribute("load");
-        load = !"false".equals(loadConfigString);
+        load = ! "false".equals(loadConfigString);
 
         NodeList gbeans = element.getElementsByTagName("gbean");
         for (int g = 0; g < gbeans.getLength(); g++) {
@@ -93,6 +98,34 @@
         this.condition = condition;
     }
 
+    public String getComment() {
+        return comment;
+    }
+
+    public void setComment(String comment) {
+        this.comment = comment;
+    }
+
+    private String getCommentText(Element element) {
+        String commentText = "";
+
+        NodeList children = element.getChildNodes();
+        Element child = null;
+
+        for (int nodePos = 0; nodePos < children.getLength(); nodePos++) {
+            if (children.item(nodePos) instanceof Element) {
+                child = (Element) children.item(nodePos);
+
+                if (child.getTagName().equals("comment")) {
+                    commentText = child.getTextContent();
+                    break;
+                }
+            }
+        }
+
+        return commentText;
+    }
+
     private boolean parseCondition() {
         if (condition == null) {
             // no condition means true
@@ -143,11 +176,20 @@
         Element module = doc.createElement("module");
         root.appendChild(module);
         module.setAttribute("name", name.toString());
-        if (!load) {
+
+        if (! load) {
             module.setAttribute("load", "false");
         }
+
         if (condition != null && condition.trim().length() != 0) {
             module.setAttribute("condition", condition);
+        }
+
+        if (comment != null && comment.trim().length() > 0) {
+            Element eleComment = doc.createElement("comment");
+            eleComment.setTextContent(comment);
+
+            module.appendChild(eleComment);
         }
 
         // GBeans

Modified: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java?view=diff&rev=561989&r1=561988&r2=561989
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
(original)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
Wed Aug  1 16:29:59 2007
@@ -306,7 +306,7 @@
                     "http://www.w3.org/2001/XMLSchema");
 
             dFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",
-                    LocalAttributeManager.class.getResourceAsStream("/META-INF/schema/attributes-1.1.xsd"));
+                    LocalAttributeManager.class.getResourceAsStream("/META-INF/schema/attributes-1.2.xsd"));
 
             DocumentBuilder builder = dFactory.newDocumentBuilder();
             builder.setErrorHandler(new ErrorHandler() {
@@ -408,7 +408,7 @@
         dFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                 "http://www.w3.org/2001/XMLSchema");
         dFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",
-                LocalAttributeManager.class.getResourceAsStream("/META-INF/schema/attributes-1.1.xsd"));
+                LocalAttributeManager.class.getResourceAsStream("/META-INF/schema/attributes-1.2.xsd"));
 
         OutputStream output = null;
         try {

Modified: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ServerOverride.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ServerOverride.java?view=diff&rev=561989&r1=561988&r2=561989
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ServerOverride.java
(original)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ServerOverride.java
Wed Aug  1 16:29:59 2007
@@ -94,11 +94,13 @@
 
     public Element writeXml(Document doc) {
         Element root = doc.createElement("attributes");
-        root.setAttribute("xmlns", "http://geronimo.apache.org/xml/ns/attributes-1.1");
+        root.setAttribute("xmlns", "http://geronimo.apache.org/xml/ns/attributes-1.2");
         doc.appendChild(doc.createComment(" ========================================================
"));
         doc.appendChild(doc.createComment(" Warning - This XML file is re-generated by Geronimo
when "));
-        doc.appendChild(doc.createComment(" changes are made to Geronimo's configuration,
therefore  "));
-        doc.appendChild(doc.createComment(" any comments added to this file will be lost.
           "));
+        doc.appendChild(doc.createComment(" changes are made to Geronimo's configuration.
           "));
+        doc.appendChild(doc.createComment(" If you want to include comments to a module,
create a    "));
+        doc.appendChild(doc.createComment(" comment element in the module definition.  Only
the      "));
+        doc.appendChild(doc.createComment(" first comment will be maintained.           
            "));
         doc.appendChild(doc.createComment(" Do not edit this file while Geronimo is running.
        "));
         doc.appendChild(doc.createComment(" ========================================================
"));
         doc.appendChild(root);

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?view=diff&rev=561989&r1=561988&r2=561989
==============================================================================
--- 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 Aug  1 16:29:59 2007
@@ -1403,7 +1403,7 @@
                              "http://www.w3.org/2001/XMLSchema");
         factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",
                              new InputStream[]{
-                                     PluginInstallerGBean.class.getResourceAsStream("/META-INF/schema/attributes-1.1.xsd"),
+                                     PluginInstallerGBean.class.getResourceAsStream("/META-INF/schema/attributes-1.2.xsd"),
                                      PluginInstallerGBean.class.getResourceAsStream("/META-INF/schema/plugins-1.1.xsd"),
                                      PluginInstallerGBean.class.getResourceAsStream("/META-INF/schema/plugins-1.2.xsd")
                              }
@@ -1929,7 +1929,7 @@
             for (int i = 0; i < data.getConfigXmls().length; i++) {
                 GBeanOverride override = data.getConfigXmls()[i];
                 Element gbean = override.writeXml(doc, content);
-                gbean.setAttribute("xmlns", "http://geronimo.apache.org/xml/ns/attributes-1.1");
+                gbean.setAttribute("xmlns", "http://geronimo.apache.org/xml/ns/attributes-1.2");
             }
             config.appendChild(content);
         }

Modified: geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/plugins-1.1.xsd
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/plugins-1.1.xsd?view=diff&rev=561989&r1=561988&r2=561989
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/plugins-1.1.xsd
(original)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/plugins-1.1.xsd
Wed Aug  1 16:29:59 2007
@@ -18,7 +18,7 @@
 
 <xs:schema targetNamespace="http://geronimo.apache.org/xml/ns/plugins-1.1"
     xmlns:list="http://geronimo.apache.org/xml/ns/plugins-1.1"
-    xmlns:atts="http://geronimo.apache.org/xml/ns/attributes-1.1"
+    xmlns:atts="http://geronimo.apache.org/xml/ns/attributes-1.2"
     xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
     attributeFormDefault="unqualified">
 
@@ -34,8 +34,8 @@
         </xs:documentation>
     </xs:annotation>
 
-    <xs:import namespace="http://geronimo.apache.org/xml/ns/attributes-1.1"
-        schemaLocation="local-attributes-1.1.xsd" />
+    <xs:import namespace="http://geronimo.apache.org/xml/ns/attributes-1.2"
+        schemaLocation="attributes-1.2.xsd" />
 
     <xs:annotation>
         <xs:documentation>

Modified: geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/plugins-1.2.xsd
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/plugins-1.2.xsd?view=diff&rev=561989&r1=561988&r2=561989
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/plugins-1.2.xsd
(original)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/plugins-1.2.xsd
Wed Aug  1 16:29:59 2007
@@ -18,12 +18,12 @@
 
 <xs:schema targetNamespace="http://geronimo.apache.org/xml/ns/plugins-1.2"
     xmlns:list="http://geronimo.apache.org/xml/ns/plugins-1.2"
-    xmlns:atts="http://geronimo.apache.org/xml/ns/attributes-1.1"
+    xmlns:atts="http://geronimo.apache.org/xml/ns/attributes-1.2"
     xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
     attributeFormDefault="unqualified">
 
-    <xs:import namespace="http://geronimo.apache.org/xml/ns/attributes-1.1"
-        schemaLocation="local-attributes-1.1.xsd"/>
+    <xs:import namespace="http://geronimo.apache.org/xml/ns/attributes-1.2"
+        schemaLocation="local-attributes-1.2.xsd"/>
 
     <xs:annotation>
         <xs:documentation>

Modified: geronimo/server/trunk/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java?view=diff&rev=561989&r1=561988&r2=561989
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java
Wed Aug  1 16:29:59 2007
@@ -213,6 +213,25 @@
         assertCopyIdentical(restaurant);
     }
 
+    private static final String REFERENCE_COMMENT_XML =
+            "<module name=\"org.apache.geronimo.config/commentTest/2.0/car\">\n" +
+            "    <comment>This comment should get properly parsed</comment>\n"
+
+            "    <gbean name=\"CommentBean\">\n" +
+            "        <attribute name=\"value\">someValue</attribute>\n" +
+            "    </gbean>\n" +
+            "</module>";
+
+    public void testCommentXml() throws Exception {
+        String comment = "This comment should get properly parsed";
+
+        InputStream in = new ByteArrayInputStream(REFERENCE_COMMENT_XML.getBytes());
+        Element module = parseXml(in, "module");
+        ConfigurationOverride commentConfig = new ConfigurationOverride(module, expressionParser);
+
+        assertNotNull(commentConfig);
+        assertEquals(commentConfig.getComment(), comment);
+    }
+
     private static final String REFERENCE_XML =
             "        <gbean name=\"EJBBuilder\">\n" +
                     "            <attribute name=\"listener\">?name=JettyWebContainer</attribute>\n"
+



Mime
View raw message