You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/03/16 19:57:09 UTC
svn commit: r923936 - in /myfaces/core/trunk/api: pom.xml
src/main/java/javax/faces/validator/BeanValidator.java
src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java
Author: lu4242
Date: Tue Mar 16 18:57:09 2010
New Revision: 923936
URL: http://svn.apache.org/viewvc?rev=923936&view=rev
Log:
MYFACES-2565 BeanValidator throws Exception if external ExpressionLanguageFactory is being used (fix class loading issue) and MYFACES-2605 java.lang.LinkageError loader constraint violation: loader (instance of org/mortbay/jetty/webapp/WebAppClassLoader) previously initiated loading for a different type with name "javax/el/ExpressionFactory" (wrong maven dependencies)
Added:
myfaces/core/trunk/api/src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java
Modified:
myfaces/core/trunk/api/pom.xml
myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java
Modified: myfaces/core/trunk/api/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/pom.xml?rev=923936&r1=923935&r2=923936&view=diff
==============================================================================
--- myfaces/core/trunk/api/pom.xml (original)
+++ myfaces/core/trunk/api/pom.xml Tue Mar 16 18:57:09 2010
@@ -443,10 +443,14 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
</dependency>
</dependencies>
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java?rev=923936&r1=923935&r2=923936&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java Tue Mar 16 18:57:09 2010
@@ -18,12 +18,19 @@
*/
package javax.faces.validator;
-import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
-import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
-import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFValidator;
-import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
-
-import javax.el.*;
+import java.beans.FeatureDescriptor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.component.PartialStateHolder;
@@ -36,10 +43,11 @@ import javax.validation.Validation;
import javax.validation.ValidatorFactory;
import javax.validation.groups.Default;
import javax.validation.metadata.BeanDescriptor;
-import java.beans.FeatureDescriptor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.*;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFValidator;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
/**
* <p>
@@ -187,18 +195,14 @@ public class BeanValidator implements Va
* @param context The FacesContext.
* @return A ValueReferenceWrapper with the necessary information about the ValueReference.
*/
+
private ValueReferenceWrapper getValueReference(final UIComponent component, final FacesContext context)
{
final ValueExpression valueExpression = component.getValueExpression("value");
final ELContext elCtx = context.getELContext();
if (_ExternalSpecifications.isUnifiedELAvailable())
{
- final ValueReference valueReference = getUELValueReference(valueExpression, elCtx);
- if (valueReference == null)
- {
- return null;
- }
- return new ValueReferenceWrapper(valueReference.getBase(), valueReference.getProperty());
+ return _BeanValidatorUELUtils.getUELValueReferenceWrapper(valueExpression, elCtx);
}
else
{
@@ -206,42 +210,6 @@ public class BeanValidator implements Va
}
}
- private ValueReference getUELValueReference(final ValueExpression valueExpression, final ELContext elCtx)
- {
- final String methodName = "getValueReference";
- final String methodSignature = valueExpression.getClass().getName() +
- "." + methodName +
- "(" + ELContext.class + ")";
- try
- {
- final Method method = valueExpression.getClass().getMethod(methodName, ELContext.class);
- if (!ValueReference.class.equals(method.getReturnType())
- && !ValueReference.class.isAssignableFrom(method.getReturnType()))
- {
- throw new NoSuchMethodException(
- methodSignature +
- "doesn't return " + ValueReference.class +
- ", but " + method.getReturnType());
- }
- return (ValueReference) method.invoke(valueExpression, elCtx);
- }
- catch (NoSuchMethodException e)
- {
- throw new FacesException(
- "MyFaces indicates Unified EL is available, but method: " +
- methodSignature +
- " is not available", e);
- }
- catch (InvocationTargetException e)
- {
- throw new FacesException("Exception invoking " + methodSignature, e);
- }
- catch (IllegalAccessException e)
- {
- throw new FacesException("Exception invoking " + methodSignature, e);
- }
- }
-
/**
* This method creates ValidatorFactory instances or retrieves them from the container.
*
Added: myfaces/core/trunk/api/src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java?rev=923936&view=auto
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java (added)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java Tue Mar 16 18:57:09 2010
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package javax.faces.validator;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.el.ValueReference;
+import javax.faces.FacesException;
+
+/**
+ * Utility class that isolates UEL calls, to prevent ClassNotFoundException
+ * when bean validation is used without it. It is a similar hack to the one
+ * used in portlet case.
+ *
+ * @since 2.0
+ * @author Leonardo Uribe (latest modification by $Author: slessard $)
+ * @version $Revision: 696523 $ $Date: 2008-09-24 18:31:37 -0400 (mer., 17 sept. 2008) $
+ */
+final class _BeanValidatorUELUtils
+{
+
+ /**
+ * Get the ValueReference from the ValueExpression.
+ *
+ * @param component The component.
+ * @param context The FacesContext.
+ * @return A ValueReferenceWrapper with the necessary information about the ValueReference.
+ */
+ public static ValueReferenceWrapper getUELValueReferenceWrapper(final ValueExpression valueExpression, final ELContext elCtx)
+ {
+ final ValueReference valueReference = getUELValueReference(valueExpression, elCtx);
+ if (valueReference == null)
+ {
+ return null;
+ }
+ return new ValueReferenceWrapper(valueReference.getBase(), valueReference.getProperty());
+ }
+
+ private static ValueReference getUELValueReference(final ValueExpression valueExpression, final ELContext elCtx)
+ {
+ final String methodName = "getValueReference";
+ final String methodSignature = valueExpression.getClass().getName() +
+ "." + methodName +
+ "(" + ELContext.class + ")";
+ try
+ {
+ final Method method = valueExpression.getClass().getMethod(methodName, ELContext.class);
+ if (!ValueReference.class.equals(method.getReturnType())
+ && !ValueReference.class.isAssignableFrom(method.getReturnType()))
+ {
+ throw new NoSuchMethodException(
+ methodSignature +
+ "doesn't return " + ValueReference.class +
+ ", but " + method.getReturnType());
+ }
+ return (ValueReference) method.invoke(valueExpression, elCtx);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new FacesException(
+ "MyFaces indicates Unified EL is available, but method: " +
+ methodSignature +
+ " is not available", e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new FacesException("Exception invoking " + methodSignature, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new FacesException("Exception invoking " + methodSignature, e);
+ }
+ }
+}