geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r591737 - in /geronimo/server/trunk/framework/modules/geronimo-system/src: main/java/org/apache/geronimo/system/configuration/ main/java/org/apache/geronimo/system/plugin/ test/java/org/apache/geronimo/system/configuration/
Date Sun, 04 Nov 2007 07:38:16 GMT
Author: djencks
Date: Sun Nov  4 00:38:14 2007
New Revision: 591737

URL: http://svn.apache.org/viewvc?rev=591737&view=rev
Log:
GERONIMO-3580 use jaxb for LocalAttributeManager.  Also fix some bugs for ServerInstance gbean

Added:
    geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerReadWriteTest.java   (with props)
Modified:
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ServerOverride.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/ServerInstance.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java?rev=591737&r1=591736&r2=591737&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java Sun Nov  4 00:38:14 2007
@@ -26,10 +26,8 @@
 import org.apache.geronimo.system.configuration.condition.ConditionParser;
 import org.apache.geronimo.system.configuration.condition.JexlConditionParser;
 import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Node;
+import org.apache.geronimo.system.plugin.model.GbeanType;
+import org.apache.geronimo.system.plugin.model.ModuleType;
 
 /**
  * @version $Rev$ $Date$
@@ -69,26 +67,18 @@
         }
     }
 
-    public ConfigurationOverride(Element element, JexlExpressionParser expressionParser) throws InvalidGBeanException {
-        name = Artifact.create(element.getAttribute("name"));
+    public ConfigurationOverride(ModuleType module, JexlExpressionParser expressionParser) throws InvalidGBeanException {
+        name = Artifact.create(module.getName());
 
-        condition = element.getAttribute("condition");
-        comment = getCommentText(element);
-        
-        String loadConfigString = element.getAttribute("load");
-        load = ! "false".equals(loadConfigString);
+        condition = module.getCondition();
+        comment = module.getComment();
+        load = module.isLoad();
 
-        NodeList gbeans = element.getElementsByTagName("gbean");
-        for (int g = 0; g < gbeans.getLength(); g++) {
-            Element gbeanElement = (Element) gbeans.item(g);
-            GBeanOverride gbean = null;
-            try {
-                gbean = new GBeanOverride(gbeanElement, expressionParser);
-            } catch (NoClassDefFoundError e) {
-                throw new RuntimeException("NCDFE: geronimo-system classloader: " + getClass().getClassLoader(), e);
-            }
+        for (GbeanType gbeanType: module.getGbean()) {
+            GBeanOverride gbean = new GBeanOverride(gbeanType, expressionParser);
             addGBean(gbean);
         }
+
     }
 
     public Artifact getName() {
@@ -111,26 +101,6 @@
         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
@@ -177,28 +147,26 @@
         gbeans.put(gbeanName, gbean);
     }
 
-    public Element writeXml(Document doc, Element root) {
-        Element module = doc.createElement("module");
-        root.appendChild(module);
-        module.setAttribute("name", name.toString());
+    public ModuleType writeXml() {
+        ModuleType module = new ModuleType();
+        module.setName(name.toString());
 
         if (condition != null && condition.trim().length() != 0) {
-            module.setAttribute("condition", condition);
+            module.setCondition(condition);
         } else if (!load) {
-            module.setAttribute("load", "false");
+            module.setLoad(false);
         }
 
         if (comment != null && comment.trim().length() > 0) {
-            Element eleComment = doc.createElement("comment");
-            eleComment.setTextContent(comment);
-
-            module.appendChild(eleComment);
+            module.setComment(comment.trim());
         }
 
         // GBeans
         for (GBeanOverride gbeanOverride : gbeans.values()) {
-            gbeanOverride.writeXml(doc, module);
+            GbeanType gbean = gbeanOverride.writeXml();
+            module.getGbean().add(gbean);
         }
         return module;
     }
+
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java?rev=591737&r1=591736&r2=591737&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java Sun Nov  4 00:38:14 2007
@@ -17,18 +17,15 @@
 package org.apache.geronimo.system.configuration;
 
 import java.beans.PropertyEditor;
-import java.io.IOException;
-import java.io.PrintWriter;
+import java.io.Reader;
 import java.io.Serializable;
 import java.io.StringReader;
-import java.io.StringWriter;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -70,6 +67,7 @@
 
     private static final Log log = LogFactory.getLog(GBeanOverride.class);
 
+    public static final String ATTRIBUTE_NAMESPACE = "http://geronimo.apache.org/xml/ns/attributes-1.2";
     private final Object name;
     private boolean load;
     private final Map<String, String> attributes = new LinkedHashMap<String, String>();
@@ -166,7 +164,7 @@
         }
 
         String gbeanInfoString = gbean.getGbeanInfo();
-        if ( gbeanInfoString != null && gbeanInfoString.length() > 0) {
+        if (gbeanInfoString != null && gbeanInfoString.length() > 0) {
             gbeanInfo = gbeanInfoString;
         } else {
             gbeanInfo = null;
@@ -192,7 +190,7 @@
                     } catch (XMLStreamException e) {
                         throw new InvalidGBeanException("Could not extract attribute value from gbean override", e);
                     }
-                    if (value.length() == 0) {
+                    if (value == null || value.length() == 0) {
                         setClearAttribute(attr.getName());
                     } else {
                         String truevalue = (String) EncryptionManager.decrypt(value);
@@ -201,175 +199,40 @@
                 }
             } else if (o instanceof ReferenceType) {
                 ReferenceType ref = (ReferenceType) o;
-                Set<AbstractNameQuery> patternSet = new HashSet<AbstractNameQuery>();
-                for (ReferenceType.Pattern pattern : ref.getPattern()) {
-                    String groupId = pattern.getGroupId();
-                    String artifactId = pattern.getArtifactId();
-                    String version = pattern.getVersion();
-                    String type = pattern.getType();
-                    String module = pattern.getModule();
-                    String name = pattern.getName();
-
-                    Artifact referenceArtifact = null;
-                    if (artifactId != null) {
-                        referenceArtifact = new Artifact(groupId, artifactId, version, type);
-                    }
-                    Map<String, String> nameMap = new HashMap<String, String>();
-                    if (module != null) {
-                        nameMap.put("module", module);
-                    }
-                    if (name != null) {
-                        nameMap.put("name", name);
+                if (ref.getPattern().isEmpty()) {
+                    setClearReference(ref.getName());
+                } else {
+                    Set<AbstractNameQuery> patternSet = new HashSet<AbstractNameQuery>();
+                    for (ReferenceType.Pattern pattern : ref.getPattern()) {
+                        String groupId = pattern.getGroupId();
+                        String artifactId = pattern.getArtifactId();
+                        String version = pattern.getVersion();
+                        String type = pattern.getType();
+                        String module = pattern.getModule();
+                        String name = pattern.getName();
+
+                        Artifact referenceArtifact = null;
+                        if (artifactId != null) {
+                            referenceArtifact = new Artifact(groupId, artifactId, version, type);
+                        }
+                        Map<String, String> nameMap = new HashMap<String, String>();
+                        if (module != null) {
+                            nameMap.put("module", module);
+                        }
+                        if (name != null) {
+                            nameMap.put("name", name);
+                        }
+                        AbstractNameQuery abstractNameQuery = new AbstractNameQuery(referenceArtifact, nameMap, Collections.EMPTY_SET);
+                        patternSet.add(abstractNameQuery);
                     }
-                    AbstractNameQuery abstractNameQuery = new AbstractNameQuery(referenceArtifact, nameMap, Collections.EMPTY_SET);
-                    patternSet.add(abstractNameQuery);
+                    ReferencePatterns patterns = new ReferencePatterns(patternSet);
+                    setReferencePatterns(ref.getName(), patterns);
                 }
-                ReferencePatterns patterns = new ReferencePatterns(patternSet);
-                getReferences().put(ref.getName(), patterns);
             }
         }
         this.expressionParser = expressionParser;
     }
 
-    public GBeanOverride(Element gbean, JexlExpressionParser expressionParser) throws InvalidGBeanException {
-        String nameString = gbean.getAttribute("name");
-        if (nameString.indexOf('?') > -1) {
-            name = new AbstractName(URI.create(nameString));
-        } else {
-            name = nameString;
-        }
-
-        String gbeanInfoString = gbean.getAttribute("gbeanInfo");
-        if (gbeanInfoString.length() > 0) {
-            gbeanInfo = gbeanInfoString;
-        } else {
-            gbeanInfo = null;
-        }
-        if (gbeanInfo != null && !(name instanceof AbstractName)) {
-            throw new InvalidGBeanException("A gbean element using the gbeanInfo attribute must be specified using a full AbstractName: name=" + nameString);
-        }
-
-        String loadString = gbean.getAttribute("load");
-        load = !"false".equals(loadString);
-
-        // attributes
-        NodeList attributes = gbean.getElementsByTagName("attribute");
-        for (int a = 0; a < attributes.getLength(); a++) {
-            Element attribute = (Element) attributes.item(a);
-
-            String attributeName = attribute.getAttribute("name");
-
-            // Check to see if there is a value attribute
-            if (attribute.hasAttribute("value")) {
-                setAttribute(attributeName, (String) EncryptionManager.decrypt(attribute.getAttribute("value")));
-                continue;
-            }
-
-            // Check to see if there is a null attribute
-            if (attribute.hasAttribute("null")) {
-                String nullString = attribute.getAttribute("null");
-                if (nullString.equals("true")) {
-                    setNullAttribute(attributeName);
-                    continue;
-                }
-            }
-
-            String rawAttribute = getContentsAsText(attribute);
-            // If there are no contents, then it's to be cleared
-            if (rawAttribute.length() == 0) {
-                setClearAttribute(attributeName);
-                continue;
-            }
-            String attributeValue = (String) EncryptionManager.decrypt(rawAttribute);
-
-            setAttribute(attributeName, attributeValue);
-        }
-
-        // references
-        NodeList references = gbean.getElementsByTagName("reference");
-        for (int r = 0; r < references.getLength(); r++) {
-            Element reference = (Element) references.item(r);
-
-            String referenceName = reference.getAttribute("name");
-
-            Set<AbstractNameQuery> objectNamePatterns = new LinkedHashSet<AbstractNameQuery>();
-            NodeList patterns = reference.getElementsByTagName("pattern");
-
-            // If there is no pattern, then its an empty set, so its a
-            // cleared value
-            if (patterns.getLength() == 0) {
-                setClearReference(referenceName);
-                continue;
-            }
-
-            for (int p = 0; p < patterns.getLength(); p++) {
-                Element pattern = (Element) patterns.item(p);
-                if (pattern == null)
-                    continue;
-
-                String groupId = getChildAsText(pattern, "groupId");
-                String artifactId = getChildAsText(pattern, "artifactId");
-                String version = getChildAsText(pattern, "version");
-                String type = getChildAsText(pattern, "type");
-                String module = getChildAsText(pattern, "module");
-                String name = getChildAsText(pattern, "name");
-
-                Artifact referenceArtifact = null;
-                if (artifactId != null) {
-                    referenceArtifact = new Artifact(groupId, artifactId, version, type);
-                }
-                Map<String, String> nameMap = new HashMap<String, String>();
-                if (module != null) {
-                    nameMap.put("module", module);
-                }
-                if (name != null) {
-                    nameMap.put("name", name);
-                }
-                AbstractNameQuery abstractNameQuery = new AbstractNameQuery(referenceArtifact, nameMap, Collections.EMPTY_SET);
-                objectNamePatterns.add(abstractNameQuery);
-            }
-
-            setReferencePatterns(referenceName, new ReferencePatterns(objectNamePatterns));
-        }
-        this.expressionParser = expressionParser;
-    }
-
-    private static String getChildAsText(Element element, String name) throws InvalidGBeanException {
-        NodeList children = element.getElementsByTagName(name);
-        if (children == null || children.getLength() == 0) {
-            return null;
-        }
-        if (children.getLength() > 1) {
-            throw new InvalidGBeanException("invalid name, too many parts named: " + name);
-        }
-        return getContentsAsText(children.item(0));
-    }
-
-    private static String getContentsAsText(Node element) throws InvalidGBeanException {
-        String value = "";
-        NodeList text = element.getChildNodes();
-        for (int t = 0; t < text.getLength(); t++) {
-            Node n = text.item(t);
-            if (n.getNodeType() == Node.TEXT_NODE) {
-                value += n.getNodeValue();
-            } else {
-                StringWriter sw = new StringWriter();
-                PrintWriter pw = new PrintWriter(sw);
-                OutputFormat of = new OutputFormat(Method.XML, null, false);
-                of.setOmitXMLDeclaration(true);
-                XMLSerializer serializer = new XMLSerializer(pw, of);
-                try {
-                    serializer.prepare();
-                    serializer.serializeNode(n);
-                    value += sw.toString();
-                } catch (IOException ioe) {
-                    throw new InvalidGBeanException("Error serializing GBean element", ioe);
-                }
-            }
-        }
-        return value.trim();
-    }
-
     public Object getName() {
         return name;
     }
@@ -439,7 +302,11 @@
     }
 
     public void setAttribute(String attributeName, String attributeValue) {
-        attributes.put(attributeName, attributeValue);
+        if (attributeValue == null || attributeValue.length() == 0) {
+            clearAttributes.add(attributeName);
+        } else {
+            attributes.put(attributeName, attributeValue);
+        }
     }
 
     public Map<String, ReferencePatterns> getReferences() {
@@ -543,10 +410,125 @@
      * GBeanOverride, adds it to the parent, and then returns the new
      * child element.
      *
-     * @param doc    document containing the module, hence also the element returned from this method.
-     * @param parent module element this override will be inserted into
      * @return newly created element for this override
      */
