Coverage Report - org.trails.descriptor.annotation.ExpressionExtension
 
Classes in this File Line Coverage Branch Coverage Complexity
ExpressionExtension
0% 
0% 
2.667
 
 1  
 package org.trails.descriptor.annotation;
 2  
 
 3  
 import ognl.Ognl;
 4  
 import ognl.OgnlException;
 5  
 import org.apache.commons.lang.Validate;
 6  
 import org.apache.commons.logging.Log;
 7  
 import org.apache.commons.logging.LogFactory;
 8  
 import org.trails.descriptor.IDescriptorExtension;
 9  
 
 10  
 import java.util.Map;
 11  
 
 12  
 
 13  0
 public abstract class ExpressionExtension implements IDescriptorExtension
 14  
 {
 15  0
         private static Log LOG = LogFactory.getLog(PossibleValuesDescriptorExtension.class);
 16  
 
 17  
         /**
 18  
          * Ognl expression that evaluated gets a list of possible values to use with
 19  
          * the current property, cannot be null.
 20  
          */
 21  
         private String expression;
 22  
 
 23  
         /**
 24  
          * Map of variables to put into the available namespace (scope) for OGNL expressions.
 25  
          */
 26  
         private Map context;
 27  
 
 28  
         /**
 29  
          * Creates a {@link ExpressionExtension}.
 30  
          *
 31  
          * @param theExpression Ognl expression that evaluated gets a list of possible
 32  
          *                      values to use with the current property, cannot be null.
 33  
          */
 34  
         public ExpressionExtension(final String theExpression)
 35  
         {
 36  0
                 super();
 37  0
                 Validate.notNull(theExpression, "The expression cannot be null");
 38  0
                 expression = theExpression;
 39  0
         }
 40  
 
 41  
 
 42  
         /**
 43  
          * Creates a {@link ExpressionExtension}.
 44  
          *
 45  
          * @param theExpression Ognl expression that evaluated gets a list of possible
 46  
          *                      values to use with the current property, cannot be null.
 47  
          * @param context
 48  
          */
 49  
         public ExpressionExtension(final String theExpression, Map context)
 50  
         {
 51  0
                 this(theExpression);
 52  0
                 this.context = context;
 53  0
         }
 54  
 
 55  
         /**
 56  
          * Gets the Ognl expression that evaluated gets a list of possible values to
 57  
          * use with the current property.
 58  
          *
 59  
          * @return a String, never null.
 60  
          */
 61  
 
 62  
 
 63  
         /**
 64  
          * Method used to initialize the value of the filtering property using the
 65  
          * value of the filtered one (for example, initialize the country based on the
 66  
          * value of the state property.
 67  
          *
 68  
          * @param model the model used by the edit page, cannot be null.
 69  
          * @return
 70  
          * @throws ognl.OgnlException
 71  
          */
 72  
         public Object evaluateExpresion(final Object model) throws OgnlException
 73  
         {
 74  0
                 Validate.notNull(model, "The model cannot be null");
 75  
                 try
 76  
                 {
 77  0
                         if (context != null)
 78  
                         {
 79  0
                                 return Ognl.getValue(expression, context, model);
 80  
                         } else
 81  
                         {
 82  0
                                 return Ognl.getValue(expression, model);
 83  
                         }
 84  0
                 } catch (OgnlException e)
 85  
                 {
 86  0
                         LOG.warn("Exception thrown evaluationg " + expression, e);
 87  0
                         throw e;
 88  
                 }
 89  
         }
 90  
 }