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 2010/03/24 13:03:17 UTC

svn commit: r927022 [2/2] - in /myfaces/extensions/validator/branches/branch_for_jsf_1_1: core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ core/src/mai...

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware4MetaDataBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware4MetaDataBean.java?rev=927022&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware4MetaDataBean.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware4MetaDataBean.java Wed Mar 24 12:03:16 2010
@@ -0,0 +1,32 @@
+/*
+ * 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.beanval.model;
+
+import javax.validation.constraints.NotNull;
+
+public class ConstraintSourceAware4MetaDataBean
+{
+    private String property;
+
+    @NotNull
+    public String getProperty()
+    {
+        return property;
+    }
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware5Bean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware5Bean.java?rev=927022&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware5Bean.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware5Bean.java Wed Mar 24 12:03:16 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.beanval.model;
+
+import org.apache.myfaces.extensions.validator.core.validation.ConstraintSource;
+import org.apache.myfaces.extensions.validator.core.validation.TargetPropertyId;
+
+@ConstraintSource(ConstraintSourceAware5MetaDataBean.class)
+public class ConstraintSourceAware5Bean
+{
+    private String property1;
+
+    @TargetPropertyId(Target4.class)
+    private String property2;
+
+    @TargetPropertyId(Target3.class)
+    public String getProperty1()
+    {
+        return property1;
+    }
+
+    public void setProperty1(String property1)
+    {
+        this.property1 = property1;
+    }
+
+    public String getProperty2()
+    {
+        return property2;
+    }
+
+    public void setProperty2(String property2)
+    {
+        this.property2 = property2;
+    }
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware5MetaDataBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware5MetaDataBean.java?rev=927022&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware5MetaDataBean.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware5MetaDataBean.java Wed Mar 24 12:03:16 2010
@@ -0,0 +1,42 @@
+/*
+ * 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.beanval.model;
+
+import javax.validation.constraints.NotNull;
+
+public class ConstraintSourceAware5MetaDataBean
+{
+    @NotNull
+    @Target3
+    private String property3;
+
+    private String property4;
+
+    @NotNull
+    @Target4
+    public String getProperty4()
+    {
+        return property4;
+    }
+
+    public void setProperty4(String property4)
+    {
+        this.property4 = property4;
+    }
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware6Bean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware6Bean.java?rev=927022&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware6Bean.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware6Bean.java Wed Mar 24 12:03:16 2010
@@ -0,0 +1,67 @@
+/*
+ * 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.beanval.model;
+
+import org.apache.myfaces.extensions.validator.test.beanval.custom.CustomConstraintSource;
+import org.apache.myfaces.extensions.validator.test.beanval.custom.CustomTargetProperty;
+import org.apache.myfaces.extensions.validator.test.beanval.custom.CustomTargetPropertyId;
+import org.apache.myfaces.extensions.validator.test.beanval.custom.CustomIgnoreConstraintSource;
+
+@CustomConstraintSource(ConstraintSourceAware6MetaDataBean.class)
+public class ConstraintSourceAware6Bean
+{
+    private String property1;
+
+    @CustomTargetPropertyId(Target4.class)
+    private String property2;
+
+    @CustomIgnoreConstraintSource
+    private String property3;
+
+    @CustomTargetProperty("property3")
+    public String getProperty1()
+    {
+        return property1;
+    }
+
+    public void setProperty1(String property1)
+    {
+        this.property1 = property1;
+    }
+
+    public String getProperty2()
+    {
+        return property2;
+    }
+
+    public void setProperty2(String property2)
+    {
+        this.property2 = property2;
+    }
+
+    public String getProperty3()
+    {
+        return property3;
+    }
+
+    public void setProperty3(String property3)
+    {
+        this.property3 = property3;
+    }
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware6MetaDataBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware6MetaDataBean.java?rev=927022&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware6MetaDataBean.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/ConstraintSourceAware6MetaDataBean.java Wed Mar 24 12:03:16 2010
@@ -0,0 +1,41 @@
+/*
+ * 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.beanval.model;
+
+import javax.validation.constraints.NotNull;
+
+public class ConstraintSourceAware6MetaDataBean
+{
+    @NotNull
+    private String property3;
+
+    private String property4;
+
+    @NotNull
+    @Target4
+    public String getProperty4()
+    {
+        return property4;
+    }
+
+    public void setProperty4(String property4)
+    {
+        this.property4 = property4;
+    }
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/Target3.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/Target3.java?rev=927022&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/Target3.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/Target3.java Wed Mar 24 12:03:16 2010
@@ -0,0 +1,33 @@
+/*
+ * 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.beanval.model;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+@Target({FIELD, METHOD})
+@Retention(RUNTIME)
+@Documented
+public @interface Target3
+{
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/Target4.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/Target4.java?rev=927022&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/Target4.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/Target4.java Wed Mar 24 12:03:16 2010
@@ -0,0 +1,33 @@
+/*
+ * 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.beanval.model;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+@Target({FIELD, METHOD})
+@Retention(RUNTIME)
+@Documented
+public @interface Target4
+{
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptor.java?rev=927022&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptor.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptor.java Wed Mar 24 12:03:16 2010
@@ -0,0 +1,74 @@
+/*
+ * 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.beanval;
+
+import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.validation.ConstraintViolation;
+import java.util.Set;
+
+/**
+ * @author Gerhard Petracek
+ * @since r4
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class MappedConstraintSourceBeanValidationModuleValidationInterceptor
+        extends BeanValidationModuleValidationInterceptor
+{
+    MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals csaBviUtils =
+            new MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals(this.logger, this.bviUtils);
+
+    @Override
+    protected void initComponentWithPropertyDetails(FacesContext facesContext,
+                                                    UIComponent uiComponent,
+                                                    PropertyDetails propertyDetails)
+    {
+        this.csaBviUtils.initComponentWithPropertyDetailsOfMappedConstraintSource(
+                facesContext, uiComponent, propertyDetails);
+    }
+
+    @Override
+    protected boolean hasBeanValidationConstraints(PropertyInformation propertyInformation)
+    {
+        PropertyDetails propertyDetails = propertyInformation.getInformation(
+                PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
+
+        return this.csaBviUtils.resolveMappedConstraintSourceFor(propertyDetails.getKey(),
+                                                              propertyDetails.getBaseObject().getClass(),
+                                                              propertyDetails.getProperty()) != null;
+    }
+
+    @Override
+    protected void processFieldValidation(FacesContext facesContext,
+                                          UIComponent uiComponent,
+                                          Object convertedObject,
+                                          PropertyInformation propertyInformation)
+    {
+        Set<ConstraintViolation> violations = this.csaBviUtils
+                .validateMappedConstraintSource(facesContext, uiComponent, convertedObject, propertyInformation);
+
+        processConstraintViolations(facesContext, uiComponent, convertedObject, violations);
+    }
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals.java?rev=927022&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals.java Wed Mar 24 12:03:16 2010
@@ -0,0 +1,556 @@
+/*
+ * 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.beanval;
+
+import org.apache.commons.logging.Log;
+import org.apache.myfaces.extensions.validator.core.ExtValContext;
+import org.apache.myfaces.extensions.validator.core.storage.MappedConstraintSourceStorage;
+import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
+import org.apache.myfaces.extensions.validator.core.property.PropertyInformation;
+import org.apache.myfaces.extensions.validator.core.validation.ConstraintSource;
+import org.apache.myfaces.extensions.validator.core.validation.IgnoreConstraintSource;
+import org.apache.myfaces.extensions.validator.core.validation.TargetProperty;
+import org.apache.myfaces.extensions.validator.core.validation.TargetPropertyId;
+import org.apache.myfaces.extensions.validator.internal.Priority;
+import org.apache.myfaces.extensions.validator.internal.ToDo;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.extensions.validator.util.ProxyUtils;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.validation.ConstraintViolation;
+import javax.validation.ValidatorFactory;
+import javax.validation.groups.Default;
+import javax.validation.metadata.ElementDescriptor;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Set;
+import java.util.Collections;
+
+/**
+ * @author Gerhard Petracek
+ * @since r4
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+class MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals
+{
+    private Log logger;
+    private BeanValidationModuleValidationInterceptorInternals bviUtils;
+
+    MappedConstraintSourceBeanValidationModuleValidationInterceptorInternals(
+            Log logger, BeanValidationModuleValidationInterceptorInternals bviUtils)
+    {
+        this.logger = logger;
+        this.bviUtils = bviUtils;
+    }
+
+    void initComponentWithPropertyDetailsOfMappedConstraintSource(FacesContext facesContext,
+                                                                  UIComponent uiComponent,
+                                                                  PropertyDetails propertyDetails)
+    {
+        Class[] foundGroups = this.bviUtils.resolveGroups(facesContext, uiComponent);
+
+        if (foundGroups == null)
+        {
+            return;
+        }
+        else if (foundGroups.length == 0)
+        {
+            foundGroups = new Class[]{Default.class};
+        }
+
+        PropertyDetails constraintSourcePropertyDetails = resolveMappedConstraintSourceFor(
+                propertyDetails.getKey(), propertyDetails.getBaseObject().getClass(), propertyDetails.getProperty());
+
+        if(constraintSourcePropertyDetails == null)
+        {
+            return;
+        }
+
+        ElementDescriptor elementDescriptor =
+                this.bviUtils.getDescriptorFor((Class) constraintSourcePropertyDetails.getBaseObject(),
+                        constraintSourcePropertyDetails.getProperty());
+
+        if (elementDescriptor == null)
+        {
+            return;
+        }
+
+        this.bviUtils.processElementDescriptor(facesContext, uiComponent, foundGroups, elementDescriptor);
+    }
+
+    Set<ConstraintViolation> validateMappedConstraintSource(FacesContext facesContext,
+                                                            UIComponent uiComponent,
+                                                            Object convertedObject,
+                                                            PropertyInformation propertyInformation)
+    {
+        Class baseBeanClass = this.bviUtils.getBaseClassType(propertyInformation);
+        String propertyName = this.bviUtils.getPropertyToValidate(propertyInformation);
+        String originalKey = getKey(propertyInformation);
+
+        PropertyDetails constraintSourcePropertyDetails =
+                resolveMappedConstraintSourceFor(originalKey, baseBeanClass, propertyName);
+
+        if(constraintSourcePropertyDetails == null)
+        {
+            return Collections.emptySet();
+        }
+
+        baseBeanClass = (Class) constraintSourcePropertyDetails.getBaseObject();
+        propertyName = constraintSourcePropertyDetails.getProperty();
+
+        Class[] groups = this.bviUtils.resolveGroups(facesContext, uiComponent);
+
+        if (groups == null)
+        {
+            return null;
+        }
+
+        ValidatorFactory validatorFactory = ExtValBeanValidationContext.getCurrentInstance().getValidatorFactory();
+        return validatorFactory
+                .usingContext()
+                .messageInterpolator(ExtValBeanValidationContext.getCurrentInstance().getMessageInterpolator())
+                .constraintValidatorFactory(validatorFactory.getConstraintValidatorFactory())
+                .traversableResolver(validatorFactory.getTraversableResolver())
+                .getValidator()
+                .validateValue(baseBeanClass, propertyName, convertedObject, groups);
+    }
+
+    private String getKey(PropertyInformation propertyInformation)
+    {
+        return ExtValUtils.getPropertyDetails(propertyInformation).getKey();
+    }
+
+    //use the PropertyDetails to avoid a new data-structure
+    //an instance of the target class isn't required in for this use-case so the class itself is stored directly
+    //a clean approach would require an additional api
+    //however, since it's only used in this class it's ok to use casting instead
+    PropertyDetails resolveMappedConstraintSourceFor(String originalKey, Class baseBeanClass, String property)
+    {
+        if (isMappedConstraintSourceCached(baseBeanClass, property))
+        {
+            return getMappedConstraintSource(baseBeanClass, property);
+        }
+
+        baseBeanClass = ProxyUtils.getUnproxiedClass(baseBeanClass);
+
+        Class newBaseBeanClass = findMappedClass(baseBeanClass, property);
+
+        //mapped source is ignored via @IgnoreConstraintSource or there is just no mapping annotation at the target
+        if(newBaseBeanClass == null)
+        {
+            tryToCacheMappedConstraintSourceMetaData(baseBeanClass, property, null);
+            return null;
+        }
+
+        String newProperty = findMappedProperty(baseBeanClass, newBaseBeanClass, property);
+
+        PropertyDetails result = new PropertyDetails(originalKey, newBaseBeanClass, newProperty);
+
+        tryToCacheMappedConstraintSourceMetaData(baseBeanClass, property, result);
+        return result;
+    }
+
+    private boolean isMappedConstraintSourceCached(Class baseBeanClass, String property)
+    {
+        return getConstraintSourceStorage().containsMapping(baseBeanClass, property);
+    }
+
+    private PropertyDetails getMappedConstraintSource(Class baseBeanClass, String property)
+    {
+        return getConstraintSourceStorage().getMappedConstraintSource(baseBeanClass, property);
+    }
+
+    private void tryToCacheMappedConstraintSourceMetaData(
+            Class originalClass, String originalProperty, PropertyDetails result)
+    {
+        getConstraintSourceStorage().storeMapping(originalClass, originalProperty, result);
+    }
+
+    private MappedConstraintSourceStorage getConstraintSourceStorage()
+    {
+        return ExtValUtils
+                .getStorage(MappedConstraintSourceStorage.class, MappedConstraintSourceStorage.class.getName());
+    }
+
+    private Class findMappedClass(Class baseBeanClass, String property)
+    {
+        Class<? extends Annotation> constraintSourceAnnotationImplementation = (Class) ExtValContext.getContext()
+                .getGlobalProperty(ConstraintSource.class.getName());
+
+        Annotation foundConstraintSourceAnnotation = tryToGetAnnotationFromProperty(
+                baseBeanClass, property, constraintSourceAnnotationImplementation);
+
+        if (foundConstraintSourceAnnotation == null)
+        {
+            foundConstraintSourceAnnotation = tryToGetAnnotationFromField(
+                    baseBeanClass, property, constraintSourceAnnotationImplementation);
+        }
+
+        if (foundConstraintSourceAnnotation == null && !isMappedConstraintSourceIgnored(baseBeanClass, property))
+        {
+            foundConstraintSourceAnnotation = tryToGetConstraintSourceAnnotationFromClass(
+                    baseBeanClass, constraintSourceAnnotationImplementation);
+        }
+
+        if (foundConstraintSourceAnnotation != null)
+        {
+            return extractValueOf(foundConstraintSourceAnnotation, Class.class);
+        }
+
+        return null;
+    }
+
+    private Method tryToGetMethod(Class baseBeanClass, String property)
+    {
+        Method method = tryToGetReadMethod(baseBeanClass, property);
+
+        if (method == null)
+        {
+            method = tryToGetReadMethodManually(baseBeanClass, property);
+        }
+        return method;
+    }
+
+    private Method tryToGetReadMethod(Class entity, String property)
+    {
+        if (useBeanInfo())
+        {
+            try
+            {
+                BeanInfo beanInfo = Introspector.getBeanInfo(entity);
+                for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors())
+                {
+                    if (property.equals(propertyDescriptor.getName()) && propertyDescriptor.getReadMethod() != null)
+                    {
+                        return propertyDescriptor.getReadMethod();
+                    }
+                }
+            }
+            catch (IntrospectionException e)
+            {
+                //do nothing
+            }
+        }
+        return null;
+    }
+
+    private boolean useBeanInfo()
+    {
+        return Boolean.TRUE.equals(ExtValContext.getContext().getGlobalProperty(BeanInfo.class.getName()));
+    }
+
+    @ToDo(value = Priority.MEDIUM, description = "refactor - it's also used in DefaultComponentMetaDataExtractor")
+    private Method tryToGetReadMethodManually(Class entity, String property)
+    {
+        property = property.substring(0, 1).toUpperCase() + property.substring(1);
+
+        try
+        {
+            //changed to official bean spec. due to caching there is no performance issue any more
+            return entity.getDeclaredMethod("is" + property);
+        }
+        catch (NoSuchMethodException e)
+        {
+            try
+            {
+                return entity.getDeclaredMethod("get" + property);
+            }
+            catch (NoSuchMethodException e1)
+            {
+                if (logger.isTraceEnabled())
+                {
+                    logger.trace("method not found - class: " + entity.getName()
+                            + " - methods: " + "get" + property + " " + "is" + property);
+                }
+
+                return null;
+            }
+        }
+    }
+
+    @ToDo(value = Priority.MEDIUM, description = "refactor - it's also used in DefaultComponentMetaDataExtractor")
+    private Field tryToGetField(Class baseBeanClass, String property)
+    {
+        Field field;
+
+        try
+        {
+            field = getDeclaredField(baseBeanClass, property);
+        }
+        catch (Exception e)
+        {
+            try
+            {
+                try
+                {
+                    field = baseBeanClass.getDeclaredField("_" + property);
+                }
+                catch (Exception e1)
+                {
+                    if (property.length() > 1 &&
+                            Character.isUpperCase(property.charAt(0)) &&
+                            Character.isUpperCase(property.charAt(1)))
+                    {
+                        //don't use Introspector#decapitalize here
+                        field = baseBeanClass
+                                .getDeclaredField(property.substring(0, 1).toLowerCase() + property.substring(1));
+                    }
+                    else
+                    {
+                        field = baseBeanClass.getDeclaredField(Introspector.decapitalize(property));
+                    }
+                }
+            }
+            catch (NoSuchFieldException e1)
+            {
+                if (logger.isTraceEnabled())
+                {
+                    logger.trace("field " + property + " or _" + property + " not found", e1);
+                }
+
+                return null;
+            }
+        }
+
+        return field;
+    }
+
+    @ToDo.List({
+      @ToDo(value = Priority.HIGH, description = "add support for instances wrapped with cglib"),
+      @ToDo(value = Priority.BLOCKING, description = "refactor - it's also used in DefaultComponentMetaDataExtractor")
+    })
+    private Field getDeclaredField(Class entity, String property) throws NoSuchFieldException
+    {
+        return entity.getDeclaredField(property);
+    }
+
+    private boolean isMappedConstraintSourceIgnored(Class baseBeanClass, String property)
+    {
+        Method method = tryToGetMethod(baseBeanClass, property);
+
+        if(method != null && method.isAnnotationPresent(getIgnoreConstraintSourceAnnotationImplementation()))
+        {
+            return true;
+        }
+
+        Field field = tryToGetField(baseBeanClass, property);
+
+        if(field != null && field.isAnnotationPresent(getIgnoreConstraintSourceAnnotationImplementation()))
+        {
+            return true;
+        }
+
+        return false;
+    }
+
+    private Annotation tryToGetConstraintSourceAnnotationFromClass(
+            Class baseBeanClass, Class<? extends Annotation> annotation)
+    {
+        if (baseBeanClass.isAnnotationPresent(annotation))
+        {
+            return baseBeanClass.getAnnotation(annotation);
+        }
+        return null;
+    }
+
+    private Class<? extends Annotation> getIgnoreConstraintSourceAnnotationImplementation()
+    {
+        return (Class) ExtValContext.getContext().getGlobalProperty(IgnoreConstraintSource.class.getName());
+    }
+
+    private String findMappedProperty(Class baseBeanClass, Class newBaseBeanClass, String originalProperty)
+    {
+        Annotation targetPropertyAnnotation = getTargetPropertyMetaData(baseBeanClass, originalProperty);
+        if (targetPropertyAnnotation != null)
+        {
+            return extractNewPropertyName(newBaseBeanClass, targetPropertyAnnotation);
+        }
+
+        return originalProperty;
+    }
+
+    private Annotation getTargetPropertyMetaData(Class baseBeanClass, String originalProperty)
+    {
+        Class<? extends Annotation> targetPropertyAnnotation = getTargetPropertyAnnotationImplementation();
+        Class<? extends Annotation> targetPropertyIdAnnotation = getTargetPropertyIdAnnotationImplementation();
+
+        Annotation result = findTargetPropertyIdAnnotation(baseBeanClass, originalProperty, targetPropertyIdAnnotation);
+
+        if (result == null)
+        {
+            result = findTargetPropertyAnnotation(baseBeanClass, originalProperty, targetPropertyAnnotation);
+        }
+
+        return result;
+    }
+
+    private Annotation findTargetPropertyIdAnnotation(Class baseBeanClass,
+                                                      String property,
+                                                      Class<? extends Annotation> targetPropertyIdAnnotation)
+    {
+        Annotation result = tryToGetAnnotationFromProperty(baseBeanClass, property, targetPropertyIdAnnotation);
+
+        if (result == null)
+        {
+            result = tryToGetAnnotationFromField(baseBeanClass, property, targetPropertyIdAnnotation);
+        }
+
+        return result;
+    }
+
+    private Annotation findTargetPropertyAnnotation(Class baseBeanClass,
+                                                    String property,
+                                                    Class<? extends Annotation> targetPropertyAnnotation)
+    {
+        Annotation result = tryToGetAnnotationFromProperty(baseBeanClass, property, targetPropertyAnnotation);
+
+        if (result == null)
+        {
+            result = tryToGetAnnotationFromField(baseBeanClass, property, targetPropertyAnnotation);
+        }
+
+        return result;
+    }
+
+    private Annotation tryToGetAnnotationFromProperty(
+            Class baseBeanClass, String property, Class<? extends Annotation> annotationClass)
+    {
+        Method method = tryToGetMethod(baseBeanClass, property);
+
+        if (method != null && method.isAnnotationPresent(annotationClass))
+        {
+            return method.getAnnotation(annotationClass);
+        }
+        return null;
+    }
+
+    private Annotation tryToGetAnnotationFromField(
+            Class baseBeanClass, String property, Class<? extends Annotation> annotationClass)
+    {
+        Field field = tryToGetField(baseBeanClass, property);
+
+        if (field != null && field.isAnnotationPresent(annotationClass))
+        {
+            return field.getAnnotation(annotationClass);
+        }
+        return null;
+    }
+
+    private Class<? extends Annotation> getTargetPropertyAnnotationImplementation()
+    {
+        return (Class) ExtValContext.getContext().getGlobalProperty(TargetProperty.class.getName());
+    }
+
+    private Class<? extends Annotation> getTargetPropertyIdAnnotationImplementation()
+    {
+        return (Class) ExtValContext.getContext().getGlobalProperty(TargetPropertyId.class.getName());
+    }
+
+    private String extractNewPropertyName(Class targetClass, Annotation annotation)
+    {
+        Object annotationValue = extractValueOf(annotation, Object.class);
+
+        //@TargetProperty
+        if (annotationValue instanceof String)
+        {
+            return (String) annotationValue;
+        }
+
+        //@TargetPropertyId
+        if (annotationValue instanceof Class)
+        {
+            return findNameOfAnnotatedProperty(targetClass, (Class) annotationValue);
+        }
+        return null;
+    }
+
+    //EXTVAL-83/use-case 5
+    private String findNameOfAnnotatedProperty(
+            Class targetClass, Class<? extends Annotation> customTargetMarkerAnnotation)
+    {
+        for(Method currentMethod : targetClass.getDeclaredMethods())
+        {
+            if(currentMethod.isAnnotationPresent(customTargetMarkerAnnotation))
+            {
+                return convertMethodToPropertyName(currentMethod.getName());
+            }
+        }
+
+        for(Field currentField : targetClass.getDeclaredFields())
+        {
+            if(currentField.isAnnotationPresent(customTargetMarkerAnnotation))
+            {
+                return convertFieldToPropertyName(currentField.getName());
+            }
+        }
+        return null;
+    }
+
+    private String convertMethodToPropertyName(String name)
+    {
+        String result = name;
+
+        if(name.startsWith("is"))
+        {
+            result = name.substring(2);
+        }
+        else if(name.startsWith("get"))
+        {
+            result = name.substring(3);
+        }
+
+        return Introspector.decapitalize(result);
+    }
+
+    private String convertFieldToPropertyName(String name)
+    {
+        if(name.startsWith("_"))
+        {
+            return name.substring(1);
+        }
+        return name;
+    }
+
+    private <T> T extractValueOf(Annotation annotation, Class<T> targetClass)
+    {
+        for (Method annotationMethod : annotation.annotationType().getDeclaredMethods())
+        {
+            if ("value".equals(annotationMethod.getName()))
+            {
+                try
+                {
+                    return (T) annotationMethod.invoke(annotation);
+                }
+                catch (Throwable t)
+                {
+                    //do nothing
+                }
+            }
+        }
+        return null;
+    }
+}

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java?rev=927022&r1=927021&r2=927022&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java Wed Mar 24 12:03:16 2010
@@ -21,6 +21,7 @@ package org.apache.myfaces.extensions.va
 import org.apache.myfaces.extensions.validator.beanval.BeanValidationModuleValidationInterceptor;
 import org.apache.myfaces.extensions.validator.beanval.HtmlCoreComponentsComponentInitializer;
 import org.apache.myfaces.extensions.validator.beanval.BeanAwareValidatorFactory;
+import org.apache.myfaces.extensions.validator.beanval.MappedConstraintSourceBeanValidationModuleValidationInterceptor;
 import org.apache.myfaces.extensions.validator.beanval.payload.ViolationSeverity;
 import org.apache.myfaces.extensions.validator.beanval.payload.DisableClientSideValidation;
 import org.apache.myfaces.extensions.validator.beanval.util.BeanValidationUtils;
@@ -59,7 +60,7 @@ public class BeanValidationStartupListen
     protected void init()
     {
         registerValidatorFactory();
-        registerBeanValidationInterceptor();
+        registerBeanValidationInterceptors();
         registerMetaDataTransformerNameMapper();
         registerGroupStorageNameMapper();
         registerModelValidationStorageNameMapper();
@@ -77,9 +78,12 @@ public class BeanValidationStartupListen
                 new BeanAwareValidatorFactory(BeanValidationUtils.getDefaultValidatorFactory()), false);
     }
 
-    protected void registerBeanValidationInterceptor()
+    protected void registerBeanValidationInterceptors()
     {
-        ExtValContext.getContext().registerRendererInterceptor(new BeanValidationModuleValidationInterceptor());
+        ExtValContext.getContext().registerRendererInterceptor(
+                new BeanValidationModuleValidationInterceptor());
+        ExtValContext.getContext().registerRendererInterceptor(
+                new MappedConstraintSourceBeanValidationModuleValidationInterceptor());
     }
 
     protected void registerMetaDataTransformerNameMapper()