commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r330626 - in /jakarta/commons/proper/betwixt/trunk: src/java/org/apache/commons/betwixt/expression/Context.java src/test/org/apache/commons/betwixt/expression/TestContextOptions.java xdocs/guide/binding.xml xdocs/tasks.xml
Date Thu, 03 Nov 2005 20:37:13 GMT
Author: rdonkin
Date: Thu Nov  3 12:37:01 2005
New Revision: 330626

URL: http://svn.apache.org/viewcvs?rev=330626&view=rev
Log:
Added some support for inheritance.

Added:
    jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/expression/TestContextOptions.java
Modified:
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/expression/Context.java
    jakarta/commons/proper/betwixt/trunk/xdocs/guide/binding.xml
    jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/expression/Context.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/expression/Context.java?rev=330626&r1=330625&r2=330626&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/expression/Context.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/expression/Context.java
Thu Nov  3 12:37:01 2005
@@ -330,5 +330,31 @@
             optionStack.pop();
         }
     }
+
+    /**
+     * Gets the value of the first option with this name.
+     * The stack of inherited options is search (starting
+     * from the current option) until an option with a non-null
+     * value for the named option is found.
+     * 
+     * @param name the name of the option to be found
+     * @return option value or null if this value is never set
+     */
+    public String getInheritedOption(String name) {
+        String result = null;
+        for (int i=0; i<optionStack.size() ; i++)
+        {
+            Options options = (Options) optionStack.peek(i);
+            if (options != null)
+            {
+                result = options.getValue(name);
+                if (result != null)
+                {
+                    break;
+                }
+            }
+        }
+        return result;
+    }
     
 }

Added: jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/expression/TestContextOptions.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/expression/TestContextOptions.java?rev=330626&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/expression/TestContextOptions.java
(added)
+++ jakarta/commons/proper/betwixt/trunk/src/test/org/apache/commons/betwixt/expression/TestContextOptions.java
Thu Nov  3 12:37:01 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.commons.betwixt.expression;
+
+import org.apache.commons.betwixt.Options;
+
+import junit.framework.TestCase;
+
+public class TestContextOptions extends TestCase {
+
+    
+    private static final String OPTION_NAME_ONE = "Option1";
+    private static final String OPTION_NAME_TWO = "Option2";
+    private static final String OPTION_NAME_THREE = "Option3";
+    private static final String OPTION_NAME_FOUR = "Option4";
+    private static final String ALPHA = "ALPHA";
+    private static final String BETA = "BETA";
+    private static final String GAMMA = "GAMMA";
+    
+    public void testOptionInheritance() throws Exception {
+        
+        Options optionsAlpha = new Options();
+        optionsAlpha.addOption(OPTION_NAME_TWO, ALPHA);
+        optionsAlpha.addOption(OPTION_NAME_THREE, ALPHA);
+        optionsAlpha.addOption(OPTION_NAME_FOUR, ALPHA);
+        Options optionsBeta = new Options();
+        optionsBeta.addOption(OPTION_NAME_TWO, BETA);
+        optionsBeta.addOption(OPTION_NAME_THREE, BETA);
+        Options optionsGamma = new Options();
+        optionsGamma.addOption(OPTION_NAME_TWO, GAMMA);
+        
+        Context context = new Context();
+        context.pushOptions(optionsAlpha);
+        context.pushOptions(optionsBeta);
+        context.pushOptions(optionsGamma);
+        
+        assertNull("Null when no option set", context.getInheritedOption(OPTION_NAME_ONE));
+        assertEquals("Return first value when that is set", GAMMA, context.getInheritedOption(OPTION_NAME_TWO));
+        assertEquals("Return first value that is set", BETA, context.getInheritedOption(OPTION_NAME_THREE));
+        assertEquals("Return first value that is set", ALPHA, context.getInheritedOption(OPTION_NAME_FOUR));
+        
+    }
+}

Modified: jakarta/commons/proper/betwixt/trunk/xdocs/guide/binding.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/xdocs/guide/binding.xml?rev=330626&r1=330625&r2=330626&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/xdocs/guide/binding.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/xdocs/guide/binding.xml Thu Nov  3 12:37:01 2005
@@ -724,7 +724,8 @@
         	<p>
 The recommended way to solve this kind of problem is to added options to the betwixt file
 which can then be picked up by the custom converter and used to determine the appropriate
-conversion.	
+conversion.	Note that options are not directly inherited. Instead use 
+<code>getInheritedOption</code> on <code>Context</code>.
         </p>
         	<p>
 For example, consider a bean representing a person with an attribute

Modified: jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml?rev=330626&r1=330625&r2=330626&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml Thu Nov  3 12:37:01 2005
@@ -199,6 +199,10 @@
 <section name='Completed'>
     <subsection name='Since 0.7'>            
         <ul>
+        	<li>
+Added <code>getInheritedOption</code> method to <code>Context</code>
to assist
+with inheritance amongst options.
+        	</li>
             <li>
 Added convenience constructor to DefaultIdStoringStrategy.
 This makes life easier for users that want to use object identity



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message