incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r928387 [9/15] - in /incubator/bval/trunk: ./ agimatec-jsr303/ agimatec-validation/ bval-core/ bval-core/.externalToolBuilders/ bval-core/.settings/ bval-core/src/ bval-core/src/main/ bval-core/src/main/java/ bval-core/src/main/java/org/ bv...
Date Sun, 28 Mar 2010 12:28:32 GMT
Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/NestedMetaProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/NestedMetaProperty.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/NestedMetaProperty.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java Sun Mar 28 12:28:25 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.bval.jsr303;
+
+
+import javax.validation.metadata.PropertyDescriptor;
+
+import org.apache.bval.model.MetaBean;
+import org.apache.bval.model.Validation;
+
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 25.02.2009 <br/>
+ * Time: 16:54:37 <br/>
+ * Copyright: Agimatec GmbH
+ */
+class PropertyDescriptorImpl extends ElementDescriptorImpl implements PropertyDescriptor {
+    private boolean cascaded;
+    private String propertyPath;
+
+    PropertyDescriptorImpl(MetaBean metaBean, Validation[] validations) {
+        super(metaBean, validations);
+    }
+
+    PropertyDescriptorImpl(Class elementClass, Validation[] validations) {
+        super(elementClass, validations);
+    }
+
+    public void setCascaded(boolean cascaded) {
+        this.cascaded = cascaded;
+    }
+
+    public boolean isCascaded() {
+        return cascaded;
+    }
+
+    public void setPropertyPath(String propertyPath) {
+        this.propertyPath = propertyPath;
+    }
+
+    public String getPropertyName() {
+        return propertyPath;
+    }
+
+    public String toString() {
+        return "PropertyDescriptorImpl{" + "returnType=" + elementClass + ", propertyPath='" +
+              propertyPath + '\'' + '}';
+    }
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/PropertyDescriptorImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/AppendValidationToList.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/AppendValidationToList.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/AppendValidationToList.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/AppendValidationToList.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,46 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.bval.jsr303.AppendValidation;
+import org.apache.bval.jsr303.ConstraintValidation;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 01.02.2010 <br/>
+ * Time: 13:41:22 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class AppendValidationToList implements AppendValidation {
+    private final List<ConstraintValidation> validations = new ArrayList();
+
+    public AppendValidationToList() {
+    }
+
+    public void append(ConstraintValidation validation) {
+        validations.add(validation);
+    }
+
+    public List<ConstraintValidation> getValidations() {        
+        return validations;
+    }
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/AppendValidationToList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/AppendValidationToList.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/AppendValidationToList.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptor.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptor.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptor.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,34 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+import javax.validation.metadata.ElementDescriptor;
+import java.util.List;
+
+/**
+ * Description: This class will disappear when such
+ * functionality is part of the JSR303 specification.<br/>
+ * User: roman <br/>
+ * Date: 11.11.2009 <br/>
+ * Time: 12:38:17 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public interface ConstructorDescriptor extends ElementDescriptor {
+    List<ParameterDescriptor> getParameterDescriptors(); //index aligned
+
+    boolean isCascaded();
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptorImpl.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptorImpl.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptorImpl.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,60 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.bval.jsr303.ElementDescriptorImpl;
+import org.apache.bval.model.MetaBean;
+import org.apache.bval.model.Validation;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 01.02.2010 <br/>
+ * Time: 10:57:39 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class ConstructorDescriptorImpl extends ElementDescriptorImpl
+      implements ConstructorDescriptor, ProcedureDescriptor {
+    private List<ParameterDescriptor> parameterDescriptors = new ArrayList();
+    private boolean cascaded;
+
+    protected ConstructorDescriptorImpl(MetaBean metaBean, Validation[] validations) {
+        super(metaBean, validations);
+    }
+
+    protected ConstructorDescriptorImpl(Class elementClass, Validation[] validations) {
+        super(elementClass, validations);
+    }
+
+    public boolean isCascaded() {
+        return cascaded;
+    }
+
+    public void setCascaded(boolean cascaded) {
+        this.cascaded = cascaded;
+    }
+
+
+    public List<ParameterDescriptor> getParameterDescriptors() //index aligned
+    {
+        return parameterDescriptors;
+    }
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ConstructorDescriptorImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptor.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptor.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptor.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,40 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+import javax.validation.metadata.BeanDescriptor;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Set;
+
+/**
+ * Description: This class will disappear when such
+ * functionality is part of the JSR303 specification.<br/>
+ * User: roman <br/>
+ * Date: 11.11.2009 <br/>
+ * Time: 12:38:45 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public interface MethodBeanDescriptor extends BeanDescriptor {
+    MethodDescriptor getConstraintsForMethod(Method method);
+
+    ConstructorDescriptor getConstraintsForConstructor(Constructor constructor);
+
+    Set<MethodDescriptor> getConstrainedMethods();
+
+    Set<ConstructorDescriptor> getConstrainedConstructors();
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,88 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.bval.jsr303.AgimatecFactoryContext;
+import org.apache.bval.jsr303.BeanDescriptorImpl;
+import org.apache.bval.model.MetaBean;
+import org.apache.bval.model.Validation;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 11.11.2009 <br/>
+ * Time: 15:18:00 <br/>
+ * Copyright: Agimatec GmbH
+ */
+class MethodBeanDescriptorImpl extends BeanDescriptorImpl
+      implements MethodBeanDescriptor {
+    private Map<Method, MethodDescriptorImpl> methodConstraints;
+    private Map<Constructor, ConstructorDescriptorImpl> constructorConstraints;
+
+    protected MethodBeanDescriptorImpl(AgimatecFactoryContext factoryContext,
+                                       MetaBean metaBean, Validation[] validations) {
+        super(factoryContext, metaBean, validations);
+    }
+
+    public void setMethodConstraints(Map<Method, MethodDescriptorImpl> methodConstraints) {
+        this.methodConstraints = methodConstraints;
+    }
+
+    public void setConstructorConstraints(
+          Map<Constructor, ConstructorDescriptorImpl> constructorConstraints) {
+        this.constructorConstraints = constructorConstraints;
+    }
+
+    public MethodDescriptor getConstraintsForMethod(Method method) {
+        return methodConstraints.get(method);
+    }
+
+    public ConstructorDescriptor getConstraintsForConstructor(Constructor constructor) {
+        return constructorConstraints.get(constructor);
+    }
+
+    public Set<MethodDescriptor> getConstrainedMethods() {
+        return new HashSet(methodConstraints.values());
+    }
+
+    public void putMethodDescriptor(Method method, MethodDescriptorImpl desc) {
+        methodConstraints.put(method, desc);
+    }
+
+    public Set<ConstructorDescriptor> getConstrainedConstructors() {
+        return new HashSet(methodConstraints.values());
+    }
+
+    public void putConstructorDescriptor(Constructor cons, ConstructorDescriptorImpl desc) {
+        constructorConstraints.put(cons, desc);
+    }
+
+    public Map<Method, MethodDescriptorImpl> getMethodConstraints() {
+        return methodConstraints;
+    }
+
+    public Map<Constructor, ConstructorDescriptorImpl> getConstructorConstraints() {
+        return constructorConstraints;
+    }
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodBeanDescriptorImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptor.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptor.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptor.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,35 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+import javax.validation.metadata.ElementDescriptor;
+import java.util.List;
+
+/**
+ * Description: This class will disappear when such
+ * functionality is part of the JSR303 specification.<br/>
+ * User: roman <br/>
+ * Date: 11.11.2009 <br/>
+ * Time: 12:38:09 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public interface MethodDescriptor extends ElementDescriptor {
+    List<ParameterDescriptor> getParameterDescriptors(); //index aligned
+
+    boolean isCascaded();
+
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,60 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.bval.jsr303.ElementDescriptorImpl;
+import org.apache.bval.model.MetaBean;
+import org.apache.bval.model.Validation;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 01.02.2010 <br/>
+ * Time: 10:38:05 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class MethodDescriptorImpl extends ElementDescriptorImpl
+      implements MethodDescriptor, ProcedureDescriptor {
+    private List<ParameterDescriptor> parameterDescriptors = new ArrayList();
+    private boolean cascaded;
+
+    protected MethodDescriptorImpl(MetaBean metaBean, Validation[] validations) {
+        super(metaBean, validations);
+    }
+
+    protected MethodDescriptorImpl(Class elementClass, Validation[] validations) {
+        super(elementClass, validations);
+    }
+
+    public List<ParameterDescriptor> getParameterDescriptors() //index aligned
+    {
+        return parameterDescriptors;
+    }
+
+    public boolean isCascaded() {
+        return cascaded;
+    }
+
+    public void setCascaded(boolean cascaded) {
+        this.cascaded = cascaded;
+    }
+
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodDescriptorImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidator.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidator.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidator.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,123 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Set;
+
+/**
+ * Description: Appendix C. Proposal for method-level validation.
+ * This interface contains the APIs added to javax.validation.Validator.
+ * It can be removed as soon as the Validator interface contains these methods.
+ * The extension is not a part of the JSR303 core specification yet, but could
+ * be in a future revision.<br/>
+ * You can access the extension via the use of the Validator.unwrap() method.<br/>
+ * User: roman <br/>
+ * Date: 11.11.2009 <br/>
+ * Time: 11:04:56 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public interface MethodValidator extends Validator {
+    /**
+     * Validate each parameter value based on the constraints described on
+     * the parameters of <code>method</code>.
+     *
+     * @param clazz           class hosting the method
+     * @param method          the method whose parameters are currectly validated
+     * @param parameterValues the parameter values passed to the method for invocation
+     * @param groups          groups targeted for validation
+     * @return set of constraint violations
+     * @throws IllegalArgumentException if the method does not belong to <code>T</code>
+     *                                  or if the Object[] does not match the method signature
+     */
+    <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz, Method method,
+                                                       Object[] parameterValues,
+                                                       Class<?>... groups);
+
+    /**
+     * Validate the parameter value based on the constraints described on
+     * the parameterIndex-th parameter of <code>method</code>.
+     *
+     * @param clazz          class hosting the method
+     * @param method         the method whose parameters are currectly validated
+     * @param parameterValue the parameter value passed to the parameterIndex-t parameter of method
+     * @param parameterIndex parameter index of the parameter validated in method
+     * @param groups         groups targeted for validation
+     * @return set of constraint violations
+     * @throws IllegalArgumentException if the method does not belong to <code>T</code>
+     *                                  or if parameterIndex is out of bound
+     */
+    <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz, Method method,
+                                                   Object parameterValue,
+                                                   int parameterIndex,
+                                                   Class<?>... groups);
+
+    /**
+     * Validate each parameter value based on the constraints described on
+     * <code>method</code>.
+     *
+     * @param clazz         class hosting the method
+     * @param method        the method whose result is validated
+     * @param returnedValue the value returned by the method invocation
+     * @param groups        groups targeted for validation
+     * @return set of constraint violations
+     * @throws IllegalArgumentException if the method does not belong to <code>T</code>
+     */
+    <T> Set<ConstraintViolation<T>> validateReturnedValue(Class<T> clazz, Method method,
+                                                       Object returnedValue,
+                                                       Class<?>... groups);
+
+    /**
+     * Validate each parameter value based on the constraints described on
+     * the parameters of <code>constructor</code>.
+     *
+     * @param clazz           class hosting the constructor
+     * @param constructor     the constructor whose parameters are currectly validated
+     * @param parameterValues the parameter values passed to the constructor for invocation
+     * @param groups          groups targeted for validation
+     * @return set of constraint violations
+     * @throws IllegalArgumentException if the constructor does not belong to <code>T</code>
+     *                                  or if the Object[] does not match the constructor signature
+     */
+    <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz,
+                                                    Constructor constructor,
+                                                    Object[] parameterValues,
+                                                    Class<?>... groups);
+
+    /**
+     * Validate the parameter value based on the constraints described on
+     * the parameterIndex-th parameter of <code>constructor</code>.
+     *
+     * @param clazz          class hosting the constructor
+     * @param constructor    the method whose parameters are currectly validated
+     * @param parameterValue the parameter value passed to the
+     *                       parameterIndex-th parameter of constructor
+     * @param parameterIndex parameter index of the parameter validated in constructor
+     * @param groups         groups targeted for validation
+     * @return set of constraint violations
+     * @throws IllegalArgumentException if the constructor does not belong to <code>T</code>
+     *                                  or if prameterIndex is out of bound
+     */
+    <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz,
+                                                   Constructor constructor,
+                                                   Object parameterValue,
+                                                   int parameterIndex,
+                                                   Class<?>... groups);
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,282 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+import org.apache.bval.jsr303.*;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.metadata.ConstraintDescriptor;
+
+import org.apache.bval.jsr303.AgimatecFactoryContext;
+import org.apache.bval.jsr303.BeanDescriptorImpl;
+import org.apache.bval.jsr303.ClassValidator;
+import org.apache.bval.jsr303.ConstraintValidation;
+import org.apache.bval.jsr303.ConstraintValidationListener;
+import org.apache.bval.jsr303.GroupValidationContext;
+import org.apache.bval.jsr303.groups.Group;
+import org.apache.bval.jsr303.groups.Groups;
+import org.apache.bval.model.MetaBean;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Description: experimental implementation of method-level-validation <br/>
+ * User: roman <br/>
+ * Date: 11.11.2009 <br/>
+ * Time: 12:36:20 <br/>
+ * Copyright: Agimatec GmbH
+ */
+class MethodValidatorImpl extends ClassValidator implements MethodValidator {
+
+    public MethodValidatorImpl(AgimatecFactoryContext factoryContext) {
+        super(factoryContext);
+    }
+
+    @Override
+    protected BeanDescriptorImpl createBeanDescriptor(MetaBean metaBean) {
+        MethodBeanDescriptorImpl descriptor = new MethodBeanDescriptorImpl(factoryContext,
+              metaBean, metaBean.getValidations());
+        MethodValidatorMetaBeanFactory factory =
+              new MethodValidatorMetaBeanFactory(factoryContext);
+        factory.buildMethodDescriptor(descriptor);
+        return descriptor;
+    }
+
+    /**
+     * enhancement: method-level-validation not yet completly implemented
+     * <pre>example:
+     * <code>
+     * public @NotNull String saveItem(@Valid @NotNull Item item, @Max(23) BigDecimal
+     * </code></pre>
+     * spec:
+     * The constraints declarations evaluated are the constraints hosted on the
+     * parameters of the method or constructor. If @Valid is placed on a parameter,
+     * constraints declared on the object itself are considered.
+     *
+     * @throws IllegalArgumentException enhancement: if the method does not belong to <code>T</code>
+     *                                  or if the Object[] does not match the method signature
+     */
+    public <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz, Method method,
+                                                              Object[] parameters,
+                                                              Class<?>... groupArray) {
+        MethodBeanDescriptorImpl beanDesc =
+              (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
+        MethodDescriptorImpl methodDescriptor =
+              (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
+        return validateParameters(methodDescriptor.getMetaBean(),
+              methodDescriptor.getParameterDescriptors(), parameters, groupArray);
+    }
+
+    public <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz, Method method,
+                                                             Object parameter,
+                                                             int parameterIndex,
+                                                             Class<?>... groupArray) {
+        MethodBeanDescriptorImpl beanDesc =
+              (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
+        MethodDescriptorImpl methodDescriptor =
+              (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
+        ParameterDescriptorImpl paramDesc = (ParameterDescriptorImpl) methodDescriptor
+              .getParameterDescriptors().get(parameterIndex);
+        return validateParameter(paramDesc, parameter, groupArray);
+    }
+
+    public <T> Set<ConstraintViolation<T>> validateParameters(Class<T> clazz,
+                                                              Constructor constructor,
+                                                              Object[] parameters,
+                                                              Class<?>... groupArray) {
+        MethodBeanDescriptorImpl beanDesc =
+              (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
+        ConstructorDescriptorImpl constructorDescriptor =
+              (ConstructorDescriptorImpl) beanDesc.getConstraintsForConstructor(constructor);
+        return validateParameters(constructorDescriptor.getMetaBean(),
+              constructorDescriptor.getParameterDescriptors(), parameters, groupArray);
+    }
+
+    public <T> Set<ConstraintViolation<T>> validateParameter(Class<T> clazz,
+                                                             Constructor constructor,
+                                                             Object parameter,
+                                                             int parameterIndex,
+                                                             Class<?>... groupArray) {
+        MethodBeanDescriptorImpl beanDesc =
+              (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
+        ConstructorDescriptorImpl methodDescriptor =
+              (ConstructorDescriptorImpl) beanDesc.getConstraintsForConstructor(constructor);
+        ParameterDescriptorImpl paramDesc = (ParameterDescriptorImpl) methodDescriptor
+              .getParameterDescriptors().get(parameterIndex);
+        return validateParameter(paramDesc, parameter, groupArray);
+    }
+
+    /**
+     * If @Valid  is placed on the method, the constraints declared on the object
+     * itself are considered.
+     */
+    public <T> Set<ConstraintViolation<T>> validateReturnedValue(Class<T> clazz, Method method,
+                                                                 Object returnedValue,
+                                                                 Class<?>... groupArray) {
+        MethodBeanDescriptorImpl beanDesc =
+              (MethodBeanDescriptorImpl) getConstraintsForClass(clazz);
+        MethodDescriptorImpl methodDescriptor =
+              (MethodDescriptorImpl) beanDesc.getConstraintsForMethod(method);
+        final GroupValidationContext<ConstraintValidationListener<Object>> context =
+              createContext(methodDescriptor.getMetaBean(), returnedValue, groupArray);
+        validateReturnedValueInContext(context, methodDescriptor);
+        ConstraintValidationListener result = context.getListener();
+        return result.getConstaintViolations();
+    }
+
+    private <T> Set<ConstraintViolation<T>> validateParameters(MetaBean metaBean,
+                                                               List<ParameterDescriptor> paramDescriptors,
+                                                               Object[] parameters,
+                                                               Class<?>... groupArray) {
+        if (parameters == null) throw new IllegalArgumentException("cannot validate null");
+        if (parameters.length > 0) {
+            try {
+                GroupValidationContext<ConstraintValidationListener<Object[]>> context =
+                      createContext(metaBean, null, groupArray);
+                for (int i = 0; i < parameters.length; i++) {
+                    ParameterDescriptorImpl paramDesc =
+                          (ParameterDescriptorImpl) paramDescriptors.get(i);
+                    context.setBean(parameters[i]);
+                    validateParameterInContext(context, paramDesc);
+                }
+                ConstraintValidationListener result = context.getListener();
+                return result.getConstaintViolations();
+            } catch (RuntimeException ex) {
+                throw unrecoverableValidationError(ex, parameters);
+            }
+        } else {
+            return Collections.EMPTY_SET;
+        }
+    }
+
+    private <T> Set<ConstraintViolation<T>> validateParameter(
+          ParameterDescriptorImpl paramDesc, Object parameter, Class<?>... groupArray) {
+        try {
+            final GroupValidationContext<ConstraintValidationListener<Object>> context =
+                  createContext(paramDesc.getMetaBean(), parameter, groupArray);
+            final ConstraintValidationListener result = context.getListener();
+            validateParameterInContext(context, paramDesc);
+            return result.getConstaintViolations();
+        } catch (RuntimeException ex) {
+            throw unrecoverableValidationError(ex, parameter);
+        }
+    }
+
+    /** validate constraints hosted on parameters of a method */
+    private <T> void validateParameterInContext(
+          GroupValidationContext<ConstraintValidationListener<T>> context,
+          ParameterDescriptorImpl paramDesc) {
+
+        final Groups groups = context.getGroups();
+
+        for (ConstraintDescriptor consDesc : paramDesc.getConstraintDescriptors()) {
+            ConstraintValidation validation = (ConstraintValidation) consDesc;
+            // 1. process groups
+            for (Group current : groups.getGroups()) {
+                context.setCurrentGroup(current);
+                validation.validate(context);
+            }
+            // 2. process sequences
+            for (List<Group> eachSeq : groups.getSequences()) {
+                for (Group current : eachSeq) {
+                    context.setCurrentGroup(current);
+                    validation.validate(context);
+                    /**
+                     * if one of the group process in the sequence leads to one or more validation failure,
+                     * the groups following in the sequence must not be processed
+                     */
+                    if (!context.getListener().isEmpty()) break;
+                }
+            }
+        }
+        if (paramDesc.isCascaded() && context.getValidatedValue() != null) {
+            context.setMetaBean(factoryContext.getMetaBeanFinder().
+                  findForClass(context.getValidatedValue().getClass()));
+            // 1. process groups
+            for (Group current : groups.getGroups()) {
+                context.setCurrentGroup(current);
+                validateContext(context);
+            }
+            // 2. process sequences
+            for (List<Group> eachSeq : groups.getSequences()) {
+                for (Group current : eachSeq) {
+                    context.setCurrentGroup(current);
+                    validateContext(context);
+                    /**
+                     * if one of the group process in the sequence leads to one or more validation failure,
+                     * the groups following in the sequence must not be processed
+                     */
+                    if (!context.getListener().isEmpty()) break;
+                }
+            }
+        }
+    }
+
+    /** validate constraints hosted on parameters of a method */
+    private <T> void validateReturnedValueInContext(
+          GroupValidationContext<ConstraintValidationListener<T>> context,
+          MethodDescriptorImpl methodDescriptor) {
+
+        final Groups groups = context.getGroups();
+
+        for (ConstraintDescriptor consDesc : methodDescriptor.getConstraintDescriptors()) {
+            ConstraintValidation validation = (ConstraintValidation) consDesc;
+            // 1. process groups
+            for (Group current : groups.getGroups()) {
+                context.setCurrentGroup(current);
+                validation.validate(context);
+            }
+            // 2. process sequences
+            for (List<Group> eachSeq : groups.getSequences()) {
+                for (Group current : eachSeq) {
+                    context.setCurrentGroup(current);
+                    validation.validate(context);
+                    /**
+                     * if one of the group process in the sequence leads to one or more validation failure,
+                     * the groups following in the sequence must not be processed
+                     */
+                    if (!context.getListener().isEmpty()) break;
+                }
+            }
+        }
+        if (methodDescriptor.isCascaded() && context.getValidatedValue() != null) {
+            context.setMetaBean(factoryContext.getMetaBeanFinder().
+                  findForClass(context.getValidatedValue().getClass()));
+            // 1. process groups
+            for (Group current : groups.getGroups()) {
+                context.setCurrentGroup(current);
+                validateContext(context);
+            }
+            // 2. process sequences
+            for (List<Group> eachSeq : groups.getSequences()) {
+                for (Group current : eachSeq) {
+                    context.setCurrentGroup(current);
+                    validateContext(context);
+                    /**
+                     * if one of the group process in the sequence leads to one or more validation failure,
+                     * the groups following in the sequence must not be processed
+                     */
+                    if (!context.getListener().isEmpty()) break;
+                }
+            }
+        }
+    }
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,153 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
+import javax.validation.Valid;
+
+import org.apache.bval.jsr303.AgimatecFactoryContext;
+import org.apache.bval.jsr303.AppendValidation;
+import org.apache.bval.jsr303.Jsr303MetaBeanFactory;
+import org.apache.bval.jsr303.util.SecureActions;
+import org.apache.bval.model.Validation;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 01.02.2010 <br/>
+ * Time: 12:07:24 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class MethodValidatorMetaBeanFactory extends Jsr303MetaBeanFactory {
+    public MethodValidatorMetaBeanFactory(AgimatecFactoryContext factoryContext) {
+        super(factoryContext);
+    }
+
+    public void buildMethodDescriptor(MethodBeanDescriptorImpl descriptor) {
+        try {
+            buildMethodConstraints(descriptor);
+            buildConstructorConstraints(descriptor);
+        } catch (Exception e) {
+            throw new IllegalArgumentException(e.getMessage(), e);
+        }
+    }
+
+    private void buildConstructorConstraints(MethodBeanDescriptorImpl beanDesc)
+          throws InvocationTargetException, IllegalAccessException {
+        beanDesc.setConstructorConstraints(new HashMap());
+
+        for (Constructor cons : beanDesc.getMetaBean().getBeanClass()
+              .getDeclaredConstructors()) {
+            if (!factoryContext.getFactory().getAnnotationIgnores()
+                  .isIgnoreAnnotations(cons)) {
+
+                ConstructorDescriptorImpl consDesc =
+                      new ConstructorDescriptorImpl(beanDesc.getMetaBean(), new Validation[0]);
+                beanDesc.putConstructorDescriptor(cons, consDesc);
+
+                Annotation[][] paramsAnnos = cons.getParameterAnnotations();
+                int idx = 0;
+                for (Annotation[] paramAnnos : paramsAnnos) {
+                    processAnnotations(consDesc, paramAnnos, idx);
+                    idx++;
+                }
+            }
+        }
+    }
+
+    private void buildMethodConstraints(MethodBeanDescriptorImpl beanDesc)
+          throws InvocationTargetException, IllegalAccessException {
+        beanDesc.setMethodConstraints(new HashMap());
+
+        for (Method method : beanDesc.getMetaBean().getBeanClass().getDeclaredMethods()) {
+            if (!factoryContext.getFactory().getAnnotationIgnores()
+                  .isIgnoreAnnotations(method)) {
+
+
+                MethodDescriptorImpl methodDesc = new MethodDescriptorImpl(
+                      beanDesc.getMetaBean(), new Validation[0]);
+                beanDesc.putMethodDescriptor(method, methodDesc);
+
+                // return value validations
+                AppendValidationToList validations = new AppendValidationToList();
+                for (Annotation anno : method.getAnnotations()) {
+                    processAnnotation(anno, methodDesc, validations);
+                }
+                methodDesc.getConstraintDescriptors().addAll(
+                      (List)validations.getValidations());
+
+                // parameter validations
+                Annotation[][] paramsAnnos = method.getParameterAnnotations();
+                int idx = 0;
+                for (Annotation[] paramAnnos : paramsAnnos) {
+                    processAnnotations(methodDesc, paramAnnos, idx);
+                    idx++;
+                }
+            }
+        }
+    }
+
+    private void processAnnotations(ProcedureDescriptor methodDesc, Annotation[] paramAnnos,
+                                    int idx)
+          throws InvocationTargetException, IllegalAccessException {
+        AppendValidationToList validations = new AppendValidationToList();
+        for (Annotation anno : paramAnnos) {
+            processAnnotation(anno, methodDesc, validations);
+        }
+        ParameterDescriptorImpl paramDesc = new ParameterDescriptorImpl(
+              methodDesc.getMetaBean(), validations.getValidations().toArray(
+              new Validation[validations.getValidations().size()]));
+        paramDesc.setIndex(idx);
+        methodDesc.getParameterDescriptors().add(paramDesc);
+    }
+
+    private void processAnnotation(Annotation annotation, ProcedureDescriptor desc,
+                                   AppendValidation validations)
+          throws InvocationTargetException, IllegalAccessException {
+
+        if (annotation instanceof Valid) {
+            desc.setCascaded(true);
+        } else {
+            Constraint vcAnno = annotation.annotationType().getAnnotation(Constraint.class);
+            if (vcAnno != null) {
+                Class<? extends ConstraintValidator<?, ?>>[] validatorClasses;
+                validatorClasses = findConstraintValidatorClasses(annotation, vcAnno);
+                applyConstraint(annotation, validatorClasses, null,
+                      desc.getMetaBean().getBeanClass(), null, validations);
+            } else {
+                /**
+                 * Multi-valued constraints
+                 */
+                Object result = SecureActions.getAnnotationValue(annotation, ANNOTATION_VALUE);
+                if (result != null && result instanceof Annotation[]) {
+                    for (Annotation each : (Annotation[]) result) {
+                        processAnnotation(each, desc, validations); // recursion
+                    }
+                }
+            }
+        }
+    }
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/MethodValidatorMetaBeanFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptor.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptor.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptor.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,39 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+import javax.validation.metadata.ElementDescriptor;
+
+/**
+ * Description: This class will disappear when such
+ * functionality is part of the JSR303 specification.<br/>
+ * User: roman <br/>
+ * Date: 11.11.2009 <br/>
+ * Time: 12:37:59 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public interface ParameterDescriptor extends ElementDescriptor {
+    /**
+     * Is the parameter marked by the <code>@Valid</code> annotation.
+     *
+     * @return <code>true</code> if the annotation is present, <code>false</code> otherwise.
+     */
+    boolean isCascaded();
+
+    int getIndex();
+}
+

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptorImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptorImpl.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptorImpl.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptorImpl.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,59 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+import org.apache.bval.jsr303.ElementDescriptorImpl;
+import org.apache.bval.model.MetaBean;
+import org.apache.bval.model.Validation;
+
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 01.02.2010 <br/>
+ * Time: 10:49:29 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class ParameterDescriptorImpl extends ElementDescriptorImpl
+      implements ParameterDescriptor {
+    private boolean cascaded;
+    private int index;
+
+    public ParameterDescriptorImpl(MetaBean metaBean, Validation[] validations) {
+        super(metaBean, validations);
+    }
+
+    public ParameterDescriptorImpl(Class elementClass, Validation[] validations) {
+        super(elementClass, validations);
+    }
+
+    public boolean isCascaded() {
+        return cascaded;
+    }
+
+    public void setCascaded(boolean cascaded) {
+        this.cascaded = cascaded;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public void setIndex(int index) {
+        this.index = index;
+    }
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ParameterDescriptorImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ProcedureDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ProcedureDescriptor.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ProcedureDescriptor.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ProcedureDescriptor.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,37 @@
+/**
+ *  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.bval.jsr303.extensions;
+
+
+import java.util.List;
+
+import org.apache.bval.model.MetaBean;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 01.02.2010 <br/>
+ * Time: 14:43:28 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public interface ProcedureDescriptor {
+    MetaBean getMetaBean();
+
+    void setCascaded(boolean b);
+
+    List<ParameterDescriptor> getParameterDescriptors();
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ProcedureDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ProcedureDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/extensions/ProcedureDescriptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Group.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Group.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Group.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Group.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,66 @@
+/*
+ * 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.bval.jsr303.groups;
+
+import javax.validation.groups.Default;
+
+/**
+ * immutable object -
+ * wrap an interface that represents a single group.
+ */
+public class Group {
+    /**
+     * the Default Group
+     */
+    public static final Group DEFAULT = new Group(Default.class);
+    
+    private final Class<?> group;
+
+    public Group(Class<?> group) {
+        this.group = group;
+    }
+
+    public Class<?> getGroup() {
+        return group;
+    }
+
+    @Override
+    public String toString() {
+        return "Group{" + "group=" + group + '}';
+    }
+
+	public boolean isDefault() {
+		return Default.class.equals(group);
+	}
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        Group group1 = (Group) o;
+
+        return !(group != null ? !group.equals(group1.group) : group1.group != null);
+    }
+
+    @Override
+    public int hashCode() {
+        return (group != null ? group.hashCode() : 0);
+    }
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Group.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Group.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Group.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Groups.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Groups.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Groups.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Groups.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,97 @@
+/*
+ * 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.bval.jsr303.groups;
+
+
+import javax.validation.GroupDefinitionException;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * defines the order to validate groups during validation.
+ * with some inspiration from reference implementation
+ *
+ * @author Roman Stumm
+ */
+public class Groups {
+    /** The list of single groups. */
+    protected List<Group> groups = new LinkedList<Group>();
+
+    /** The list of sequences. */
+    protected List<List<Group>> sequences = new LinkedList<List<Group>>();
+
+    public List<Group> getGroups() {
+        return groups;
+    }
+
+    public List<List<Group>> getSequences() {
+        return sequences;
+    }
+
+    void insertGroup(Group group) {
+        if (!groups.contains(group)) {
+            groups.add(group);
+        }
+    }
+
+    void insertSequence(List<Group> groups) {
+        if (groups == null || groups.isEmpty()) {
+            return;
+        }
+
+        if (!sequences.contains(groups)) {
+            sequences.add(groups);
+        }
+    }
+
+    public void assertDefaultGroupSequenceIsExpandable(List<Group> defaultGroups) {
+        for (List<Group> groupList : sequences) {
+            int idx = groupList.indexOf(Group.DEFAULT);
+            if (idx != -1) {
+                ensureExpandable(groupList, defaultGroups, idx);
+            }
+        }
+    }
+
+    private void ensureExpandable(List<Group> groupList, List<Group> defaultGroupList,
+                                  int defaultGroupIndex) {
+        for (int i = 0; i < defaultGroupList.size(); i++) {
+            Group group = defaultGroupList.get(i);
+            if (group.isDefault()) {
+                continue; // the default group is the one we want to replace
+            }
+            int index = groupList
+                  .indexOf(group); // sequence contains group of default group sequence
+            if (index == -1) {
+                continue; // if group is not in the sequence
+            }
+
+            if ((i == 0 && index == defaultGroupIndex - 1) ||
+                  (i == defaultGroupList.size() - 1 && index == defaultGroupIndex + 1)) {
+                // if we are at the beginning or end of he defaultGroupSequence and the
+                // matches are either directly before or after we can continue,
+                // since we basically have two groups
+                continue;
+            }
+            throw new GroupDefinitionException("Unable to expand default group list" +
+                  defaultGroupList + " into sequence " + groupList);
+        }
+    }
+
+}
\ No newline at end of file

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Groups.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Groups.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/Groups.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,131 @@
+/*
+ * 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.bval.jsr303.groups;
+
+
+import javax.validation.GroupSequence;
+import javax.validation.ValidationException;
+import javax.validation.groups.Default;
+import java.util.*;
+
+/**
+ * Description: compute group order, based on the hibernate validator algorithm
+ * to guarantee compatibility with interpretation of spec by reference implementation <br/>
+ * Implementation is thread-safe.
+ * User: roman <br/>
+ * Date: 09.04.2009 <br/>
+ * Time: 09:15:50 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class GroupsComputer {
+    /** The default group array used in case any of the validate methods is called without a group. */
+    public static final Class<?>[] DEFAULT_GROUP_ARRAY = new Class<?>[]{Default.class};
+    private static final Groups DEFAULT_GROUPS;
+
+    static {
+        DEFAULT_GROUPS =
+              new GroupsComputer().computeGroups(Arrays.asList(DEFAULT_GROUP_ARRAY));
+    }
+
+    /** caching resolved groups in a thread-safe map. */
+    private final Map<Class<?>, List<Group>> resolvedSequences =
+          Collections.synchronizedMap(new HashMap<Class<?>, List<Group>>());
+
+    public Groups computeGroups(Class<?>[] groups) {
+        if (groups == null) {
+            throw new IllegalArgumentException("null passed as group");
+        }
+
+        // if no groups is specified use the default
+        if (groups.length == 0) {
+            return DEFAULT_GROUPS;
+        }
+
+        return computeGroups(Arrays.asList(groups));
+    }
+
+
+    protected Groups computeGroups(Collection<Class<?>> groups) {
+        if (groups == null || groups.size() == 0) {
+            throw new IllegalArgumentException("At least one group has to be specified.");
+        }
+
+        for (Class<?> clazz : groups) {
+            if (!clazz.isInterface()) {
+                throw new ValidationException(
+                      "A group has to be an interface. " + clazz.getName() + " is not.");
+            }
+        }
+
+        Groups chain = new Groups();
+        for (Class<?> clazz : groups) {
+            GroupSequence anno = clazz.getAnnotation(GroupSequence.class);
+            if (anno == null) {
+                Group group = new Group(clazz);
+                chain.insertGroup(group);
+                insertInheritedGroups(clazz, chain);
+            } else {
+                insertSequence(clazz, anno, chain);
+            }
+        }
+
+        return chain;
+    }
+
+    private void insertInheritedGroups(Class<?> clazz, Groups chain) {
+        for (Class<?> extendedInterface : clazz.getInterfaces()) {
+            Group group = new Group(extendedInterface);
+            chain.insertGroup(group);
+            insertInheritedGroups(extendedInterface, chain);
+        }
+    }
+
+    private void insertSequence(Class<?> clazz, GroupSequence anno, Groups chain) {
+        List<Group> sequence;
+        if (resolvedSequences.containsKey(clazz)) {
+            sequence = resolvedSequences.get(clazz);
+        } else {
+            sequence = resolveSequence(clazz, anno, new HashSet<Class<?>>());
+        }
+        chain.insertSequence(sequence);
+    }
+
+    private List<Group> resolveSequence(Class<?> group, GroupSequence sequenceAnnotation,
+                                        Set<Class<?>> processedSequences) {
+        if (processedSequences.contains(group)) {
+            throw new ValidationException("Cyclic dependency in groups definition");
+        } else {
+            processedSequences.add(group);
+        }
+        List<Group> resolvedGroupSequence = new LinkedList<Group>();
+        Class<?>[] sequenceArray = sequenceAnnotation.value();
+        for (Class<?> clazz : sequenceArray) {
+            GroupSequence anno = clazz.getAnnotation(GroupSequence.class);
+            if (anno == null) {
+                resolvedGroupSequence.add(new Group(clazz)); // group part of sequence
+            } else {
+                List<Group> tmpSequence =
+                      resolveSequence(clazz, anno, processedSequences);  // recursion!
+                resolvedGroupSequence.addAll(tmpSequence);
+            }
+        }
+        resolvedSequences.put(group, resolvedGroupSequence);
+        return resolvedGroupSequence;
+    }
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/groups/GroupsComputer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingRelevant.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingRelevant.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingRelevant.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingRelevant.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,31 @@
+/*
+ * 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.bval.jsr303.resolver;
+
+/**
+ * Description: indicator interface to let the implementation choose
+ * whether results of traversable resolver should be cached <br/>
+ * User: roman <br/>
+ * Date: 25.11.2009 <br/>
+ * Time: 13:59:20 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public interface CachingRelevant {
+    boolean needsCaching();
+}

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingRelevant.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingRelevant.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingRelevant.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingTraversableResolver.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingTraversableResolver.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingTraversableResolver.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/resolver/CachingTraversableResolver.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,153 @@
+/*
+ * 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.bval.jsr303.resolver;
+
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
+import java.lang.annotation.ElementType;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Cache results of a delegated traversable resovler to optimize calls
+ * It works only for a single validate* call and should not be used if
+ * the TraversableResolver is accessed concurrently
+ * <p/>
+ * Date: 25.11.2009 <br/>
+ * Time: 13:56:18 <br/>
+ *
+ * @author Roman Stumm (based on the code of Emmanuel Bernard)
+ */
+public class CachingTraversableResolver implements TraversableResolver, CachingRelevant {
+    private TraversableResolver delegate;
+    private Map<CacheEntry, CacheEntry> cache = new HashMap<CacheEntry, CacheEntry>();
+
+    /** @return true when a CachingTraversableResolver is to be used during validation */
+    public static boolean needsCaching(TraversableResolver resolver) {
+        // caching, if we do not know exactly
+        return !(resolver instanceof CachingRelevant) ||
+              ((CachingRelevant) resolver).needsCaching();
+    }
+
+    public CachingTraversableResolver(TraversableResolver delegate) {
+        this.delegate = delegate;
+    }
+
+    public static TraversableResolver cacheFor(TraversableResolver traversableResolver) {
+        if (needsCaching(traversableResolver)) {
+            return new CachingTraversableResolver(traversableResolver);
+        } else {
+            return traversableResolver;
+        }
+    }
+
+    public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
+                               Class<?> rootBeanType, Path pathToTraversableObject,
+                               ElementType elementType) {
+        CacheEntry currentLH = new CacheEntry(traversableObject, traversableProperty,
+              rootBeanType, pathToTraversableObject, elementType);
+        CacheEntry cachedLH = cache.get(currentLH);
+        if (cachedLH == null) {
+            currentLH.reachable = delegate.isReachable(traversableObject, traversableProperty,
+                  rootBeanType, pathToTraversableObject, elementType);
+            cache.put(currentLH, currentLH);
+            cachedLH = currentLH;
+        } else if (cachedLH.reachable == null) {
+            cachedLH.reachable = delegate.isReachable(traversableObject, traversableProperty,
+                  rootBeanType, pathToTraversableObject, elementType);
+        }
+        return cachedLH.reachable;
+    }
+
+    public boolean isCascadable(Object traversableObject, Path.Node traversableProperty,
+                                Class<?> rootBeanType, Path pathToTraversableObject,
+                                ElementType elementType) {
+        CacheEntry currentLH = new CacheEntry(traversableObject, traversableProperty,
+              rootBeanType, pathToTraversableObject, elementType);
+        CacheEntry cachedLH = cache.get(currentLH);
+        if (cachedLH == null) {
+            currentLH.cascadable = delegate.isCascadable(traversableObject,
+                  traversableProperty, rootBeanType, pathToTraversableObject, elementType);
+            cache.put(currentLH, currentLH);
+            cachedLH = currentLH;
+        } else if (cachedLH.cascadable == null) {
+            cachedLH.cascadable = delegate.isCascadable(traversableObject, traversableProperty,
+                  rootBeanType, pathToTraversableObject, elementType);
+        }
+        return cachedLH.cascadable;
+    }
+
+    public boolean needsCaching() {
+        return false;  // I am the cache. Do not need cache for cache
+    }
+
+    private static class CacheEntry {
+        private final Object object;
+        private final Path.Node node;
+        private final Class<?> type;
+        private final Path path;
+        private final ElementType elementType;
+        private final int hashCode;
+
+        private Boolean reachable;
+        private Boolean cascadable;
+
+
+        private CacheEntry(Object traversableObject, Path.Node traversableProperty,
+                           Class<?> rootBeanType, Path pathToTraversableObject,
+                           ElementType elementType) {
+            this.object = traversableObject;
+            this.node = traversableProperty;
+            this.type = rootBeanType;
+            this.path = pathToTraversableObject;
+            this.elementType = elementType;
+            this.hashCode = buildHashCode();
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+
+            CacheEntry that = (CacheEntry) o;
+
+            return elementType == that.elementType && path.equals(that.path) &&
+                  type.equals(that.type) &&
+                  !(object != null ? !object.equals(that.object) : that.object != null) &&
+                  node.equals(that.node);
+
+        }
+
+        @Override
+        public int hashCode() {
+            return hashCode;
+        }
+
+        private int buildHashCode() {
+            int result = object != null ? object.hashCode() : 0;
+            result = 31 * result + node.hashCode();
+            result = 31 * result + type.hashCode();
+            result = 31 * result + path.hashCode();
+            result = 31 * result + elementType.hashCode();
+            return result;
+        }
+    }
+}
\ No newline at end of file



Mime
View raw message