geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r721726 - in /geronimo/server/trunk/framework/modules/geronimo-system/src: main/java/org/apache/geronimo/system/configuration/GBeanOverride.java test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java
Date Sat, 29 Nov 2008 21:44:00 GMT
Author: gawor
Date: Sat Nov 29 13:44:00 2008
New Revision: 721726

URL: http://svn.apache.org/viewvc?rev=721726&view=rev
Log:
ensure an attribute or a reference exists in one map at a time - should be really using one
map for attributes and another one for references (GERONIMO-4407)

Modified:
    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/test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java

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=721726&r1=721725&r2=721726&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
Sat Nov 29 13:44:00 2008
@@ -184,7 +184,7 @@
                 }
                 
                 if (attr.isNull()) {
-                    getNullAttributes().add(attr.getName());
+                    setNullAttribute(attr.getName());
                 } else {
                     String value;
                     try {
@@ -198,7 +198,7 @@
                         setClearAttribute(attr.getName());
                     } else {
                         String truevalue = (String) EncryptionManager.decrypt(value);
-                        getAttributes().put(attr.getName(), truevalue);
+                        setAttribute(attr.getName(), truevalue);
                     }
                 }
             } else if (o instanceof ReferenceType) {
@@ -295,14 +295,21 @@
 
     public void setClearAttribute(String attributeName) {
         clearAttributes.add(attributeName);
+        // remove attribute from other maps
+        nullAttributes.remove(attributeName);
+        attributes.remove(attributeName);
     }
 
     public void setNullAttribute(String attributeName) {
         nullAttributes.add(attributeName);
+        // remove attribute from other maps
+        clearAttributes.remove(attributeName);
+        attributes.remove(attributeName);
     }
 
     public void setClearReference(String referenceName) {
         clearReferences.add(referenceName);
+        references.remove(referenceName);
     }
 
     public void setAttribute(String attributeName, Object attributeValue, String attributeType,
ClassLoader classLoader) throws InvalidAttributeException {
@@ -312,9 +319,12 @@
 
     public void setAttribute(String attributeName, String attributeValue) {
         if (attributeValue == null || attributeValue.length() == 0) {
-            clearAttributes.add(attributeName);
+            setClearAttribute(attributeName);
         } else {
             attributes.put(attributeName, attributeValue);
+            // remove attribute from other maps
+            clearAttributes.remove(attributeName);
+            nullAttributes.remove(attributeName);
         }
     }
     
@@ -328,6 +338,7 @@
 
     public void setReferencePatterns(String name, ReferencePatterns patterns) {
         references.put(name, patterns);
+        clearReferences.remove(name);
     }
 
     public boolean applyOverrides(GBeanData data, Artifact configName, AbstractName gbeanName,
ClassLoader classLoader) throws InvalidConfigException {
@@ -452,11 +463,12 @@
             String name = entry.getKey();
             String value = entry.getValue();
             if (value == null) {
-                setNullAttribute(name);
-            } else {
-                if (isNullAttribute(name)) {
-                    nullAttributes.remove(name);
-                }
+                nullAttributes.add(name);
+                clearAttributes.remove(name);
+            } else {                
+                nullAttributes.remove(name);
+                clearAttributes.remove(name);
+
                 if (name.toLowerCase().indexOf("password") > -1) {
                     value = EncryptionManager.encrypt(value);
                 }

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java?rev=721726&r1=721725&r2=721726&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java
Sat Nov 29 13:44:00 2008
@@ -20,11 +20,14 @@
 package org.apache.geronimo.system.configuration;
 
 import java.beans.PropertyEditorSupport;
+import java.net.URI;
 import java.util.Collection;
 import java.util.Collections;
 
 import junit.framework.TestCase;
 
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.ReferencePatterns;
 import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
 import org.apache.geronimo.system.plugin.model.AttributeType;
 import org.apache.geronimo.system.plugin.model.GbeanType;
@@ -112,6 +115,83 @@
         assertNull(attributeType.getPropertyEditor());
     }
     
+    public void testReferences() throws Exception {
+        GBeanOverride override;
+        
+        override = new GBeanOverride(gbeanType, new JexlExpressionParser());        
+        override.setClearReference("foo");
+        override.setReferencePatterns("foo", new ReferencePatterns(new AbstractName(new URI("/foo/bar/car?foo=bar"))));
+        override.writeXml();
+        
+        assertFalse(override.isClearReference("foo"));
+        assertFalse(override.getClearReferences().contains("foo"));        
+        assertTrue(override.getReferencePatterns("foo") != null);
+        assertTrue(override.getReferences().containsKey("foo"));
+        
+        override = new GBeanOverride(gbeanType, new JexlExpressionParser());   
+        override.setReferencePatterns("foo", new ReferencePatterns(new AbstractName(new URI("/foo/bar/car?foo=bar"))));
       
+        override.setClearReference("foo");
+        override.writeXml();
+        
+        assertTrue(override.isClearReference("foo"));
+        assertTrue(override.getClearReferences().contains("foo"));        
+        assertFalse(override.getReferencePatterns("foo") != null);
+        assertFalse(override.getReferences().containsKey("foo"));        
+    }
+    
+    public void testAttributes() throws Exception {
+        GBeanOverride override;
+        
+        override = new GBeanOverride(gbeanType, new JexlExpressionParser()); 
+        override.setNullAttribute("foo");
+        override.setClearAttribute("foo");
+        override.setAttribute("foo", "bar");
+        override.writeXml();
+        
+        assertFalse(override.isNullAttribute("foo"));
+        assertFalse(override.getNullAttributes().contains("foo"));    
+        assertFalse(override.isClearAttribute("foo"));
+        assertFalse(override.getClearAttributes().contains("foo"));  
+        assertTrue(override.getAttribute("foo") != null);
+        assertTrue(override.getAttributes().containsKey("foo"));
+            
+        override = new GBeanOverride(gbeanType, new JexlExpressionParser()); 
+        override.setAttribute("foo", "bar");
+        override.setNullAttribute("foo");
+        override.setClearAttribute("foo");
+        override.writeXml();
+        
+        assertFalse(override.isNullAttribute("foo"));
+        assertFalse(override.getNullAttributes().contains("foo"));    
+        assertFalse(override.getAttribute("foo") != null);
+        assertFalse(override.getAttributes().containsKey("foo"));        
+        assertTrue(override.isClearAttribute("foo"));
+        assertTrue(override.getClearAttributes().contains("foo"));  
+        
+        override = new GBeanOverride(gbeanType, new JexlExpressionParser()); 
+        override.setClearAttribute("foo");
+        override.setAttribute("foo", "bar");
+        override.setNullAttribute("foo");
+        override.writeXml();
+            
+        assertFalse(override.getAttribute("foo") != null);
+        assertFalse(override.getAttributes().containsKey("foo"));        
+        assertFalse(override.isClearAttribute("foo"));
+        assertFalse(override.getClearAttributes().contains("foo"));         
+        assertTrue(override.isNullAttribute("foo"));
+        assertTrue(override.getNullAttributes().contains("foo"));
+        
+        override = new GBeanOverride(gbeanType, new JexlExpressionParser()); 
+        override.setAttribute("bar1", "foo");
+        override.setAttribute("bar2", "foo");
+        override.getAttributes().put("foo", null);
+        GbeanType gbean = override.writeXml();
+        assertEquals(3, gbean.getAttributeOrReference().size());
+        AttributeType attribute = (AttributeType)gbean.getAttributeOrReference().get(2);
+        assertEquals("foo", attribute.getName());
+        assertTrue(attribute.isNull());
+    }
+    
     public interface Service {
     }
     



Mime
View raw message