geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r391883 - in /geronimo/branches/1.1/modules: kernel/src/java/org/apache/geronimo/gbean/ system/src/java/org/apache/geronimo/system/configuration/ system/src/test/org/apache/geronimo/system/configuration/
Date Thu, 06 Apr 2006 02:42:56 GMT
Author: jgenender
Date: Wed Apr  5 19:42:54 2006
New Revision: 391883

URL: http://svn.apache.org/viewcvs?rev=391883&view=rev
Log:
Merge in the config.xml empty string, null, and reference removal code from trunk

Modified:
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanData.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/GBeanOverride.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
    geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/ServerOverrideTest.java

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanData.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanData.java?rev=391883&r1=391882&r2=391883&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanData.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanData.java
Wed Apr  5 19:42:54 2006
@@ -73,6 +73,13 @@
     public GBeanInfo getGBeanInfo() {
         return gbeanInfo;
     }
+    
+    public void clearAttribute(String name){
+        attributes.remove(name);
+    }
+    public void clearReference(String name){
+        references.remove(name);
+    }  
 
     public void setGBeanInfo(GBeanInfo gbeanInfo) {
         this.gbeanInfo = gbeanInfo;

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/GBeanOverride.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/GBeanOverride.java?rev=391883&r1=391882&r2=391883&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/GBeanOverride.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/GBeanOverride.java
Wed Apr  5 19:42:54 2006
@@ -19,6 +19,7 @@
 import java.beans.PropertyEditor;
 import java.io.PrintWriter;
 import java.net.URI;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -49,6 +50,9 @@
     private boolean load;
     private final Map attributes = new LinkedHashMap();
     private final Map references = new LinkedHashMap();
+    private final ArrayList clearAttributes = new ArrayList();
+    private final ArrayList nullAttributes = new ArrayList();
+    private final ArrayList clearReferences = new ArrayList();
     private final String gbeanInfo;
 
     public GBeanOverride(String name, boolean load) {
@@ -115,7 +119,32 @@
             Element attribute = (Element) attributes.item(a);
 
             String attributeName = attribute.getAttribute("name");
-            String attributeValue = (String)EncryptionManager.decrypt(getContentsAsText(attribute));
+
+            // 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);
         }
 
@@ -128,8 +157,19 @@
 
             Set objectNamePatterns = new LinkedHashSet();
             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 < references.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");
@@ -203,10 +243,50 @@
         return (String) attributes.get(attributeName);
     }
 
+    public ArrayList getClearAttributes() {
+        return clearAttributes;
+    }
+    
+    public ArrayList getNullAttributes() {
+        return nullAttributes;
+    }
+
+    public boolean getNullAttribute(String attributeName) {
+        return nullAttributes.contains(attributeName);
+    }
+    
+    public boolean getClearAttribute(String attributeName) {
+        return clearAttributes.contains(attributeName);
+    }
+
+    public ArrayList getClearReferences() {
+        return clearReferences;
+    }
+
+    public boolean getClearReference(String referenceName) {
+        return clearReferences.contains(referenceName);
+    }
+
+    public void setClearAttribute(String attributeName) {
+        if (!clearAttributes.contains(attributeName))
+            clearAttributes.add(attributeName);
+    }
+    
+    public void setNullAttribute(String attributeName) {
+        if (!nullAttributes.contains(attributeName))
+            nullAttributes.add(attributeName);
+    }
+
+    public void setClearReference(String referenceName) {
+        if (!clearReferences.contains(referenceName))
+            clearReferences.add(referenceName);
+    }
+
     public void setAttribute(String attributeName, Object attributeValue, String attributeType)
throws InvalidAttributeException {
         String stringValue = getAsText(attributeValue, attributeType);
         attributes.put(attributeName, stringValue);
     }
+
     public void setAttribute(String attributeName, String attributeValue) {
         attributes.put(attributeName, attributeValue);
     }
@@ -249,7 +329,22 @@
             if(name.toLowerCase().indexOf("password") > -1) {
                 value = EncryptionManager.encrypt(value);
             }
-            out.println("      <attribute name=\"" + name + "\">" +  value + "</attribute>");
+            if (value.length() == 0)
+                out.println("      <attribute name=\"" + name + "\" value=\"\" />");
+            else
+                out.println("      <attribute name=\"" + name + "\">" +  value + "</attribute>");
+        }
+
+        // cleared attributes
+        for (Iterator iterator = clearAttributes.iterator(); iterator.hasNext();) {
+            String name = (String) iterator.next();
+            out.println("      <attribute name=\"" + name + "\" />");
+        }
+        
+        // Null attributes
+        for (Iterator iterator = nullAttributes.iterator(); iterator.hasNext();) {
+            String name = (String) iterator.next();
+            out.println("      <attribute name=\"" + name + "\" null=\"true\" />");
         }
 
         // references
@@ -286,6 +381,12 @@
                 out.println("</pattern>");
             }
             out.println("      </reference>");
