incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r928387 [4/15] - in /incubator/bval/trunk: ./ agimatec-jsr303/ agimatec-validation/ bval-core/ bval-core/.externalToolBuilders/ bval-core/.settings/ bval-core/src/ bval-core/src/main/ bval-core/src/main/java/ bval-core/src/main/java/org/ bv...
Date Sun, 28 Mar 2010 12:28:32 GMT
Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaBeanURLLoader.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaBeanURLLoader.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaBeanURLLoader.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaBeanURLLoader.java Sun Mar 28 12:28:25 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 org.apache.bval.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();
+        }
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaBeanURLLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaBeanURLLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaElement.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaElement.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaElement.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaElement.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,146 @@
+/**
+ *  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.xml;
+
+import static org.apache.bval.model.Features.Property.*;
+
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+
+import org.apache.bval.model.MetaProperty;
+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());
+        }
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaElement.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaFeature.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaFeature.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaFeature.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaFeature.java Sun Mar 28 12:28:25 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 org.apache.bval.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;
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaFeature.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaFeature.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaProperty.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaProperty.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaProperty.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaProperty.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,105 @@
+/**
+ *  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.xml;
+
+import static org.apache.bval.model.Features.Property.*;
+
+import org.apache.bval.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());
+        }
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaProperty.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidator.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidator.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidator.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidator.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,78 @@
+/**
+ *  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.xml;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+import com.thoughtworks.xstream.annotations.XStreamOmitField;
+
+import java.io.Serializable;
+
+import org.apache.bval.model.Validation;
+
+/**
+ * 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;
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidatorReference.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidatorReference.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidatorReference.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidatorReference.java Sun Mar 28 12:28:25 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 org.apache.bval.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;
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidatorReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValidatorReference.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValue.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValue.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValue.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValue.java Sun Mar 28 12:28:25 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 org.apache.bval.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";
+}

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaValue.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/main/resources/org/apache/bval/json/bean-infos-json.ftl
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/resources/org/apache/bval/json/bean-infos-json.ftl?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/resources/org/apache/bval/json/bean-infos-json.ftl (added)
+++ incubator/bval/trunk/bval-core/src/main/resources/org/apache/bval/json/bean-infos-json.ftl Sun Mar 28 12:28:25 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/bval-core/src/test/java/org/apache/bval/BeanValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/BeanValidatorTest.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/BeanValidatorTest.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/BeanValidatorTest.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,129 @@
+/**
+ *  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;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.apache.bval.BeanValidator;
+import org.apache.bval.MetaBeanFinder;
+import org.apache.bval.MetaBeanManagerFactory;
+import org.apache.bval.ValidationResults;
+import org.apache.bval.example.BusinessObject;
+import org.apache.bval.example.BusinessObjectAddress;
+import org.apache.bval.model.Features;
+import org.apache.bval.model.MetaBean;
+import org.apache.bval.routines.Reasons;
+import org.apache.bval.xml.XMLMetaBeanURLLoader;
+
+/**
+ * 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("org.apache.bval.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);
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/BeanValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/BeanValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/BeanValidatorTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/MetaBeanManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/MetaBeanManagerTest.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/MetaBeanManagerTest.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/MetaBeanManagerTest.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,170 @@
+/**
+ *  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;
+
+import freemarker.template.TemplateException;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.bval.MetaBeanFinder;
+import org.apache.bval.MetaBeanManager;
+import org.apache.bval.example.BusinessEnum;
+import org.apache.bval.example.BusinessObject;
+import org.apache.bval.example.BusinessObjectAddress;
+import org.apache.bval.json.JSONGenerator;
+import org.apache.bval.model.DynaTypeEnum;
+import org.apache.bval.model.MetaBean;
+import org.apache.bval.model.MetaProperty;
+import org.apache.bval.xml.XMLMetaBeanURLLoader;
+
+/**
+ * MetaBeanManager Tester.
+ *
+ * @author ${USER}
+ * @version 1.0
+ * @since <pre>07/05/2007</pre>
+ *        Copyright: Agimatec GmbH 2008
+ */
+public class MetaBeanManagerTest extends TestCase {
+    MetaBeanManager mbm = new MetaBeanManager();
+
+    public MetaBeanManagerTest(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+        mbm.getBuilder().addLoader(new XMLMetaBeanURLLoader(
+              BusinessObject.class.getResource("test-beanInfos.xml")));
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testEnrichCopies() throws Exception {
+        Map<String, MetaBean> copies = mbm.enrichCopies(new XMLMetaBeanURLLoader(
+              BusinessObject.class.getResource("test-beanInfos-custom.xml")).load());
+        assertNotNull(copies);
+        MetaBean mb = copies.get(BusinessObject.class.getName());
+        assertFalse(mb.getProperty("lastName").isMandatory());
+        MetaBean mb2 = mbm.findForClass(BusinessObject.class);
+        assertTrue(mb2.getProperty("lastName").isMandatory());
+    }
+
+    public void testCopy() {
+        MetaBean mb = mbm.findForClass(BusinessObject.class);
+        MetaBean mb2 = mb.copy();
+        assertTrue(mb2 != mb);
+        assertTrue(mb2.getProperty("dateBirth") != mb.getProperty("dateBirth"));
+    }
+
+    public void testFindForClass() throws Exception {
+        MetaBeanFinder finder = mbm;
+        MetaBean info = finder.findForClass(BusinessObject.class);
+        assertNotNull(info);
+        assertTrue(info == info.getProperty("address").getMetaBean().getProperty("owner")
+              .getMetaBean());
+        assertTrue(info == info.getProperty("addresses").getMetaBean()
+              .getProperty("owner").getMetaBean());
+        assertTrue(info.getProperty("email").getJavaScriptValidations().length > 0);
+    }
+
+    public void testBeanInfosCustomPatchGenerated()
+          throws IOException, TemplateException {
+        MetaBean mbean = mbm.findForClass(BusinessObject.class);
+        MetaProperty mprop = mbean.getProperty("lastName");
+        assertTrue(mprop.isMandatory());
+
+        mbm.getCache().removeFromCache(mbean);
+        mbm.getBuilder().addLoader(new XMLMetaBeanURLLoader(
+              BusinessObject.class.getResource("test-beanInfos-custom.xml")));
+        mbean = mbm.findForClass(BusinessObject.class);
+        mprop = mbean.getProperty("lastName");
+        assertTrue(!mprop.isMandatory());
+
+        JSONGenerator converter = new JSONGenerator();
+
+        List<MetaBean> metaBeans = new ArrayList(2);
+        metaBeans.add(mbean);
+        MetaBean mbean2 = mbm.findForId("UnknownObject");
+        metaBeans.add(mbean2);
+        String json = converter.toJSON(metaBeans);
+        assertNotNull(json);
+        System.out.println(json);
+    }
+
+    public void testFindAll() {
+        Map<String, MetaBean> all = mbm.findAll();
+        assertNotNull(all);
+        Map<String, MetaBean> all2 = mbm.findAll();
+        assertEquals(all.size(), all2.size());
+        assertTrue(all.get(BusinessObject.class.getName()) ==
+              all2.get(BusinessObject.class.getName()));
+        assertTrue(all.get(BusinessObject.class.getName()) != null);
+        MetaBean bean = all.get(BusinessObject.class.getName());
+        assertTrue(bean == bean.getProperty("address").getMetaBean().getProperty("owner")
+              .getMetaBean());
+        assertTrue(bean == bean.getProperty("addresses").getMetaBean()
+              .getProperty("owner").getMetaBean());
+    }
+
+    public void testJSON() throws Exception {
+        MetaBean info = mbm.findForClass(BusinessObject.class);
+        MetaBean info2 = info.getProperty("address").getMetaBean();
+
+        // empty default bean without xml backup
+        MetaBean info3 = mbm.findForClass(BusinessObjectAddress.class);
+        JSONGenerator converter = new JSONGenerator();
+
+        List<MetaBean> metaBeans = new ArrayList(2);
+        metaBeans.add(info);
+        metaBeans.add(info2);
+        metaBeans.add(info3);
+        String json = converter.toJSON(metaBeans);
+        assertNotNull(json);
+        System.out.println(json);
+    }
+
+    public void testJSON_dynaTypeEnum() throws Exception {
+        MetaBean info = mbm.findForClass(BusinessObject.class);
+        MetaProperty choice = info.getProperty("choice");
+        choice.setType(new DynaTypeEnum(BusinessEnum.class, "CUSTOM_1", "CUSTOM_2"));
+
+        JSONGenerator converter = new JSONGenerator();
+
+        List<MetaBean> metaBeans = new ArrayList(1);
+        metaBeans.add(info);
+        String json = converter.toJSON(metaBeans);
+        assertNotNull(json);
+//        System.out.println(json);
+        assertTrue(json.indexOf("CUSTOM_1")>0);
+        assertTrue(json.indexOf("CUSTOM_2")>0);
+        assertTrue(json.indexOf("VALUE1")<0);
+    }
+
+    public static Test suite() {
+        return new TestSuite(MetaBeanManagerTest.class);
+    }
+
+}

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/MetaBeanManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/MetaBeanManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/MetaBeanManagerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/ValidationResultsTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/ValidationResultsTest.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/ValidationResultsTest.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/ValidationResultsTest.java Sun Mar 28 12:28:25 2010
@@ -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;
+
+import org.apache.bval.BeanValidationContext;
+import org.apache.bval.ValidationResults;
+import org.apache.bval.model.MetaProperty;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * ValidationResults Tester.
+ *
+ * @author ${USER}
+ * @version 1.0
+ *          Copyright: Agimatec GmbH 2008
+ * @since <pre>07/06/2007</pre>
+ */
+public class ValidationResultsTest extends TestCase {
+    private ValidationResults results;
+
+    public ValidationResultsTest(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+        results = new ValidationResults();
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testValidationResults() throws Exception {
+        assertTrue(results.isEmpty());
+        BeanValidationContext ctx = new BeanValidationContext(results);
+        ctx.setBean(this);
+        ctx.setMetaProperty(new MetaProperty());
+        ctx.getMetaProperty().setName("prop");
+        results.addError("test", ctx);
+        assertFalse(results.isEmpty());
+        assertTrue(results.hasErrorForReason("test"));
+        assertTrue(results.hasError(this, "prop"));
+        assertTrue(results.hasError(this, null));
+        assertFalse(results.hasError(this, "prop2"));
+    }
+
+    public static Test suite() {
+        return new TestSuite(ValidationResultsTest.class);
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/ValidationResultsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/ValidationResultsTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/ValidationResultsTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessEnum.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessEnum.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessEnum.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessEnum.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,28 @@
+/**
+ *  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.example;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 10.07.2007 <br/>
+ * Time: 16:32:24 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public enum BusinessEnum {
+    VALUE1, VALUE2, VALUE3
+}

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessEnum.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessEnum.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessEnum.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObject.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObject.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObject.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObject.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,137 @@
+/**
+ *  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.example;
+
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 05.07.2007 <br/>
+ * Time: 11:41:34 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public class BusinessObject {
+    private long userId;
+    private int numericValue;
+    private String firstName, lastName, title;
+    private Date dateBirth;
+    private Timestamp validTo;
+    private String email;
+    private BusinessEnum choice;
+    private BusinessObjectAddress address;
+    private List<BusinessObjectAddress> addresses;
+    private List properties;
+
+    public BusinessEnum getChoice() {
+        return choice;
+    }
+
+    public void setChoice(BusinessEnum choice) {
+        this.choice = choice;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public Date getDateBirth() {
+        return dateBirth;
+    }
+
+    public void setDateBirth(Date dateBirth) {
+        this.dateBirth = dateBirth;
+    }
+
+    public Timestamp getValidTo() {
+        return validTo;
+    }
+
+    public void setValidTo(Timestamp validTo) {
+        this.validTo = validTo;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public BusinessObjectAddress getAddress() {
+        return address;
+    }
+
+    public void setAddress(BusinessObjectAddress address) {
+        this.address = address;
+    }
+
+    public void setNumericValue(int newNumericValue) {
+        numericValue = newNumericValue;
+    }
+
+    public int getNumericValue() {
+        return numericValue;
+    }
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(long userId) {
+        this.userId = userId;
+    }
+
+    public List<BusinessObjectAddress> getAddresses() {
+        return addresses;
+    }
+
+    public void setAddresses(List<BusinessObjectAddress> addresses) {
+        this.addresses = addresses;
+    }
+
+    public List getProperties() {
+        return properties;
+    }
+
+    public void setProperties(List properties) {
+        this.properties = properties;
+    }
+}
\ No newline at end of file

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObject.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObject.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectAddress.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectAddress.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectAddress.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectAddress.java Sun Mar 28 12:28:25 2010
@@ -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.example;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 06.07.2007 <br/>
+ * Time: 09:13:50 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public class BusinessObjectAddress {
+    private String city, country;
+    private BusinessObject owner;
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getCountry() {
+        return country;
+    }
+
+    public void setCountry(String country) {
+        this.country = country;
+    }
+
+    public BusinessObject getOwner() {
+        return owner;
+    }
+
+    public void setOwner(BusinessObject owner) {
+        this.owner = owner;
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectAddress.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectAddress.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectAddress.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java Sun Mar 28 12:28:25 2010
@@ -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.example;
+
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.beans.SimpleBeanInfo;
+
+import org.apache.bval.model.Features;
+
+/** Copyright: Agimatec GmbH 2008 */
+public class BusinessObjectBeanInfo extends SimpleBeanInfo {
+    Class targetClass = BusinessObject.class;
+
+    @Override
+    public BeanInfo[] getAdditionalBeanInfo() {
+        ExplicitBeanInfo bi = new ExplicitBeanInfo();
+        bi.setPropertyDescriptors(_getPropertyDescriptors());
+        return new BeanInfo[]{bi};
+    }
+
+    public PropertyDescriptor[] _getPropertyDescriptors() {
+        try {
+            PropertyDescriptor numericValue = new PropertyDescriptor("numericValue",
+                    targetClass, "getNumericValue", "setNumericValue");
+            numericValue.setValue(Features.Property.MAX_VALUE, new Integer(100));
+            numericValue.setValue(Features.Property.MIN_VALUE, new Integer(-100));
+            return new PropertyDescriptor[]{numericValue};
+        } catch (IntrospectionException ex) {
+            ex.printStackTrace();
+            return null;
+        }
+    }
+}
+
+class ExplicitBeanInfo extends SimpleBeanInfo {
+    private PropertyDescriptor[] propertyDescriptors;
+
+    @Override
+    public PropertyDescriptor[] getPropertyDescriptors() {
+        return propertyDescriptors;
+    }
+
+    public void setPropertyDescriptors(PropertyDescriptor[] propertyDescriptors) {
+        this.propertyDescriptors = propertyDescriptors;
+    }
+}
\ No newline at end of file

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/ExampleBusinessObjectService.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/ExampleBusinessObjectService.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/ExampleBusinessObjectService.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/ExampleBusinessObjectService.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,46 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bval.example;
+
+
+import java.util.List;
+
+import org.apache.bval.Validate;
+import org.apache.bval.ValidationResults;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 09.07.2007 <br/>
+ * Time: 13:51:59 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public interface ExampleBusinessObjectService {
+    /** validated method example */
+    @Validate
+    public void saveBusinessObject(@Validate BusinessObject object, Object other);
+
+    @Validate
+    public void saveBusinessObjects(@Validate BusinessObject[] object);
+
+    /** explicit validation example */
+    public ValidationResults validateBusinessObject(
+            @Validate("BusinessObject")BusinessObject object);
+
+    /** query by example - example */
+    public List<BusinessObject> findBusinessObjects(BusinessObject example);
+}

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/ExampleBusinessObjectService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/ExampleBusinessObjectService.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/example/ExampleBusinessObjectService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/model/MetaPropertyTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/model/MetaPropertyTest.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/model/MetaPropertyTest.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/model/MetaPropertyTest.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,55 @@
+/**
+ *  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.model;
+
+import org.apache.bval.example.BusinessEnum;
+import org.apache.bval.model.DynaTypeEnum;
+import org.apache.bval.model.MetaProperty;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * MetaProperty Tester.
+ *
+ * @author <Authors name>
+ * @since <pre>02/12/2009</pre>
+ * @version 1.0
+ */
+public class MetaPropertyTest extends TestCase {
+    public MetaPropertyTest(String name) {
+        super(name);
+    }
+
+
+    public void testGetTypeClass() throws Exception {
+        MetaProperty prop = new MetaProperty();
+        prop.setType(String.class);
+        assertEquals(String.class, prop.getTypeClass());
+        assertEquals(String.class, prop.getType());
+        prop.setType(new DynaTypeEnum(BusinessEnum.class, BusinessEnum.VALUE1.name(),
+              BusinessEnum.VALUE3.name()));
+        assertEquals(BusinessEnum.class, prop.getTypeClass());
+        assertEquals(2, ((DynaTypeEnum)prop.getType()).getEnumConstants().length);
+    }
+
+
+    public static Test suite() {
+        return new TestSuite(MetaPropertyTest.class);
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/model/MetaPropertyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/model/MetaPropertyTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/model/MetaPropertyTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,231 @@
+/**
+ *  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.routines;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.bval.BeanValidationContext;
+import org.apache.bval.model.Features;
+import org.apache.bval.model.MetaProperty;
+import org.apache.bval.model.ValidationContext;
+import org.apache.bval.model.ValidationListener;
+import org.apache.bval.routines.Reasons;
+import org.apache.bval.routines.StandardValidation;
+import org.apache.bval.xml.XMLMetaValue;
+
+/**
+ * StandardValidation Tester.
+ *
+ * @author ${USER}
+ * @version 1.0
+ * @since <pre>07/06/2007</pre>
+ *        Copyright: Agimatec GmbH 2008
+ */
+public class StandardValidationTest extends TestCase implements ValidationListener {
+    private StandardValidation validation;
+    private BeanValidationContext context;
+    private List<String> reasons = new ArrayList<String>();
+    private MetaProperty metaProperty;
+    private String stringValue;
+    private Date dateValue;
+    private int intValue;
+
+    public StandardValidationTest(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+        validation = new StandardValidation();
+        context = new BeanValidationContext(this);
+        metaProperty = new MetaProperty();
+        context.setBean(this, null);
+        context.setMetaProperty(metaProperty);
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public String getStringValue() {
+        return stringValue;
+    }
+
+    public void testValidateMandatory() {
+        metaProperty.setName("stringValue");
+
+        // test not-null value that is mandatory
+        metaProperty.setMandatory(true);
+        stringValue = "some value";
+        validation.validateMandatory(context);
+        assertTrue(reasons.isEmpty());
+
+        // test null value that is mandatory
+        context.unknownValue();
+        stringValue = null;
+        validation.validateMandatory(context);
+        assertTrue(reasons.contains(Reasons.MANDATORY));
+
+        // test null value that is NOT mandatory
+        context.unknownValue();
+        metaProperty.setMandatory(false);
+        reasons.clear();
+        validation.validateMandatory(context);
+        assertTrue(reasons.isEmpty());
+    }
+
+    public void testValidateMaxLength() {
+        metaProperty.setName("stringValue");
+        metaProperty.putFeature(Features.Property.MAX_LENGTH, 5);
+        stringValue = "1234";
+        validation.validateMaxLength(context);
+        assertTrue(reasons.isEmpty());
+        context.unknownValue();
+        stringValue = "much too long";
+        validation.validateMaxLength(context);
+        assertTrue(reasons.contains(Reasons.MAX_LENGTH));
+    }
+
+    public void testValidateMinLength() {
+        metaProperty.setName("stringValue");
+        metaProperty.putFeature(Features.Property.MIN_LENGTH, 5);
+        stringValue = "123456";
+        validation.validateMinLength(context);
+        assertTrue(reasons.isEmpty());
+        context.unknownValue();
+        stringValue = "123";
+        validation.validateMinLength(context);
+        assertTrue(reasons.contains(Reasons.MIN_LENGTH));
+    }
+
+    public void testValidateMaxValue() {
+        metaProperty.setName("stringValue");
+        metaProperty.putFeature(Features.Property.MAX_VALUE, "9999");
+        stringValue = "1111";
+        validation.validateMaxValue(context);
+        assertTrue(reasons.isEmpty());
+        context.unknownValue();
+        stringValue = "99999";
+        validation.validateMaxValue(context);
+        assertTrue(reasons.contains(Reasons.MAX_VALUE));
+    }
+
+    public void testValidateMinValue() {
+        metaProperty.setName("stringValue");
+        metaProperty.putFeature(Features.Property.MIN_VALUE, "5555");
+        stringValue = "8888";
+        validation.validateMinValue(context);
+        assertTrue(reasons.isEmpty());
+        context.unknownValue();
+        stringValue = "3333";
+        validation.validateMinValue(context);
+        assertTrue(reasons.contains(Reasons.MIN_VALUE));
+    }
+
+    public int getIntValue() {
+        return intValue;
+    }
+
+    public void testValidateMinValue_MixedNumber() {
+        metaProperty.setName("intValue");
+        metaProperty.putFeature(Features.Property.MIN_VALUE, new Long(0));
+        intValue = 5;
+        validation.validateMinValue(context);
+        assertTrue(reasons.isEmpty());
+        context.unknownValue();
+        intValue = -1;
+        validation.validateMinValue(context);
+        assertTrue(reasons.contains(Reasons.MIN_VALUE));
+    }
+
+    public void testValidateMinValue_Date_Timestamp() {
+        metaProperty.setName("dateValue");
+        Date dt = new Date();
+        metaProperty.putFeature(Features.Property.MIN_VALUE, dt);
+        dateValue = new Timestamp(dt.getTime()+1000);
+        validation.validateMinValue(context);
+        assertTrue(reasons.isEmpty());
+        context.unknownValue();
+        dateValue = new Timestamp(dt.getTime()-1000);
+        validation.validateMinValue(context);
+        assertTrue(reasons.contains(Reasons.MIN_VALUE));
+    }
+
+    public void testValidateMaxValue_AlphabeticString() {
+        metaProperty.setName("stringValue");
+        metaProperty.putFeature(Features.Property.MAX_VALUE, "BBBB");
+        stringValue = "AAAA";
+        validation.validateMaxValue(context);
+        assertTrue(reasons.isEmpty());
+        context.unknownValue();
+        stringValue = "BBBC";
+        validation.validateMaxValue(context);
+        assertTrue(reasons.contains(Reasons.MAX_VALUE));
+    }
+
+    public void testValidateRegExp() {
+        // regexp for Zip
+        String regexp = "[a-zA-Z\\- \\d]*";
+        metaProperty.setName("stringValue");
+        metaProperty.putFeature(Features.Property.REG_EXP, regexp);
+        stringValue = "53773";
+        validation.validateRegExp(context);
+        assertTrue(reasons.isEmpty());
+        context.unknownValue();
+        stringValue = "5355/7"; // invalid zip value
+        validation.validateRegExp(context);
+        assertTrue(reasons.contains(Reasons.REG_EXP));
+    }
+
+    public Date getDateValue() {
+        return dateValue;
+    }
+
+    public void testValidateTimeLag() {
+        metaProperty.setName("dateValue");
+        metaProperty.putFeature(Features.Property.TIME_LAG, XMLMetaValue.TIMELAG_Past);
+
+        dateValue = new Date(System.currentTimeMillis() - 10000);
+        validation.validateTimeLag(context);
+        assertTrue(reasons.isEmpty());
+
+        metaProperty.putFeature(Features.Property.TIME_LAG, XMLMetaValue.TIMELAG_Future);
+        validation.validateTimeLag(context);
+        assertTrue(reasons.contains(Reasons.TIME_LAG));
+
+    }
+
+    public static Test suite() {
+        return new TestSuite(StandardValidationTest.class);
+    }
+
+    public void addError(String reason, ValidationContext context) {
+        reasons.add(reason);
+    }
+
+    public void addError(ValidationListener.Error error, ValidationContext context) {
+        reasons.add(error.getReason());
+    }
+
+}

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/routines/StandardValidationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/xml/XMLMetaBeanInfosTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/xml/XMLMetaBeanInfosTest.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/xml/XMLMetaBeanInfosTest.java (added)
+++ incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/xml/XMLMetaBeanInfosTest.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,177 @@
+/**
+ *  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.xml;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.bval.example.BusinessObject;
+import org.apache.bval.example.BusinessObjectAddress;
+import org.apache.bval.xml.XMLMapper;
+import org.apache.bval.xml.XMLMetaBean;
+import org.apache.bval.xml.XMLMetaBeanInfos;
+import org.apache.bval.xml.XMLMetaBeanReference;
+import org.apache.bval.xml.XMLMetaProperty;
+import org.apache.bval.xml.XMLMetaValidator;
+import org.apache.bval.xml.XMLMetaValue;
+
+/**
+ * XMLMetaBean Tester.
+ *
+ * @author ${USER}
+ * @version 1.0
+ *          Copyright: Agimatec GmbH 2008
+ * @since <pre>07/05/2007</pre>
+ */
+public class XMLMetaBeanInfosTest extends TestCase {
+
+    public XMLMetaBeanInfosTest(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testBeanInfosToXML() {
+        XMLMetaBeanInfos infos = new XMLMetaBeanInfos();
+        infos.setBeans(new ArrayList());
+        infos.setValidators(new ArrayList());
+
+        XMLMetaValidator validator = new XMLMetaValidator();
+        validator.setId("mandatory");
+        validator.setJava("org.apache.bval.MandatoryValidator");
+
+        infos.getValidators().add(validator);
+
+        validator = new XMLMetaValidator();
+        validator.setId("email");
+        validator.setJava("org.apache.bval.EMailValidation");
+
+        infos.getValidators().add(validator);
+
+        XMLMetaBean bean = new XMLMetaBean();
+        bean.putFeature("DOMAIN", "TestProfile");
+        bean.putFeature("label-key", "business-object-label");
+        bean.setId("User");
+        bean.setImpl(BusinessObject.class.getName());
+        bean.setProperties(new ArrayList<XMLMetaProperty>());
+        XMLMetaProperty property = new XMLMetaProperty();
+        property.setName("userId");
+        property.setMandatory(XMLMetaValue.MANDATORY);
+        bean.getProperties().add(property);
+
+        property = new XMLMetaProperty();
+        property.setName("firstName");
+        property.setMandatory(XMLMetaValue.MANDATORY);
+        property.setMaxLength(100);
+        bean.getProperties().add(property);
+
+        property = new XMLMetaProperty();
+        property.setName("lastName");
+        property.setMandatory(XMLMetaValue.MANDATORY);
+        property.setMaxLength(100);
+        bean.getProperties().add(property);
+
+        property = new XMLMetaProperty();
+        property.setName("title");
+        property.setMandatory(XMLMetaValue.OPTIONAL);
+        property.setMaxLength(10);
+        bean.getProperties().add(property);
+
+        property = new XMLMetaProperty();
+        property.setName("dateBirth");
+        property.setMandatory(XMLMetaValue.OPTIONAL);
+        property.setTimeLag(XMLMetaValue.TIMELAG_Past);
+        bean.getProperties().add(property);
+
+        property = new XMLMetaProperty();
+        property.setName("validTo");
+        property.setMandatory(XMLMetaValue.OPTIONAL);
+        property.setTimeLag(XMLMetaValue.TIMELAG_Future);
+        bean.getProperties().add(property);
+
+        property = new XMLMetaProperty();
+        property.setName("email");
+        property.putFeature(XMLMetaValue.ANNOKEY_Widget, "entry");
+        property.putFeature(XMLMetaValue.ANNOKEY_TableColumn, true);
+        Map formatterMap = new HashMap();
+        formatterMap.put("locale", "DE");
+        formatterMap.put("style", "info");
+        property.putFeature("ajax-formatter", formatterMap);
+        property.addValidator("email");
+        bean.getProperties().add(property);
+
+        infos.getBeans().add(bean);
+
+        XMLMetaBean bean2 = new XMLMetaBean();
+        bean2.setId("Address");
+        bean2.setImpl(BusinessObjectAddress.class.getName());
+        property = new XMLMetaProperty();
+        property.setName("city");
+        bean2.putProperty(property);
+        property = new XMLMetaProperty();
+        property.setName("country");
+        property.setMaxLength(10);
+        property.setMandatory(XMLMetaValue.MANDATORY);
+        bean2.putProperty(property);
+
+        XMLMetaBeanReference relation = new XMLMetaBeanReference();
+        relation.setName("address");
+        relation.setBeanId("Address");
+        relation.setMandatory(XMLMetaValue.OPTIONAL);
+//        relation.setDisplayName("UserAddress");
+        bean.putBeanRef(relation);
+
+        infos.getBeans().add(bean2);
+
+        String xml = XMLMapper.getInstance().getXStream().toXML(infos);
+//        System.out.println(xml);
+        XMLMetaBeanInfos infos2 =
+              (XMLMetaBeanInfos) XMLMapper.getInstance().getXStream().fromXML(xml);
+        assertEquals(2, infos2.getBeans().size());
+    }
+
+
+    public void testMaxValueParsing() {
+        String xml = "\n" +
+              "<beanInfos>  <bean id=\"com.agimatec.connecta.model.Profile\">\n" +
+              "    <property name=\"activationDay\" minValue=\"1\" maxValue=\"31\"/>\n" +
+              "    <property name=\"activationMonth\" minValue=\"1\" maxValue=\"12\"/>\n" +
+              "  </bean></beanInfos>";
+        XMLMetaBeanInfos beanInfos = (XMLMetaBeanInfos) XMLMapper.getInstance()
+              .getXStream().fromXML(xml);
+        assertNotNull(beanInfos);
+        assertEquals(Integer.valueOf(31),
+              beanInfos.getBeans().get(0).getProperty("activationDay").getMaxValue());
+        assertEquals(Integer.valueOf(1),
+              beanInfos.getBeans().get(0).getProperty("activationDay").getMinValue());
+    }
+
+    public static Test suite() {
+        return new TestSuite(XMLMetaBeanInfosTest.class);
+    }
+}

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/xml/XMLMetaBeanInfosTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/xml/XMLMetaBeanInfosTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/trunk/bval-core/src/test/java/org/apache/bval/xml/XMLMetaBeanInfosTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/trunk/bval-core/src/test/resources/log4j.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/resources/log4j.xml?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/resources/log4j.xml (added)
+++ incubator/bval/trunk/bval-core/src/test/resources/log4j.xml Sun Mar 28 12:28:25 2010
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!--                                                                       -->
+<!--  Log4j Configuration                                                  -->
+<!--                                                                       -->
+<!-- ===================================================================== -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+    <param name="Threshold" value="DEBUG"/>
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%d %-5p %c - %m%n"/>
+    </layout>
+  </appender>
+
+  <root>
+    <appender-ref ref="CONSOLE"/>
+  </root>
+
+</log4j:configuration>

Propchange: incubator/bval/trunk/bval-core/src/test/resources/log4j.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/resources/log4j.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: incubator/bval/trunk/bval-core/src/test/resources/log4j.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/bval/trunk/bval-core/src/test/resources/org/apache/bval/example/test-beanInfos-custom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/test/resources/org/apache/bval/example/test-beanInfos-custom.xml?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/test/resources/org/apache/bval/example/test-beanInfos-custom.xml (added)
+++ incubator/bval/trunk/bval-core/src/test/resources/org/apache/bval/example/test-beanInfos-custom.xml Sun Mar 28 12:28:25 2010
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beanInfos>
+
+  <bean id="org.apache.bval.example.BusinessObject"
+        impl="org.apache.bval.example.BusinessObject">
+    <property name="lastName" mandatory="false"/>
+    <property name="unknownName" mandatory="true"/>
+  </bean>
+
+  <bean id="UnknownObject" impl="org.apache.bval.UnknownClass">
+    <property name="fullName" mandatory="true"/>
+  </bean>
+</beanInfos>
\ No newline at end of file

Propchange: incubator/bval/trunk/bval-core/src/test/resources/org/apache/bval/example/test-beanInfos-custom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/trunk/bval-core/src/test/resources/org/apache/bval/example/test-beanInfos-custom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: incubator/bval/trunk/bval-core/src/test/resources/org/apache/bval/example/test-beanInfos-custom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message