incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r924153 [12/13] - in /incubator/bval/trunk: ./ agimatec-jsr303/ agimatec-jsr303/src/ agimatec-jsr303/src/main/ agimatec-jsr303/src/main/java/ agimatec-jsr303/src/main/java/com/ agimatec-jsr303/src/main/java/com/agimatec/ agimatec-jsr303/src...
Date Wed, 17 Mar 2010 04:39:14 GMT
Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/FieldAccess.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/FieldAccess.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/FieldAccess.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/FieldAccess.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,82 @@
+/**
+ *  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 com.agimatec.validation.util;
+
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+import java.security.PrivilegedAction;
+
+/**
+ * Description: direct field access.<br/>
+ * User: roman <br/>
+ * Date: 29.10.2009 <br/>
+ * Time: 12:13:08 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class FieldAccess extends AccessStrategy {
+
+    private final Field field;
+
+    public Type getJavaType() {
+        return field.getGenericType();
+    }
+
+    public FieldAccess(Field field) {
+        this.field = field;
+        if(!field.isAccessible()) {
+            field.setAccessible(true);
+        }
+    }
+
+    public Object get(final Object instance) {
+        return PrivilegedActions.run(new PrivilegedAction<Object>() {
+            public Object run() {
+                try {
+                    return field.get(instance);
+                } catch (IllegalAccessException e) {
+                    throw new IllegalArgumentException(e);
+                }
+            }
+        });
+    }
+
+    public ElementType getElementType() {
+        return ElementType.FIELD;
+    }
+
+    public String getPropertyName() {
+        return field.getName();
+    }
+
+    public String toString() {
+        return field.toString();
+    }
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        FieldAccess that = (FieldAccess) o;
+
+        return field.equals(that.field);
+    }
+
+    public int hashCode() {
+        return field.hashCode();
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/MethodAccess.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/MethodAccess.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/MethodAccess.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/MethodAccess.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,121 @@
+/**
+ *  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 com.agimatec.validation.util;
+
+import java.beans.Introspector;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.security.PrivilegedAction;
+
+/**
+ * Description: invoke a zero-argument method (getter)<br/>
+ * User: roman <br/>
+ * Date: 29.10.2009 <br/>
+ * Time: 12:12:46 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class MethodAccess extends AccessStrategy {
+    private final Method method;
+    private final String propertyName;
+
+    public Type getJavaType() {
+        return method.getGenericReturnType();
+    }
+
+    public MethodAccess(Method method) {
+        this(getPropertyName(method), method);
+    }
+
+    public MethodAccess(String propertyName, Method method) {
+        this.method = method;
+        this.propertyName = propertyName;
+        if (!method.isAccessible()) {
+            method.setAccessible(true);
+        }
+    }
+
+    /**
+     * Process bean properties getter by applying the JavaBean naming conventions.
+     *
+     * @param member the member for which to get the property name.
+     * @return The bean method name with the "is" or "get" prefix stripped off, <code>null</code>
+     *         the method name id not according to the JavaBeans standard.
+     */
+    public static String getPropertyName(Method member) {
+        String name = null;
+        String methodName = member.getName();
+        if (methodName.startsWith("is")) {
+            name = Introspector.decapitalize(methodName.substring(2));
+        } /* else if ( methodName.startsWith("has")) {
+				name = Introspector.decapitalize( methodName.substring( 3 ) );
+			} */
+        // setter annotation is NOT supported in the spec
+        /*  else if (method.getName().startsWith("set") && method.getParameterTypes().length == 1) {
+           propName = Introspector.decapitalize(method.getName().substring(3));
+       } */
+        else if (methodName.startsWith("get")) {
+            name = Introspector.decapitalize(methodName.substring(3));
+        }
+        return name;
+    }
+
+    /**
+     * normally the propertyName of the getter method, e.g.<br>
+     * method: getName() -> propertyName: name<br>
+     * method: isValid() -> propertyName: valid<br>
+     */
+    public String getPropertyName() {
+        return propertyName;
+    }
+
+    public Object get(final Object instance) {
+        return PrivilegedActions.run(new PrivilegedAction<Object>() {
+            public Object run() {
+                try {
+                    return method.invoke(instance);
+                } catch (IllegalAccessException e) {
+                    throw new IllegalArgumentException(e);
+                } catch (InvocationTargetException e) {
+                    throw new IllegalArgumentException(e);
+                }
+            }
+        });
+    }
+
+    public ElementType getElementType() {
+        return ElementType.METHOD;
+    }
+
+    public String toString() {
+        return method.toString();
+    }
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        MethodAccess that = (MethodAccess) o;
+
+        return method.equals(that.method);
+    }
+
+    public int hashCode() {
+        return method.hashCode();
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/PrivilegedActions.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/PrivilegedActions.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/PrivilegedActions.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/PrivilegedActions.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,149 @@
+/**
+ *  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 com.agimatec.validation.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Description: utility methods to perform actions with AccessController or without. <br/>
+ * User: roman <br/>
+ * Date: 29.10.2009 <br/>
+ * Time: 11:57:36 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class PrivilegedActions {
+    /**
+     * create a new instance.
+     *
+     * @param cls - the class (no interface, non-abstract, has accessible default no-arg-constructor)
+     * @return a new instance
+     * @throws IllegalArgumentException on any error to wrap target exceptions.
+     */
+    public static <T> T newInstance(final Class<T> cls) {
+        return newInstance(cls, IllegalArgumentException.class);
+    }
+
+    public static <T, E extends RuntimeException> T newInstance(final Class<T> cls,
+                                                                final Class<E> exception,
+                                                                final Class[] paramTypes,
+                                                                final Object[] values) {
+        return run(new PrivilegedAction<T>() {
+            public T run() {
+                try {
+                    Constructor<T> cons = cls.getConstructor(paramTypes);
+                    if (!cons.isAccessible()) {
+                        cons.setAccessible(true);
+                    }
+                    return cons.newInstance(values);
+                } catch (Exception e) {
+                    throw newException("Cannot instantiate : " + cls, exception, e);
+                }
+            }
+        });
+    }
+
+    /**
+     * create a new instance of the class using the default no-arg constructor.
+     * perform newInstance() call with AccessController.doPrivileged() if possible.
+     *
+     * @param cls       - the type to create a new instance from
+     * @param exception - type of exception to throw when newInstance() call fails
+     * @return the new instance of 'cls'
+     */
+    public static <T, E extends RuntimeException> T newInstance(final Class<T> cls,
+                                                                final Class<E> exception) {
+        return run(new PrivilegedAction<T>() {
+            public T run() {
+                try {
+                    return cls.newInstance();
+                } catch (Exception e) {
+                    throw newException("Cannot instantiate : " + cls, exception, e);
+                }
+            }
+
+
+        });
+    }
+
+    private static <E extends RuntimeException> RuntimeException newException(String msg,
+                                                                              final Class<E> exception,
+                                                                              Throwable e) {
+        try {
+            Constructor<E> co = exception.getConstructor(String.class, Throwable.class);
+            try {
+                return co.newInstance(msg, e);
+            } catch (Exception e1) {
+                //noinspection ThrowableInstanceNeverThrown
+                return new RuntimeException(msg, e); // fallback
+            }
+        } catch (NoSuchMethodException e1) {
+            //noinspection ThrowableInstanceNeverThrown
+            return new RuntimeException(msg, e); // fallback
+        }
+    }
+
+    /**
+     * perform action with AccessController.doPrivileged() if possible.
+     *
+     * @param action - the action to run
+     * @return result of running the action
+     */
+    public static <T> T run(PrivilegedAction<T> action) {
+        if (System.getSecurityManager() != null) {
+            return AccessController.doPrivileged(action);
+        } else {
+            return action.run();
+        }
+    }
+
+    public static Object getAnnotationValue(final Annotation annotation, final String name)
+          throws IllegalAccessException, InvocationTargetException {
+        return run(new PrivilegedAction() {
+            public Object run() {
+                Method valueMethod = null;
+                try {
+                    valueMethod = annotation.annotationType().getDeclaredMethod(name);
+                } catch (NoSuchMethodException ex) { /* do nothing */ }
+                if (null != valueMethod) {
+                    try {
+                        return valueMethod.invoke(annotation);
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+                return null;
+            }
+        });
+    }
+
+    public static ClassLoader getClassLoader(final Class clazz) {
+        return run(new PrivilegedAction<ClassLoader>() {
+            public ClassLoader run() {
+                ClassLoader cl = Thread.currentThread().getContextClassLoader();
+                if (cl == null) {
+                    cl = clazz.getClassLoader();
+                }
+                return cl;
+            }
+        });
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/PropertyAccess.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/PropertyAccess.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/PropertyAccess.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/util/PropertyAccess.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,155 @@
+/**
+ *  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 com.agimatec.validation.util;
+
+import org.apache.commons.beanutils.PropertyUtils;
+
+import java.beans.PropertyDescriptor;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Type;
+import java.util.Map;
+
+/**
+ * Description: Undefined dynamic strategy. Uses PropertyUtils or tries to determine
+ * field to access the value<br/>
+ * User: roman <br/>
+ * Date: 29.10.2009 <br/>
+ * Time: 12:27:27 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class PropertyAccess extends AccessStrategy {
+    private final Class beanClass;
+    private final String propertyName;
+    private Field rememberField;
+
+    public PropertyAccess(Class clazz, String propertyName) {
+        this.beanClass = clazz;
+        this.propertyName = propertyName;
+    }
+
+    public ElementType getElementType() {
+        return ElementType.METHOD;
+    }
+
+    public static Object getProperty(Object bean, String property) throws
+          InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+        if (bean instanceof Map) {
+            return ((Map) bean).get(property);
+        } else { // supports DynaBean and standard Objects
+            return PropertyUtils.getSimpleProperty(bean, property);
+        }
+    }
+
+    public String toString() {
+        return "Property{" + beanClass.getName() + '.' + propertyName + '}';
+    }
+
+    public Type getJavaType() {
+        /*if(Map.class.isAssignableFrom(beanClass)) {
+            return beanClass. 
+        }*/
+        if (rememberField != null) {  // use cached field of previous access
+            return rememberField.getGenericType();
+        }
+        for (PropertyDescriptor each : PropertyUtils.getPropertyDescriptors(beanClass)) {
+            if (each.getName().equals(propertyName) && each.getReadMethod() != null) {
+                return each.getReadMethod().getGenericReturnType();
+            }
+        }
+        try { // try public field
+            return beanClass.getField(propertyName).getGenericType();
+        } catch (NoSuchFieldException ex2) {
+            // search for private/protected field up the hierarchy
+            Class theClass = beanClass;
+            while (theClass != null) {
+                try {
+                    return theClass.getDeclaredField(propertyName).getGenericType();
+                } catch (NoSuchFieldException ex3) {
+                    // do nothing
+                }
+                theClass = theClass.getSuperclass();
+            }
+        }
+        return Object.class; // unknown type: allow any type?? 
+    }
+
+    public String getPropertyName() {
+        return propertyName;
+    }
+
+    public Object get(Object bean) {
+        try {
+            if (rememberField != null) {  // cache field of previous access
+                return rememberField.get(bean);
+            }
+
+            try {   // try public method
+                return getProperty(bean, propertyName);
+            } catch (NoSuchMethodException ex) {
+                Object value;
+                try { // try public field
+                    Field aField = bean.getClass().getField(propertyName);
+                    value = aField.get(bean);
+                    rememberField = aField;
+                    return value;
+                } catch (NoSuchFieldException ex2) {
+                    // search for private/protected field up the hierarchy
+                    Class theClass = bean.getClass();
+                    while (theClass != null) {
+                        try {
+                            Field aField = theClass
+                                  .getDeclaredField(propertyName);
+                            if (!aField.isAccessible()) {
+                                aField.setAccessible(true);
+                            }
+                            value = aField.get(bean);
+                            rememberField = aField;
+                            return value;
+                        } catch (NoSuchFieldException ex3) {
+                            // do nothing
+                        }
+                        theClass = theClass.getSuperclass();
+                    }
+                    throw new IllegalArgumentException(
+                          "cannot access field " + propertyName);
+                }
+            }
+        } catch (IllegalArgumentException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new IllegalArgumentException("cannot access " + propertyName, e);
+        }
+    }
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        PropertyAccess that = (PropertyAccess) o;
+
+        return beanClass.equals(that.beanClass) && propertyName.equals(that.propertyName);
+    }
+
+    public int hashCode() {
+        int result;
+        result = beanClass.hashCode();
+        result = 31 * result + propertyName.hashCode();
+        return result;
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLFeaturesCapable.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLFeaturesCapable.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLFeaturesCapable.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLFeaturesCapable.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,99 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package com.agimatec.validation.xml;
+
+import com.agimatec.validation.model.FeaturesCapable;
+import com.thoughtworks.xstream.annotations.XStreamImplicit;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 10.07.2007 <br/>
+ * Time: 13:11:56 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public class XMLFeaturesCapable implements Serializable {
+    @XStreamImplicit
+    private List<XMLMetaFeature> features;
+    @XStreamImplicit(itemFieldName = "validator")
+    private List<XMLMetaValidatorReference> validators;
+
+    public List<XMLMetaFeature> getFeatures() {
+        return features;
+    }
+
+    public void setFeatures(List<XMLMetaFeature> features) {
+        this.features = features;
+    }
+
+    public void putFeature(String key, Object value) {
+        XMLMetaFeature anno = findFeature(key);
+        if (features == null) features = new ArrayList<XMLMetaFeature>();
+        if (anno == null) {
+            features.add(new XMLMetaFeature(key, value));
+        } else {
+            anno.setValue(value);
+        }
+    }
+
+    public void removeFeature(String key) {
+        XMLMetaFeature anno = findFeature(key);
+        if (anno != null) {
+            getFeatures().remove(anno);
+        }
+    }
+
+    public Object getFeature(String key) {
+        XMLMetaFeature anno = findFeature(key);
+        return anno == null ? null : anno.getValue();
+    }
+
+    private XMLMetaFeature findFeature(String key) {
+        if (features == null) return null;
+        for (XMLMetaFeature anno : features) {
+            if (key.equals(anno.getKey())) return anno;
+        }
+        return null;
+    }
+
+    public List<XMLMetaValidatorReference> getValidators() {
+        return validators;
+    }
+
+    public void setValidators(List<XMLMetaValidatorReference> validators) {
+        this.validators = validators;
+    }
+
+    public void addValidator(String validatorId) {
+        if (validators == null) validators = new ArrayList<XMLMetaValidatorReference>();
+        validators.add(new XMLMetaValidatorReference(validatorId));
+    }
+
+    public void mergeFeaturesInto(FeaturesCapable fc) {
+        if (getFeatures() != null) {
+            fc.optimizeRead(false);
+            for (XMLMetaFeature each : getFeatures()) {
+                fc.putFeature(each.getKey(), each.getValue());
+            }
+            fc.optimizeRead(true);
+        }
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMapper.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMapper.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMapper.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMapper.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,49 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import com.thoughtworks.xstream.XStream;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 14:54:13 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public class XMLMapper {
+    private static final XMLMapper instance = new XMLMapper();
+
+    private final XStream xStream;
+
+    private XMLMapper() {
+        xStream = new XStream();
+        xStream.processAnnotations(new Class[] {XMLFeaturesCapable.class,
+                XMLMetaFeature.class, XMLMetaBean.class, XMLMetaBeanInfos.class,
+                XMLMetaBeanReference.class, XMLMetaElement.class, XMLMetaProperty.class,
+                XMLMetaValidator.class, XMLMetaValidatorReference.class});
+        xStream.setMode(XStream.NO_REFERENCES);
+    }
+
+    public static XMLMapper getInstance() {
+        return instance;
+    }
+
+    public XStream getXStream() {
+        return xStream;
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBean.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBean.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBean.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBean.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,157 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+import com.thoughtworks.xstream.annotations.XStreamImplicit;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 14:25:19 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+@XStreamAlias("bean")
+public class XMLMetaBean extends XMLFeaturesCapable {
+    @XStreamAsAttribute()
+    private String id;
+    @XStreamAsAttribute()
+    private String name;
+    @XStreamAsAttribute()
+    private String impl;
+    @XStreamImplicit
+    private List<XMLMetaProperty> properties;
+    @XStreamImplicit
+    private List<XMLMetaBeanReference> beanRelations;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getImpl() {
+        return impl;
+    }
+
+    public void setImpl(String impl) {
+        this.impl = impl;
+    }
+
+    public List<XMLMetaProperty> getProperties() {
+        return properties;
+    }
+
+    public void setProperties(List<XMLMetaProperty> properties) {
+        this.properties = properties;
+    }
+
+    public void addProperty(XMLMetaProperty property) {
+        if (properties == null) properties = new ArrayList();
+        properties.add(property);
+    }
+
+    public void putProperty(XMLMetaProperty property) {
+        if (property.getName() != null) {
+            XMLMetaProperty prop = findProperty(property.getName());
+            if (prop != null) {
+                properties.remove(prop);
+            }
+        }
+        addProperty(property);
+    }
+
+    public XMLMetaProperty removeProperty(String name) {
+        XMLMetaProperty prop = findProperty(name);
+        if (prop != null) {
+            properties.remove(prop);
+        }
+        return prop;
+    }
+
+    public XMLMetaProperty getProperty(String name) {
+        return findProperty(name);
+    }
+
+    private XMLMetaProperty findProperty(String name) {
+        if (properties == null) return null;
+        for (XMLMetaProperty prop : properties) {
+            if (name.equals(prop.getName())) return prop;
+        }
+        return null;
+    }
+
+    public List<XMLMetaBeanReference> getBeanRefs() {
+        return beanRelations;
+    }
+
+    public void setBeanRefs(List<XMLMetaBeanReference> beanRelations) {
+        this.beanRelations = beanRelations;
+    }
+
+
+    public void addBeanRef(XMLMetaBeanReference beanRelation) {
+        if (beanRelations == null) beanRelations = new ArrayList();
+        beanRelations.add(beanRelation);
+    }
+
+    public void putBeanRef(XMLMetaBeanReference beanRelation) {
+        if (beanRelation.getName() != null) {
+            XMLMetaBeanReference relation = findBeanRef(beanRelation.getName());
+            if (relation != null) {
+                beanRelations.remove(relation);
+            }
+        }
+        addBeanRef(beanRelation);
+    }
+
+    public XMLMetaBeanReference removeBeanRef(String name) {
+        XMLMetaBeanReference relation = findBeanRef(name);
+        if (relation != null) {
+            beanRelations.remove(relation);
+        }
+        return relation;
+    }
+
+    public XMLMetaBeanReference getBeanRef(String name) {
+        return findBeanRef(name);
+    }
+
+    private XMLMetaBeanReference findBeanRef(String name) {
+        if (beanRelations == null) return null;
+        for (XMLMetaBeanReference relation : beanRelations) {
+            if (name.equals(relation.getName())) return relation;
+        }
+        return null;
+    }
+
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanFactory.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanFactory.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanFactory.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,237 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import com.agimatec.validation.MetaBeanFactory;
+import static com.agimatec.validation.model.Features.Property.JAVASCRIPT_VALIDATION_FUNCTIONS;
+import com.agimatec.validation.model.FeaturesCapable;
+import com.agimatec.validation.model.MetaBean;
+import com.agimatec.validation.model.MetaProperty;
+import com.agimatec.validation.routines.StandardValidation;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * Description: Create or enrich MetaBeans from agimatec beanInfos xml<br/>
+ * User: roman <br/>
+ * Date: 07.10.2009 <br/>
+ * Time: 13:19:05 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class XMLMetaBeanFactory implements MetaBeanFactory {
+    private static final Log log = LogFactory.getLog(XMLMetaBeanFactory.class);
+
+    // use LinkedHashMap to keep sequence of loaders
+    private final Map<XMLMetaBeanLoader, XMLMetaBeanInfos> resources =
+          new LinkedHashMap();
+
+    private StandardValidation standardValidation = StandardValidation.getInstance();
+
+    public interface Visitor {
+        /**
+         * @param xmlMeta  - null or the bean found
+         * @param xmlInfos - all infos in a single unit (xml file)
+         * @throws Exception
+         */
+        void visit(XMLMetaBean xmlMeta, XMLMetaBeanInfos xmlInfos) throws Exception;
+
+        MetaBean getMetaBean();
+    }
+
+    public static class XMLResult {
+        public XMLMetaBean xmlMeta;
+        public XMLMetaBeanInfos xmlInfos;
+
+        public XMLResult(XMLMetaBean metaBean, XMLMetaBeanInfos metaInfos) {
+            this.xmlMeta = metaBean;
+            this.xmlInfos = metaInfos;
+        }
+
+        public XMLResult() {
+        }
+    }
+
+    public void buildMetaBean(final MetaBean metaBean) throws Exception {
+        if(metaBean.getId() == null) return;
+         visitXMLBeanMeta(metaBean.getId(), new Visitor() {
+            public void visit(XMLMetaBean xmlMeta, XMLMetaBeanInfos xmlInfos)
+                  throws Exception {
+                enrichMetaBean(metaBean, new XMLResult(xmlMeta, xmlInfos));
+            }
+
+            public MetaBean getMetaBean() {
+                return metaBean;
+            }
+        });
+    }
+
+    /** XMLMetaBeanLoader are used to know "locations" where to get BeanInfos from. */
+    public Collection<XMLMetaBeanLoader> getLoaders() {
+        return resources.keySet();
+    }
+
+    public void addLoader(XMLMetaBeanLoader loader) {
+        resources.put(loader, null);
+    }
+
+    public StandardValidation getStandardValidation() {
+        return standardValidation;
+    }
+
+    /** customize the implementation of standardValidation for this builder. */
+    public void setStandardValidation(StandardValidation standardValidation) {
+        this.standardValidation = standardValidation;
+    }
+
+    public void enrichMetaBean(MetaBean meta, XMLResult result) throws Exception {
+        if (result.xmlMeta.getId() != null) {
+            meta.setId(result.xmlMeta.getId());
+        }
+        if (result.xmlMeta.getName() != null) {
+            meta.setName(result.xmlMeta.getName());
+        }
+/*        if (meta.getBeanClass() == null && result.xmlMeta.getImpl() != null) {
+            meta.setBeanClass(findLocalClass(result.xmlMeta.getImpl()));
+        }*/
+        result.xmlMeta.mergeFeaturesInto(meta);
+        enrichValidations(meta, result.xmlMeta, result, false);
+        if (result.xmlMeta.getProperties() != null) {
+            for (XMLMetaProperty xmlProp : result.xmlMeta.getProperties()) {
+                enrichElement(meta, xmlProp, result);
+            }
+        }
+        if (result.xmlMeta.getBeanRefs() != null) {
+            for (XMLMetaBeanReference xmlRef : result.xmlMeta.getBeanRefs()) {
+                enrichElement(meta, xmlRef, result);
+            }
+        }
+    }
+
+    protected void enrichValidations(FeaturesCapable prop, XMLFeaturesCapable xmlProp,
+                                     XMLResult result, boolean addStandard)
+          throws Exception {
+        if (xmlProp.getValidators() != null) {
+            String[] func = prop.getFeature(JAVASCRIPT_VALIDATION_FUNCTIONS);
+            List<String> jsValidators = new ArrayList<String>(
+                  xmlProp.getValidators().size() + (func == null ? 0 : func.length));
+            if (func != null && func.length > 0) {
+                jsValidators.addAll(Arrays.asList(func));
+            }
+            boolean useStandard = prop instanceof MetaProperty;
+            for (XMLMetaValidatorReference valRef : xmlProp.getValidators()) {
+                if (standardValidation != null &&
+                      valRef.getRefId().equals(standardValidation.getValidationId())) {
+                    useStandard = false;
+                }
+                XMLMetaValidator validator =
+                      result.xmlInfos.getValidator(valRef.getRefId());
+                if (validator != null) {
+                    if (validator.getValidation() != null) {
+                        prop.addValidation(validator.getValidation());
+                    }
+                    if (validator.getJsFunction() != null &&
+                          !jsValidators.contains(validator.getJsFunction())) {
+                        jsValidators.add(validator.getJsFunction());
+                    }
+                }
+            }
+            if (!jsValidators.isEmpty()) {
+                prop.putFeature(JAVASCRIPT_VALIDATION_FUNCTIONS,
+                      jsValidators.toArray(new String[jsValidators.size()]));
+            }
+            if (useStandard && standardValidation != null) {
+                if (!prop.hasValidation(standardValidation))
+                    prop.addValidation(standardValidation);
+            }
+        } else if (addStandard && standardValidation != null &&
+              !prop.hasValidation(standardValidation)) {
+            prop.addValidation(standardValidation);
+        }
+    }
+
+    protected MetaProperty enrichElement(MetaBean meta, XMLMetaElement xmlProp,
+                                         XMLResult result) throws Exception {
+        MetaProperty prop = meta.getProperty(xmlProp.getName());
+        if (prop == null) {
+            prop = new MetaProperty();
+            prop.setName(xmlProp.getName());
+            meta.putProperty(xmlProp.getName(), prop);
+        }
+        xmlProp.mergeInto(prop);
+        enrichValidations(prop, xmlProp, result, true);
+        return prop;
+    }
+
+
+    public void visitXMLBeanMeta(String beanId, Visitor visitor) throws Exception {
+        for (Map.Entry<XMLMetaBeanLoader, XMLMetaBeanInfos> entry : resources
+              .entrySet()) {
+            if (entry.getValue() == null) {
+                // load when not already loaded
+                try {
+                    entry.setValue(entry.getKey().load());
+                } catch (IOException e) {
+                    handleLoadException(entry.getKey(), e);
+                }
+            }
+            if (entry.getValue() != null) { // search in loaded infos for the 'name'
+                if (beanId == null) {
+                    visitor.visit(null, entry.getValue());
+                } else {
+                    XMLMetaBean found = entry.getValue().getBean(beanId);
+                    if (found != null) {
+                        visitor.visit(found, entry.getValue());
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * find a bean by the bean-id (=bean.name)
+     *
+     * @return null or the bean found from the first loader that has it.
+     */
+    protected XMLResult findXMLBeanMeta(String beanId) {
+        for (Map.Entry<XMLMetaBeanLoader, XMLMetaBeanInfos> entry : resources
+              .entrySet()) {
+            if (entry.getValue() == null) {
+                // load when not already loaded
+                try {
+                    entry.setValue(entry.getKey().load());
+                } catch (IOException e) {
+                    handleLoadException(entry.getKey(), e);
+                }
+            }
+            if (entry.getValue() != null) { // search in loaded infos for the 'name'
+                XMLMetaBean found = entry.getValue().getBean(beanId);
+                if (found != null) {
+                    return new XMLResult(found, entry.getValue());
+                }
+            }
+        }
+        return null; // not found!
+    }
+
+    public void handleLoadException(Object loader, IOException e) {
+        log.error("error loading " + loader, e);
+    }
+
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanInfos.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanInfos.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanInfos.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanInfos.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,136 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import com.agimatec.validation.model.Validation;
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+import com.thoughtworks.xstream.annotations.XStreamImplicit;
+import com.thoughtworks.xstream.annotations.XStreamOmitField;
+import org.apache.commons.collections.FastHashMap;
+import org.apache.commons.lang.ClassUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Description: root element of a xml-beanInfos document<br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 14:58:11 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+@XStreamAlias("beanInfos")
+public class XMLMetaBeanInfos {
+    @XStreamAsAttribute
+    private String id;
+    @XStreamAsAttribute
+    private String version;
+    @XStreamImplicit
+    private List<XMLMetaValidator> validators;
+    @XStreamImplicit
+    private List<XMLMetaBean> beans;
+    @XStreamOmitField
+    private Map<String, XMLMetaBean> beanLookup;
+    @XStreamOmitField
+    private Map<String, XMLMetaValidator> validationLookup;
+
+    /**
+     * used for identification, may be empty, if there is no database origin for this object.
+     * could also contain a file-name - can be used flexible...
+     */
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    /**
+     * used for change-detection, when some other component caches MetaBeans based on this
+     * object. when the version changes, the cache could compare to its version state and recompute.
+     * can be used flexible...
+     */
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public List<XMLMetaValidator> getValidators() {
+        return validators;
+    }
+
+    public void setValidators(List<XMLMetaValidator> validators) {
+        this.validators = validators;
+    }
+
+    public List<XMLMetaBean> getBeans() {
+        return beans;
+    }
+
+    public void setBeans(List<XMLMetaBean> beans) {
+        this.beans = beans;
+    }
+
+    public XMLMetaBean getBean(String id) {
+        if (beans == null) return null;
+        if (beanLookup == null) initBeanLookup();
+        return beanLookup.get(id);
+    }
+
+    private void initBeanLookup() {
+        beanLookup = new FastHashMap();
+        for (XMLMetaBean bean : beans) {
+            beanLookup.put(bean.getId(), bean);
+        }
+        ((FastHashMap) beanLookup).setFast(true);
+    }
+
+    private void initValidationLookup() throws Exception {
+        validationLookup = new FastHashMap();
+        for (XMLMetaValidator xv : validators) {
+            if (xv.getJava() != null) {
+                Validation validation =
+                        (Validation) ClassUtils.getClass(xv.getJava()).newInstance();
+                xv.setValidation(validation);
+                validationLookup.put(xv.getId(), xv);
+            }
+        }
+        ((FastHashMap) validationLookup).setFast(true);
+    }
+
+    public void addBean(XMLMetaBean bean) {
+        if (beans == null) beans = new ArrayList();
+        beans.add(bean);
+    }
+
+    public XMLMetaValidator getValidator(String id) throws Exception {
+        if (validators == null) return null;
+        if (validationLookup == null) initValidationLookup();
+        return validationLookup.get(id);
+    }
+
+    public void addValidator(XMLMetaValidator validator) {
+        if (validators == null) validators = new ArrayList();
+        validators.add(validator);
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanLoader.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanLoader.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanLoader.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanLoader.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,30 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import java.io.IOException;
+
+/**
+ * Description: XMLMetaBeanLoader are used to know "locations" where to get BeanInfos from.<br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 16:21:51 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public interface XMLMetaBeanLoader {
+    XMLMetaBeanInfos load() throws IOException;
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanReference.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanReference.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanReference.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanReference.java Wed Mar 17 04:39:07 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 com.agimatec.validation.xml;
+
+import static com.agimatec.validation.model.Features.Property.REF_BEAN_ID;
+import com.agimatec.validation.model.MetaProperty;
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 14:48:01 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+@XStreamAlias("relationship")
+public class XMLMetaBeanReference extends XMLMetaElement {
+    @XStreamAsAttribute
+    private String beanId;
+
+    public XMLMetaBeanReference(String refId) {
+        this.beanId = refId;
+    }
+
+    public XMLMetaBeanReference() {
+    }
+
+    /** id of referenced target bean of the relationship */
+    public String getBeanId() {
+        return beanId;
+    }
+
+    public void setBeanId(String beanId) {
+        this.beanId = beanId;
+    }
+
+    @Override
+    public void mergeInto(MetaProperty prop) throws ClassNotFoundException {
+        super.mergeInto(prop);   // call super!
+        if (getBeanId() != null) {
+            prop.putFeature(REF_BEAN_ID, getBeanId());
+        }
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanRegistry.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanRegistry.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanRegistry.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanRegistry.java Wed Mar 17 04:39:07 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 com.agimatec.validation.xml;
+
+/**
+ * Description: Interface of the object that holds all XMLMetaBeanLoaders <br/>
+ * User: roman.stumm <br/>
+ * Date: 06.07.2007 <br/>
+ * Time: 09:21:38 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public interface XMLMetaBeanRegistry {
+    /**
+     * add a loader for xml bean infos.
+     * the registry should use the loader in the sequence they have been added.
+     */
+    void addLoader(XMLMetaBeanLoader loader);
+
+    /**
+     * convenience method to add a loader for a xml file in the classpath
+     *
+     * @param resource - path of xml file in classpath
+     */
+    void addResourceLoader(String resource);
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanURLLoader.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanURLLoader.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanURLLoader.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaBeanURLLoader.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,49 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 06.07.2007 <br/>
+ * Time: 09:17:30 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public class XMLMetaBeanURLLoader implements XMLMetaBeanLoader {
+    private final URL url;
+
+    public XMLMetaBeanURLLoader(URL url) {
+        if (url == null) throw new NullPointerException("URL required");
+        this.url = url;
+    }
+
+    public XMLMetaBeanInfos load() throws IOException {
+        InputStream stream = url.openStream();
+        try {
+            XMLMetaBeanInfos beanInfos = (XMLMetaBeanInfos) XMLMapper.getInstance()
+                    .getXStream().fromXML(stream);
+            beanInfos.setId(url.toExternalForm());
+            return beanInfos;
+        } finally {
+            stream.close();
+        }
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaElement.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaElement.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaElement.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaElement.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,144 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import static com.agimatec.validation.model.Features.Property.*;
+import com.agimatec.validation.model.MetaProperty;
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+import org.apache.commons.lang.ClassUtils;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 14:48:36 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public class XMLMetaElement extends XMLFeaturesCapable {
+
+    @XStreamAsAttribute()
+    private String name;
+    @XStreamAsAttribute()
+    private String mandatory;
+
+    @XStreamAsAttribute()
+    private Integer minLength;
+    @XStreamAsAttribute()
+    private Integer maxLength;
+    @XStreamAsAttribute()
+    private Boolean readonly;
+    @XStreamAsAttribute()
+    private Boolean hidden;
+    @XStreamAsAttribute()
+    private Boolean denied;
+    /**
+     * normally the type is determined by the implementation class.
+     * in case, no implementation class is given, the xml can
+     * contain the type directly.
+     */
+    @XStreamAsAttribute()
+    private String type;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getMandatory() {
+        return mandatory;
+    }
+
+    public void setMandatory(String mandatory) {
+        this.mandatory = mandatory;
+    }
+
+    public Integer getMinLength() {
+        return minLength;
+    }
+
+    public void setMinLength(Integer minLength) {
+        this.minLength = minLength;
+    }
+
+    public Integer getMaxLength() {
+        return maxLength;
+    }
+
+    public void setMaxLength(Integer maxLength) {
+        this.maxLength = maxLength;
+    }
+
+    public Boolean getReadonly() {
+        return readonly;
+    }
+
+    public void setReadonly(Boolean readonly) {
+        this.readonly = readonly;
+    }
+
+    public Boolean getDenied() {
+        return denied;
+    }
+
+    public void setDenied(Boolean denied) {
+        this.denied = denied;
+    }
+
+    public Boolean getHidden() {
+        return hidden;
+    }
+
+    public void setHidden(Boolean hidden) {
+        this.hidden = hidden;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public void mergeInto(MetaProperty prop) throws ClassNotFoundException {
+        mergeFeaturesInto(prop);
+        if (getType() != null && getType().length() > 0) {
+            prop.setType(ClassUtils.getClass(getType())); // enhancement: or use getGenericType() ?
+        }
+        if (getHidden() != null) {
+            prop.putFeature(HIDDEN, getHidden().booleanValue());
+        }
+        if (getMandatory() != null) {
+            prop.putFeature(MANDATORY, getMandatory().equals("true"));
+        }
+        if (getMaxLength() != null) {
+            prop.putFeature(MAX_LENGTH, getMaxLength());
+        }
+        if (getMinLength() != null) {
+            prop.putFeature(MIN_LENGTH, getMinLength());
+        }
+        if (getReadonly() != null) {
+            prop.putFeature(READONLY, getReadonly());
+        }
+        if (getDenied() != null) {
+            prop.putFeature(DENIED, getDenied());
+        }
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaFeature.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaFeature.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaFeature.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaFeature.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,62 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+
+import java.io.Serializable;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 15:32:13 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+@XStreamAlias("feature")
+public class XMLMetaFeature implements Serializable {
+    @XStreamAsAttribute
+    private String key;
+    @XStreamAsAttribute
+    private Object value;
+
+    public XMLMetaFeature(String key, Object value) {
+        this.key = key;
+        this.value = value;
+    }
+
+    public XMLMetaFeature() {
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+
+    public Object getValue() {
+        return value;
+    }
+
+    public void setValue(Object value) {
+        this.value = value;
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaProperty.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaProperty.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaProperty.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaProperty.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,103 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import static com.agimatec.validation.model.Features.Property.*;
+import com.agimatec.validation.model.MetaProperty;
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 14:27:30 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+@XStreamAlias("property")
+public class XMLMetaProperty extends XMLMetaElement {
+
+    /**
+     * if you need other types (Long, double, String) for maxValue and
+     * minValue, configure via
+     * <pre>
+     * &lt;feature key="maxValue">
+     *   &lt;value class="java.lang.Long">1000&lt;/value>
+     * &lt;/feature>
+     * </pre>
+     * instead with explicit typing.
+     */
+    @XStreamAsAttribute()
+    private Integer maxValue; // XStream requires a non-abstract type to parse XML
+    @XStreamAsAttribute()
+    private Integer minValue; // XStream requires a non-abstract type to parse XML
+
+    private String regexp;
+
+    @XStreamAsAttribute()
+    private String timeLag;
+
+
+    public Integer getMaxValue() {
+        return maxValue;
+    }
+
+    public void setMaxValue(Integer maxValue) {
+        this.maxValue = maxValue;
+    }
+
+    public Integer getMinValue() {
+        return minValue;
+    }
+
+    public void setMinValue(Integer minValue) {
+        this.minValue = minValue;
+    }
+
+    public String getRegexp() {
+        return regexp;
+    }
+
+    public void setRegexp(String regexp) {
+        this.regexp = regexp;
+    }
+
+    public String getTimeLag() {
+        return timeLag;
+    }
+
+    public void setTimeLag(String timeLag) {
+        this.timeLag = timeLag;
+    }
+
+    @Override
+    public void mergeInto(MetaProperty prop) throws ClassNotFoundException {
+        super.mergeInto(prop);   // call super!
+        if (getMaxValue() != null) {
+            prop.putFeature(MAX_VALUE, getMaxValue());
+        }
+        if (getMinValue() != null) {
+            prop.putFeature(MIN_VALUE, getMinValue());
+        }
+        if (getRegexp() != null) {
+            prop.putFeature(REG_EXP, getRegexp());
+        }
+        if (getTimeLag() != null) {
+            prop.putFeature(TIME_LAG, getTimeLag());
+        }
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValidator.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValidator.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValidator.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,77 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import com.agimatec.validation.model.Validation;
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+import com.thoughtworks.xstream.annotations.XStreamOmitField;
+
+import java.io.Serializable;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 14:34:46 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+@XStreamAlias("validator")
+public class XMLMetaValidator implements Serializable {
+    @XStreamAsAttribute
+    private String id;
+    @XStreamAsAttribute
+    private String java;  // implementation of Validation
+
+    @XStreamAsAttribute
+    private String jsFunction; // name of java script function
+
+    @XStreamOmitField
+    private Validation validation;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getJava() {
+        return java;
+    }
+
+    public void setJava(String java) {
+        this.java = java;
+    }
+
+    public void setValidation(Validation validation) {
+        this.validation = validation;
+    }
+
+    public Validation getValidation() {
+        return validation;
+    }
+
+    public String getJsFunction() {
+        return jsFunction;
+    }
+
+    public void setJsFunction(String jsFunction) {
+        this.jsFunction = jsFunction;
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValidatorReference.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValidatorReference.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValidatorReference.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValidatorReference.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,50 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+
+import java.io.Serializable;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 15:27:18 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+@XStreamAlias("validator-ref")
+public class XMLMetaValidatorReference implements Serializable {
+    @XStreamAsAttribute
+    private String refId;
+
+    public XMLMetaValidatorReference(String id) {
+        this.refId = id;
+    }
+
+    public XMLMetaValidatorReference() {
+    }
+
+    public String getRefId() {
+        return refId;
+    }
+
+    public void setRefId(String refId) {
+        this.refId = refId;
+    }
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValue.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValue.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValue.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/java/com/agimatec/validation/xml/XMLMetaValue.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,38 @@
+/**
+ *  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 com.agimatec.validation.xml;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 15:18:17 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public interface XMLMetaValue {
+    // keys for Annotations
+    public static final String ANNOKEY_Widget = "WIDGET";
+    public static final String ANNOKEY_TableColumn = "TABLE_COLUMN";
+
+    // values for TIMELAG
+    public static final String TIMELAG_Past = "PAST";
+    public static final String TIMELAG_Future = "FUTURE";
+
+    // values for MANDATORY
+    public static final String MANDATORY = "true";
+    public static final String OPTIONAL = "false";
+}

Added: incubator/bval/trunk/agimatec-validation/src/main/resources/com/agimatec/validation/json/bean-infos-json.ftl
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/main/resources/com/agimatec/validation/json/bean-infos-json.ftl?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/main/resources/com/agimatec/validation/json/bean-infos-json.ftl (added)
+++ incubator/bval/trunk/agimatec-validation/src/main/resources/com/agimatec/validation/json/bean-infos-json.ftl Wed Mar 17 04:39:07 2010
@@ -0,0 +1,64 @@
+agimatec.namespace("agimatec.metadata");
+
+(function(){
+<#assign var = 0>
+<#assign varrefs = {}>
+
+<#list metaBeans as metaBean>
+<#assign varrefs = varrefs + {metaBean.id : var}>
+var metaBean${var} = {
+ "id" : "${metaBean.id}",
+ <#if metaBean.beanClass??>"beanClass" : "${metaBean.beanClass.name}",</#if>
+ <#if metaBean.name??>"name" : "${metaBean.name}",</#if>
+ "features" :{<#rt/>
+   <#list metaBean.features?keys as featureKey>
+      <#assign value = metaBean.features[featureKey]>
+   "${featureKey}" : <#if
+          value?is_string>"${value}"<#elseif
+          value?is_boolean>${value?string}<#elseif
+          value?is_number>${value}<#elseif
+          value?is_date>${value?string.full}<#elseif
+          !(value??)>null<#elseif value?is_sequence>[<#list value as v>"${v}"<#if v_has_next>,</#if></#list>]<#elseif
+          value?is_hash>{<#list value?keys as key>"${key}" : "${value[key]}"<#if key_has_next>,</#if></#list>}<#else
+          >"?"</#if><#rt/><#if
+          featureKey_has_next>,</#if>
+   </#list>
+   <#lt/>},
+ "properties" :{
+   <#list metaBean.properties as property>
+     "${property.name}":{
+       "name" : "${property.name}",
+       <#if property.type??>"type" : "${property.type.name}",</#if>
+       "features" : {<#if property.type?? &&
+       property.type.enum>"enum" : {<#list property.type.enumConstants as enum>"${enum.name()}": "${enum.name()}"<#if enum_has_next>, </#if></#list>}<#if property.features?size &gt; 0>,</#if></#if><#list
+       property.features?keys as featureKey>
+       <#assign value = property.features[featureKey]>
+       "${featureKey}" : <#rt/><#if
+          value?is_string>"${value}"<#elseif
+          value?is_boolean>${value?string}<#elseif
+          value?is_number>${value}<#elseif
+          value?is_date>${value?string.full}<#elseif
+          !(value??)>null<#elseif value?is_sequence>[<#list value as v>"${v}"<#if v_has_next>,</#if></#list>]<#elseif
+          value?is_hash_ex>{<#list value?keys as key>"${key}" : "${value[key]}"<#if key_has_next>,</#if></#list>}<#else
+          >"?"</#if><#rt/><#if featureKey_has_next>,</#if>
+       </#list>
+       }
+     }<#if property_has_next>,</#if>
+   </#list>
+   }
+};
+<#assign var = var + 1>
+</#list>
+
+<#assign var = 0>
+<#list metaBeans as metaBean><#list
+    metaBean.properties as property><#if
+    property.metaBean?? && varrefs[property.metaBean.id]??>
+metaBean${var}.properties.${property.name}.metaBean = metaBean${varrefs[property.metaBean.id]};
+</#if></#list><#assign var = var + 1></#list><#assign var = 0>
+agimatec.metadata.metaBeans = {
+<#list metaBeans as metaBean>
+       "${metaBean.id}" : metaBean${var}<#if metaBean_has_next>,</#if>
+       <#assign var = var + 1>
+</#list>};
+})();
\ No newline at end of file

Added: incubator/bval/trunk/agimatec-validation/src/test/java/com/agimatec/validation/BeanValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-validation/src/test/java/com/agimatec/validation/BeanValidatorTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-validation/src/test/java/com/agimatec/validation/BeanValidatorTest.java (added)
+++ incubator/bval/trunk/agimatec-validation/src/test/java/com/agimatec/validation/BeanValidatorTest.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,124 @@
+/**
+ *  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 com.agimatec.validation;
+
+import com.agimatec.validation.example.BusinessObject;
+import com.agimatec.validation.example.BusinessObjectAddress;
+import com.agimatec.validation.model.Features;
+import com.agimatec.validation.model.MetaBean;
+import com.agimatec.validation.routines.Reasons;
+import com.agimatec.validation.xml.XMLMetaBeanURLLoader;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+/**
+ * BeanValidator Tester.
+ *
+ * @author ${USER}
+ * @version 1.0
+ * @since <pre>07/06/2007</pre>
+ *        Copyright: Agimatec GmbH 2008
+ */
+public class BeanValidatorTest extends TestCase {
+    public BeanValidatorTest(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testValidateMapAsBean() {
+        MetaBeanManagerFactory.getRegistry().addLoader(new XMLMetaBeanURLLoader(
+              BusinessObject.class.getResource("test-beanInfos.xml")));
+
+        MetaBean mb = MetaBeanManagerFactory.getFinder()
+              .findForId("com.agimatec.validation.example.Address");
+
+        // 1. validate a bean
+        BusinessObjectAddress adr = new BusinessObjectAddress();
+        BeanValidator<ValidationResults> validator = new BeanValidator();
+        ValidationResults results = validator.validate(adr, mb);
+        assertEquals(2,
+              results.getErrorsByReason().get(Features.Property.MANDATORY).size());
+
+        // 2. validate a map with the same metabean
+        validator.setTreatMapsLikeBeans(true);
+        results = validator.validate(new HashMap(), mb);
+        assertFalse(results.isEmpty());
+        assertEquals(2,
+              results.getErrorsByReason().get(Features.Property.MANDATORY).size());
+
+        // 3. validate as empty map (jsr303 behavior)
+        validator.setTreatMapsLikeBeans(false);
+        results = validator.validate(new HashMap(), mb);
+        assertTrue(results.isEmpty());
+    }
+
+    public void testValidate() {
+        MetaBeanFinder finder = MetaBeanManagerFactory.getFinder();
+        MetaBeanManagerFactory.getRegistry().addLoader(new XMLMetaBeanURLLoader(
+              BusinessObject.class.getResource("test-beanInfos.xml")));
+        MetaBean info = finder.findForClass(BusinessObject.class);
+        BusinessObject object = new BusinessObject();
+        object.setAddress(new BusinessObjectAddress());
+        object.getAddress().setOwner(object);
+        BeanValidator<ValidationResults> validator = new BeanValidator();
+        ValidationResults results = validator.validate(object, info);
+        assertTrue(results.hasErrorForReason(Reasons.MANDATORY));
+        assertTrue(results.hasError(object, null));
+        assertTrue(results.hasError(object.getAddress(), null));
+
+        assertTrue(
+              validator.validateProperty(object, info.getProperty("firstName")).hasError(
+                    object, "firstName"));
+
+        object.setUserId(1L);
+        object.setFirstName("Hans");
+        object.setLastName("Tester");
+        object.setAddress(new BusinessObjectAddress());
+        object.getAddress().setOwner(object);
+        assertFalse(validator.validate(object, info).isEmpty());
+
+        object.getAddress().setCountry("0123456789012345678");
+        assertFalse(validator.validate(object, info).isEmpty());
+
+        object.getAddress().setCountry("Germany");
+        object.setAddresses(new ArrayList());
+        object.getAddresses().add(object.getAddress());
+        object.getAddresses().add(object.getAddress());
+        object.getAddresses().add(object.getAddress());
+        assertTrue(validator.validate(object, info).isEmpty());
+
+        // 4th address is too much!
+        object.getAddresses().add(object.getAddress());
+        assertFalse(
+              validator.validate(object, info).isEmpty()); // cardinality error found
+    }
+
+    public static Test suite() {
+        return new TestSuite(BeanValidatorTest.class);
+    }
+}



Mime
View raw message