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 [3/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/model/ValidationContext.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationContext.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationContext.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationContext.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,72 @@
+/**
+ *  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.util.AccessStrategy;
+
+/**
+ * Description: Interface of the context that holds all state information
+ * during the validation process<br/>
+ * User: roman.stumm <br/>
+ * Date: 28.04.2008 <br/>
+ * Time: 09:36:02 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public interface ValidationContext<T extends ValidationListener> {
+    Object getPropertyValue();
+
+    /** get the value by using the given access strategy and cache it */
+    Object getPropertyValue(AccessStrategy access);
+
+    String getPropertyName();
+
+    T getListener();
+
+    Object getBean();
+
+    MetaBean getMetaBean();
+
+    void setMetaBean(MetaBean metaBean);
+
+    MetaProperty getMetaProperty();
+
+    void setBean(Object bean);
+
+    boolean collectValidated();
+
+    void setBean(Object aBean, MetaBean aMetaBean);
+
+    void setMetaProperty(MetaProperty metaProperty);
+
+    /** step deeper into association at 'prop' */
+    void moveDown(MetaProperty prop, AccessStrategy access);
+
+    /** step out from a validation of associated objects. */
+    void moveUp(Object bean, MetaBean metaBean);
+
+    /**
+     * set the index of the object currently validated into the context.
+     * used to create the propertyPath with [index] information for collections.
+     */
+    void setCurrentIndex(int index);
+
+    /**
+     * set the key of the object in a map currently validated into the context.
+     * used to create the propertyPath with [key] information for maps.
+     */
+    void setCurrentKey(Object key);
+}

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

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

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

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationListener.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationListener.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationListener.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/model/ValidationListener.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,81 @@
+/**
+ *  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 java.io.Serializable;
+
+import org.apache.bval.ValidationResults;
+
+
+/**
+ * Description: The interface to collect errors found during validation<br/>
+ * User: roman.stumm <br/>
+ * Date: 06.07.2007 <br/>
+ * Time: 13:18:24 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public interface ValidationListener {
+    /**
+     * Simple API to add an error reason during validation.
+     * Error notification added from a {@link Validation} with context information
+     * taken from the given {@link ValidationContext}.
+     *
+     * @param reason  a constant describing the reason. This is normally the key of the
+     *                feature that was violated in the object 'owner' for property 'propertyName'
+     * @param context - contains
+     *                bean =         the object that contains the error (owner)
+     *                propertyName = the Name of the attribute that caused the error
+     */
+    void addError(String reason, ValidationContext context);
+
+    /** Alternative method to add a fully initialized {@link ValidationResults.Error} object. */
+    void addError(Error error, ValidationContext context);
+
+    /**
+     * an object holding a single validation constraint violation
+     * found during the validation process.
+     */
+    public class Error implements Serializable {
+        final String reason;
+        final Object owner;
+        final String propertyName;
+
+        public Error(String aReason, Object aOwner, String aPropertyName) {
+            this.reason = aReason;
+            this.owner = aOwner;
+            this.propertyName = aPropertyName;
+        }
+
+        public String getReason() {
+            return reason;
+        }
+
+        public Object getOwner() {
+            return owner;
+        }
+
+        public String getPropertyName() {
+            return propertyName;
+        }
+
+        public String toString() {
+            return "Error{" + "reason='" + reason + '\'' + ", propertyName='" +
+                  propertyName + '\'' + '}';
+        }
+    }
+}

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

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

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

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidation.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidation.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidation.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/EMailValidation.java Sun Mar 28 12:28:25 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 org.apache.bval.routines;
+
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.bval.model.Validation;
+import org.apache.bval.model.ValidationContext;
+
+/**
+ * Description: example validation for email addresses using a regular expression
+ * (taken from hibernate EmailValidator)<br/>
+ * User: roman.stumm <br/>
+ * Date: 06.07.2007 <br/>
+ * Time: 16:51:16 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public class EMailValidation implements Validation {
+    private static String ATOM =
+            "[^\\x00-\\x1F^\\(^\\)^\\<^\\>^\\@^\\,^\\;^\\:^\\\\^\\\"^\\.^\\[^\\]^\\s]";
+    private static String DOMAIN = "(" + ATOM + "+(\\." + ATOM + "+)*";
+    private static String IP_DOMAIN = "\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\]";
+    private static final java.util.regex.Pattern DEFAULT_PATTERN;
+
+    static {
+        DEFAULT_PATTERN = java.util.regex.Pattern.compile(
+                "^" + ATOM + "+(\\." + ATOM + "+)*@"
+                        + DOMAIN
+                        + "|"
+                        + IP_DOMAIN
+                        + ")$",
+                java.util.regex.Pattern.CASE_INSENSITIVE
+        );
+    }
+
+    private java.util.regex.Pattern pattern = DEFAULT_PATTERN;
+
+    public void validate(ValidationContext context) {
+        if (context.getPropertyValue() == null) return;
+        if (!isValid(context.getPropertyValue(), pattern)) {
+            context.getListener().addError(Reasons.EMAIL_ADDRESS, context);
+        }
+    }
+
+    public Pattern getPattern() {
+        return pattern;
+    }
+
+    public void setPattern(Pattern pattern) {
+        this.pattern = pattern;
+    }
+
+    public static boolean isValid(Object value) {
+        return isValid(value, DEFAULT_PATTERN);
+    }
+
+    private static boolean isValid(Object value, Pattern aPattern) {
+        if (value == null) return true;
+        if (!(value instanceof String)) return false;
+        String string = (String) value;
+        if (string.length() == 0) return true;
+        Matcher m = aPattern.matcher(string);
+        return m.matches();
+    }
+
+}

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

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

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

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/NOPValidation.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/NOPValidation.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/NOPValidation.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/NOPValidation.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,34 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bval.routines;
+
+import org.apache.bval.model.Validation;
+import org.apache.bval.model.ValidationContext;
+
+/**
+ * Description: DO NOTHING VALIDATION (can be used to turn off standard validation)<br/>
+ * User: roman.stumm <br/>
+ * Date: 06.07.2007 <br/>
+ * Time: 16:51:28 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public class NOPValidation implements Validation {
+
+    public void validate(ValidationContext context) {
+        // do nothing
+    }
+}

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

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

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

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/Reasons.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/Reasons.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/Reasons.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/Reasons.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,35 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bval.routines;
+
+import org.apache.bval.model.Features;
+
+/**
+ * Description: StandardReasons for validation errors found in
+ * {@link org.apache.bval.ValidationResults}<br/>
+ * User: roman.stumm <br/>
+ * Date: 06.07.2007 <br/>
+ * Time: 13:20:43 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public interface Reasons extends Features.Property {
+    // The reasons inherited from Features are VALIDATION features only.
+    // INFO features are not meant to be validated.
+
+    // Add more reasons here.
+    String EMAIL_ADDRESS = "emailAddress";
+}

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

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

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

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/StandardValidation.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/StandardValidation.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/StandardValidation.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/routines/StandardValidation.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,179 @@
+/**
+ *  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 static org.apache.bval.routines.Reasons.*;
+
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.apache.bval.model.Features;
+import org.apache.bval.model.MetaProperty;
+import org.apache.bval.model.Validation;
+import org.apache.bval.model.ValidationContext;
+import org.apache.bval.xml.XMLMetaValue;
+
+/**
+ * Description: This class implements the standard validations for properties!
+ * You can subclass this class and replace the implementation
+ * in the beanInfo-xml by providing it a validation "standard"<br/>
+ * User: roman.stumm <br/>
+ * Date: 06.07.2007 <br/>
+ * Time: 12:41:06 <br/>
+ * Copyright: Agimatec GmbH 2008
+ */
+public class StandardValidation implements Validation {
+    /** key for this validation in the validation list of the beanInfos */
+    public String getValidationId() {
+        return "standard";
+    }
+
+    public void validate(ValidationContext context) {
+        validateMandatory(context);
+        validateMaxLength(context);
+        validateMinLength(context);
+        validateMaxValue(context);
+        validateMinValue(context);
+        validateRegExp(context);
+        validateTimeLag(context);
+    }
+
+    protected void validateTimeLag(ValidationContext context) {
+        String lag = (String) context.getMetaProperty().getFeature(TIME_LAG);
+        if (lag == null) return;
+        if (context.getPropertyValue() == null) return;
+        long date = ((Date) context.getPropertyValue()).getTime();
+        long now = System.currentTimeMillis();
+        if (XMLMetaValue.TIMELAG_Future.equals(lag)) {
+            if (date < now) {
+                context.getListener().addError(TIME_LAG, context);
+            }
+        } else if (XMLMetaValue.TIMELAG_Past.equals(lag)) {
+            if (date > now) {
+                context.getListener().addError(TIME_LAG, context);
+            }
+        } else {
+            throw new IllegalArgumentException("unknown timelag " + lag + " at " + context);
+        }
+    }
+
+    private static final String REG_EXP_PATTERN = "cachedRegExpPattern";
+
+    protected void validateRegExp(ValidationContext context) {
+        final MetaProperty meta = context.getMetaProperty();
+        final String regExp = (String) meta.getFeature(REG_EXP);
+        if (regExp == null) return;
+        if (context.getPropertyValue() == null) return;
+
+        final String value = String.valueOf(context.getPropertyValue());
+        try {
+            Pattern pattern = (Pattern) meta.getFeature(REG_EXP_PATTERN);
+            if (pattern == null) {
+                pattern = Pattern.compile(regExp);
+                meta.putFeature(REG_EXP_PATTERN, pattern);
+            }
+            if (!pattern.matcher(value).matches()) {
+                context.getListener().addError(REG_EXP, context);
+            }
+        } catch (PatternSyntaxException e) {
+            throw new IllegalArgumentException(
+                  "regular expression malformed. regexp " + regExp + " at " + context, e);
+        }
+    }
+
+    protected void validateMinValue(ValidationContext context) {
+        Comparable minValue = (Comparable) context.getMetaProperty().getFeature(MIN_VALUE);
+        if (minValue == null || context.getPropertyValue() == null) return;
+        if (compare(context, minValue, context.getPropertyValue()) > 0) {
+            context.getListener().addError(MIN_VALUE, context);
+        }
+    }
+
+    protected void validateMaxValue(ValidationContext context) {
+        Comparable maxValue = (Comparable) context.getMetaProperty().getFeature(MAX_VALUE);
+        if (maxValue == null || context.getPropertyValue() == null) return;
+        if (compare(context, maxValue, context.getPropertyValue()) < 0) {
+            context.getListener().addError(MAX_VALUE, context);
+        }
+    }
+
+    private int compare(ValidationContext context, Comparable constraintValue,
+                        Object currentValue) {
+        int r;
+        if (constraintValue.getClass().isAssignableFrom(currentValue.getClass())) {
+            r = constraintValue.compareTo(context.getPropertyValue());
+        } else if (currentValue instanceof Number) {
+            double dv = ((Number) currentValue).doubleValue();
+            double mdv = ((Number) constraintValue).doubleValue();
+            r = mdv > dv ? 1 : -1;
+        } else {
+            r = String.valueOf(constraintValue).compareTo(String.valueOf(currentValue));
+        }
+        return r;
+    }
+
+    protected void validateMaxLength(ValidationContext context) {
+        Integer maxLength = (Integer) context.getMetaProperty()
+              .getFeature(Features.Property.MAX_LENGTH);
+        if (maxLength == null) return;
+        if (context.getPropertyValue() == null) return;
+
+        final Object value = context.getPropertyValue();
+        int length = 0;
+        if (value instanceof String) {
+            length = ((String) value).length();
+        } else if (value instanceof Collection) {
+            length = ((Collection) value).size();
+        }
+        if (length > maxLength) {
+            context.getListener().addError(MAX_LENGTH, context);
+        }
+    }
+
+    protected void validateMinLength(ValidationContext context) {
+        Integer maxLength = (Integer) context.getMetaProperty()
+              .getFeature(Features.Property.MIN_LENGTH);
+        if (maxLength == null) return;
+        if (context.getPropertyValue() == null) return;
+
+        final Object value = context.getPropertyValue();
+        int length = 0;
+        if (value instanceof String) {
+            length = ((String) value).length();
+        } else if (value instanceof Collection) {
+            length = ((Collection) value).size();
+        }
+        if (length < maxLength) {
+            context.getListener().addError(MIN_LENGTH, context);
+        }
+    }
+
+    protected void validateMandatory(ValidationContext context) {
+        if (context.getMetaProperty().isMandatory()) {
+            if (context.getPropertyValue() == null) {
+                context.getListener().addError(MANDATORY, context);
+            }
+        }
+    }
+
+    public static StandardValidation getInstance() {
+        return new StandardValidation();
+    }
+}

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

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

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

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/AccessStrategy.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/AccessStrategy.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/AccessStrategy.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/util/AccessStrategy.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,44 @@
+/**
+ *  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.util;
+
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Type;
+
+/**
+ * Description: abstract class to encapsulate different strategies
+ * to get the value of a Property.<br/>
+ * User: roman <br/>
+ * Date: 29.10.2009 <br/>
+ * Time: 12:12:08 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public abstract class AccessStrategy {
+    /**
+     * get the value from the given instance.
+     * @param instance
+     * @return the value
+     * @throws IllegalArgumentException in case of an error
+     */
+    public abstract Object get(Object instance);
+
+    public abstract ElementType getElementType();
+
+    public abstract Type getJavaType();
+
+    public abstract String getPropertyName();
+}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLFeaturesCapable.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLFeaturesCapable.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLFeaturesCapable.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLFeaturesCapable.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,100 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bval.xml;
+
+import com.thoughtworks.xstream.annotations.XStreamImplicit;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.bval.model.FeaturesCapable;
+
+/**
+ * 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);
+        }
+    }
+}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Added: incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaBeanRegistry.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaBeanRegistry.java?rev=928387&view=auto
==============================================================================
--- incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaBeanRegistry.java (added)
+++ incubator/bval/trunk/bval-core/src/main/java/org/apache/bval/xml/XMLMetaBeanRegistry.java Sun Mar 28 12:28:25 2010
@@ -0,0 +1,39 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.bval.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);
+}

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

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

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



Mime
View raw message