You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by rm...@apache.org on 2013/08/26 15:59:20 UTC

svn commit: r1517540 [8/15] - in /bval/branches/bval-11/bval-jsr: ./ src/ src/main/ src/main/appended-resources/ src/main/appended-resources/META-INF/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/bval/ src/main/j...

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterAccess.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterAccess.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterAccess.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,95 @@
+/*
+ *  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.jsr;
+
+import org.apache.bval.util.AccessStrategy;
+
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Type;
+
+
+/**
+ * Implementation of {@link org.apache.bval.util.AccessStrategy} for method parameters.
+ *
+ * @author Carlos Vara
+ */
+public class ParameterAccess extends AccessStrategy {
+
+    private Type paramType;
+    private int paramIdx;
+
+    /**
+     * Create a new ParameterAccess instance.
+     * @param paramType
+     * @param paramIdx
+     */
+    public ParameterAccess(Type paramType, int paramIdx ) {
+        this.paramType = paramType;
+        this.paramIdx = paramIdx;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Object get(Object instance) {
+        throw new UnsupportedOperationException("Obtaining a parameter value not yet implemented");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public ElementType getElementType() {
+        return ElementType.PARAMETER;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Type getJavaType() {
+        return this.paramType;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getPropertyName() {
+        return "" + paramIdx;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        final ParameterAccess that = (ParameterAccess) o;
+        return paramIdx == that.paramIdx && paramType.equals(that.paramType);
+    }
+
+    @Override
+    public int hashCode() {
+        int result = paramType.hashCode();
+        result = 31 * result + paramIdx;
+        return result;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterDescriptorImpl.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterDescriptorImpl.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParameterDescriptorImpl.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,86 @@
+/*
+ *  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.jsr;
+
+import org.apache.bval.jsr.groups.Group;
+import org.apache.bval.jsr.groups.GroupConversionDescriptorImpl;
+import org.apache.bval.model.MetaBean;
+import org.apache.bval.model.Validation;
+
+import javax.validation.metadata.GroupConversionDescriptor;
+import javax.validation.metadata.ParameterDescriptor;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+
+/**
+ * Description: {@link javax.validation.metadata.ParameterDescriptor} implementation.<br/>
+ */
+public class ParameterDescriptorImpl extends ElementDescriptorImpl implements ParameterDescriptor {
+    private final Set<GroupConversionDescriptor> groupConversions = new CopyOnWriteArraySet<GroupConversionDescriptor>();
+    private final String name;
+    private int index;
+
+    /**
+     * Create a new ParameterDescriptorImpl instance.
+     * @param metaBean
+     * @param validations
+     */
+    public ParameterDescriptorImpl(MetaBean metaBean, Validation[] validations, String name) {
+        super(metaBean, metaBean.getBeanClass(), validations);
+        this.name = name;
+    }
+
+    /**
+     * Create a new ParameterDescriptorImpl instance.
+     * @param elementClass
+     * @param validations
+     */
+    public ParameterDescriptorImpl(Class<?> elementClass, Validation[] validations, String name) {
+        super(elementClass, validations);
+        this.name = name;
+    }
+
+    public Set<GroupConversionDescriptor> getGroupConversions() {
+        return groupConversions;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getIndex() {
+        return index;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Set the index of the referenced parameter.
+     * @param index
+     */
+    public void setIndex(int index) {
+        this.index = index;
+    }
+
+    @Override
+    public void addGroupMapping(final Group from, final Group to) {
+        groupConversions.add(new GroupConversionDescriptorImpl(from, to));
+        super.addGroupMapping(from, to);
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParametersAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParametersAccess.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParametersAccess.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ParametersAccess.java Mon Aug 26 13:59:15 2013
@@ -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.jsr;
+
+import org.apache.bval.util.AccessStrategy;
+
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Type;
+
+public class ParametersAccess extends AccessStrategy {
+    @Override
+    public Object get(final Object instance) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public ElementType getElementType() {
+        return ElementType.PARAMETER;
+    }
+
+    @Override
+    public Type getJavaType() {
+        return Object[].class;
+    }
+
+    @Override
+    public String getPropertyName() {
+        return null;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ProcedureDescriptor.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ProcedureDescriptor.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ProcedureDescriptor.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ProcedureDescriptor.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,51 @@
+/*
+ *  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.jsr;
+
+
+import org.apache.bval.jsr.groups.Group;
+import org.apache.bval.model.MetaBean;
+
+import javax.validation.metadata.ParameterDescriptor;
+import java.util.List;
+
+/**
+ * Description: superinterface of {@link javax.validation.metadata.ConstructorDescriptor} and {@link org.apache.bval.jsr.MethodDescriptor}.<br/>
+ */
+public interface ProcedureDescriptor {
+    /**
+     * Get the owning metabean.
+     * @return MetaBean
+     */
+    MetaBean getMetaBean();
+
+    /**
+     * Set whether this procedure should be validated.
+     * @param b
+     */
+    void setCascaded(boolean b);
+
+    /**
+     * Get the parameter descriptors of this procedure.
+     * @return {@link java.util.List} of {@link javax.validation.metadata.ParameterDescriptor}
+     */
+    List<ParameterDescriptor> getParameterDescriptors();
+
+    void addGroupMapping(Group from, Group to);
+
+    Group mapGroup(Group current);
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/PropertyDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/PropertyDescriptorImpl.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/PropertyDescriptorImpl.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/PropertyDescriptorImpl.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,68 @@
+/*
+ * 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.jsr;
+
+import org.apache.bval.model.Features;
+import org.apache.bval.model.MetaProperty;
+
+import javax.validation.metadata.PropertyDescriptor;
+
+/**
+ * Description: {@link PropertyDescriptor} implementation.<br/>
+ *
+ * TODO: use it instead of MetaProperty!
+ */
+class PropertyDescriptorImpl extends ElementDescriptorImpl implements PropertyDescriptor {
+    private String propertyPath;
+
+    /**
+     * Create a new PropertyDescriptorImpl instance.
+     * 
+     * @param property
+     */
+    PropertyDescriptorImpl(MetaProperty property) {
+        super(property.getParentMetaBean(), property.getTypeClass(), property.getValidations());
+        setCascaded(property.getMetaBean() != null || property.getFeature(Features.Property.REF_CASCADE) != null);
+        setPropertyPath(property.getName());
+    }
+
+    /**
+     * Set the referenced property path.
+     * 
+     * @param propertyPath
+     */
+    public void setPropertyPath(String propertyPath) {
+        this.propertyPath = propertyPath;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getPropertyName() {
+        return propertyPath;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() {
+        return "PropertyDescriptorImpl{" + "returnType=" + elementClass + ", propertyPath='" + propertyPath + '\''
+            + '}';
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnAccess.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnAccess.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnAccess.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnAccess.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,76 @@
+/*
+ *  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.jsr;
+
+import org.apache.bval.util.AccessStrategy;
+
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Type;
+
+/**
+ * Implementation of {@link org.apache.bval.util.AccessStrategy} for method return values.
+ *
+ * @author Carlos Vara
+ */
+public class ReturnAccess extends AccessStrategy {
+
+    private Type returnType;
+
+    /**
+     * Create a new ReturnAccess instance.
+     * @param returnType
+     */
+    public ReturnAccess(Type returnType) {
+        this.returnType = returnType;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Object get(Object instance) {
+        throw new UnsupportedOperationException("Obtaining a method return value not yet implemented");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public ElementType getElementType() {
+        return ElementType.METHOD;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Type getJavaType() {
+        return this.returnType;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getPropertyName() {
+        return "Return value";
+    }
+
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnValueDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnValueDescriptorImpl.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnValueDescriptorImpl.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/ReturnValueDescriptorImpl.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012-2013, Red Hat, Inc. and/or its affiliates, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jsr;
+
+import org.apache.bval.model.MetaBean;
+
+import javax.validation.metadata.ReturnValueDescriptor;
+import java.util.Collection;
+
+public class ReturnValueDescriptorImpl extends ElementDescriptorImpl implements ReturnValueDescriptor {
+    public ReturnValueDescriptorImpl(final MetaBean metaBean, Class<?> returnType, final Collection<ConstraintValidation<?>> list, boolean cascaded) {
+        super(metaBean, returnType, list.toArray(new ConstraintValidation<?>[list.size()]));
+        setCascaded(cascaded);
+    }
+
+    public boolean hasConstraints() {
+        return false;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/UnknownPropertyException.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/UnknownPropertyException.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/UnknownPropertyException.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/UnknownPropertyException.java Mon Aug 26 13:59:15 2013
@@ -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.jsr;
+
+import javax.validation.ValidationException;
+
+/**
+ * Internal exception thrown when trying to access a property that doesn't exist
+ * in a bean.
+ * 
+ * @version $Rev: 1166451 $ $Date: 2011-09-08 00:32:26 +0200 (jeu., 08 sept. 2011) $
+ * 
+ * @author Carlos Vara
+ */
+public class UnknownPropertyException extends ValidationException {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Create a new UnknownPropertyException instance.
+     * @param message
+     */
+    public UnknownPropertyException(String message) {
+        super(message);
+    }
+
+    /**
+     * Create a new UnknownPropertyException instance.
+     */
+    public UnknownPropertyException() {
+        super();
+    }
+
+    /**
+     * Create a new UnknownPropertyException instance.
+     * @param message
+     * @param cause
+     */
+    public UnknownPropertyException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Create a new UnknownPropertyException instance.
+     * @param cause
+     */
+    public UnknownPropertyException(Throwable cause) {
+        super(cause);
+    }
+
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Group.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Group.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Group.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Group.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,83 @@
+/*
+ * 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.jsr.groups;
+
+import org.apache.commons.lang3.ObjectUtils;
+
+import javax.validation.groups.Default;
+
+/**
+ * Immutable object that wraps an interface representing a single group.
+ */
+public final class Group {
+    /**
+     * the Default Group
+     */
+    public static final Group DEFAULT = new Group(Default.class);
+
+    private final Class<?> group;
+
+    /**
+     * Create a new Group instance.
+     * @param group
+     */
+    public Group(Class<?> group) {
+        this.group = group;
+    }
+
+    /**
+     * Get the actual group class.
+     * @return
+     */
+    public Class<?> getGroup() {
+        return group;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        return "Group{" + "group=" + group + '}';
+    }
+
+    /**
+     * Learn whether the group represented is the default group.
+     * @return boolean
+     */
+	public boolean isDefault() {
+		return Default.class.equals(group);
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+    @Override
+    public boolean equals(final Object o) {
+        return this == o || o instanceof Group && ObjectUtils.equals(group, ((Group) o).group);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        return (group != null ? group.hashCode() : 0);
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversionDescriptorImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversionDescriptorImpl.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversionDescriptorImpl.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupConversionDescriptorImpl.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,43 @@
+/*
+ *  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.jsr.groups;
+
+import javax.validation.ConstraintDeclarationException;
+import javax.validation.GroupSequence;
+import javax.validation.metadata.GroupConversionDescriptor;
+
+public class GroupConversionDescriptorImpl implements GroupConversionDescriptor {
+    private final Class<?> to;
+    private final Class<?> from;
+
+    public GroupConversionDescriptorImpl(final Group from, final Group to) {
+        this.from = from.getGroup();
+        if (this.from.getAnnotation(GroupSequence.class) != null) {
+            throw new ConstraintDeclarationException("from() can't get a group sequence");
+        }
+
+        this.to = to.getGroup();
+    }
+
+    public Class<?> getFrom() {
+        return from;
+    }
+
+    public Class<?> getTo() {
+        return to;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Groups.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Groups.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Groups.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/Groups.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,117 @@
+/*
+ * 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.jsr.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>>();
+
+    /**
+     * Get the Groups.
+     * @return {@link List} of {@link Group}.
+     */
+    public List<Group> getGroups() {
+        return groups;
+    }
+
+    /**
+     * Get the Group sequences.
+     * @return {@link List} of {@link List} of {@link Group}
+     */
+    public List<List<Group>> getSequences() {
+        return sequences;
+    }
+
+    /**
+     * Insert a {@link Group}.
+     * @param group to insert
+     */
+    void insertGroup(Group group) {
+        if (!groups.contains(group)) {
+            groups.add(group);
+        }
+    }
+
+    /**
+     * Insert a sequence.
+     * @param groups {@link List} of {@link Group} to insert
+     */
+    void insertSequence(List<Group> groups) {
+        if (groups == null || groups.isEmpty()) {
+            return;
+        }
+
+        if (!sequences.contains(groups)) {
+            sequences.add(groups);
+        }
+    }
+
+    /**
+     * Assert that the default group can be expanded to <code>defaultGroups</code>.
+     * @param defaultGroups
+     */
+    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

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupsComputer.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupsComputer.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupsComputer.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/groups/GroupsComputer.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,145 @@
+/*
+ * 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.jsr.groups;
+
+
+import javax.validation.GroupDefinitionException;
+import javax.validation.GroupSequence;
+import javax.validation.ValidationException;
+import javax.validation.groups.Default;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Description: compute group order, based on the RI behavior as to guarantee
+ * compatibility with interpretations of the spec.<br/>
+ * Implementation is thread-safe.
+ */
+public class GroupsComputer {
+    public static final Class<?>[] DEFAULT_GROUP = new Class<?>[]{Default.class};
+
+    /** The default group array used in case any of the validate methods is called without a group. */
+    private static final Groups DEFAULT_GROUPS;
+    static {
+        DEFAULT_GROUPS = new GroupsComputer().computeGroups(Arrays.asList(DEFAULT_GROUP));
+    }
+
+    /** caching resolved groups in a thread-safe map. */
+    private final Map<Class<?>, List<Group>> resolvedSequences = new ConcurrentHashMap<Class<?>, List<Group>>();
+
+    /**
+     * Compute groups from an array of group classes.
+     * @param groups
+     * @return {@link Groups}
+     */
+    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));
+    }
+
+    /**
+     * Main compute implementation.
+     * @param groups
+     * @return {@link 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 (final Class<?> clazz : groups) {
+            if (clazz == null) {
+                throw new IllegalArgumentException("At least one group has to be specified.");
+            }
+
+            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 GroupDefinitionException("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;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/parameter/DefaultParameterNameProvider.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/parameter/DefaultParameterNameProvider.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/parameter/DefaultParameterNameProvider.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/parameter/DefaultParameterNameProvider.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.jsr.parameter;
+
+import javax.validation.ParameterNameProvider;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DefaultParameterNameProvider implements ParameterNameProvider {
+    private static final String ARG = "arg";
+
+    public List<String> getParameterNames(Constructor<?> constructor) {
+        return names(constructor.getParameterTypes().length);
+    }
+
+    public List<String> getParameterNames(Method method) {
+        return names(method.getParameterTypes().length);
+    }
+
+    private static List<String> names(final int length) {
+        final List<String> list = new ArrayList<String>();
+        for (int i = 0; i < length; i++) {
+            list.add(ARG + i);
+        }
+        return list;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/CachingRelevant.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/CachingRelevant.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/CachingRelevant.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/CachingRelevant.java Mon Aug 26 13:59:15 2013
@@ -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.bval.jsr.resolver;
+
+import javax.validation.TraversableResolver;
+
+/**
+ * Description: indicator interface to let the implementation choose
+ * whether results of traversable resolver should be cached.<br/>
+ */
+public interface CachingRelevant {
+    /**
+     * Learn whether the results of the {@link TraversableResolver} should be cached.
+     * @return boolean
+     */
+    boolean needsCaching();
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/CachingTraversableResolver.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/CachingTraversableResolver.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/CachingTraversableResolver.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/CachingTraversableResolver.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,192 @@
+/*
+ * 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.jsr.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>();
+
+    /**
+     * Convenience method to check whether caching is necessary on a given {@link TraversableResolver}.
+     * @param resolver to check
+     * @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();
+    }
+
+    /**
+     * Create a new CachingTraversableResolver instance.
+     * @param delegate
+     */
+    public CachingTraversableResolver(TraversableResolver delegate) {
+        this.delegate = delegate;
+    }
+
+    /**
+     * If necessary, return a caching wrapper for the specified {@link TraversableResolver}.
+     * @param traversableResolver
+     * @return {@link TraversableResolver}
+     * @see #needsCaching(TraversableResolver)
+     */
+    public static TraversableResolver cacheFor(TraversableResolver traversableResolver) {
+        if (needsCaching(traversableResolver)) {
+            return new CachingTraversableResolver(traversableResolver);
+        } else {
+            return traversableResolver;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    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;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    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;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsCaching() {
+        return false;  // I am the cache. Do not need cache for cache
+    }
+
+    /**
+     * Entry in the 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;
+
+        /**
+         * Create a new CacheEntry instance.
+         * @param traversableObject
+         * @param traversableProperty
+         * @param rootBeanType
+         * @param pathToTraversableObject
+         * @param elementType
+         */
+        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();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @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);
+
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @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

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/DefaultTraversableResolver.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/DefaultTraversableResolver.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/DefaultTraversableResolver.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/DefaultTraversableResolver.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,109 @@
+/*
+ * 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.jsr.resolver;
+
+import org.apache.bval.util.reflection.Reflection;
+import org.apache.commons.lang3.ClassUtils;
+
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
+import java.lang.annotation.ElementType;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/** @see javax.validation.TraversableResolver */
+public class DefaultTraversableResolver implements TraversableResolver, CachingRelevant {
+    private static final Logger log = Logger.getLogger(DefaultTraversableResolver.class.getName());
+    private static final boolean LOG_FINEST = log.isLoggable(Level.FINEST);
+
+    /** Class to load to check whether JPA 2 is on the classpath. */
+    private static final String PERSISTENCE_UTIL_CLASSNAME =
+          "javax.persistence.PersistenceUtil";
+
+    /** Class to instantiate in case JPA 2 is on the classpath. */
+    private static final String JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME =
+          "org.apache.bval.jsr.resolver.JPATraversableResolver";
+
+
+    private TraversableResolver jpaTR;
+
+    /**
+     * Create a new DefaultTraversableResolver instance.
+     */
+    public DefaultTraversableResolver() {
+        initJpa();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
+                               Class<?> rootBeanType, Path pathToTraversableObject,
+                               ElementType elementType) {
+        return jpaTR == null || jpaTR.isReachable(traversableObject, traversableProperty,
+              rootBeanType, pathToTraversableObject, elementType);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isCascadable(Object traversableObject, Path.Node traversableProperty,
+                                Class<?> rootBeanType, Path pathToTraversableObject,
+                                ElementType elementType) {
+        return jpaTR == null || jpaTR.isCascadable(traversableObject, traversableProperty,
+              rootBeanType, pathToTraversableObject, elementType);
+    }
+
+    /** Tries to load detect and load JPA. */
+    @SuppressWarnings("unchecked")
+    private void initJpa() {
+        final ClassLoader classLoader = getClassLoader();
+        try {
+            Reflection.INSTANCE.getClass(classLoader, PERSISTENCE_UTIL_CLASSNAME);
+            if (LOG_FINEST) {
+                log.log(Level.FINEST, String.format("Found %s on classpath.", PERSISTENCE_UTIL_CLASSNAME));
+            }
+        } catch (final Exception e) {
+            log.log(Level.FINEST, String.format("Cannot find %s on classpath. All properties will per default be traversable.", PERSISTENCE_UTIL_CLASSNAME));
+            return;
+        }
+
+        try {
+            Class<? extends TraversableResolver> jpaAwareResolverClass =
+              (Class<? extends TraversableResolver>)
+                ClassUtils.getClass(classLoader, JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME, true);
+            jpaTR = jpaAwareResolverClass.newInstance();
+            if (LOG_FINEST) {
+                log.log(Level.FINEST, String.format("Instantiated an instance of %s.", JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME));
+            }
+        } catch (final Exception e) {
+			log.log(Level.WARNING, String.format("Unable to load or instantiate JPA aware resolver %s. All properties will per default be traversable.", JPA_AWARE_TRAVERSABLE_RESOLVER_CLASSNAME), e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsCaching() {
+        return jpaTR != null && CachingTraversableResolver.needsCaching(jpaTR);
+    }
+
+    private static ClassLoader getClassLoader()
+    {
+      return Reflection.INSTANCE.getClassLoader(DefaultTraversableResolver.class);
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/JPATraversableResolver.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/JPATraversableResolver.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/JPATraversableResolver.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/JPATraversableResolver.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,53 @@
+/*
+ * 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.jsr.resolver;
+
+import javax.persistence.Persistence;
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
+import java.lang.annotation.ElementType;
+
+
+/** @see javax.validation.TraversableResolver */
+public class JPATraversableResolver implements TraversableResolver, CachingRelevant {
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
+                               Class<?> rootBeanType, Path pathToTraversableObject,
+                               ElementType elementType) {
+        return traversableObject == null || Persistence.getPersistenceUtil()
+              .isLoaded(traversableObject, traversableProperty.getName());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isCascadable(Object traversableObject, Path.Node traversableProperty,
+                                Class<?> rootBeanType, Path pathToTraversableObject,
+                                ElementType elementType) {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsCaching() {
+        return true; // yes
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/SimpleTraversableResolver.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/SimpleTraversableResolver.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/SimpleTraversableResolver.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/resolver/SimpleTraversableResolver.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.jsr.resolver;
+
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
+import java.lang.annotation.ElementType;
+
+/**
+ * Description: traversable resolver that does always resolve.<br/>
+ */
+public class SimpleTraversableResolver implements TraversableResolver, CachingRelevant {
+    /**
+     * {@inheritDoc}
+     *  @return <code>true</code>
+     */
+    public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
+                               Class<?> rootBeanType, Path pathToTraversableObject,
+                               java.lang.annotation.ElementType elementType) {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @return <code>true</code>
+     */
+    public boolean isCascadable(Object traversableObject, Path.Node traversableProperty,
+                                Class<?> rootBeanType, Path pathToTraversableObject,
+                                ElementType elementType) {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @return <code>false</code>
+     */
+    public boolean needsCaching() {
+        return false;  // no
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/ClassHelper.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,83 @@
+/*
+ * 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.jsr.util;
+
+import org.apache.commons.lang3.ClassUtils;
+
+import java.io.Serializable;
+import java.security.AccessController;
+import java.util.List;
+
+/**
+ * Common operations on classes that do not require an {@link AccessController}.
+ * 
+ * @author Carlos Vara
+ */
+public class ClassHelper {
+
+    private ClassHelper() {
+        // No instances please
+    }
+
+    /**
+     * Fill the list with the full class/interface hierarchy of the given class.
+     * List is ordered from the most to less specific.
+     *
+     * @param allClasses
+     *            The current list of classes in the hierarchy.
+     * @param clazz
+     */
+    static public List<Class<?>> fillFullClassHierarchyAsList(List<Class<?>> allClasses, Class<?> clazz) {
+        if (clazz == null || clazz == Object.class || clazz == Serializable.class) {
+            return allClasses;
+        }
+        if (allClasses.contains(clazz)) {
+            return allClasses;
+        }
+        allClasses.add(clazz);
+        fillFullClassHierarchyAsList(allClasses, clazz.getSuperclass());
+        for (Class<?> subClass : clazz.getInterfaces()) {
+            fillFullClassHierarchyAsList(allClasses, subClass);
+        }
+        return allClasses;
+    }
+
+    /**
+     * @deprecated Will be removed for security reasons.
+     *
+     * Perform ClassUtils.getClass functions with Java 2 Security enabled.
+     */
+    @Deprecated
+    public static Class<?> getClass(String className) throws ClassNotFoundException {
+        return getClass(className, true);
+    }
+
+    /**
+     * @deprecated Will be removed for security reasons.
+     *
+     * Perform ClassUtils.getClass functions with Java 2 Security enabled.
+     */
+    @Deprecated
+    public static Class<?> getClass(String className, boolean initialize) throws ClassNotFoundException {
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        if (loader == null)
+          loader = ClassHelper.class.getClassLoader();
+        return ClassUtils.getClass(loader, className, initialize);
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/EnumerationConverter.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/EnumerationConverter.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/EnumerationConverter.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/EnumerationConverter.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,75 @@
+/*
+ * 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.jsr.util;
+
+import org.apache.commons.beanutils.Converter;
+
+/**
+ * A {@code org.apache.commons.beanutils.Converter} implementation to handle
+ * Enumeration type.
+ *
+ * $Id: EnumerationConverter.java 1226560 2012-01-02 22:18:19Z mbenson $
+ */
+public final class EnumerationConverter implements Converter {
+
+    /**
+     * The static converter instance.
+     */
+    private static final EnumerationConverter INSTANCE = new EnumerationConverter();
+
+    /**
+     * Returns this converter instance.
+     *
+     * @return this converter instance.
+     */
+    public static EnumerationConverter getInstance() {
+        return INSTANCE;
+    }
+
+    /**
+     * This class can't be instantiated.
+     */
+    private EnumerationConverter() {
+        // do nothing
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    public Object convert(Class type, Object value) {
+        if (!type.isEnum()) {
+            throw new RuntimeException("Only enum types supported in this version!");
+        }
+
+        if (value == null) {
+            throw new RuntimeException("Null values not supported in this version!");
+        }
+
+        if (String.class != value.getClass()) {
+            throw new RuntimeException("Only java.lang.String values supported in this version!");
+        }
+
+        String stringValue = (String) value;
+
+        final Class<Enum> enumClass = (Class<Enum>) type;
+        return Enum.valueOf(enumClass, stringValue);
+    }
+
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/IOs.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/IOs.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/IOs.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/IOs.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.jsr.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class IOs {
+    private IOs() {
+        // no-op
+    }
+
+    public static InputStream convertToMarkableInputStream(final InputStream stream) {
+        if (stream == null) {
+            return null;
+        }
+
+        if (stream.markSupported()) {
+            return stream;
+        } else {
+            try {
+                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                final byte[] buffer = new byte[1024];
+                int length;
+                while ((length = stream.read(buffer)) != -1) {
+                    baos.write(buffer, 0, length);
+                }
+                return new ByteArrayInputStream(baos.toByteArray());
+            } catch (final IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    public static void closeQuietly(Closeable closeable) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (IOException e) {
+                // do nothing
+            }
+        }
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/LeafNodeBuilderCustomizableContextImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/LeafNodeBuilderCustomizableContextImpl.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/LeafNodeBuilderCustomizableContextImpl.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/LeafNodeBuilderCustomizableContextImpl.java Mon Aug 26 13:59:15 2013
@@ -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.jsr.util;
+
+import org.apache.bval.jsr.ConstraintValidatorContextImpl;
+
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ElementKind;
+
+public class LeafNodeBuilderCustomizableContextImpl implements ConstraintValidatorContext.ConstraintViolationBuilder.LeafNodeBuilderCustomizableContext {
+    private final ConstraintValidatorContextImpl context;
+    private final PathImpl path;
+    private final String template;
+    private final NodeImpl node;
+
+    public LeafNodeBuilderCustomizableContextImpl(final ConstraintValidatorContextImpl parent, String messageTemplate, PathImpl propertyPath) {
+        context = parent;
+        template = messageTemplate;
+        path = propertyPath;
+        node = new NodeImpl((String) null);
+        node.setKind(ElementKind.BEAN);
+    }
+
+    public ConstraintValidatorContext.ConstraintViolationBuilder.LeafNodeContextBuilder inIterable() {
+        path.getLeafNode().setInIterable(true);
+        return new LeafNodeContextBuilderImpl();
+    }
+
+    public ConstraintValidatorContext addConstraintViolation() {
+        context.addError(template, path);
+        return context;
+    }
+
+    private class LeafNodeContextBuilderImpl implements ConstraintValidatorContext.ConstraintViolationBuilder.LeafNodeContextBuilder {
+        public ConstraintValidatorContext.ConstraintViolationBuilder.LeafNodeBuilderDefinedContext atKey(Object key) {
+            path.getLeafNode().setKey(key);
+            return new LeafNodeBuilderDefinedContextImpl(context, template, path);
+        }
+
+        public ConstraintValidatorContext.ConstraintViolationBuilder.LeafNodeBuilderDefinedContext atIndex(Integer index) {
+            path.getLeafNode().setIndex(index);
+            return new LeafNodeBuilderDefinedContextImpl(context, template, path);
+        }
+
+        public ConstraintValidatorContext addConstraintViolation() {
+            context.addError(template, path);
+            return context;
+        }
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/LeafNodeBuilderDefinedContextImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/LeafNodeBuilderDefinedContextImpl.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/LeafNodeBuilderDefinedContextImpl.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/LeafNodeBuilderDefinedContextImpl.java Mon Aug 26 13:59:15 2013
@@ -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.jsr.util;
+
+import org.apache.bval.jsr.ConstraintValidatorContextImpl;
+
+import javax.validation.ConstraintValidatorContext;
+
+public class LeafNodeBuilderDefinedContextImpl implements ConstraintValidatorContext.ConstraintViolationBuilder.LeafNodeBuilderDefinedContext {
+    private final ConstraintValidatorContextImpl context;
+    private final String template;
+    private final PathImpl path;
+
+    public LeafNodeBuilderDefinedContextImpl(final ConstraintValidatorContextImpl context, final String tpl, final PathImpl path) {
+        this.context = context;
+        this.template = tpl;
+        this.path = path;
+    }
+
+    public ConstraintValidatorContext addConstraintViolation() {
+        context.addError(template, path);
+        return context;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderCustomizableContextImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderCustomizableContextImpl.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderCustomizableContextImpl.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderCustomizableContextImpl.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,95 @@
+/*
+ * 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.jsr.util;
+
+
+import org.apache.bval.jsr.ConstraintValidatorContextImpl;
+
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ElementKind;
+
+/**
+ * Description: implementation of {@link javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext}.<br/>
+ */
+final class NodeBuilderCustomizableContextImpl
+      implements ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext {
+    private final ConstraintValidatorContextImpl parent;
+    private final String messageTemplate;
+    private final PathImpl propertyPath;
+    private NodeImpl node;
+
+    /**
+     * Create a new NodeBuilderCustomizableContextImpl instance.
+     * @param contextImpl
+     * @param template
+     * @param path
+     * @param name
+     */
+    NodeBuilderCustomizableContextImpl(ConstraintValidatorContextImpl contextImpl, String template,
+                              PathImpl path, String name) {
+        parent = contextImpl;
+        messageTemplate = template;
+        propertyPath = path;
+        node = new NodeImpl(name);
+        node.setKind(ElementKind.PROPERTY);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder inIterable() {
+        // Modifies the "previous" node in the path
+        node.setInIterable(true);
+        return new NodeContextBuilderImpl(parent, messageTemplate, propertyPath, node);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(String name) {
+        propertyPath.addNode(node);
+        node = new NodeImpl(name);
+        return this; // Re-use this instance
+    }
+
+    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addPropertyNode(String name) {
+        propertyPath.addNode(node);
+        node = new NodeImpl.PropertyNodeImpl(name);
+        node.setKind(ElementKind.PROPERTY);
+        return null;
+    }
+
+    public ConstraintValidatorContext.ConstraintViolationBuilder.LeafNodeBuilderCustomizableContext addBeanNode() {
+        propertyPath.addNode(node);
+        node = new NodeImpl((String) null);
+        node.setKind(ElementKind.BEAN);
+        return new LeafNodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ConstraintValidatorContext addConstraintViolation() {
+        propertyPath.addNode(node);
+        node = null;
+        parent.addError(messageTemplate, propertyPath);
+        return parent;
+    }
+    
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderDefinedContextImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderDefinedContextImpl.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderDefinedContextImpl.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeBuilderDefinedContextImpl.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,75 @@
+/*
+ * 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.jsr.util;
+
+
+import org.apache.bval.jsr.ConstraintValidatorContextImpl;
+
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ElementKind;
+
+/**
+ * Description: Implementation of {@link NodeBuilderDefinedContext}.<br/>
+ */
+public final class NodeBuilderDefinedContextImpl
+      implements ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext {
+    private final ConstraintValidatorContextImpl parent;
+    private final String messageTemplate;
+    private final PathImpl propertyPath;
+
+    /**
+     * Create a new NodeBuilderDefinedContextImpl instance.
+     * @param contextImpl
+     * @param template
+     * @param path
+     */
+    public NodeBuilderDefinedContextImpl(ConstraintValidatorContextImpl contextImpl, String template,
+                    PathImpl path) {
+        parent = contextImpl;
+        messageTemplate = template;
+        propertyPath = path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(String name) {
+        // Node not yet added, wait until more information is provided
+        return new NodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath, name);
+    }
+
+    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addPropertyNode(String name) {
+        return new NodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath, name);
+    }
+
+    public ConstraintValidatorContext.ConstraintViolationBuilder.LeafNodeBuilderCustomizableContext addBeanNode() {
+        final NodeImpl node = new NodeImpl((String) null);
+        node.setKind(ElementKind.BEAN);
+        propertyPath.addNode(node);
+        return new LeafNodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ConstraintValidatorContext addConstraintViolation() {
+        parent.addError(messageTemplate, propertyPath);
+        return parent;
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeContextBuilderImpl.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeContextBuilderImpl.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeContextBuilderImpl.java (added)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/util/NodeContextBuilderImpl.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,100 @@
+/*
+ * 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.jsr.util;
+
+
+import org.apache.bval.jsr.ConstraintValidatorContextImpl;
+
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder;
+
+/**
+ * Description: Implementation of {@link NodeContextBuilder}.<br/>
+ */
+final class NodeContextBuilderImpl
+      implements ConstraintValidatorContext.ConstraintViolationBuilder.NodeContextBuilder {
+    private final ConstraintValidatorContextImpl parent;
+    private final String messageTemplate;
+    private final PathImpl propertyPath;
+    // The name of the last "added" node, it will only be added if it has a non-null name
+    // The actual incorporation in the path will take place when the definition of the current leaf node is complete
+    private final NodeImpl node;
+
+    /**
+     * Create a new NodeContextBuilderImpl instance.
+     * @param contextImpl
+     * @param template
+     * @param path
+     */
+    NodeContextBuilderImpl(ConstraintValidatorContextImpl contextImpl,
+                                    String template, PathImpl path, NodeImpl node) {
+        parent = contextImpl;
+        messageTemplate = template;
+        propertyPath = path;
+        this.node = node;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext atKey(
+          Object key) {
+        node.setKey(key);
+        propertyPath.addNode(node);
+        return new NodeBuilderDefinedContextImpl(parent, messageTemplate, propertyPath);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext atIndex(
+          Integer index) {
+        node.setIndex(index);
+        propertyPath.addNode(node);
+        return new NodeBuilderDefinedContextImpl(parent, messageTemplate, propertyPath);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addNode(
+          String name) {
+        propertyPath.addNode(node);
+        return new NodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath, name);
+    }
+
+    public ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext addPropertyNode(String name) {
+        propertyPath.addProperty(name);
+        return new NodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath, node.getName());
+    }
+
+    public ConstraintValidatorContext.ConstraintViolationBuilder.LeafNodeBuilderCustomizableContext addBeanNode() {
+        return new LeafNodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ConstraintValidatorContext addConstraintViolation() {
+        propertyPath.addNode(node);
+        parent.addError(messageTemplate, propertyPath);
+        return parent;
+    }
+    
+}
\ No newline at end of file