Coverage Report - org.apache.tapestry.listener.ListenerMapPropertyAccessor
 
Classes in this File Line Coverage Branch Coverage Complexity
ListenerMapPropertyAccessor
0%
0/25
0%
0/10
2.8
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.listener;
 16  
 
 17  
 import java.util.Map;
 18  
 
 19  
 import ognl.ObjectPropertyAccessor;
 20  
 import ognl.OgnlContext;
 21  
 import ognl.OgnlException;
 22  
 import ognl.OgnlRuntime;
 23  
 import ognl.PropertyAccessor;
 24  
 import ognl.enhance.ExpressionCompiler;
 25  
 import ognl.enhance.UnsupportedCompilationException;
 26  
 
 27  
 /**
 28  
  * Exposes {@link org.apache.tapestry.IActionListener} listeners provided
 29  
  * by the {@link org.apache.tapestry.listener.ListenerMap} as read-only
 30  
  * properties of the map.
 31  
  * 
 32  
  * @author Howard Lewis Ship
 33  
  * @since 2.2
 34  
  */
 35  
 
 36  0
 public class ListenerMapPropertyAccessor extends ObjectPropertyAccessor implements PropertyAccessor
 37  
 {
 38  
 
 39  
     /**
 40  
      * Checks to see if the ListenerMapImpl provides the named listener,
 41  
      * returning the listener if it does. Otherwise, invokes the super
 42  
      * implementation.
 43  
      */
 44  
 
 45  
     public Object getProperty(Map context, Object target, Object name)
 46  
         throws OgnlException
 47  
     {
 48  0
         ListenerMap map = (ListenerMap) target;
 49  0
         String listenerName = (String) name;
 50  
 
 51  0
         if (map.canProvideListener(listenerName))
 52  0
             return map.getListener(listenerName);
 53  
 
 54  0
         return super.getProperty(context, target, name);
 55  
     }
 56  
 
 57  
     /**
 58  
      * Returns true if the ListenerMap contains the named listener, otherwise
 59  
      * invokes super-implementation.
 60  
      */
 61  
 
 62  
     public boolean hasGetProperty(Map context, Object target, Object oname)
 63  
         throws OgnlException
 64  
     {
 65  0
         ListenerMap map = (ListenerMap) target;
 66  0
         String listenerName = (String) oname;
 67  
 
 68  0
         if (map.canProvideListener(listenerName)) return true;
 69  
 
 70  0
         return super.hasGetProperty(context, target, oname);
 71  
     }
 72  
     
 73  
     public Class getPropertyClass(OgnlContext context, Object target, Object name)
 74  
     {
 75  0
         ListenerMap map = (ListenerMap) target;
 76  0
         String listenerName = (String) name;
 77  
         
 78  0
         if (map.canProvideListener(listenerName))
 79  0
             return map.getListener(listenerName).getClass();
 80  
         
 81  0
         return super.getPropertyClass(context, target, name);
 82  
     }
 83  
     
 84  
     public String getSourceAccessor(OgnlContext context, Object target, Object name)
 85  
     {
 86  0
         ListenerMap map = (ListenerMap) target;
 87  0
         String listenerName = ((String)name).replaceAll("\"", "");
 88  
         
 89  0
         if (map.canProvideListener(listenerName)) {
 90  
             
 91  0
             Class type = OgnlRuntime.getCompiler().getInterfaceClass(map.getListener(listenerName).getClass());
 92  
             
 93  0
             ExpressionCompiler.addCastString(context, "((" + type.getName() + ")");
 94  
             
 95  0
             context.setCurrentAccessor(ListenerMap.class);
 96  0
             context.setCurrentType(type);
 97  
             
 98  0
             return ".getListener(" + name + "))";
 99  
         }
 100  
         
 101  0
         return super.getSourceAccessor(context, target, name);
 102  
     }
 103  
     
 104  
     public String getSourceSetter(OgnlContext context, Object target, Object name)
 105  
     {
 106  0
         throw new UnsupportedCompilationException("Can't set listeners on ListenerMap.");
 107  
     }
 108  
 }