You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2009/11/01 22:47:33 UTC
svn commit: r831765 [2/2] - in /myfaces/extensions/validator/trunk:
core/src/main/java/org/apache/myfaces/extensions/validator/core/
core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/
core/src/main/java/org/apache/myfaces/exte...
Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java?rev=831765&r1=831764&r2=831765&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java Sun Nov 1 21:47:32 2009
@@ -169,7 +169,7 @@
{
if (metaDataEntry.getValue() instanceof BeanValidation)
{
- processMetaData((BeanValidation) metaDataEntry.getValue(),
+ tryToProcessMetaData((BeanValidation) metaDataEntry.getValue(),
base,
foundGroupsForPropertyValidation,
restrictedGroupsForPropertyValidation,
@@ -180,7 +180,7 @@
{
for (BeanValidation currentBeanValidation : ((BeanValidation.List) metaDataEntry.getValue()).value())
{
- processMetaData(currentBeanValidation,
+ tryToProcessMetaData(currentBeanValidation,
base,
foundGroupsForPropertyValidation,
restrictedGroupsForPropertyValidation,
@@ -253,7 +253,7 @@
{
if (objectToInspect.getClass().isAnnotationPresent(BeanValidation.class))
{
- processMetaData(objectToInspect.getClass().getAnnotation(BeanValidation.class),
+ tryToProcessMetaData(objectToInspect.getClass().getAnnotation(BeanValidation.class),
objectToInspect,
foundGroupsForPropertyValidation,
restrictedGroupsForPropertyValidation,
@@ -265,7 +265,7 @@
for (BeanValidation currentBeanValidation :
(objectToInspect.getClass().getAnnotation(BeanValidation.List.class)).value())
{
- processMetaData(currentBeanValidation,
+ tryToProcessMetaData(currentBeanValidation,
objectToInspect,
foundGroupsForPropertyValidation,
restrictedGroupsForPropertyValidation,
@@ -298,7 +298,7 @@
}
}
- private static void processMetaData(BeanValidation beanValidation,
+ private static void tryToProcessMetaData(BeanValidation beanValidation,
Object metaDataSourceObject,
List<Class> foundGroupsForPropertyValidation,
List<Class> restrictedGroupsForPropertyValidation,
@@ -307,26 +307,45 @@
{
for (String currentViewId : beanValidation.viewIds())
{
- if ((currentViewId.equals(FacesContext.getCurrentInstance().getViewRoot().getViewId()) ||
- currentViewId.equals("*")) && isValidationPermitted(beanValidation))
+ if (useMetaDataForViewId(beanValidation, currentViewId))
{
- if (isModelValidation(beanValidation))
- {
- addModelValidationEntry(
- beanValidation, metaDataSourceObject,
- modelValidationEntryList, restrictedGroupsForModelValidation);
- }
- else
- {
- processGroups(
- beanValidation, foundGroupsForPropertyValidation, restrictedGroupsForPropertyValidation);
- }
-
- return;
+ processMetaData(beanValidation,
+ metaDataSourceObject,
+ foundGroupsForPropertyValidation,
+ restrictedGroupsForPropertyValidation,
+ modelValidationEntryList,
+ restrictedGroupsForModelValidation);
+ break;
}
}
}
+ private static boolean useMetaDataForViewId(BeanValidation beanValidation, String currentViewId)
+ {
+ return (currentViewId.equals(FacesContext.getCurrentInstance().getViewRoot().getViewId()) ||
+ currentViewId.equals("*")) && isValidationPermitted(beanValidation);
+ }
+
+ private static void processMetaData(BeanValidation beanValidation,
+ Object metaDataSourceObject,
+ List<Class> foundGroupsForPropertyValidation,
+ List<Class> restrictedGroupsForPropertyValidation,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation)
+ {
+ if (isModelValidation(beanValidation))
+ {
+ addModelValidationEntry(
+ beanValidation, metaDataSourceObject,
+ modelValidationEntryList, restrictedGroupsForModelValidation);
+ }
+ else
+ {
+ processGroups(
+ beanValidation, foundGroupsForPropertyValidation, restrictedGroupsForPropertyValidation);
+ }
+ }
+
private static void addTargetsForModelValidation(ModelValidationEntry modelValidationEntry, Object defaultTarget)
{
if (isDefaultTarget(modelValidationEntry))
Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleKey.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleKey.java?rev=831765&r1=831764&r2=831765&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleKey.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/PropertyValidationModuleKey.java Sun Nov 1 21:47:32 2009
@@ -20,11 +20,13 @@
import org.apache.myfaces.extensions.validator.internal.UsageInformation;
import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.core.ValidationModuleKey;
/**
* @author Gerhard Petracek
* @since x.x.3
*/
+@ValidationModuleKey
@UsageInformation(UsageCategory.API)
public interface PropertyValidationModuleKey
{
Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/annotation/extractor/DefaultPropertyScanningMetaDataExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/annotation/extractor/DefaultPropertyScanningMetaDataExtractor.java?rev=831765&r1=831764&r2=831765&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/annotation/extractor/DefaultPropertyScanningMetaDataExtractor.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/annotation/extractor/DefaultPropertyScanningMetaDataExtractor.java Sun Nov 1 21:47:32 2009
@@ -29,6 +29,7 @@
import org.apache.myfaces.extensions.validator.internal.UsageInformation;
import org.apache.myfaces.extensions.validator.internal.UsageCategory;
import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.extensions.validator.PropertyValidationModuleKey;
import javax.faces.context.FacesContext;
@@ -45,7 +46,8 @@
public static MetaDataExtractor getInstance()
{
- return ExtValUtils.createInterceptedMetaDataExtractor(new DefaultPropertyScanningMetaDataExtractor());
+ return ExtValUtils.createInterceptedMetaDataExtractorFor(
+ new DefaultPropertyScanningMetaDataExtractor(), PropertyValidationModuleKey.class);
}
@Override
Added: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/test/core/interceptor/RegistrationModuleMetaDataExtractionInterceptorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/test/core/interceptor/RegistrationModuleMetaDataExtractionInterceptorTestCase.java?rev=831765&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/test/core/interceptor/RegistrationModuleMetaDataExtractionInterceptorTestCase.java (added)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/test/core/interceptor/RegistrationModuleMetaDataExtractionInterceptorTestCase.java Sun Nov 1 21:47:32 2009
@@ -0,0 +1,198 @@
+/*
+ * 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 org.apache.myfaces.extensions.validator.test.core.interceptor;
+
+import org.apache.myfaces.extensions.validator.test.AbstractExValViewControllerTestCase;
+import org.apache.myfaces.extensions.validator.core.ExtValContext;
+import org.apache.myfaces.extensions.validator.core.InvocationOrder;
+import org.apache.myfaces.extensions.validator.core.ValidationModuleAware;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
+import org.apache.myfaces.extensions.validator.core.interceptor.MetaDataExtractionInterceptor;
+import org.apache.myfaces.extensions.validator.PropertyValidationModuleKey;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import java.util.List;
+
+public class RegistrationModuleMetaDataExtractionInterceptorTestCase extends AbstractExValViewControllerTestCase
+{
+ /**
+ * Construct a new instance of the test.
+ *
+ * @param name Name of the test.
+ */
+ public RegistrationModuleMetaDataExtractionInterceptorTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(RegistrationModuleMetaDataExtractionInterceptorTestCase.class);
+ }
+
+ public void testModulePropertyValidationInterceptorInitialization()
+ {
+ resetExtValContext();
+
+ ExtValContext.getContext().addMetaDataExtractionInterceptor(new TestGlobalPropertyValidationInterceptor());
+ ExtValContext.getContext().addMetaDataExtractionInterceptor(new TestGlobalMetaDataExtractionInterceptor1000());
+ ExtValContext.getContext().addMetaDataExtractionInterceptor(new TestModuleMetaDataExtractionInterceptor2());
+ ExtValContext.getContext().addMetaDataExtractionInterceptor(new TestModuleMetaDataExtractionInterceptor3());
+ ExtValContext.getContext().addMetaDataExtractionInterceptor(new TestGlobalMetaDataExtractionInterceptor1());
+
+ checkGlobalOnlyPropertyValidationInterceptors();
+ checkModuleAwarePropertyValidationInterceptorsWithTestModule();
+ checkModuleAwarePropertyValidationInterceptorsWithPropertyValidationModule();
+ }
+
+ private void checkGlobalOnlyPropertyValidationInterceptors()
+ {
+ List<MetaDataExtractionInterceptor> result = ExtValContext.getContext().getMetaDataExtractionInterceptors();
+
+ int resultLength = 3;
+ assertEquals(resultLength, result.size());
+
+ for(int i = 0; i < resultLength; i++)
+ {
+ switch (i)
+ {
+ case 0:
+ assertEquals(TestGlobalMetaDataExtractionInterceptor1.class, result.get(i).getClass());
+ break;
+ case 1:
+ assertEquals(TestGlobalMetaDataExtractionInterceptor1000.class, result.get(i).getClass());
+ break;
+ case 2:
+ assertEquals(TestGlobalPropertyValidationInterceptor.class, result.get(i).getClass());
+ break;
+ }
+ }
+ }
+
+ private void checkModuleAwarePropertyValidationInterceptorsWithTestModule()
+ {
+ List<MetaDataExtractionInterceptor> result = ExtValContext.getContext().getMetaDataExtractionInterceptorsFor(TestModule.class);
+
+ int resultLength = 5;
+ assertTrue(result.size() == resultLength);
+
+ for(int i = 0; i < resultLength; i++)
+ {
+ switch (i)
+ {
+ case 0:
+ assertTrue(result.get(i) instanceof TestGlobalMetaDataExtractionInterceptor1);
+ break;
+ case 1:
+ assertTrue(result.get(i) instanceof TestModuleMetaDataExtractionInterceptor2);
+ break;
+ case 2:
+ assertTrue(result.get(i) instanceof TestModuleMetaDataExtractionInterceptor3);
+ break;
+ case 3:
+ assertTrue(result.get(i) instanceof TestGlobalMetaDataExtractionInterceptor1000);
+ break;
+ case 4:
+ assertTrue(result.get(i) instanceof TestGlobalPropertyValidationInterceptor);
+ break;
+ }
+ }
+ }
+
+ private void checkModuleAwarePropertyValidationInterceptorsWithPropertyValidationModule()
+ {
+ List<MetaDataExtractionInterceptor> result = ExtValContext.getContext().getMetaDataExtractionInterceptorsFor(PropertyValidationModuleKey.class);
+
+ int resultLength = 4;
+ assertTrue(result.size() == resultLength);
+
+ for(int i = 0; i < resultLength; i++)
+ {
+ switch (i)
+ {
+ case 0:
+ assertEquals(TestGlobalMetaDataExtractionInterceptor1.class, result.get(i).getClass());
+ break;
+ case 1:
+ assertEquals(TestModuleMetaDataExtractionInterceptor2.class, result.get(i).getClass());
+ break;
+ case 2:
+ assertEquals(TestGlobalMetaDataExtractionInterceptor1000.class, result.get(i).getClass());
+ break;
+ case 3:
+ assertEquals(TestGlobalPropertyValidationInterceptor.class, result.get(i).getClass());
+ break;
+ }
+ }
+ }
+
+ class TestGlobalPropertyValidationInterceptor implements MetaDataExtractionInterceptor
+ {
+ public void afterExtracting(PropertyInformation propertyInformation)
+ {
+ }
+ }
+
+ @InvocationOrder(1)
+ class TestGlobalMetaDataExtractionInterceptor1 implements MetaDataExtractionInterceptor
+ {
+ public void afterExtracting(PropertyInformation propertyInformation)
+ {
+ }
+ }
+
+ @InvocationOrder(2)
+ class TestModuleMetaDataExtractionInterceptor2 implements MetaDataExtractionInterceptor, ValidationModuleAware
+ {
+ public void afterExtracting(PropertyInformation propertyInformation)
+ {
+ }
+
+ public String[] getModuleKeys()
+ {
+ return new String[] {PropertyValidationModuleKey.class.getName(), TestModule.class.getName()};
+ }
+ }
+
+ @InvocationOrder(3)
+ class TestModuleMetaDataExtractionInterceptor3 implements MetaDataExtractionInterceptor, ValidationModuleAware
+ {
+ public void afterExtracting(PropertyInformation propertyInformation)
+ {
+ }
+
+ public String[] getModuleKeys()
+ {
+ return new String[] {TestModule.class.getName()};
+ }
+ }
+
+ class TestModule
+ {
+ }
+
+ @InvocationOrder(1000)
+ class TestGlobalMetaDataExtractionInterceptor1000 implements MetaDataExtractionInterceptor
+ {
+ public void afterExtracting(PropertyInformation propertyInformation)
+ {
+ }
+ }
+}
\ No newline at end of file