You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by an...@apache.org on 2006/06/05 14:53:02 UTC

svn commit: r411773 - in /tapestry/tapestry4/trunk/framework/src: descriptor/META-INF/ java/org/apache/tapestry/services/impl/ test/org/apache/tapestry/services/impl/

Author: andyhot
Date: Mon Jun  5 05:53:01 2006
New Revision: 411773

URL: http://svn.apache.org/viewvc?rev=411773&view=rev
Log:
[TAPESTRY-929] Configuration point for OGNL NullHandlers

Added:
    tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/NullHandlerContribution.java
Modified:
    tapestry/tapestry4/trunk/framework/src/descriptor/META-INF/tapestry.ognl.xml
    tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/ExpressionEvaluatorImpl.java
    tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExpressionEvaluator.java

Modified: tapestry/tapestry4/trunk/framework/src/descriptor/META-INF/tapestry.ognl.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/descriptor/META-INF/tapestry.ognl.xml?rev=411773&r1=411772&r2=411773&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/descriptor/META-INF/tapestry.ognl.xml (original)
+++ tapestry/tapestry4/trunk/framework/src/descriptor/META-INF/tapestry.ognl.xml Mon Jun  5 05:53:01 2006
@@ -27,6 +27,7 @@
       <construct class="impl.ExpressionEvaluatorImpl">
         <set-object property="applicationSpecification" value="infrastructure:applicationSpecification"/>
         <set-configuration property="contributions" configuration-id="PropertyAccessors"/>
+        <set-configuration property="nullHandlerContributions" configuration-id="NullHandlers"/>
       </construct>
     </invoke-factory>
   </service-point>
@@ -39,6 +40,33 @@
       </construct>
     </invoke-factory>
   </service-point>
+  
+  <configuration-point id="NullHandlers">
+    
+    Defines handler objects mapped to particular classes. OGNL NullHandler objects
+    allow specifying how nulls are handled within OGNL expressions on a class-by-class
+    basis.
+    
+    <schema>
+      
+      <element name="null-handler">
+        
+        <attribute name="class" required="true" translator="class">
+          The class for which the null handler will be used.
+        </attribute>
+        
+        <attribute name="object" required="true" translator="object">
+          An object implementing the OGNL accessor interface.
+        </attribute>
+        
+        <conversion class="impl.NullHandlerContribution">
+          <map attribute="class" property="subjectClass"/>
+          <map attribute="object" property="handler"/>
+        </conversion>
+      </element>
+      
+    </schema>
+  </configuration-point>  
   
   <configuration-point id="PropertyAccessors">
     

Modified: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/ExpressionEvaluatorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/ExpressionEvaluatorImpl.java?rev=411773&r1=411772&r2=411773&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/ExpressionEvaluatorImpl.java (original)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/ExpressionEvaluatorImpl.java Mon Jun  5 05:53:01 2006
@@ -46,6 +46,8 @@
     private TypeConverter _typeConverter;
 
     private List _contributions;
+    
+    private List _nullHandlerContributions;
 
     // Context, with a root of null, used when evaluating an expression
     // to see if it is a constant.
@@ -72,6 +74,15 @@
 
             OgnlRuntime.setPropertyAccessor(c.getSubjectClass(), c.getAccessor());
         }
+        
+        Iterator j = _nullHandlerContributions.iterator();
+
+        while (j.hasNext())
+        {
+            NullHandlerContribution h = (NullHandlerContribution) j.next();
+            System.out.println("Configuring: " + h.getSubjectClass());
+            OgnlRuntime.setNullHandler(h.getSubjectClass(), h.getHandler());
+        }        
 
         _defaultContext = Ognl.createDefaultContext(null, _ognlResolver, _typeConverter);
 
@@ -153,4 +164,9 @@
     {
         _contributions = contributions;
     }
+    
+    public void setNullHandlerContributions(List nullHandlerContributions)
+    {
+        _nullHandlerContributions = nullHandlerContributions;
+    }    
 }

Added: tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/NullHandlerContribution.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/NullHandlerContribution.java?rev=411773&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/NullHandlerContribution.java (added)
+++ tapestry/tapestry4/trunk/framework/src/java/org/apache/tapestry/services/impl/NullHandlerContribution.java Mon Jun  5 05:53:01 2006
@@ -0,0 +1,54 @@
+// Copyright 2004, 2005, 2006 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.tapestry.services.impl;
+
+import ognl.NullHandler;
+
+import org.apache.hivemind.impl.BaseLocatable;
+
+/**
+ * A contribution to the <code>tapestry.ognl.NullHandlers</code> configuration point; this
+ * provides the Class and {@link ognl.NullHandler}that will be passed to
+ * {@link ognl.OgnlRuntime#setNullHandler(java.lang.Class, ognl.NullHandler)}.
+ * 
+ * @author Andreas Andreou
+ * @since 4.1
+ */
+public class NullHandlerContribution extends BaseLocatable
+{
+    private Class _subjectClass;
+
+    private NullHandler _handler;
+
+    public NullHandler getHandler()
+    {
+        return _handler;
+    }
+
+    public void setHandler(NullHandler handler)
+    {
+        _handler = handler;
+    }
+
+    public Class getSubjectClass()
+    {
+        return _subjectClass;
+    }
+
+    public void setSubjectClass(Class subjectClass)
+    {
+        _subjectClass = subjectClass;
+    }
+}

Modified: tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExpressionEvaluator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExpressionEvaluator.java?rev=411773&r1=411772&r2=411773&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExpressionEvaluator.java (original)
+++ tapestry/tapestry4/trunk/framework/src/test/org/apache/tapestry/services/impl/TestExpressionEvaluator.java Mon Jun  5 05:53:01 2006
@@ -150,6 +150,7 @@
 
         ee.setApplicationSpecification(newAppSpec());
         ee.setContributions(Collections.EMPTY_LIST);
+        ee.setNullHandlerContributions(Collections.EMPTY_LIST);
 
         replayControls();
 
@@ -216,6 +217,7 @@
         ee.setExpressionCache(cache);
         ee.setApplicationSpecification(as);
         ee.setContributions(Collections.EMPTY_LIST);
+        ee.setNullHandlerContributions(Collections.EMPTY_LIST);
 
         ee.initializeService();