geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r593629 - in /geronimo/server/trunk/framework/modules/geronimo-system/src: main/java/org/apache/geronimo/system/configuration/ main/java/org/apache/geronimo/system/configuration/condition/ test/java/org/apache/geronimo/system/configuration/
Date Fri, 09 Nov 2007 19:29:02 GMT
Author: gawor
Date: Fri Nov  9 11:29:01 2007
New Revision: 593629

URL: http://svn.apache.org/viewvc?rev=593629&view=rev
Log:
expose the same set of variables to expression and condition parser

Added:
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/ParserUtils.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/LocalAttributeManager.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JavaVariable.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JexlConditionParser.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/OgnlConditionParser.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/MockGBean.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=593629&r1=593628&r2=593629&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
Fri Nov  9 11:29:01 2007
@@ -33,17 +33,18 @@
  * @version $Rev$ $Date$
  */
 class ConfigurationOverride {
+    
+    /**
+     * Default condition parser.
+     */
+    private static final ConditionParser DEFAULT_COND_PARSER = new JexlConditionParser();
+    
     private final Artifact name;
     private boolean load;
     private String condition;
     private String comment;
     private final Map<Object, GBeanOverride> gbeans = new LinkedHashMap<Object,
GBeanOverride>();
-
-    /**
-     * Cached condition parser; lazy init on the first call to {@link #parseCondition()}
-     * when {@link #condition} is non-null.
-     */
-    private static ConditionParser parser;
+    private ConditionParser parser = DEFAULT_COND_PARSER;
 
     public ConfigurationOverride(Artifact name, boolean load) {
         this.name = name;
@@ -79,6 +80,7 @@
             addGBean(gbean);
         }
 
+        parser = new JexlConditionParser(expressionParser.getVariables());
     }
 
     public Artifact getName() {
@@ -105,11 +107,6 @@
         if (condition == null) {
             // no condition means true
             return true;
-        }
-
-        // Create a parser if one does not already exist
-        if (parser == null) {
-            parser = new JexlConditionParser();
         }
         
         return parser.evaluate(condition);

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=593629&r1=593628&r2=593629&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
Fri Nov  9 11:29:01 2007
@@ -57,6 +57,7 @@
 import org.apache.geronimo.kernel.config.PersistentConfigurationList;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
+import org.apache.geronimo.system.configuration.condition.ParserUtils;
 import org.apache.geronimo.system.plugin.model.GbeanType;
 import org.apache.geronimo.system.plugin.model.AttributesType;
 import org.apache.geronimo.system.plugin.PluginXmlUtil;
@@ -104,7 +105,7 @@
         configSubstitutionsFile = resolvedPropertiesFile == null? null: serverInfo.resolveServer(resolvedPropertiesFile);
         localConfigSubstitutions = loadConfigSubstitutions(configSubstitutionsFile);
         prefix = System.getProperty(SUBSTITUTION_PREFIX_PREFIX, configSubstitutionsPrefix);
-        Map<String, String> configSubstitutions = loadAllConfigSubstitutions(localConfigSubstitutions,
prefix);
+        Map<String, Object> configSubstitutions = loadAllConfigSubstitutions(localConfigSubstitutions,
prefix);
         expressionParser = new JexlExpressionParser(configSubstitutions);
         this.readOnly = readOnly;
         this.serverInfo = serverInfo;
@@ -215,7 +216,7 @@
 
     public void addConfigSubstitutions(Properties properties) {
         localConfigSubstitutions.putAll(properties);
-        Map<String, String> configSubstutions = loadAllConfigSubstitutions(localConfigSubstitutions,
prefix);
+        Map<String, Object> configSubstutions = loadAllConfigSubstitutions(localConfigSubstitutions,
prefix);
         storeConfigSubstitutions(configSubstitutionsFile, localConfigSubstitutions);
         expressionParser.setVariables(configSubstutions);
     }
@@ -558,8 +559,8 @@
         }
     }
 
-    private static Map<String, String> loadAllConfigSubstitutions(Properties configSubstitutions,
String prefix) {
-        Map<String, String> vars = new HashMap<String, String>();
+    private static Map<String, Object> loadAllConfigSubstitutions(Properties configSubstitutions,
String prefix) {
+        Map<String, Object> vars = new HashMap<String, Object>();
         //most significant are the command line system properties
         addGeronimoSubstitutions(vars, System.getProperties(), prefix);
         //environment variables are next
@@ -568,6 +569,7 @@
         if (configSubstitutions != null) {
             addGeronimoSubstitutions(vars, configSubstitutions, "");
         }
+        ParserUtils.addDefaultVariables(vars);
         return vars;
     }
 
@@ -605,7 +607,7 @@
         }
     }
 
