geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r468233 - in /geronimo/server/trunk/modules/geronimo-system/src/main: java/org/apache/geronimo/system/configuration/ java/org/apache/geronimo/system/plugin/ resources/META-INF/schema/
Date Fri, 27 Oct 2006 02:09:34 GMT
Author: jdillon
Date: Thu Oct 26 19:09:34 2006
New Revision: 468233

URL: http://svn.apache.org/viewvc?view=rev&rev=468233
Log:
(GERONIMO-2525) Allow mixed content in attributes

Added:
    geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/attributes-1.1.xsd
      - copied, changed from r454011, geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/local-attributes-1.1.xsd
Removed:
    geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/local-attributes-1.1.xsd
Modified:
    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/configuration/LocalAttributeManager.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

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?view=diff&rev=468233&r1=468232&r2=468233
==============================================================================
--- 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
Thu Oct 26 19:09:34 2006
@@ -21,6 +21,7 @@
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.io.Serializable;
+import java.io.StringReader;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -31,6 +32,9 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+
 import org.apache.geronimo.common.propertyeditor.PropertyEditors;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
@@ -39,12 +43,14 @@
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.ReferencePatterns;
 import org.apache.geronimo.kernel.InvalidGBeanException;
+import org.apache.geronimo.kernel.util.XmlUtil;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.util.EncryptionManager;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
 
 /**
  * @version $Rev$ $Date$
@@ -126,8 +132,7 @@
 
             // Check to see if there is a value attribute
             if (attribute.hasAttribute("value")) {
-                setAttribute(attributeName, (String) EncryptionManager
-                        .decrypt(attribute.getAttribute("value")));
+                setAttribute(attributeName, (String) EncryptionManager.decrypt(attribute.getAttribute("value")));
                 continue;
             }
 
@@ -146,8 +151,7 @@
                 setClearAttribute(attributeName);
                 continue;
             }
-            String attributeValue = (String) EncryptionManager
-                    .decrypt(rawAttribute);
+            String attributeValue = (String) EncryptionManager.decrypt(rawAttribute);
 
             setAttribute(attributeName, attributeValue);
         }
@@ -350,7 +354,8 @@
             String value = (String) entry.getValue();
             if (value == null) {
                 setNullAttribute(name);
-            } else {
+            }
+            else {
                 if (getNullAttribute(name)) {
                     nullAttributes.remove(name);
                 }
@@ -360,10 +365,39 @@
                 Element attribute = doc.createElement("attribute");
                 attribute.setAttribute("name", name);
                 gbean.appendChild(attribute);
-                if (value.length() == 0)
+                if (value.length() == 0) {
                     attribute.setAttribute("value", "");
-                else
-                    attribute.appendChild(doc.createTextNode(value));
+                }
+                else {
+                    try {
+                        //
+                        // NOTE: Construct a new document to handle mixed content attribute
values
+                        //       then add nodes which are children of the first node.  This
allows
+                        //       value to be XML or text.
+                        //
+                        
+                        DocumentBuilderFactory factory = XmlUtil.newDocumentBuilderFactory();
+                        DocumentBuilder builder = factory.newDocumentBuilder();
+
+                        // Wrap value in an element to be sure we can handle xml or text
values
+                        String xml = "<fragment>" + value + "</fragment>";
+                        InputSource input = new InputSource(new StringReader(xml));
+                        Document fragment = builder.parse(input);
+
+                        Node root = fragment.getFirstChild();
+                        NodeList children = root.getChildNodes();
+                        for (int i=0; i<children.getLength(); i++) {
+                            Node child = children.item(i);
+
+                            // Import the child (and its children) into the new document
+                            child = doc.importNode(child, true);
+                            attribute.appendChild(child);
+                        }
+                    }
+                    catch (Exception e) {
+                        throw new RuntimeException("Failed to write attribute value fragment:
" + e.getMessage(), e);
+                    }
+                }
             }
         }
 
@@ -393,17 +427,20 @@
             Element reference = doc.createElement("reference");
             reference.setAttribute("name", name);
             gbean.appendChild(reference);
+
             Set patternSet;
             if (patterns.isResolved()) {
                 patternSet = Collections.singleton(new AbstractNameQuery(patterns.getAbstractName()));
             } else {
                 patternSet = patterns.getPatterns();
             }
+
             for (Iterator patternIterator = patternSet.iterator(); patternIterator.hasNext();)
{
                 AbstractNameQuery pattern = (AbstractNameQuery) patternIterator.next();
                 Element pat = doc.createElement("pattern");
                 reference.appendChild(pat);
                 Artifact artifact = pattern.getArtifact();
+
                 if (artifact != null) {
                     if (artifact.getGroupId() != null) {
                         Element group = doc.createElement("groupId");
@@ -426,18 +463,19 @@
                         pat.appendChild(type);
                     }
                 }
+
                 Map nameMap = pattern.getName();
                 if (nameMap.get("module") != null) {
                     Element module = doc.createElement("module");
                     module.appendChild(doc.createTextNode(nameMap.get("module").toString()));
                     pat.appendChild(module);
                 }
+
                 if (nameMap.get("name") != null) {
                     Element patName = doc.createElement("name");
                     patName.appendChild(doc.createTextNode(nameMap.get("name").toString()));
                     pat.appendChild(patName);
                 }
-//                out.print(pattern.toString());
             }
         }
 
@@ -448,6 +486,7 @@
             reference.setAttribute("name", name);
             gbean.appendChild(reference);
         }
+
         return gbean;
     }
 

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=468233&r1=468232&r2=468233
==============================================================================
--- 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
Thu Oct 26 19:09:34 2006
@@ -79,13 +79,13 @@
  * @version $Rev$ $Date$
  */
 public class LocalAttributeManager implements PluginAttributeStore, PersistentConfigurationList,
