Save This Page
Home » xwork-2.1.1-src » com.opensymphony.xwork2.ognl » [javadoc | source]
    1   package com.opensymphony.xwork2.ognl;
    2   
    3   import java.beans.IntrospectionException;
    4   import java.beans.PropertyDescriptor;
    5   import java.lang.reflect.Field;
    6   import java.lang.reflect.Method;
    7   import java.util.Collection;
    8   import java.util.Map;
    9   
   10   import ognl.Ognl;
   11   import ognl.OgnlException;
   12   import ognl.OgnlRuntime;
   13   
   14   import com.opensymphony.xwork2.inject.Inject;
   15   import com.opensymphony.xwork2.util.reflection.ReflectionException;
   16   import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
   17   
   18   public class OgnlReflectionProvider implements ReflectionProvider {
   19       
   20       private OgnlUtil ognlUtil;
   21       
   22       @Inject
   23       public void setOgnlUtil(OgnlUtil ognlUtil) {
   24           this.ognlUtil = ognlUtil;
   25       }
   26   
   27       public Field getField(Class inClass, String name) {
   28           return OgnlRuntime.getField(inClass, name);
   29       }
   30   
   31       public Method getGetMethod(Class targetClass, String propertyName)
   32               throws IntrospectionException, ReflectionException {
   33           try {
   34               return OgnlRuntime.getGetMethod(null, targetClass, propertyName);
   35           } catch (OgnlException e) {
   36               throw new ReflectionException(e);
   37           }
   38       }
   39   
   40       public Method getSetMethod(Class targetClass, String propertyName)
   41               throws IntrospectionException, ReflectionException {
   42           try {
   43               return OgnlRuntime.getSetMethod(null, targetClass, propertyName);
   44           } catch (OgnlException e) {
   45               throw new ReflectionException(e);
   46           }
   47       }
   48   
   49       public void setProperties(Map props, Object o, Map context) {
   50           ognlUtil.setProperties(props, o, context);
   51       }
   52   
   53       public void setProperties(Map props, Object o, Map context,
   54               boolean throwPropertyExceptions) {
   55           ognlUtil.setProperties(props, o, context, throwPropertyExceptions);
   56           
   57       }
   58   
   59       public void setProperties(Map properties, Object o) {
   60           ognlUtil.setProperties(properties, o);
   61       }
   62   
   63       public PropertyDescriptor getPropertyDescriptor(Class targetClass,
   64               String propertyName) throws IntrospectionException,
   65               ReflectionException {
   66           try {
   67               return OgnlRuntime.getPropertyDescriptor(targetClass, propertyName);
   68           } catch (OgnlException e) {
   69               throw new ReflectionException(e);
   70           }
   71       }
   72   
   73       public void copy(Object from, Object to, Map context,
   74               Collection exclusions, Collection inclusions) {
   75           ognlUtil.copy(from, to, context, exclusions, inclusions);
   76       }
   77   
   78       public Object getRealTarget(String property, Map context, Object root)
   79               throws ReflectionException {
   80           try {
   81               return ognlUtil.getRealTarget(property, context, root);
   82           } catch (OgnlException e) {
   83               throw new ReflectionException(e);
   84           }
   85       }
   86   
   87       public void setProperty(String name, Object value, Object o, Map context) {
   88           ognlUtil.setProperty(name, value, o, context);
   89       }
   90   
   91       public Map getBeanMap(Object source) throws IntrospectionException,
   92               ReflectionException {
   93           try {
   94               return ognlUtil.getBeanMap(source);
   95           } catch (OgnlException e) {
   96               throw new ReflectionException(e);
   97           }
   98       }
   99   
  100       public Object getValue(String expression, Map context, Object root)
  101               throws ReflectionException {
  102           try {
  103               return ognlUtil.getValue(expression, context, root);
  104           } catch (OgnlException e) {
  105               throw new ReflectionException(e);
  106           }
  107       }
  108   
  109       public void setValue(String expression, Map context, Object root,
  110               Object value) throws ReflectionException {
  111           try {
  112               Ognl.setValue(expression, context, root, value);
  113           } catch (OgnlException e) {
  114               throw new ReflectionException(e);
  115           }
  116       }
  117   
  118       public PropertyDescriptor[] getPropertyDescriptors(Object source)
  119               throws IntrospectionException {
  120           return ognlUtil.getPropertyDescriptors(source);
  121       }
  122   
  123   }

Save This Page
Home » xwork-2.1.1-src » com.opensymphony.xwork2.ognl » [javadoc | source]