+    public GbeanType writeXml() {
+        GbeanType gbean = new GbeanType();
+        String gbeanName;
+        if (name instanceof String) {
+            gbeanName = (String) name;
+        } else {
+            gbeanName = name.toString();
+        }
+        gbean.setName(gbeanName);
+        if (gbeanInfo != null) {
+            gbean.setGbeanInfo(gbeanInfo);
+        }
+        if (!load) {
+            gbean.setLoad(false);
+        }
+
+        // attributes
+        for (Map.Entry<String, String> entry : attributes.entrySet()) {
+            String name = entry.getKey();
+            String value = entry.getValue();
+            if (value == null) {
+                setNullAttribute(name);
+            } else {
+                if (getNullAttribute(name)) {
+                    nullAttributes.remove(name);
+                }
+                if (name.toLowerCase().indexOf("password") > -1) {
+                    value = EncryptionManager.encrypt(value);
+                }
+/**
+ * if there was a value such as jdbc url with &amp; then when that value was oulled
+ * from the config.xml the &amp; would have been replaced/converted to '&', we need to check
+ * and change it back because an & would create a parse exception.
+ */
+                value = "<attribute xmlns='" + ATTRIBUTE_NAMESPACE + "'>" + value.replaceAll("&(?!amp;)", "&amp;") + "</attribute>";
+                Reader reader = new StringReader(value);
+                try {
+                    AttributeType attribute = PluginXmlUtil.loadAttribute(reader);
+                    attribute.setName(name);
+                    gbean.getAttributeOrReference().add(attribute);
+                } catch (Exception e) {
+                    log.error("Could not serialize attribute " + name + " in gbean " + gbeanName + ", value: " + value, e);
+                }
+            }
+        }
+
+        // cleared attributes
+        for (String name : clearAttributes) {
+            AttributeType attribute = new AttributeType();
+            attribute.setName(name);
+            gbean.getAttributeOrReference().add(attribute);
+        }
+
+        // Null attributes
+        for (String name : nullAttributes) {
+            AttributeType attribute = new AttributeType();
+            attribute.setName(name);
+            attribute.setNull(true);
+            gbean.getAttributeOrReference().add(attribute);
+        }
+
+        // references
+        for (Map.Entry<String, ReferencePatterns> entry : references.entrySet()) {
+            String name = entry.getKey();
+            ReferencePatterns patterns = entry.getValue();
+            ReferenceType reference = new ReferenceType();
+            reference.setName(name);
+
+            Set<AbstractNameQuery> patternSet;
+            if (patterns.isResolved()) {
+                patternSet = Collections.singleton(new AbstractNameQuery(patterns.getAbstractName()));
+            } else {
+                patternSet = patterns.getPatterns();
+            }
+
+            for (AbstractNameQuery pattern : patternSet) {
+                ReferenceType.Pattern patternType = new ReferenceType.Pattern();
+                Artifact artifact = pattern.getArtifact();
+
+                if (artifact != null) {
+                    if (artifact.getGroupId() != null) {
+                        patternType.setGroupId(artifact.getGroupId());
+                    }
+                    if (artifact.getArtifactId() != null) {
+                        patternType.setArtifactId(artifact.getArtifactId());
+                    }
+                    if (artifact.getVersion() != null) {
+                        patternType.setVersion(artifact.getVersion().toString());
+                    }
+                    if (artifact.getType() != null) {
+                        patternType.setType(artifact.getType());
+                    }
+                }
+
+                Map nameMap = pattern.getName();
+                if (nameMap.get("module") != null) {
+                    patternType.setModule((String) nameMap.get("module"));
+                }
+
+                if (nameMap.get("name") != null) {
+                    patternType.setName((String) nameMap.get("name"));
+                }
+                reference.getPattern().add(patternType);
+            }
+            gbean.getAttributeOrReference().add(reference);
+        }
+
+        // cleared references
+        for (String name : clearReferences) {
+            ReferenceType reference = new ReferenceType();
+            reference.setName(name);
+            gbean.getAttributeOrReference().add(reference);
+        }
+
+        return gbean;
+    }
+
     public Element writeXml(Document doc, Element parent) {
         String gbeanName;
         if (name instanceof String) {

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java?rev=591737&r1=591736&r2=591737&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java Sun Nov  4 00:38:14 2007
@@ -16,15 +16,16 @@
  */
 package org.apache.geronimo.system.configuration;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.Writer;
+import java.io.Reader;
+import java.io.FileReader;
+import java.io.BufferedReader;
+import java.io.FileWriter;
+import java.io.BufferedWriter;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -35,15 +36,9 @@
 import java.util.Timer;
 import java.util.TimerTask;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
+import javax.xml.bind.JAXBException;
+import javax.xml.stream.XMLStreamException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -61,16 +56,12 @@
 import org.apache.geronimo.kernel.config.ManageableAttributeStore;
 import org.apache.geronimo.kernel.config.PersistentConfigurationList;
 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.model.GbeanType;
+import org.apache.geronimo.system.plugin.model.AttributesType;
+import org.apache.geronimo.system.plugin.PluginXmlUtil;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
 
 /**
  * Stores managed attributes in an XML file on the local filesystem.
@@ -315,78 +306,32 @@
         if (!attributeFile.exists()) {
             return;
         }
-        InputStream input = new BufferedInputStream(new FileInputStream(attributeFile));
-        InputSource source = new InputSource(input);
-        source.setSystemId(attributeFile.toString());
-        DocumentBuilderFactory dFactory = XmlUtil.newDocumentBuilderFactory();
+        Reader input = new BufferedReader(new FileReader(attributeFile));
 
         try {
-            dFactory.setValidating(true);
-            dFactory.setNamespaceAware(true);
-            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.2.xsd"));
-
-            DocumentBuilder builder = dFactory.newDocumentBuilder();
-            builder.setErrorHandler(new ErrorHandler() {
-                public void error(SAXParseException e) {
-                    log.error("Unable to read saved manageable attributes. " +
-                            "SAX parse error: " + e.getMessage() +
-                            " at line " + e.getLineNumber() +
-                            ", column " + e.getColumnNumber() +
-                            " in entity " + e.getSystemId());
+            serverOverride = read(input, expressionParser);
 
-                    if (log.isTraceEnabled()) {
-                        log.trace("Exception deatils", e);
-                    }
-
-                    // TODO throw an exception here?
-                }
-
-                public void fatalError(SAXParseException e) {
-                    log.error("Unable to read saved manageable attributes. " +
-                            "Fatal SAX parse error: " + e.getMessage() +
-                            " at line " + e.getLineNumber() +
-                            ", column " + e.getColumnNumber() +
-                            " in entity " + e.getSystemId());
-
-                    if (log.isTraceEnabled()) {
-                        log.trace("Exception deatils", e);
-                    }
-
-                    // TODO throw an exception here?
-                }
-
-                public void warning(SAXParseException e) {
-                    log.error("SAX parse warning whilst reading saved manageable attributes: " +
-                            e.getMessage() +
-                            " at line " + e.getLineNumber() +
-                            ", column " + e.getColumnNumber() +
-                            " in entity " + e.getSystemId());
-
-                    if (log.isTraceEnabled()) {
-                        log.trace("Exception deatils", e);
-                    }
-                }
-            });
-
-            Document doc = builder.parse(source);
-            Element root = doc.getDocumentElement();
-            serverOverride = new ServerOverride(root, expressionParser);
         } catch (SAXException e) {
             log.error("Unable to read saved manageable attributes", e);
         } catch (ParserConfigurationException e) {
             log.error("Unable to read saved manageable attributes", e);
         } catch (InvalidGBeanException e) {
             log.error("Unable to read saved manageable attributes", e);
+        } catch (JAXBException e) {
+            log.error("Unable to read saved manageable attributes", e);
+        } catch (XMLStreamException e) {
+            log.error("Unable to read saved manageable attributes", e);
         } finally {
             // input is always non-null
             input.close();
         }
     }
 
+    static ServerOverride read(Reader input, JexlExpressionParser expressionParser) throws ParserConfigurationException, IOException, SAXException, JAXBException, XMLStreamException, InvalidGBeanException {
+        AttributesType attributes = PluginXmlUtil.loadAttributes(input);
+        return new ServerOverride(attributes, expressionParser);
+    }
+
     public synchronized void save() throws IOException {
         if (readOnly) {
             return;
@@ -424,48 +369,27 @@
     }
 
     private static void saveXmlToFile(File file, ServerOverride serverOverride) {
-        DocumentBuilderFactory dFactory = XmlUtil.newDocumentBuilderFactory();
-        dFactory.setValidating(true);
-        dFactory.setNamespaceAware(true);
-        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.2.xsd"));
-
-        OutputStream output = null;
         try {
-            Document doc = dFactory.newDocumentBuilder().newDocument();
-            serverOverride.writeXml(doc);
-            TransformerFactory xfactory = XmlUtil.newTransformerFactory();
-            Transformer xform = xfactory.newTransformer();
-            xform.setOutputProperty(OutputKeys.INDENT, "yes");
-            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 
-            // constructor as problems were encountered with the file not being closed.
-            StreamResult sr = new StreamResult(output);
-            xform.transform(new DOMSource(doc), sr);
-
-            output.flush();
-        } catch (FileNotFoundException e) {
-            // file is directory or cannot be created/opened
-            log.error("Unable to write config.xml", e);
-        } catch (ParserConfigurationException e) {
-            log.error("Unable to write config.xml", e);
-        } catch (TransformerException e) {
-            log.error("Unable to write config.xml", e);
+            Writer fileOut = new FileWriter(file);
+            try {
+                Writer writer = new BufferedWriter(fileOut);
+                write(serverOverride, writer);
+            } catch (JAXBException e) {
+                log.error("Unable to write config.xml", e);
+            } catch (XMLStreamException e) {
+                log.error("Unable to write config.xml", e);
+            } finally {
+                fileOut.close();
+            }
         } catch (IOException e) {
             log.error("Unable to write config.xml", e);
-        } finally {
-            if (output != null) {
-                try {
-                    output.close();
-                } catch (IOException ignored) {
-                    // ignored
-                }
-            }
         }
+   }
+
+    static void write(ServerOverride serverOverride, Writer writer) throws XMLStreamException, JAXBException, IOException {
+        AttributesType attributes = serverOverride.writeXml();
+        PluginXmlUtil.writeAttributes(attributes, writer);
+        writer.flush();
     }
 
     //PersistentConfigurationList

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ServerOverride.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ServerOverride.java?rev=591737&r1=591736&r2=591737&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ServerOverride.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ServerOverride.java Sun Nov  4 00:38:14 2007
@@ -16,9 +16,7 @@
  */
 package org.apache.geronimo.system.configuration;
 
-import java.io.PrintWriter;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -26,9 +24,8 @@
 import org.apache.geronimo.kernel.InvalidGBeanException;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Document;
+import org.apache.geronimo.system.plugin.model.AttributesType;
+import org.apache.geronimo.system.plugin.model.ModuleType;
 
 /**
  * @version $Rev$ $Date$
@@ -39,20 +36,15 @@
     public ServerOverride() {
     }
 
-    public ServerOverride(Element element, JexlExpressionParser expressionParser) throws InvalidGBeanException {
-        NodeList configs = element.getElementsByTagName("module");
-        for (int i = 0; i < configs.getLength(); i++) {
-            Element configurationElement = (Element) configs.item(i);
-            ConfigurationOverride configuration = new ConfigurationOverride(configurationElement, expressionParser);
-            addConfiguration(configuration);
+    public ServerOverride(AttributesType attributes, JexlExpressionParser expressionParser) throws InvalidGBeanException {
+        for (ModuleType moduleType: attributes.getModule()) {
+            ConfigurationOverride module = new ConfigurationOverride(moduleType, expressionParser);
+            addConfiguration(module);
         }
-
         // The config.xml file in 1.0 use configuration instead of module
-        configs = element.getElementsByTagName("configuration");
-        for (int i = 0; i < configs.getLength(); i++) {
-            Element configurationElement = (Element) configs.item(i);
-            ConfigurationOverride configuration = new ConfigurationOverride(configurationElement, expressionParser);
-            addConfiguration(configuration);
+        for (ModuleType moduleType: attributes.getConfiguration()) {
+            ConfigurationOverride module = new ConfigurationOverride(moduleType, expressionParser);
+            addConfiguration(module);
         }
     }
 
@@ -61,7 +53,7 @@
     }
 
     public ConfigurationOverride getConfiguration(Artifact configurationName, boolean create) {
-        ConfigurationOverride configuration = (ConfigurationOverride) configurations.get(configurationName);
+        ConfigurationOverride configuration = configurations.get(configurationName);
         if (create && configuration == null) {
             configuration = new ConfigurationOverride(configurationName, true);
             configurations.put(configurationName, configuration);
@@ -82,16 +74,25 @@
     }
 
     public Artifact[] queryConfigurations(Artifact query) {
-        List list = new ArrayList();
-        for (Iterator it = configurations.keySet().iterator(); it.hasNext();) {
-            Artifact test = (Artifact) it.next();
-            if(query.matches(test)) {
+        List<Artifact> list = new ArrayList<Artifact>();
+        for (Artifact test : configurations.keySet()) {
+            if (query.matches(test)) {
                 list.add(test);
             }
         }
-        return (Artifact[]) list.toArray(new Artifact[list.size()]);
+        return list.toArray(new Artifact[list.size()]);
+    }
+
+    public AttributesType writeXml() {
+        AttributesType attributes = new AttributesType();
+        for (ConfigurationOverride module: configurations.values()) {
+            ModuleType moduleType = module.writeXml();
+            attributes.getModule().add(moduleType);
+        }
+        return attributes;
     }
 
+/*
     public Element writeXml(Document doc) {
         Element root = doc.createElement("attributes");
         root.setAttribute("xmlns", "http://geronimo.apache.org/xml/ns/attributes-1.2");
@@ -111,4 +112,5 @@
         }
         return root;
     }
+*/
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java?rev=591737&r1=591736&r2=591737&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/PluginXmlUtil.java Sun Nov  4 00:38:14 2007
@@ -51,21 +51,32 @@
 import org.apache.geronimo.system.plugin.model.PluginListType;
 import org.apache.geronimo.system.plugin.model.PluginArtifactType;
 import org.apache.geronimo.system.plugin.model.AttributeType;
+import org.apache.geronimo.system.plugin.model.AttributesType;
+import org.apache.geronimo.system.plugin.model.ModuleType;
+import org.apache.geronimo.system.plugin.model.GbeanType;
 
 /**
- * @version $Rev:$ $Date:$
+ * @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;
+    public static final JAXBContext ATTRIBUTES_CONTEXT;
+    public static final JAXBContext ATTRIBUTE_CONTEXT;
+    public static final JAXBContext MODULE_CONTEXT;
+    public static final JAXBContext GBEAN_CONTEXT;
 
     static {
         try {
             PLUGIN_CONTEXT = JAXBContext.newInstance(PluginType.class);
             PLUGIN_LIST_CONTEXT = JAXBContext.newInstance(PluginListType.class);
             PLUGIN_ARTIFACT_CONTEXT = JAXBContext.newInstance(PluginArtifactType.class);
+            ATTRIBUTES_CONTEXT = JAXBContext.newInstance(AttributesType.class);
+            MODULE_CONTEXT = JAXBContext.newInstance(ModuleType.class);
+            GBEAN_CONTEXT = JAXBContext.newInstance(GbeanType.class);
+            ATTRIBUTE_CONTEXT = JAXBContext.newInstance(AttributeType.class);
         } catch (JAXBException e) {
             throw new RuntimeException("Could not create jaxb contexts for plugin types");
         }
@@ -91,7 +102,6 @@
         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);
@@ -99,9 +109,19 @@
         int start = s.indexOf('>');
         start = s.indexOf('>', start + 1);
         int end = s.lastIndexOf('<');
+        if (end < start) {
+            return null;
+        }
         return s.substring(start + 1, end).trim();
     }
 
+    public static void writeAttributes(AttributesType metadata, Writer out) throws XMLStreamException, JAXBException {
+        Marshaller marshaller = PLUGIN_LIST_CONTEXT.createMarshaller();
+        marshaller.setProperty("jaxb.formatted.output", true);
+        JAXBElement<AttributesType> element = new ObjectFactory().createAttributes(metadata);
+        marshaller.marshal(element, out);
+    }
+
     /**
      * Read a set of plugin metadata from a DOM document.
      */
@@ -150,6 +170,35 @@
         JAXBElement<PluginListType> element = unmarshaller.unmarshal(xmlStream, PluginListType.class);
         PluginListType pluginList = element.getValue();
         return pluginList;
+    }
+
+    public static AttributesType loadAttributes(Reader in) throws ParserConfigurationException, IOException, SAXException, JAXBException, XMLStreamException {
+        Unmarshaller unmarshaller = ATTRIBUTES_CONTEXT.createUnmarshaller();
+        XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
+        JAXBElement<AttributesType> element = unmarshaller.unmarshal(xmlStream, AttributesType.class);
+        AttributesType pluginList = element.getValue();
+        return pluginList;
+    }
+    public static ModuleType loadModule(Reader in) throws ParserConfigurationException, IOException, SAXException, JAXBException, XMLStreamException {
+        Unmarshaller unmarshaller = MODULE_CONTEXT.createUnmarshaller();
+        XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
+        JAXBElement<ModuleType> element = unmarshaller.unmarshal(xmlStream, ModuleType.class);
+        ModuleType pluginList = element.getValue();
+        return pluginList;
+    }
+    public static GbeanType loadGbean(Reader in) throws ParserConfigurationException, IOException, SAXException, JAXBException, XMLStreamException {
+        Unmarshaller unmarshaller = GBEAN_CONTEXT.createUnmarshaller();
+        XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
+        JAXBElement<GbeanType> element = unmarshaller.unmarshal(xmlStream, GbeanType.class);
+        GbeanType pluginList = element.getValue();
+        return pluginList;
+    }
+    public static AttributeType loadAttribute(Reader in) throws ParserConfigurationException, IOException, SAXException, JAXBException, XMLStreamException {
+        Unmarshaller unmarshaller = ATTRIBUTE_CONTEXT.createUnmarshaller();
+        XMLStreamReader xmlStream = XMLINPUT_FACTORY.createXMLStreamReader(in);
+        JAXBElement<AttributeType> element = unmarshaller.unmarshal(xmlStream, AttributeType.class);
+        AttributeType attributeType = element.getValue();
+        return attributeType;
     }
 
     public static class NamespaceFilter extends XMLFilterImpl {

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/ServerInstance.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/ServerInstance.java?rev=591737&r1=591736&r2=591737&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/ServerInstance.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/plugin/ServerInstance.java Sun Nov  4 00:38:14 2007
@@ -26,7 +26,7 @@
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
 public class ServerInstance {
 
@@ -35,6 +35,12 @@
     private final AliasedArtifactResolver artifactResolver;
 
 
+    public ServerInstance() {
+        serverName = null;
+        attributeStore = null;
+        artifactResolver = null;
+    }
+
     public ServerInstance(String serverName, PluginAttributeStore attributeStore, AliasedArtifactResolver artifactResolver) {
         this.serverName = serverName;
         this.attributeStore = attributeStore;
@@ -55,7 +61,7 @@
     public static final GBeanInfo GBEAN_INFO;
 
     static {
-        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ServerInstance.class);
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ServerInstance.class, "ServerInstance");
         infoFactory.addAttribute("serverName", String.class, true, true);
         infoFactory.addReference("PluginAttributeStore", PluginAttributeStore.class, "AttributeStore");
         infoFactory.addReference("ArtifactResolver", AliasedArtifactResolver.class, "ArtifactResolver");

Added: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerReadWriteTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerReadWriteTest.java?rev=591737&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerReadWriteTest.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerReadWriteTest.java Sun Nov  4 00:38:14 2007
@@ -0,0 +1,271 @@
+/*
+ * 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.configuration;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class LocalAttributeManagerReadWriteTest extends TestCase {
+
+    private static final String CONFIG =
+            "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
+                    "<ns2:attributes xmlns:ns2=\"http://geronimo.apache.org/xml/ns/attributes-1.2\" xmlns=\"http://geronimo.apache.org/xml/ns/plugins-1.3\">\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/ca-helper-jetty/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/jasper/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/j2ee-server/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/transaction/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/jetty6/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"JettyWebConnector\">\n" +
+                    "            <ns2:attribute name=\"host\">${ServerHostname}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"port\">${HTTPPort + PortOffset}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"redirectPort\">${HTTPSPortPrimary + PortOffset}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "        <ns2:gbean name=\"JettyAJP13Connector\">\n" +
+                    "            <ns2:attribute name=\"host\">${ServerHostname}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"port\">${AJPPort + PortOffset}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"redirectPort\">${HTTPSPortPrimary + PortOffset}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "        <ns2:gbean name=\"JettySSLConnector\">\n" +
+                    "            <ns2:attribute name=\"host\">${ServerHostname}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"port\">${HTTPSPort + PortOffset}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/clustering/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"Node\">\n" +
+                    "            <ns2:attribute name=\"nodeName\">${clusterNodeName}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/webservices-common/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/myfaces-deployer/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/myfaces/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/j2ee-deployer/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"WebBuilder\">\n" +
+                    "            <ns2:attribute name=\"defaultNamespace\">http://geronimo.apache.org/xml/ns/j2ee/web/jetty-2.0</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "        <ns2:gbean name=\"EnvironmentEntryBuilder\">\n" +
+                    "            <ns2:attribute name=\"eeNamespaces\">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/activemq-ra/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"ActiveMQ RA\">\n" +
+                    "            <ns2:attribute name=\"ServerUrl\">tcp://${ServerHostname}:${ActiveMQPort + PortOffset}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/activemq-broker/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"ActiveMQ.tcp.default\">\n" +
+                    "            <ns2:attribute name=\"host\">${ServerHostname}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"port\">${ActiveMQPort + PortOffset}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "        <ns2:gbean name=\"ActiveMQ.stomp.default\">\n" +
+                    "            <ns2:attribute name=\"host\">${ServerHostname}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"port\">${ActiveMQStompPort + PortOffset}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/system-database/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"DerbyNetwork\">\n" +
+                    "            <ns2:attribute name=\"host\">${ServerHostname}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"port\">${DerbyPort + PortOffset}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/connector-deployer/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"ResourceRefBuilder\">\n" +
+                    "            <ns2:attribute name=\"eeNamespaces\">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"defaultEnvironment\">\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></ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "        <ns2:gbean name=\"AdminObjectRefBuilder\">\n" +
+                    "            <ns2:attribute name=\"eeNamespaces\">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "        <ns2:gbean name=\"ClientResourceRefBuilder\">\n" +
+                    "            <ns2:attribute name=\"eeNamespaces\">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"defaultEnvironment\">\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>client-corba-yoko</environment:artifactId>\n" +
+                    "                            <environment:type>car</environment:type>\n" +
+                    "            </environment:dependency>\n" +
+                    "          </environment:dependencies>\n" +
+                    "        </environment:environment></ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/jasper-deployer/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/jetty6-deployer/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/client-security/2.1-SNAPSHOT/car\" load=\"false\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/client/2.1-SNAPSHOT/car\" load=\"false\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/axis2-ejb-deployer/2.1-SNAPSHOT/car\" condition=\"props['org.apache.geronimo.jaxws.provider'] == 'axis2'\">\n" +
+                    "        <ns2:gbean name=\"Axis2ModuleBuilderExtension\">\n" +
+                    "            <ns2:attribute name=\"listener\">?name=${webcontainer}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/jaxws-ejb-deployer/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/jaxws-deployer/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/openejb-deployer/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"EjbRefBuilder\">\n" +
+                    "            <ns2:attribute name=\"eeNamespaces\">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "        <ns2:gbean name=\"ClientEjbRefBuilder\">\n" +
+                    "            <ns2:attribute name=\"eeNamespaces\">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"host\">${ServerHostname}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"port\">${OpenEJBPort + PortOffset}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/openejb/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"EJBNetworkService\">\n" +
+                    "            <ns2:attribute name=\"port\">${OpenEJBPort + PortOffset}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"host\">${ServerHostname}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/openjpa/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/axis2-deployer/2.1-SNAPSHOT/car\" condition=\"props['org.apache.geronimo.jaxws.provider'] == 'axis2'\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/axis2/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/axis2-ejb/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.plugins/system-database-jetty/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.plugins/console-jetty/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.plugins/pluto-support/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/spring/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/transformer-agent/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/remote-deploy-jetty/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/cxf-ejb/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/cxf/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.plugins/debugviews-jetty/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/dojo-jetty6/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/persistence-jpa10-deployer/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"PersistenceUnitBuilder\">\n" +
+                    "            <ns2:attribute name=\"defaultPersistenceProviderClassName\">org.apache.openjpa.persistence.PersistenceProviderImpl</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"defaultPersistenceUnitProperties\">openjpa.Log=commons\n" +
+                    "                                        openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=true)\n" +
+                    "                                        openjpa.jdbc.UpdateManager=operation-order\n" +
+                    "                                        openjpa.Sequence=table(Table=OPENJPASEQ, Increment=100)</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"defaultEnvironment\">\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>openjpa</environment:artifactId>\n" +
+                    "                            <environment:type>car</environment:type>\n" +
+                    "            </environment:dependency>\n" +
+                    "          </environment:dependencies>\n" +
+                    "        </environment:environment></ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.plugins/activemq-jetty/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/jetty6-clustering-wadi/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/wadi-clustering/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"DefaultBackingStrategyFactory\">\n" +
+                    "            <ns2:attribute name=\"nbReplica\">${ReplicaCount}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "        <ns2:gbean name=\"DefaultDispatcherHolder\">\n" +
+                    "            <ns2:attribute name=\"endPointURI\">${EndPointURI}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"clusterName\">${ClusterName}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/uddi-jetty6/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/axis/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/axis-deployer/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"AxisModuleBuilderExtension\">\n" +
+                    "            <ns2:attribute name=\"listener\">?name=${webcontainer}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"defaultEnvironment\">\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>${webcontainerName}</environment:artifactId>\n" +
+                    "                            <environment:type>car</environment:type>\n" +
+                    "            </environment:dependency>\n" +
+                    "          </environment:dependencies>\n" +
+                    "        </environment:environment></ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/j2ee-corba-yoko/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"NameServer\">\n" +
+                    "            <ns2:attribute name=\"port\">${COSNamingPort + PortOffset}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"host\">${COSNamingHost}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "        <ns2:gbean name=\"Server\">\n" +
+                    "            <ns2:attribute name=\"port\">${ORBSSLPort + PortOffset}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"host\">${ORBSSLHost}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "        <ns2:gbean name=\"UnprotectedServer\">\n" +
+                    "            <ns2:attribute name=\"port\">${ORBPort + PortOffset}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"host\">${ORBHost}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/mejb/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/jetty6-clustering-builder-wadi/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"JettyClusteringBuilder\">\n" +
+                    "            <ns2:attribute name=\"defaultSweepInterval\">${DefaultWadiSweepInterval}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"defaultNumPartitions\">${DefaultWadiNumPartitions}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/hot-deployer/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"HotDeployer\">\n" +
+                    "            <ns2:attribute name=\"path\">deploy/</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"pollIntervalMillis\">2000</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/openejb-corba-deployer/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/client-corba-yoko/2.1-SNAPSHOT/car\" load=\"false\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/javamail/2.1-SNAPSHOT/car\">\n" +
+                    "        <ns2:gbean name=\"SMTPTransport\">\n" +
+                    "            <ns2:attribute name=\"host\">${SMTPHost}</ns2:attribute>\n" +
+                    "            <ns2:attribute name=\"port\">${SMTPPort + PortOffset}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/cxf-deployer/2.1-SNAPSHOT/car\" condition=\"props.getProperty('org.apache.geronimo.jaxws.provider', 'cxf') == 'cxf'\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/welcome-jetty/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/sharedlib/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/client-deployer/2.1-SNAPSHOT/car\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/client-transaction/2.1-SNAPSHOT/car\" load=\"false\"/>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.configs/cxf-ejb-deployer/2.1-SNAPSHOT/car\" condition=\"props.getProperty('org.apache.geronimo.jaxws.provider', 'cxf') == 'cxf'\">\n" +
+                    "        <ns2:gbean name=\"CXFModuleBuilderExtension\">\n" +
+                    "            <ns2:attribute name=\"listener\">?name=${webcontainer}</ns2:attribute>\n" +
+                    "        </ns2:gbean>\n" +
+                    "    </ns2:module>\n" +
+                    "    <ns2:module name=\"org.apache.geronimo.plugins/plancreator-jetty/2.1-SNAPSHOT/car\"/>\n" +
+                    "</ns2:attributes>\n";
+    
+    public void testReadWrite() throws Exception {
+        Reader reader = new StringReader(CONFIG);
+        JexlExpressionParser parser = new JexlExpressionParser();
+        ServerOverride serverOverride = LocalAttributeManager.read(reader, parser);
+        StringWriter writer = new StringWriter();
+        LocalAttributeManager.write(serverOverride, writer);
+        String result = writer.toString();
+        assertEquals(CONFIG, result);
+    }
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerReadWriteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerReadWriteTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerReadWriteTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java?rev=591737&r1=591736&r2=591737&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java Sun Nov  4 00:38:14 2007
@@ -16,45 +16,32 @@
  */
 package org.apache.geronimo.system.configuration;
 
-import junit.framework.TestCase;
-import org.apache.geronimo.gbean.AbstractNameQuery;
-import org.apache.geronimo.gbean.ReferencePatterns;
-import org.apache.geronimo.gbean.GBeanData;
-import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.util.XmlUtil;
-import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.dom.DOMSource;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.Iterator;
+import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
-import java.util.HashMap;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.ReferencePatterns;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
+import org.apache.geronimo.system.plugin.PluginXmlUtil;
+import org.apache.geronimo.system.plugin.model.GbeanType;
+import org.apache.geronimo.system.plugin.model.ModuleType;
 
 /**
  * @version $Rev$ $Date$
  */
 public class ServerOverrideTest extends TestCase {
-    private static final Log log = LogFactory.getLog(ServerOverrideTest.class);
     private JexlExpressionParser expressionParser;
 
     protected void setUp() throws java.lang.Exception {
@@ -101,7 +88,7 @@
     }
 
     private ReferencePatterns getReferencePatterns(AbstractNameQuery[] queries) {
-        Set querySet = new LinkedHashSet(Arrays.asList(queries));
+        Set<AbstractNameQuery> querySet = new LinkedHashSet<AbstractNameQuery>(Arrays.asList(queries));
         return new ReferencePatterns(querySet);
     }
 
@@ -214,7 +201,7 @@
     }
 
     private static final String REFERENCE_COMMENT_XML =
-            "<module name=\"org.apache.geronimo.config/commentTest/2.0/car\">\n" +
+            "<module name=\"org.apache.geronimo.config/commentTest/2.0/car\" xmlns='" + GBeanOverride.ATTRIBUTE_NAMESPACE + "'>\n" +
             "    <comment>This comment should get properly parsed</comment>\n" +
             "    <gbean name=\"CommentBean\">\n" +
             "        <attribute name=\"value\">someValue</attribute>\n" +
@@ -224,8 +211,8 @@
     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");
+        Reader in = new StringReader(REFERENCE_COMMENT_XML);
+        ModuleType module = PluginXmlUtil.loadModule(in);
         ConfigurationOverride commentConfig = new ConfigurationOverride(module, expressionParser);
 
         assertNotNull(commentConfig);
@@ -233,7 +220,7 @@
     }
 
     private static final String REFERENCE_XML =
-            "        <gbean name=\"EJBBuilder\">\n" +
+            "        <gbean name=\"EJBBuilder\" xmlns='\" + GBeanOverride.ATTRIBUTE_NAMESPACE + \"'>\n" +
                     "            <attribute name=\"listener\">?name=JettyWebContainer</attribute>\n" +
                     "            <reference name=\"ServiceBuilders\">\n" +
                     "                <pattern>\n" +
@@ -251,21 +238,21 @@
                     "        </gbean>";
 
     public void testReferenceXml() throws Exception {
-        InputStream in = new ByteArrayInputStream(REFERENCE_XML.getBytes());
-        Element gbeanElement = parseXml(in, "gbean");
+        Reader in = new StringReader(REFERENCE_XML);
+        GbeanType gbeanElement = PluginXmlUtil.loadGbean(in);
         GBeanOverride gbean = new GBeanOverride(gbeanElement, expressionParser);
         assertCopyIdentical(gbean);
     }
 
     private static final String EXPRESSION_XML =
-            "        <gbean name=\"mockGBean\">\n" +
+            "        <gbean name=\"mockGBean\" xmlns='\" + GBeanOverride.ATTRIBUTE_NAMESPACE + \"'>\n" +
                     "            <attribute name=\"value\">${host}</attribute>\n" +
                     "            <attribute name=\"port\">${port}</attribute>\n" +
                     "        </gbean>";
 
     public void testExpressionXml() throws Exception {
-        InputStream in = new ByteArrayInputStream(EXPRESSION_XML.getBytes());
-        Element gbeanElement = parseXml(in, "gbean");
+        Reader in = new StringReader(EXPRESSION_XML);
+        GbeanType gbeanElement = PluginXmlUtil.loadGbean(in);
         GBeanOverride gbean = new GBeanOverride(gbeanElement, expressionParser);
         assertCopyIdentical(gbean);
         GBeanData data = new GBeanData(MockGBean.GBEAN_INFO);
@@ -304,8 +291,8 @@
         Map actualGBeans = actual.getConfigurations();
         assertEquals(expectedGBeans.size(), actualGBeans.size());
 
-        for (Iterator iterator = expectedGBeans.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry) iterator.next();
+        for (Object o : expectedGBeans.entrySet()) {
+            Map.Entry entry = (Map.Entry) o;
             Object name = entry.getKey();
             ConfigurationOverride expectedConfiguration = (ConfigurationOverride) entry.getValue();
             ConfigurationOverride actualConfiguration = (ConfigurationOverride) actualGBeans.get(name);
@@ -324,8 +311,8 @@
         Map actualGBeans = actual.getGBeans();
         assertEquals(expectedGBeans.size(), actualGBeans.size());
 
-        for (Iterator iterator = expectedGBeans.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry) iterator.next();
+        for (Object o : expectedGBeans.entrySet()) {
+            Map.Entry entry = (Map.Entry) o;
             Object name = entry.getKey();
             GBeanOverride expectedGBean = (GBeanOverride) entry.getValue();
             GBeanOverride actualGBean = (GBeanOverride) actualGBeans.get(name);
@@ -347,50 +334,15 @@
     }
 
     private ServerOverride copy(ServerOverride server) throws Exception {
-        Document doc = createDocument();
-        return new ServerOverride(readElement(server.writeXml(doc), "attributes"), expressionParser);
+        return new ServerOverride(server.writeXml(), expressionParser);
     }
 
     private ConfigurationOverride copy(ConfigurationOverride configuration) throws Exception {
-        Document doc = createDocument();
-        Element root = doc.createElement("temp");
-        doc.appendChild(root);
-        return new ConfigurationOverride(readElement(configuration.writeXml(doc, root), "module"), expressionParser);
+        return new ConfigurationOverride(configuration.writeXml(), expressionParser);
     }
 
     private GBeanOverride copy(GBeanOverride gbean) throws Exception {
-        Document doc = createDocument();
-        Element root = doc.createElement("temp");
-        doc.appendChild(root);
-        return new GBeanOverride(readElement(gbean.writeXml(doc, root), "gbean"), expressionParser);
-    }
-
-    private Element parseXml(InputStream in, String name) throws Exception {
-        DocumentBuilderFactory documentBuilderFactory = XmlUtil.newDocumentBuilderFactory();
-        Document doc = documentBuilderFactory.newDocumentBuilder().parse(in);
-        Element elem = doc.getDocumentElement();
-        if(elem.getNodeName().equals(name)) {
-            return elem;
-        }
-        NodeList list = elem.getElementsByTagName(name);
-        return (Element) list.item(0);
+        return new GBeanOverride(gbean.writeXml(), expressionParser);
     }
 
-    private Document createDocument() throws ParserConfigurationException {
-        DocumentBuilderFactory dFactory = XmlUtil.newDocumentBuilderFactory();
-        dFactory.setValidating(false);
-        return dFactory.newDocumentBuilder().newDocument();
-    }
-
-    private Element readElement(Element e, String name) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        TransformerFactory xfactory = XmlUtil.newTransformerFactory();
-        Transformer xform = xfactory.newTransformer();
-        xform.setOutputProperty(OutputKeys.INDENT, "yes");
-        xform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
-        xform.transform(new DOMSource(e), new StreamResult(out));
-        log.debug(new String(out.toByteArray()));
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-        return parseXml(in, name);
-    }
 }



Mime
View raw message