bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1513957 - in /bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval: el/ELFacade.java jsr303/ConstraintDescriptorImpl.java jsr303/ConstraintViolationImpl.java jsr303/util/NodeImpl.java
Date Wed, 14 Aug 2013 16:52:28 GMT
Author: rmannibucau
Date: Wed Aug 14 16:52:27 2013
New Revision: 1513957

URL: http://svn.apache.org/r1513957
Log:
caching some hashCode + reworking EL interpolator impl

Modified:
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/el/ELFacade.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintDescriptorImpl.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintViolationImpl.java
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeImpl.java

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/el/ELFacade.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/el/ELFacade.java?rev=1513957&r1=1513956&r2=1513957&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/el/ELFacade.java (original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/el/ELFacade.java Wed Aug
14 16:52:27 2013
@@ -25,7 +25,6 @@ import javax.el.ExpressionFactory;
 import javax.el.FunctionMapper;
 import javax.el.ListELResolver;
 import javax.el.MapELResolver;
-import javax.el.PropertyNotWritableException;
 import javax.el.ResourceBundleELResolver;
 import javax.el.ValueExpression;
 import javax.el.VariableMapper;
@@ -46,18 +45,18 @@ public final class ELFacade implements M
         }
         EXPRESSION_FACTORY = ef;
     }