GBeanLifecycle {
-    private final static Log log = LogFactory.getLog(LocalAttributeManager.class);
+    private static final Log log = LogFactory.getLog(LocalAttributeManager.class);
 
-    private final static String CONFIG_FILE_PROPERTY = "org.apache.geronimo.config.file";
+    private static final String CONFIG_FILE_PROPERTY = "org.apache.geronimo.config.file";
 
-    private final static String BACKUP_EXTENSION = ".bak";
-    private final static String TEMP_EXTENSION = ".working";
-    private final static int SAVE_BUFFER_MS = 5000;
+    private static final String BACKUP_EXTENSION = ".bak";
+    private static final String TEMP_EXTENSION = ".working";
+    private static final int SAVE_BUFFER_MS = 5000;
 
     private final ServerInfo serverInfo;
     private final String configFile;
@@ -382,12 +382,8 @@
             dFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                                  "http://www.w3.org/2001/XMLSchema");
             
-            //
-            // TODO: Change to latest attributes schema
-            //
-            
             dFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",
-                                 LocalAttributeManager.class.getResourceAsStream("/META-INF/schema/local-attributes-1.1.xsd"));
+                                 LocalAttributeManager.class.getResourceAsStream("/META-INF/schema/attributes-1.1.xsd"));
 
             DocumentBuilder builder = dFactory.newDocumentBuilder();
             builder.setErrorHandler(new ErrorHandler() {
@@ -489,7 +485,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/local-attributes-1.1.xsd"));
+                             LocalAttributeManager.class.getResourceAsStream("/META-INF/schema/attributes-1.1.xsd"));
 
         OutputStream output = null;
         try {
@@ -498,7 +494,7 @@
             TransformerFactory xfactory = XmlUtil.newTransformerFactory();
             Transformer xform = xfactory.newTransformer();
             xform.setOutputProperty(OutputKeys.INDENT, "yes");
-            xform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+            xform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
             output = new BufferedOutputStream(new FileOutputStream(file));
 
             // use a FileOutputStream instead of a File on the StreamResult 

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=468233&r1=468232&r2=468233
==============================================================================
--- 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
Thu Oct 26 19:09:34 2006
@@ -1251,7 +1251,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/local-attributes-1.1.xsd"),
+                                     PluginInstallerGBean.class.getResourceAsStream("/META-INF/schema/attributes-1.1.xsd"),
                                      PluginInstallerGBean.class.getResourceAsStream("/META-INF/schema/plugins-1.1.xsd"),
                              }
         );

Copied: geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/attributes-1.1.xsd
(from r454011, geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/local-attributes-1.1.xsd)
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/attributes-1.1.xsd?view=diff&rev=468233&p1=geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/local-attributes-1.1.xsd&r1=454011&p2=geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/attributes-1.1.xsd&r2=468233
==============================================================================
--- geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/local-attributes-1.1.xsd
(original)
+++ geronimo/server/trunk/modules/geronimo-system/src/main/resources/META-INF/schema/attributes-1.1.xsd
Thu Oct 26 19:09:34 2006
@@ -26,10 +26,9 @@
 
     <xsd:annotation>
         <xsd:documentation>
-            <![CDATA[
             The definition of the XML format for storing manageable attribute values.
             Should look like this:
-
+            <![CDATA[
             <attributes>
                 <module name="mygroup/mycomponent/1.1/jar">
                     <gbean name="MyNetworkService">
@@ -69,14 +68,12 @@
     <xsd:complexType name="gbeanType">
         <xsd:annotation>
             <xsd:documentation>
-                <![CDATA[
                 Note that the name attribute for a gbean element may hold
                 either the full GBeanName, or only the value for the
                 "name=" portion of the GBeanName.  If there are multiple
                 GBeans in the module with manageable attributes and
                 the same "name=" portion of the GBeanName, then all must be
                 listed and all must be listed with a full GBeanName.
-                ]]>
             </xsd:documentation>
         </xsd:annotation>
         <xsd:choice minOccurs="0" maxOccurs="unbounded">
@@ -89,15 +86,24 @@
     </xsd:complexType>
 
     <xsd:complexType name="attributeType">
-        <xsd:simpleContent>
-            <xsd:extension base="xsd:string">
+        <xsd:annotation>
+            <xsd:documentation>
+                Provides the definition of a single named attribute.  Attributes are mixed
type
+                and can include simple text and elements.
+            </xsd:documentation>
+        </xsd:annotation>
+        <xsd:complexContent mixed="true">
+            <xsd:restriction base="xsd:anyType">
+                <xsd:sequence>
+                    <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
+                </xsd:sequence>
                 <xsd:attribute name="name" use="required"/>
                 <xsd:attribute name="null" use="optional"/>
                 <xsd:attribute name="value" use="optional"/>
-            </xsd:extension>
-        </xsd:simpleContent>
+            </xsd:restriction>
+        </xsd:complexContent>
     </xsd:complexType>
-
+    
     <xsd:complexType name="referenceType">
         <xsd:sequence>
             <xsd:element name="pattern" minOccurs="0" maxOccurs="unbounded">

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=468233&r1=468232&r2=468233
==============================================================================
--- 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
Thu Oct 26 19:09:34 2006
@@ -26,7 +26,7 @@
         >
 
     <xs:import namespace="http://geronimo.apache.org/xml/ns/attributes-1.1"
-               schemaLocation="local-attributes-1.1.xsd"/>
+               schemaLocation="attributes-1.1.xsd"/>
 
     <xs:annotation>
         <xs:documentation>



Mime
View raw message