You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2009/10/25 11:35:05 UTC
svn commit: r829526 - in /myfaces/core/trunk/api/src/main/java/javax/faces:
component/UIInput.java component/_ExternalSpecifications.java
validator/BeanValidator.java validator/_ExternalSpecifications.java
Author: jankeesvanandel
Date: Sun Oct 25 10:35:05 2009
New Revision: 829526
URL: http://svn.apache.org/viewvc?rev=829526&view=rev
Log:
MYFACES-2386 Refactor Bean Validation "constants" to package-private class
Fixed, but not very happy with the implementation. I currently have 2 identical classes (_ExternalSpecifications.java), but I don't think there is an alternative that passes the TCK.
Added:
myfaces/core/trunk/api/src/main/java/javax/faces/component/_ExternalSpecifications.java
myfaces/core/trunk/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java
Modified:
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java
myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java?rev=829526&r1=829525&r2=829526&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java Sun Oct 25 10:35:05 2009
@@ -406,7 +406,7 @@
// Some extra rules are required for Bean Validation.
if (validatorId.equals(BeanValidator.VALIDATOR_ID))
{
- if (!BeanValidator.isAvailable)
+ if (!_ExternalSpecifications.isBeanValidationAvailable)
{
return false;
}
@@ -442,7 +442,7 @@
validateEmptyFields = validateEmptyFields.toLowerCase();
}
- if (validateEmptyFields.equals("auto") && BeanValidator.isAvailable)
+ if (validateEmptyFields.equals("auto") && _ExternalSpecifications.isBeanValidationAvailable)
{
return true;
}
Added: myfaces/core/trunk/api/src/main/java/javax/faces/component/_ExternalSpecifications.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_ExternalSpecifications.java?rev=829526&view=auto
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_ExternalSpecifications.java (added)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_ExternalSpecifications.java Sun Oct 25 10:35:05 2009
@@ -0,0 +1,99 @@
+/*
+ * 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.component;
+
+import javax.validation.Validation;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * <p>
+ * Package-private utility class for determining which specifications are available
+ * in the current process. See JIRA issue: http://issues.apache.org/jira/browse/MYFACES-2386
+ * </p>
+ *
+ * @author Jan-Kees van Andel
+ * @since 2.0
+ */
+class _ExternalSpecifications
+{
+
+ //private static final Log log = LogFactory.getLog(BeanValidator.class);
+ private static final Logger log = Logger.getLogger(_ExternalSpecifications.class.getName());
+
+ /**
+ * This boolean indicates if Bean Validation is present.
+ *
+ * Eager initialization is used for performance. This means Bean Validation binaries
+ * should not be added at runtime after this variable has been set.
+ */
+ static final boolean isBeanValidationAvailable;
+ static
+ {
+ boolean tmp = false;
+ try
+ {
+ tmp = (Class.forName("javax.validation.Validation") != null);
+
+ if (tmp)
+ {
+ try
+ {
+ // Trial-error approach to check for Bean Validation impl existence.
+ Validation.buildDefaultValidatorFactory().getValidator();
+ }
+ catch (Throwable t)
+ {
+ log.log(Level.FINE, "Error initializing Bean Validation (could be normal)", t);
+ tmp = false;
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ log.log(Level.FINE, "Error loading class (could be normal)", t);
+ tmp = false;
+ }
+ isBeanValidationAvailable = tmp;
+ }
+
+ /**
+ * This boolean indicates if Unified EL is present.
+ *
+ * Eager initialization is used for performance. This means Unified EL binaries
+ * should not be added at runtime after this variable has been set.
+ */
+ static final boolean isUnifiedELAvailable;
+ static
+ {
+ boolean tmp = false;
+ try
+ {
+ //TODO: Check this class name when Unified EL for Java EE6 is final.
+ tmp = (Class.forName("javax.el.ValueReference") != null);
+ }
+ catch (Throwable t)
+ {
+ log.log(Level.FINE, "Error loading class (could be normal)", t);
+ tmp = false;
+ }
+ isUnifiedELAvailable = tmp;
+ }
+
+}
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=829526&r1=829525&r2=829526&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 Sun Oct 25 10:35:05 2009
@@ -18,21 +18,11 @@
*/
package javax.faces.validator;
-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 java.util.logging.Level;
-import java.util.logging.Logger;
+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 javax.el.ELContext;
-import javax.el.ELResolver;
-import javax.el.FunctionMapper;
-import javax.el.ValueExpression;
-import javax.el.VariableMapper;
+import javax.el.*;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.component.PartialStateHolder;
@@ -45,10 +35,9 @@
import javax.validation.ValidatorFactory;
import javax.validation.groups.Default;
import javax.validation.metadata.BeanDescriptor;
-
-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 java.beans.FeatureDescriptor;
+import java.util.*;
+import java.util.logging.Logger;
/**
* <p>
@@ -119,64 +108,6 @@
private boolean _initialStateMarked = false;
/**
- * This boolean indicates if Bean Validation is present.
- *
- * Eager initialization is used for performance. This means Bean Validation binaries
- * should not be added at runtime after this variable has been set.
- */
- public static final boolean isAvailable;
- static
- {
- boolean tmp = false;
- try
- {
- tmp = (Class.forName("javax.validation.Validation") != null);
-
- if (tmp)
- {
- try
- {
- // Trial-error approach to check for Bean Validation impl existence.
- Validation.buildDefaultValidatorFactory().getValidator();
- }
- catch (Throwable t)
- {
- log.log(Level.FINE, "Error initializing Bean Validation (could be normal)", t);
- tmp = false;
- }
- }
- }
- catch (Throwable t)
- {
- log.log(Level.FINE, "Error loading class (could be normal)", t);
- tmp = false;
- }
- isAvailable = tmp;
- }
-
- /**
- * This boolean indicates if Unified EL is present.
- *
- * Eager initialization is used for performance. This means Unified EL binaries
- * should not be added at runtime after this variable has been set.
- */
- private static final boolean isUnifiedELAvailable;
- static {
- boolean tmp = false;
- try
- {
- //TODO: Check this class name when Unified EL for Java EE6 is final.
- tmp = (Class.forName("javax.el.ValueReference") != null);
- }
- catch (Throwable t)
- {
- log.log(Level.FINE, "Error loading class (could be normal)", t);
- tmp = false;
- }
- isUnifiedELAvailable = tmp;
- }
-
- /**
* {@inheritDoc}
*/
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
@@ -254,7 +185,7 @@
*/
private ValueReferenceWrapper getValueReference(UIComponent component, FacesContext context)
{
- if (isUnifiedELAvailable)
+ if (_ExternalSpecifications.isUnifiedELAvailable)
{
//TODO: Implement when Unified EL for Java EE6 is available.
throw new FacesException("Unified EL for Java EE6 support is not yet implemented");
@@ -291,7 +222,7 @@
}
else
{
- if (BeanValidator.isAvailable)
+ if (_ExternalSpecifications.isBeanValidationAvailable)
{
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
servletCtx.setAttribute(VALIDATOR_FACTORY_KEY, attr);
Added: myfaces/core/trunk/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java?rev=829526&view=auto
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java (added)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java Sun Oct 25 10:35:05 2009
@@ -0,0 +1,99 @@
+/*
+ * 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 javax.validation.Validation;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * <p>
+ * Package-private utility class for determining which specifications are available
+ * in the current process. See JIRA issue: http://issues.apache.org/jira/browse/MYFACES-2386
+ * </p>
+ *
+ * @author Jan-Kees van Andel
+ * @since 2.0
+ */
+class _ExternalSpecifications
+{
+
+ //private static final Log log = LogFactory.getLog(BeanValidator.class);
+ private static final Logger log = Logger.getLogger(_ExternalSpecifications.class.getName());
+
+ /**
+ * This boolean indicates if Bean Validation is present.
+ *
+ * Eager initialization is used for performance. This means Bean Validation binaries
+ * should not be added at runtime after this variable has been set.
+ */
+ static final boolean isBeanValidationAvailable;
+ static
+ {
+ boolean tmp = false;
+ try
+ {
+ tmp = (Class.forName("javax.validation.Validation") != null);
+
+ if (tmp)
+ {
+ try
+ {
+ // Trial-error approach to check for Bean Validation impl existence.
+ Validation.buildDefaultValidatorFactory().getValidator();
+ }
+ catch (Throwable t)
+ {
+ log.log(Level.FINE, "Error initializing Bean Validation (could be normal)", t);
+ tmp = false;
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ log.log(Level.FINE, "Error loading class (could be normal)", t);
+ tmp = false;
+ }
+ isBeanValidationAvailable = tmp;
+ }
+
+ /**
+ * This boolean indicates if Unified EL is present.
+ *
+ * Eager initialization is used for performance. This means Unified EL binaries
+ * should not be added at runtime after this variable has been set.
+ */
+ static final boolean isUnifiedELAvailable;
+ static
+ {
+ boolean tmp = false;
+ try
+ {
+ //TODO: Check this class name when Unified EL for Java EE6 is final.
+ tmp = (Class.forName("javax.el.ValueReference") != null);
+ }
+ catch (Throwable t)
+ {
+ log.log(Level.FINE, "Error loading class (could be normal)", t);
+ tmp = false;
+ }
+ isUnifiedELAvailable = tmp;
+ }
+
+}