+    private static final ELResolver RESOLVER = initResolver();
 
     public String interpolate(final String message, final Map<String, Object> annotationParameters,
final Object validatedValue) {
-        final ELResolver resolver = initResolver();
-        final BValELContext context = new BValELContext(resolver);
-        final VariableMapper variables = context.getVariableMapper();
-        for (final Map.Entry<String, Object> var : annotationParameters.entrySet())
{
-            variables.setVariable(var.getKey(), new ValueExpressionLiteral(var.getValue()));
-        }
-        variables.setVariable("validatedValue", new ValueExpressionLiteral(validatedValue));
-
         try {
             if (EXPRESSION_FACTORY != null) {
+                final BValELContext context = new BValELContext();
+                final VariableMapper variables = context.getVariableMapper();
+                for (final Map.Entry<String, Object> var : annotationParameters.entrySet())
{
+                    variables.setVariable(var.getKey(), EXPRESSION_FACTORY.createValueExpression(var.getValue(),
Object.class));
+                }
+                variables.setVariable("validatedValue", EXPRESSION_FACTORY.createValueExpression(validatedValue,
Object.class));
+
                 // #{xxx} shouldn't be evaluated
                 return EXPRESSION_FACTORY.createValueExpression(context, message.replace("#{",
"\\#{"), String.class).getValue(context).toString();
             }
@@ -79,19 +78,17 @@ public final class ELFacade implements M
     }
 
     private static class BValELContext extends ELContext {
-        private final ELResolver resolver;
         private final FunctionMapper functions;
         private final VariableMapper variables;
 
-        public BValELContext(final ELResolver resolver) {
-            this.resolver = resolver;
+        public BValELContext() {
             this.variables = new BValVariableMapper();
             this.functions = new BValFunctionMapper();
         }
 
         @Override
         public ELResolver getELResolver() {
-            return resolver;
+            return RESOLVER;
         }
 
         @Override
@@ -118,7 +115,7 @@ public final class ELFacade implements M
         @Override
         public ValueExpression resolveVariable(final String variable) {
             if ("formatter".equals(variable)) {
-                return new ValueExpressionLiteral(new BValFormatter());
+                return EXPRESSION_FACTORY.createValueExpression(new BValFormatter(), Object.class);
             }
             return variables.get(variable);
         }
@@ -138,63 +135,4 @@ public final class ELFacade implements M
             return formatter.format(format, args);
         }
     }
-
-    private static final class ValueExpressionLiteral extends ValueExpression {
-        private final Object value;
-
-        public ValueExpressionLiteral(final Object value) {
-            this.value = value;
-        }
-
-        @Override
-        public Object getValue(final ELContext context) {
-            return value;
-        }
-
-        @Override
-        public void setValue(final ELContext context, final Object value) {
-            throw new PropertyNotWritableException(value.toString());
-        }
-
-        @Override
-        public boolean isReadOnly(final ELContext context) {
-            return true;
-        }
-
-        @Override
-        public Class<?> getType(final ELContext context) {
-            return (this.value != null) ? this.value.getClass() : null;
-        }
-
-        @Override
-        public Class<?> getExpectedType() {
-            return String.class;
-        }
-
-        @Override
-        public String getExpressionString() {
-            return (this.value != null) ? this.value.toString() : null;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            return (obj instanceof ValueExpressionLiteral && this
-                    .equals((ValueExpressionLiteral) obj));
-        }
-
-        public boolean equals(final ValueExpressionLiteral ve) {
-            return (ve != null && (this.value != null && ve.value != null
&& (this.value == ve.value || this.value
-                    .equals(ve.value))));
-        }
-
-        @Override
-        public int hashCode() {
-            return (this.value != null) ? this.value.hashCode() : 0;
-        }
-
-        @Override
-        public boolean isLiteralText() {
-            return true;
-        }
-    }
 }

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintDescriptorImpl.java?rev=1513957&r1=1513956&r2=1513957&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintDescriptorImpl.java
(original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintDescriptorImpl.java
Wed Aug 14 16:52:27 2013
@@ -47,6 +47,7 @@ public class ConstraintDescriptorImpl<T 
     private final boolean reportAsSingleViolation;
     private final ConstraintTarget validationAppliesTo;
     private final String template;
+    private final int hashCode;
 
     /**
      * Create a new ConstraintDescriptorImpl instance.
@@ -84,6 +85,7 @@ public class ConstraintDescriptorImpl<T 
         this.reportAsSingleViolation = reportAsSingleViolation;
         this.validationAppliesTo = validationAppliesTo;
         this.template = messageTemplate;
+        this.hashCode = computeHashCode();
     }
 
     /**
@@ -167,6 +169,10 @@ public class ConstraintDescriptorImpl<T 
 
     @Override
     public int hashCode() {
+        return hashCode;
+    }
+
+    public int computeHashCode() {
         int result = annotation.annotationType().hashCode();
         result = 31 * result + (groups != null ? groups.hashCode() : 0);
         result = 31 * result + (payload != null ? payload.hashCode() : 0);

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintViolationImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintViolationImpl.java?rev=1513957&r1=1513956&r2=1513957&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintViolationImpl.java
(original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/ConstraintViolationImpl.java
Wed Aug 14 16:52:27 2013
@@ -45,6 +45,7 @@ class ConstraintViolationImpl<T> impleme
     private final ConstraintDescriptor<?> constraintDescriptor;
     private final Object returnValue;
     private final Object[] parameters;
+    private final int hashCode;
 
     /**
      * Create a new ConstraintViolationImpl instance.
@@ -75,6 +76,7 @@ class ConstraintViolationImpl<T> impleme
         this.elementType = elementType;
         this.returnValue = returnValue;
         this.parameters = parameters;
+        this.hashCode = computeHashCode();
     }
 
     /**
@@ -192,6 +194,10 @@ class ConstraintViolationImpl<T> impleme
 
     @Override
     public int hashCode() {
+        return hashCode;
+    }
+
+    public int computeHashCode() {
         int result = messageTemplate != null ? messageTemplate.hashCode() : 0;
         result = 31 * result + (message != null ? message.hashCode() : 0);
         result = 31 * result + (rootBean != null ? rootBean.hashCode() : 0);

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeImpl.java?rev=1513957&r1=1513956&r2=1513957&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeImpl.java
(original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/jsr303/util/NodeImpl.java
Wed Aug 14 16:52:27 2013
@@ -25,12 +25,6 @@ import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
 
-/**
- * Description: a node (property) as part of a Path.
- * (Implementation based on reference implementation) <br/>
- *
- * TODO: split it in several impl
- */
 public class NodeImpl implements Path.Node, Serializable {
 
     private static final long serialVersionUID = 1L;



Mime
View raw message