You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by mb...@apache.org on 2018/02/25 20:10:37 UTC
[2/8] bval git commit: remove obsolete modules,
moving required core code to jsr
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMapper.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMapper.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMapper.java
deleted file mode 100644
index 69562b8..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMapper.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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/>
- */
-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;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBean.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBean.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBean.java
deleted file mode 100644
index 4aab9ab..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBean.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 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/>
- */
-@XStreamAlias("bean")
-public class XMLMetaBean extends XMLFeaturesCapable {
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
- @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<XMLMetaProperty>();
- 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<XMLMetaBeanReference>();
- 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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanBuilder.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanBuilder.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanBuilder.java
deleted file mode 100644
index 771b169..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanBuilder.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * 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 org.apache.bval.IntrospectorMetaBeanFactory;
-import org.apache.bval.MetaBeanBuilder;
-import org.apache.bval.MetaBeanFactory;
-import org.apache.bval.model.MetaBean;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Description: <br>
- * User: roman.stumm<br>
- * Date: 17.06.2010<br>
- * Time: 10:10:46<br>
- */
-public class XMLMetaBeanBuilder extends MetaBeanBuilder {
- private XMLMetaBeanFactory xmlFactory;
-
- public XMLMetaBeanBuilder(MetaBeanFactory[] factories) {
- setFactories(factories);
- }
-
- public XMLMetaBeanBuilder() {
- setFactories(new MetaBeanFactory[] { new IntrospectorMetaBeanFactory(), new XMLMetaBeanFactory() });
- }
-
- @Override
- public void setFactories(MetaBeanFactory[] factories) {
- super.setFactories(factories);
- updateXmlFactory();
- }
-
- public void addLoader(XMLMetaBeanLoader loader) {
- assertXmlFactory();
- xmlFactory.addLoader(loader);
- }
-
- @Override
- public MetaBean buildForId(String beanInfoId) throws Exception {
- final XMLMetaBeanFactory.Visitor v;
- assertXmlFactory();
- xmlFactory.visitXMLBeanMeta(beanInfoId, v = new XMLMetaBeanFactory.Visitor() {
- private MetaBean meta;
-
- @Override
- public MetaBean getMetaBean() {
- return meta;
- }
-
- @Override
- public void visit(XMLMetaBean xmlMeta, XMLMetaBeanInfos xmlInfos) throws Exception {
- if (meta == null) {
- meta = createMetaBean(xmlMeta);
- }
- xmlFactory.enrichMetaBean(meta, new XMLMetaBeanFactory.XMLResult(xmlMeta, xmlInfos));
- }
-
- });
- if (v.getMetaBean() == null) {
- throw new IllegalArgumentException("MetaBean " + beanInfoId + " not found");
- }
- return v.getMetaBean();
- }
-
- @Override
- public Map<String, MetaBean> buildAll() throws Exception {
- final Map<String, MetaBean> all = super.buildAll();
- if (xmlFactory != null) {
- xmlFactory.visitXMLBeanMeta(null, new XMLMetaBeanFactory.Visitor() {
- @Override
- public void visit(XMLMetaBean empty, XMLMetaBeanInfos xmlInfos) throws Exception {
- if (xmlInfos.getBeans() == null)
- return; // empty file, ignore
- XMLMetaBeanFactory.XMLResult carrier = new XMLMetaBeanFactory.XMLResult(null, xmlInfos);
-
- for (XMLMetaBean xmlMeta : xmlInfos.getBeans()) {
- MetaBean meta = all.get(xmlMeta.getId());
- if (meta == null) {
- meta = createMetaBean(xmlMeta);
- all.put(xmlMeta.getId(), meta);
- }
- carrier.xmlMeta = xmlMeta;
- xmlFactory.enrichMetaBean(meta, carrier);
- }
- }
-
- @Override
- public MetaBean getMetaBean() {
- return null; // do nothing
- }
- });
- }
- return all;
- }
-
- public Map<String, MetaBean> enrichCopies(Map<String, MetaBean> all, XMLMetaBeanInfos... infosArray)
- throws Exception {
- assertXmlFactory();
- final Map<String, MetaBean> copies = new HashMap<String, MetaBean>(all.size());
- boolean nothing = true;
- XMLMetaBeanFactory.XMLResult carrier = new XMLMetaBeanFactory.XMLResult();
- for (XMLMetaBeanInfos xmlMetaBeanInfos : infosArray) {
- carrier.xmlInfos = xmlMetaBeanInfos;
- if (xmlMetaBeanInfos == null)
- continue;
- try {
- for (XMLMetaBean xmlMeta : xmlMetaBeanInfos.getBeans()) {
- nothing = false;
- MetaBean copy = copies.get(xmlMeta.getId());
- if (copy == null) { // ist noch nicht kopiert
- MetaBean meta = all.get(xmlMeta.getId());
- if (meta == null) { // gibt es nicht
- copy = createMetaBean(xmlMeta);
- } else { // gibt es, jetzt kopieren
- copy = meta.copy();
- }
- copies.put(xmlMeta.getId(), copy);
- }
- carrier.xmlMeta = xmlMeta;
- xmlFactory.enrichMetaBean(copy, carrier);
- }
- } catch (IOException e) {
- xmlFactory.handleLoadException(xmlMetaBeanInfos, e);
- }
- }
- if (nothing)
- return all;
- for (Map.Entry<String, MetaBean> entry : all.entrySet()) {
- /*
- * alle unveraenderten werden AUCH KOPIERT (nur zwar nur, wegen
- * potentieller CrossReferenzen durch Relationships)
- */
- if (!copies.containsKey(entry.getKey())) {
- if (entry.getValue().hasRelationships()) {
- copies.put(entry.getKey(), (MetaBean) entry.getValue().copy());
- } else { // no relationship: do not clone()
- copies.put(entry.getKey(), entry.getValue());
- }
- }
- }
- return copies;
- }
-
- private MetaBean createMetaBean(XMLMetaBean xmlMeta) throws Exception {
- return buildForClass(findLocalClass(xmlMeta.getImpl()));
- }
-
- private void updateXmlFactory() {
- for (MetaBeanFactory each : getFactories()) {
- if (each instanceof XMLMetaBeanFactory) { // use the first one!
- xmlFactory = (XMLMetaBeanFactory) each;
- return;
- }
- }
- xmlFactory = null; // none
- }
-
- public XMLMetaBeanFactory getXmlFactory() {
- return xmlFactory;
- }
-
- private void assertXmlFactory() {
- if (xmlFactory == null) {
- throw new IllegalStateException("no xmlFactory available");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanFactory.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanFactory.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanFactory.java
deleted file mode 100644
index 27407d9..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanFactory.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * 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 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 java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static org.apache.bval.model.Features.Property.JAVASCRIPT_VALIDATION_FUNCTIONS;
-
-/**
- * Description: Create or enrich MetaBeans from apache beanInfos xml<br/>
- */
-public class XMLMetaBeanFactory implements MetaBeanFactory {
- private static final Logger logger = Logger.getLogger(XMLMetaBeanFactory.class.getName());
-
- // use LinkedHashMap to keep sequence of loaders
- private final Map<XMLMetaBeanLoader, XMLMetaBeanInfos> resources =
- new LinkedHashMap<XMLMetaBeanLoader, XMLMetaBeanInfos>();
-
- 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() {
- }
- }
-
- @Override
- public void buildMetaBean(final MetaBean metaBean) throws Exception {
- if (metaBean.getId() == null)
- return;
- visitXMLBeanMeta(metaBean.getId(), new Visitor() {
- @Override
- public void visit(XMLMetaBean xmlMeta, XMLMetaBeanInfos xmlInfos) throws Exception {
- enrichMetaBean(metaBean, new XMLResult(xmlMeta, xmlInfos));
- }
-
- @Override
- 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);
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- protected void enrichValidations(FeaturesCapable prop, XMLFeaturesCapable xmlProp, XMLResult result,
- boolean addStandard) throws Exception {
- if (xmlProp.getValidators() != null) {
- // obsolete code? remove from here --->
- 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));
- } // <--- to here
- 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) {
- logger.log(Level.SEVERE, String.format("Error loading %s", loader), e);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanInfos.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanInfos.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanInfos.java
deleted file mode 100644
index 0126fc6..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanInfos.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.bval.util.reflection.Reflection;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Description: root element of a xml-beanInfos document<br/>
- */
-@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() {
- final HashMap<String, XMLMetaBean> map = new HashMap<String, XMLMetaBean>(beans.size());
- for (XMLMetaBean bean : beans) {
- map.put(bean.getId(), bean);
- }
- beanLookup = new ConcurrentHashMap<String, XMLMetaBean>(map);
- }
-
- private void initValidationLookup() throws Exception {
- final HashMap<String, XMLMetaValidator> map = new HashMap<String, XMLMetaValidator>(validators.size());
- for (XMLMetaValidator xv : validators) {
- if (xv.getJava() != null) {
- Validation validation = (Validation) Reflection.toClass(xv.getJava())
- .getConstructor().newInstance();
- xv.setValidation(validation);
- map.put(xv.getId(), xv);
- }
- }
- validationLookup = new ConcurrentHashMap<String, XMLMetaValidator>(map);
- }
-
- public void addBean(XMLMetaBean bean) {
- if (beans == null)
- beans = new ArrayList<XMLMetaBean>();
- 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<XMLMetaValidator>();
- validators.add(validator);
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanLoader.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanLoader.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanLoader.java
deleted file mode 100644
index 851c74e..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanLoader.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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/>
- */
-public interface XMLMetaBeanLoader {
- XMLMetaBeanInfos load() throws IOException;
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java
deleted file mode 100644
index 38c8f94..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * 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 org.apache.bval.MetaBeanManager;
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.MetaProperty;
-import org.apache.bval.util.reflection.Reflection;
-import org.apache.commons.weaver.privilizer.Privilizing;
-import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
-
-import java.util.Map;
-
-import static org.apache.bval.model.Features.Property.REF_BEAN_ID;
-
-/**
- * Description: internal implementation class to construct metabeans with
- * factories and from xstream xml files. You can register different
- * XMLMetaBeanLoaders (see addLoader()) to register xstream-xml-files that
- * contain meta-data. You can merge + unify meta data with method
- * enrichCopies(). <br/>
- * User: roman.stumm<br>
- * Date: 17.06.2010<br>
- * Time: 09:47:14<br>
- */
-@Privilizing(@CallTo(Reflection.class))
-public class XMLMetaBeanManager extends MetaBeanManager implements XMLMetaBeanRegistry, MetaBeanEnricher {
- public XMLMetaBeanManager() {
- this(new XMLMetaBeanBuilder());
- }
-
- public XMLMetaBeanManager(XMLMetaBeanBuilder builder) {
- super(builder);
- }
-
- @Override
- public void addResourceLoader(String resource) {
- addLoader(new XMLMetaBeanURLLoader(Reflection.getClassLoader(getClass()).getResource(resource)));
- }
-
- @Override
- public synchronized void addLoader(XMLMetaBeanLoader loader) {
- ((XMLMetaBeanBuilder) builder).addLoader(loader);
- cache.clear(); // clear because new loaders can affect ALL MetaBeans
- // already created!
- complete = false;
- }
-
- /**
- * @param infos
- * - the patches to apply
- * @return all MetaBeans for classes that have a xml descriptor and
- * additional the MetaBeans loaded by the given loaders. The given
- * loaders may also return patches for MetaBeans that have also been
- * returned by other loaders. The beans with patches for references
- * to patched beans will be copied.
- */
- @Override
- public Map<String, MetaBean> enrichCopies(XMLMetaBeanInfos... infos) {
- Map<String, MetaBean> cached = findAll();
- try {
- Map<String, MetaBean> patched = ((XMLMetaBeanBuilder) builder).enrichCopies(cached, infos);
- for (Object entry : patched.values()) {
- MetaBean meta = (MetaBean) entry;
- computeRelationships(meta, patched);
- }
- return patched;
- } catch (RuntimeException e) {
- throw e; // do not wrap runtime exceptions
- } catch (Exception e) {
- throw new IllegalArgumentException("error enriching beanInfos", e);
- }
- }
-
- /**
- *
- * @return all MetaBeans for classes that have a xml descriptor: key =
- * bean.id, value = MetaBean
- */
- public Map<String, MetaBean> findAll() {
- if (!complete) {
- try {
- Map<String, MetaBean> allBuilt = builder.buildAll();
- for (MetaBean meta : allBuilt.values()) {
- MetaBean cached = cache.findForId(meta.getId());
- if (cached == null) {
- cache.cache(meta);
- }
- }
- Map<String, MetaBean> map = cache.findAll();
- for (Object oentry : map.values()) {
- MetaBean meta = (MetaBean) oentry;
- computeRelationships(meta, map);
- }
- complete = true;
- return map;
- } catch (RuntimeException e) {
- throw e; // do not wrap runtime exceptions
- } catch (Exception e) {
- throw new IllegalArgumentException("error creating beanInfos", e);
- }
- } else {
- return cache.findAll();
- }
- }
-
- protected void computeRelationships(MetaBean beanInfo, Map<String, MetaBean> cached) {
- for (MetaProperty prop : beanInfo.getProperties()) {
- String beanRef = (String) prop.getFeature(REF_BEAN_ID);
- if (beanRef != null) {
- prop.setMetaBean(cached.get(beanRef));
- }
- }
- }
-
- @Override
- protected void computeRelatedMetaBean(MetaProperty prop, String beanRef) {
- if (beanRef != null) {
- prop.setMetaBean(findForId(beanRef));
- } else {
- super.computeRelatedMetaBean(prop, beanRef);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManagerFactory.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManagerFactory.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManagerFactory.java
deleted file mode 100644
index 2fea938..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManagerFactory.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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 org.apache.bval.MetaBeanFinder;
-
-/**
- * Description: <br>
- * User: roman.stumm<br>
- * Date: 17.06.2010<br>
- * Time: 10:06:37<br>
- */
-public class XMLMetaBeanManagerFactory {
- private static XMLMetaBeanManager manager = new XMLMetaBeanManager();
-
- /**
- * global meta bean finder.
- * @return
- */
- public static MetaBeanFinder getFinder() {
- return manager;
- }
-
- /**
- * set global meta bean manager, that is responsible
- * for finding, caching, xml registry and enrichment algorithm.
- * @param finder
- */
- public static void setManager(XMLMetaBeanManager finder) {
- manager = finder;
- }
-
- /**
- * global meta bean registry
- * @return
- */
- public static XMLMetaBeanRegistry getRegistry() {
- return manager;
- }
-
- /**
- * global meta bean enricher
- * @return
- */
- public static MetaBeanEnricher getEnricher() {
- return manager;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanReference.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanReference.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanReference.java
deleted file mode 100644
index 9bc1153..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanReference.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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 org.apache.bval.model.Features;
-import org.apache.bval.model.MetaProperty;
-
-/**
- * Description: <br/>
- */
-@XStreamAlias("relationship")
-public class XMLMetaBeanReference extends XMLMetaElement {
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
- @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(Features.Property.REF_BEAN_ID, getBeanId());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanRegistry.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanRegistry.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanRegistry.java
deleted file mode 100644
index ef11f98..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanRegistry.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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/>
- */
-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);
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanURLLoader.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanURLLoader.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanURLLoader.java
deleted file mode 100644
index d26d0ef..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanURLLoader.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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/>
- */
-public class XMLMetaBeanURLLoader implements XMLMetaBeanLoader {
- private final URL url;
-
- public XMLMetaBeanURLLoader(URL url) {
- if (url == null)
- throw new NullPointerException("URL required");
- this.url = url;
- }
-
- @Override
- 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();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaElement.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaElement.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaElement.java
deleted file mode 100644
index 09da499..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaElement.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * 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.XStreamAsAttribute;
-import org.apache.bval.model.MetaProperty;
-import org.apache.bval.util.reflection.Reflection;
-
-import static org.apache.bval.model.Features.Property.DENIED;
-import static org.apache.bval.model.Features.Property.HIDDEN;
-import static org.apache.bval.model.Features.Property.MANDATORY;
-import static org.apache.bval.model.Features.Property.MAX_LENGTH;
-import static org.apache.bval.model.Features.Property.MIN_LENGTH;
-import static org.apache.bval.model.Features.Property.READONLY;
-
-/**
- * Description: <br/>
- */
-public class XMLMetaElement extends XMLFeaturesCapable {
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
- @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(Reflection.toClass(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());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaFeature.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaFeature.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaFeature.java
deleted file mode 100644
index 79776b7..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaFeature.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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/>
- */
-@XStreamAlias("feature")
-public class XMLMetaFeature implements Serializable {
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
- @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;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaProperty.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaProperty.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaProperty.java
deleted file mode 100644
index 4b22f37..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaProperty.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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 org.apache.bval.model.MetaProperty;
-
-import static org.apache.bval.model.Features.Property.MAX_VALUE;
-import static org.apache.bval.model.Features.Property.MIN_VALUE;
-import static org.apache.bval.model.Features.Property.REG_EXP;
-import static org.apache.bval.model.Features.Property.TIME_LAG;
-
-/**
- * Description: <br/>
- */
-@XStreamAlias("property")
-public class XMLMetaProperty extends XMLMetaElement {
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
- /**
- * if you need other types (Long, double, String) for maxValue and
- * minValue, configure via
- * <pre>
- * <feature key="maxValue">
- * <value class="java.lang.Long">1000</value>
- * </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());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValidator.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValidator.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValidator.java
deleted file mode 100644
index 9bb7f95..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValidator.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 org.apache.bval.model.Validation;
-
-import java.io.Serializable;
-
-/**
- * Description: <br/>
- */
-@XStreamAlias("validator")
-public class XMLMetaValidator implements Serializable {
-
- @XStreamOmitField
- private static final long serialVersionUID = 1L;
-
- @XStreamAsAttribute
- private String id;
- @XStreamAsAttribute
- private String java; // implementation of Validation
-
- @XStreamAsAttribute
- private String jsFunction; // name of java script function
-
- @XStreamOmitField
- private transient 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;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValidatorReference.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValidatorReference.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValidatorReference.java
deleted file mode 100644
index c6627c5..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValidatorReference.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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/>
- */
-@XStreamAlias("validator-ref")
-public class XMLMetaValidatorReference implements Serializable {
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
- @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;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValue.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValue.java b/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValue.java
deleted file mode 100644
index 9da06ec..0000000
--- a/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaValue.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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/>
- */
-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";
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/test/java/org/apache/bval/example/BusinessEnum.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/test/java/org/apache/bval/example/BusinessEnum.java b/bval-xstream/src/test/java/org/apache/bval/example/BusinessEnum.java
deleted file mode 100644
index 1d793f6..0000000
--- a/bval-xstream/src/test/java/org/apache/bval/example/BusinessEnum.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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/>
- */
-public enum BusinessEnum {
- VALUE1, VALUE2, VALUE3
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/test/java/org/apache/bval/example/BusinessObject.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/test/java/org/apache/bval/example/BusinessObject.java b/bval-xstream/src/test/java/org/apache/bval/example/BusinessObject.java
deleted file mode 100644
index 4b511d5..0000000
--- a/bval-xstream/src/test/java/org/apache/bval/example/BusinessObject.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * 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/>
- */
-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;
-
- 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;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/test/java/org/apache/bval/example/BusinessObjectAddress.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/test/java/org/apache/bval/example/BusinessObjectAddress.java b/bval-xstream/src/test/java/org/apache/bval/example/BusinessObjectAddress.java
deleted file mode 100644
index 9a6c18b..0000000
--- a/bval-xstream/src/test/java/org/apache/bval/example/BusinessObjectAddress.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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/>
- */
-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;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java b/bval-xstream/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java
deleted file mode 100644
index 2d6fb78..0000000
--- a/bval-xstream/src/test/java/org/apache/bval/example/BusinessObjectBeanInfo.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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 org.apache.bval.model.Features;
-
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.PropertyDescriptor;
-import java.beans.SimpleBeanInfo;
-
-/**
- * Description: <br/>
- */
-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
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/test/java/org/apache/bval/routines/StandardValidationTest.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/test/java/org/apache/bval/routines/StandardValidationTest.java b/bval-xstream/src/test/java/org/apache/bval/routines/StandardValidationTest.java
deleted file mode 100644
index 862d39b..0000000
--- a/bval-xstream/src/test/java/org/apache/bval/routines/StandardValidationTest.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * 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.junit.Assert.assertTrue;
-
-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.Features.Property;
-import org.apache.bval.model.MetaProperty;
-import org.apache.bval.model.ValidationContext;
-import org.apache.bval.model.ValidationListener;
-import org.apache.bval.xml.XMLMetaValue;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * StandardValidation Tester.
- */
-public class StandardValidationTest implements ValidationListener {
- private StandardValidation validation;
- private BeanValidationContext<StandardValidationTest> context;
- private List<String> reasons = new ArrayList<String>();
- private MetaProperty metaProperty;
- private String stringValue;
- private Date dateValue;
- private int intValue;
-
- @Before
- public void setUp() throws Exception {
- validation = new StandardValidation();
- context = new BeanValidationContext<StandardValidationTest>(this);
- metaProperty = new MetaProperty();
- context.setBean(this, null);
- context.setMetaProperty(metaProperty);
- }
-
- public String getStringValue() {
- return stringValue;
- }
-
- @Test
- 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(Property.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(Property.MAX_LENGTH));
- }
-
- @Test
- 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(Property.MIN_LENGTH));
- }
-
- @Test
- 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(Property.MAX_VALUE));
- }
-
- @Test
- 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(Property.MIN_VALUE));
- }
-
- public int getIntValue() {
- return intValue;
- }
-
- @Test
- 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(Property.MIN_VALUE));
- }
-
- @Test
- 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(Property.MIN_VALUE));
- }
-
- @Test
- 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(Property.MAX_VALUE));
- }
-
- @Test
- 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(Property.REG_EXP));
- }
-
- public Date getDateValue() {
- return dateValue;
- }
-
- @Test
- 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(Property.TIME_LAG));
-
- }
-
- @Override
- public <T extends ValidationListener> void addError(String reason, ValidationContext<T> context) {
- reasons.add(reason);
- }
-
- @Override
- public <T extends ValidationListener> void addError(ValidationListener.Error error, ValidationContext<T> context) {
- reasons.add(error.getReason());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/ed299e4f/bval-xstream/src/test/java/org/apache/bval/xml/BeanValidatorTest.java
----------------------------------------------------------------------
diff --git a/bval-xstream/src/test/java/org/apache/bval/xml/BeanValidatorTest.java b/bval-xstream/src/test/java/org/apache/bval/xml/BeanValidatorTest.java
deleted file mode 100644
index e7ea584..0000000
--- a/bval-xstream/src/test/java/org/apache/bval/xml/BeanValidatorTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import org.apache.bval.BeanValidator;
-import org.apache.bval.MetaBeanFinder;
-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.Features.Property;
-import org.apache.bval.model.MetaBean;
-import org.junit.Test;
-
-/**
- * BeanValidator Tester.
- */
-public class BeanValidatorTest {
-
- @Test
- public void testValidateMapAsBean() {
- XMLMetaBeanManagerFactory.getRegistry()
- .addLoader(new XMLMetaBeanURLLoader(BusinessObject.class.getResource("test-beanInfos.xml")));
-
- MetaBean mb = XMLMetaBeanManagerFactory.getFinder().findForId("org.apache.bval.example.Address");
-
- // 1. validate a bean
- BusinessObjectAddress adr = new BusinessObjectAddress();
- BeanValidator<ValidationResults> validator = new BeanValidator<ValidationResults>();
- 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<String, Object>(), 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<Object, Object>(), mb);
- assertTrue(results.isEmpty());
- }
-
- @Test
- public void testValidate() {
- MetaBeanFinder finder = XMLMetaBeanManagerFactory.getFinder();
- XMLMetaBeanManagerFactory.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>();
- ValidationResults results = validator.validate(object, info);
- assertTrue(results.hasErrorForReason(Property.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<BusinessObjectAddress>());
- 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
- }
-
-}