+        }
+
+        // cleared references
+        for (Iterator iterator = clearReferences.iterator(); iterator.hasNext();) {
+            String name = (String) iterator.next();
+            out.println("      <reference name=\"" + name + "\" />");
         }
 
         out.println("    </gbean>");

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java?rev=391883&r1=391882&r2=391883&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
Wed Apr  5 19:42:54 2006
@@ -58,7 +58,7 @@
 /**
  * Stores managed attributes in an XML file on the local filesystem.
  *
- * @version $Rev: 386505 $ $Date$
+ * @version $Rev$ $Date$
  */
 public class LocalAttributeManager implements ManageableAttributeStore, PersistentConfigurationList,
GBeanLifecycle {
     private final static Log log = LogFactory.getLog(LocalAttributeManager.class);
@@ -182,6 +182,22 @@
             data.setAttribute(attributeName, value);
         }
 
+        //Clear attributes
+        for (Iterator iterator = gbean.getClearAttributes().iterator(); iterator.hasNext();){
+           String attribute = (String) iterator.next(); 
+           if (gbean.getClearAttribute(attribute)){
+               data.clearAttribute(attribute);
+           }    
+        }   
+        
+        //Null attributes
+        for (Iterator iterator = gbean.getNullAttributes().iterator(); iterator.hasNext();){
+           String attribute = (String) iterator.next(); 
+           if (gbean.getNullAttribute(attribute)){
+               data.setAttribute(attribute, null);
+           }
+        }
+
         // set references
         for (Iterator iterator = gbean.getReferences().entrySet().iterator(); iterator.hasNext();)
{
             Map.Entry entry = (Map.Entry) iterator.next();
@@ -196,6 +212,15 @@
 
             data.setReferencePatterns(referenceName, referencePatterns);
         }
+
+        //Clear references
+        for (Iterator iterator = gbean.getClearReferences().iterator(); iterator.hasNext();){
+           String reference = (String) iterator.next(); 
+           if (gbean.getClearReference(reference)){
+               data.clearReference(reference);
+           }
+        }
+
         return true;
     }
 

Modified: geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/ServerOverrideTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/ServerOverrideTest.java?rev=391883&r1=391882&r2=391883&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/ServerOverrideTest.java
(original)
+++ geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/ServerOverrideTest.java
Wed Apr  5 19:42:54 2006
@@ -120,12 +120,18 @@
         GBeanOverride pizza = new GBeanOverride("Pizza", false);
         pizza.setAttribute("cheese", "mozzarella");
         pizza.setAttribute("size", "x-large");
+        pizza.setAttribute("emptyString", "");
+        pizza.setClearAttribute("greenPeppers");
+        pizza.setNullAttribute("pineapple");
+
         AbstractNameQuery pizzaOvenQuery = getAbstractNameQuery(":name=PizzaOven,j2eeType=oven");
         AbstractNameQuery toasterOvenQuery = getAbstractNameQuery(":name=ToasterOven,j2eeType=oven,*");
         AbstractNameQuery[] queries = new AbstractNameQuery[]{pizzaOvenQuery, toasterOvenQuery};
         ReferencePatterns ovenPatterns = getReferencePatterns(queries);
         pizza.setReferencePatterns("oven", ovenPatterns);
-         assertCopyIdentical(dinnerMenu);
+        pizza.setClearReference("microwave");
+
+        assertCopyIdentical(dinnerMenu);
 
         dinnerMenu.addGBean(pizza);
         assertCopyIdentical(dinnerMenu);
@@ -146,11 +152,15 @@
         GBeanOverride pizza = new GBeanOverride("Pizza", false);
         pizza.setAttribute("cheese", "mozzarella");
         pizza.setAttribute("size", "x-large");
+        pizza.setAttribute("emptyString", "");
+        pizza.setClearAttribute("greenPeppers");
+        pizza.setNullAttribute("pineapple");
         AbstractNameQuery pizzaOvenQuery = getAbstractNameQuery(":name=PizzaOven,j2eeType=oven");
         AbstractNameQuery toasterOvenQuery = getAbstractNameQuery(":name=ToasterOven,j2eeType=oven,*");
         AbstractNameQuery[] queries = new AbstractNameQuery[]{pizzaOvenQuery, toasterOvenQuery};
         ReferencePatterns ovenPatterns = getReferencePatterns(queries);
         pizza.setReferencePatterns("oven", ovenPatterns);
+        pizza.setClearReference("microwave");
         dinnerMenu.addGBean(pizza);
         GBeanOverride garlicCheeseBread = new GBeanOverride("Garlic Cheese Bread", true);
         ReferencePatterns toasterOvenPatterns = new ReferencePatterns(Collections.singleton(toasterOvenQuery));
@@ -238,6 +248,9 @@
         assertEquals(expected.getName(), actual.getName());
         assertEquals(expected.isLoad(), actual.isLoad());
         assertEquals(expected.getAttributes(), actual.getAttributes());
+        assertEquals(expected.getClearAttributes(), actual.getClearAttributes());
+        assertEquals(expected.getNullAttributes(), actual.getNullAttributes());
+        assertEquals(expected.getClearReferences(), actual.getClearReferences());
     }
 
     private ServerOverride copy(ServerOverride server) throws Exception {



Mime
View raw message