[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...
Gavin King
gavin.king at jboss.com
Wed Feb 14 00:46:29 EST 2007
User: gavin
Date: 07/02/14 00:46:29
Modified: src/main/org/jboss/seam/core Expressions.java
Log:
introduced meta-model for non-component objects
Revision Changes Path
1.15 +38 -1 jboss-seam/src/main/org/jboss/seam/core/Expressions.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Expressions.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Expressions.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- Expressions.java 8 Jan 2007 12:47:59 -0000 1.14
+++ Expressions.java 14 Feb 2007 05:46:29 -0000 1.15
@@ -1,4 +1,4 @@
-//$Id: Expressions.java,v 1.14 2007/01/08 12:47:59 sbryzak2 Exp $
+//$Id: Expressions.java,v 1.15 2007/02/14 05:46:29 gavin Exp $
package org.jboss.seam.core;
import static org.jboss.seam.InterceptionType.NEVER;
@@ -8,7 +8,9 @@
import javax.faces.context.FacesContext;
+import org.hibernate.validator.InvalidValue;
import org.jboss.seam.Component;
+import org.jboss.seam.Model;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Intercept;
@@ -143,6 +145,41 @@
}
+ /**
+ * Validate that a value can be assigned to the property
+ * identified by a value expression.
+ *
+ * @param propertyExpression a value expression
+ * @param value the value that is to be assigned
+ *
+ * @return the validation failures, as InvalidValues
+ */
+ public InvalidValue[] validate(String propertyExpression, Object value)
+ {
+ int dot = propertyExpression.lastIndexOf('.');
+ int bracket = propertyExpression.lastIndexOf('[');
+ if (dot<=0 && bracket<=0)
+ {
+ return new InvalidValue[0];
+ }
+ //String componentName;
+ String propertyName;
+ if (dot>bracket)
+ {
+ //componentName = propertyExpression.substring(2, dot);
+ propertyName = propertyExpression.substring( dot+1, propertyExpression.length()-1 );
+ }
+ else
+ {
+ //componentName = propertyExpression.substring(2, bracket);
+ propertyName = propertyExpression.substring( bracket+1, propertyExpression.length()-2 );
+ }
+ String modelExpression = propertyExpression.substring(0, dot) + '}';
+
+ Object model = createValueBinding(modelExpression).getValue(); //TODO: cache the ValueBinding object!
+ return Model.forClass( model.getClass() ).getValidator().getPotentialInvalidValues(propertyName, value);
+ }
+
public static interface ValueBinding<T> extends Serializable
{
public String getExpressionString();
More information about the jboss-cvs-commits
mailing list