-    private static void addGeronimoSubstitutions(Map<String, String> vars, Map props,
String prefix) {
+    private static void addGeronimoSubstitutions(Map<String, Object> vars, Map props,
String prefix) {
         if (prefix != null) {
             int start = prefix.length();
             for (Object o : props.entrySet()) {

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JavaVariable.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JavaVariable.java?rev=593629&r1=593628&r2=593629&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JavaVariable.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JavaVariable.java
Fri Nov  9 11:29:01 2007
@@ -32,7 +32,7 @@
         return SystemUtils.JAVA_VENDOR;
     }
 
-    public String getVresion() {
+    public String getVersion() {
         return SystemUtils.JAVA_VERSION;
     }
 

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JexlConditionParser.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JexlConditionParser.java?rev=593629&r1=593628&r2=593629&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JexlConditionParser.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JexlConditionParser.java
Fri Nov  9 11:29:01 2007
@@ -24,6 +24,7 @@
 import org.apache.commons.jexl.ExpressionFactory;
 import org.apache.commons.jexl.JexlContext;
 import org.apache.commons.jexl.JexlHelper;
+import org.apache.commons.jexl.context.HashMapContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -44,19 +45,19 @@
 
     private final Map<String, Object> vars;
 
+    public JexlConditionParser(final Map vars) {
+        if (vars == null) {
+            throw new IllegalArgumentException("vars");
+        }
+        this.vars = vars;
+    }
+    
     public JexlConditionParser() {
         // Setup the default vars
         vars = new HashMap<String, Object>();
-        
-        vars.put("java", new JavaVariable());
-        vars.put("os", new OsVariable());
-        
-        // Install properties (to allow getProperty(x,y) to be used for defaults
-        Properties props = new Properties();
-        props.putAll(System.getProperties());
-        vars.put("props", props);
+        ParserUtils.addDefaultVariables(vars);
     }
-
+    
     /**
      * Evaluate a condition expression.
      *
@@ -113,5 +114,5 @@
         }
 
         return result;
-    }
+    }    
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/OgnlConditionParser.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/OgnlConditionParser.java?rev=593629&r1=593628&r2=593629&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/OgnlConditionParser.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/OgnlConditionParser.java
Fri Nov  9 11:29:01 2007
@@ -43,17 +43,17 @@
     
     private final Map<String, Object> vars;
     
+    public OgnlConditionParser(final Map vars) {
+        if (vars == null) {
+            throw new IllegalArgumentException("vars");
+        }
+        this.vars = vars;
+    }
+    
     public OgnlConditionParser() {
         // Setup the default vars
         vars = new HashMap<String, Object>();
-        
-        vars.put("java", new JavaVariable());
-        vars.put("os", new OsVariable());
-        
-        // Install properties (to allow getProperty(x,y) to be used for defaults
-        Properties props = new Properties();
-        props.putAll(System.getProperties());
-        vars.put("props", props);
+        ParserUtils.addDefaultVariables(vars);
     }
     
     /**

Added: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/ParserUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/ParserUtils.java?rev=593629&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/ParserUtils.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/ParserUtils.java
Fri Nov  9 11:29:01 2007
@@ -0,0 +1,51 @@
+/**
+ *  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.condition;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.jexl.context.HashMapContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Basic parser utility functions.
+ *
+ * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
+ */
+public class ParserUtils {
+
+    public static void addDefaultVariables(Map vars) {
+        vars.put("java", new JavaVariable());    
+        vars.put("os", new OsVariable());
+    
+        // Install properties (to allow getProperty(x,y) to be used for defaults
+        Properties props = new Properties();
+        props.putAll(System.getProperties());
+        vars.put("props", props);
+    }
+       
+    public static class DebugHashMapContext extends HashMapContext {
+        private static final Log LOG = LogFactory.getLog(DebugHashMapContext.class);
+        public Object get(Object o) {
+            Object r = super.get(o);
+            LOG.debug("Get property: " + o + " " + r);
+            return r;
+        }
+    }
+}

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

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/MockGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/MockGBean.java?rev=593629&r1=593628&r2=593629&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/MockGBean.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/MockGBean.java
Fri Nov  9 11:29:01 2007
@@ -26,6 +26,7 @@
 
     private String value;
     private int port;
+    private String expression;
 
     public String getValue() {
         return value;
@@ -36,6 +37,14 @@
     }
 
 
+    public String getExpression() {
+        return expression;
+    }
+
+    public void setExpression(String value) {
+        this.expression = value;
+    }
+    
     public int getPort() {
         return port;
     }
@@ -52,6 +61,7 @@
         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(MockGBean.class);
         infoFactory.addAttribute("value", String.class, true);
         infoFactory.addAttribute("port", int.class, true);
+        infoFactory.addAttribute("expression", String.class, true);
 
         GBEAN_INFO = infoFactory.getBeanInfo();
     }

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=593629&r1=593628&r2=593629&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
Fri Nov  9 11:29:01 2007
@@ -34,6 +34,7 @@
 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.configuration.condition.ParserUtils;
 import org.apache.geronimo.system.plugin.PluginXmlUtil;
 import org.apache.geronimo.system.plugin.model.GbeanType;
 import org.apache.geronimo.system.plugin.model.ModuleType;
@@ -49,6 +50,7 @@
         subs.put("host", "localhost");
         subs.put("port", "8080");
         subs.put("portOffset", "1");
+        ParserUtils.addDefaultVariables(subs);
         expressionParser = new JexlExpressionParser(subs);
     }
 
@@ -248,6 +250,7 @@
             "        <gbean name=\"mockGBean\" xmlns='\" + GBeanOverride.ATTRIBUTE_NAMESPACE
+ \"'>\n" +
                     "            <attribute name=\"value\">${host}</attribute>\n"
+
                     "            <attribute name=\"port\">${port}</attribute>\n"
+
+                    "            <attribute name=\"expression\">${host}</attribute>\n"
+
                     "        </gbean>";
 
     public void testExpressionXml() throws Exception {
@@ -265,6 +268,10 @@
         gbean.setAttribute("port", "${port + portOffset}");
         gbean.applyOverrides(data, null, null, getClass().getClassLoader());
         assertEquals(8081, data.getAttribute("port"));
+        
+        gbean.setAttribute("expression", "${if (java == null) 'null'; else 'non-null';}");
+        gbean.applyOverrides(data, null, null, getClass().getClassLoader());
+        assertEquals("non-null", data.getAttribute("expression"));
     }
 
     private void assertCopyIdentical(ServerOverride server) throws Exception {



Mime
View raw message