[jboss-cvs] JBossAS SVN: r73091 - in projects/jboss-jsr303/trunk: core/src/main/org/jboss/jsr303/core/plugins and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 6 18:59:23 EDT 2008
Author: alesj
Date: 2008-05-06 18:59:23 -0400 (Tue, 06 May 2008)
New Revision: 73091
Added:
projects/jboss-jsr303/trunk/core/src/main/org/jboss/jsr303/core/plugins/
projects/jboss-jsr303/trunk/core/src/main/org/jboss/jsr303/core/plugins/BaseValidator.java
projects/jboss-jsr303/trunk/core/src/main/org/jboss/jsr303/core/spi/
projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/core/
projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/core/XmlToMetaData.java
projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/
projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/BeanMetaData.java
projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ConstraintMetaData.java
projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ConstraintsMetaData.java
projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ParameterMetaData.java
projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/PropertyMetaData.java
projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/parser/
projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/parser/ConstraintsParser.java
Log:
Emmanuel's learning code. :-)
Added: projects/jboss-jsr303/trunk/core/src/main/org/jboss/jsr303/core/plugins/BaseValidator.java
===================================================================
--- projects/jboss-jsr303/trunk/core/src/main/org/jboss/jsr303/core/plugins/BaseValidator.java (rev 0)
+++ projects/jboss-jsr303/trunk/core/src/main/org/jboss/jsr303/core/plugins/BaseValidator.java 2008-05-06 22:59:23 UTC (rev 73091)
@@ -0,0 +1,135 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jsr303.core.plugins;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
+import javax.validation.ElementDescriptor;
+import javax.validation.InvalidConstraint;
+import javax.validation.Validator;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.config.spi.Configuration;
+import org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.repository.MetaDataRepository;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.reflect.spi.FieldInfo;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BaseValidator<T> implements Validator<T>
+{
+ MetaDataRepository repository = new BasicMetaDataRepository();
+ Configuration configuration = new PropertyConfiguration();
+
+ public Set<InvalidConstraint<T>> validate(T object, String... groups)
+ {
+ Set<InvalidConstraint<T>> invalid = new HashSet<InvalidConstraint<T>>();
+ try
+ {
+ ScopeKey key = new ScopeKey(CommonLevels.INSTANCE, object.getClass());
+ MetaData metaData = repository.getMetaData(key);
+ BeanInfo beanInfo = configuration.getBeanInfo(object.getClass());
+
+ checkForConstraints(object, invalid, metaData);
+
+ Set<PropertyInfo> properties = beanInfo.getProperties();
+ for (PropertyInfo pi : properties)
+ {
+ FieldInfo fi = pi.getFieldInfo();
+ Signature signature;
+ if (fi != null)
+ signature = new FieldSignature(fi.getName());
+ else
+ signature = new MethodSignature(pi.getGetter());
+
+ MetaData componentMetaData = metaData.getComponentMetaData(signature);
+ checkForConstraints(pi.get(object), invalid, componentMetaData);
+ }
+
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+ catch (Throwable t)
+ {
+ }
+ return null;
+ }
+
+ private void checkForConstraints(Object object, Set<InvalidConstraint<T>> invalid, MetaData metaData)
+ throws InstantiationException, IllegalAccessException
+ {
+ Annotation[] annotations = metaData.getAnnotations();
+ for(Annotation annotation : annotations)
+ {
+ ConstraintValidator cv = annotation.annotationType().getAnnotation(ConstraintValidator.class);
+ if (cv != null)
+ {
+ Class<? extends Constraint> constraintClass = cv.value();
+ Constraint constraint = constraintClass.newInstance();
+ boolean isValid = constraint.isValid(object);
+ if (isValid == false)
+ invalid.add(null);
+ }
+ }
+ }
+
+ public Set<InvalidConstraint<T>> validateProperty(T object, String propertyName, String... groups)
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Set<InvalidConstraint<T>> validateValue(String propertyName, Object value, String... groups)
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean hasConstraints()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ElementDescriptor getBeanConstraints()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ElementDescriptor getConstraintsForProperty(String propertyName)
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Set<String> getValidatedProperties()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Added: projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/core/XmlToMetaData.java
===================================================================
--- projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/core/XmlToMetaData.java (rev 0)
+++ projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/core/XmlToMetaData.java 2008-05-06 22:59:23 UTC (rev 73091)
@@ -0,0 +1,57 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jsr303.xml.core;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.config.spi.Configuration;
+import org.jboss.jsr303.xml.metadata.BeanMetaData;
+import org.jboss.jsr303.xml.metadata.ConstraintMetaData;
+import org.jboss.jsr303.xml.metadata.PropertyMetaData;
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.signature.FieldSignature;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class XmlToMetaData
+{
+ static Configuration configuration = new PropertyConfiguration();
+
+ public static void fillMetaData(BeanMetaData bmd) throws Exception
+ {
+ MemoryMetaDataLoader metaData = new MemoryMetaDataLoader(new ScopeKey(CommonLevels.CLASS, bmd.getName()));
+ BeanInfo beanInfo = configuration.getBeanInfo(bmd.getName(), null);
+
+ for (PropertyMetaData pmd : bmd.getFields())
+ {
+ String name = pmd.getName();
+ ScopeKey scope = new ScopeKey(CommonLevels.JOINPOINT_OVERRIDE, name);
+ MemoryMetaDataLoader loader = new MemoryMetaDataLoader(scope);
+ metaData.addComponentMetaDataRetrieval(new FieldSignature(name), loader);
+ for(ConstraintMetaData cmd : pmd.getConstraints())
+ loader.addAnnotation(cmd.getAnnotationInstance(null));
+ }
+ }
+}
Added: projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/BeanMetaData.java
===================================================================
--- projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/BeanMetaData.java (rev 0)
+++ projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/BeanMetaData.java 2008-05-06 22:59:23 UTC (rev 73091)
@@ -0,0 +1,71 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jsr303.xml.metadata;
+
+import java.util.Set;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at XmlType(name="beansType", propOrder={"fields", "getters"})
+public class BeanMetaData
+{
+ private String name;
+ private Set<PropertyMetaData> fields;
+ private Set<PropertyMetaData> getters;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ @XmlAttribute
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public Set<PropertyMetaData> getFields()
+ {
+ return fields;
+ }
+
+ @XmlElement(name = "field")
+ public void setFields(Set<PropertyMetaData> fields)
+ {
+ this.fields = fields;
+ }
+
+ public Set<PropertyMetaData> getGetters()
+ {
+ return getters;
+ }
+
+ @XmlElement(name = "getter")
+ public void setGetters(Set<PropertyMetaData> getters)
+ {
+ this.getters = getters;
+ }
+}
Added: projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ConstraintMetaData.java
===================================================================
--- projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ConstraintMetaData.java (rev 0)
+++ projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ConstraintMetaData.java 2008-05-06 22:59:23 UTC (rev 73091)
@@ -0,0 +1,68 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jsr303.xml.metadata;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.annotation.factory.AnnotationCreator;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at XmlType(name="constraintType", propOrder={"parameters"})
+public class ConstraintMetaData
+{
+ private String className;
+ private List<ParameterMetaData> parameters;
+
+ public Annotation getAnnotationInstance(ClassLoader classLoader) throws Exception
+ {
+ String annotationExp = "@" + className + "(" + ")";
+ return (Annotation)AnnotationCreator.createAnnotation(annotationExp, classLoader);
+ }
+
+ public String getClassName()
+ {
+ return className;
+ }
+
+ @XmlAttribute(name = "class")
+ public void setClassName(String className)
+ {
+ this.className = className;
+ }
+
+ public List<ParameterMetaData> getParameters()
+ {
+ return parameters;
+ }
+
+ @XmlElement(name = "param")
+ public void setParameters(List<ParameterMetaData> parameters)
+ {
+ this.parameters = parameters;
+ }
+}
\ No newline at end of file
Added: projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ConstraintsMetaData.java
===================================================================
--- projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ConstraintsMetaData.java (rev 0)
+++ projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ConstraintsMetaData.java 2008-05-06 22:59:23 UTC (rev 73091)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jsr303.xml.metadata;
+
+import java.util.Set;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at JBossXmlSchema(namespace="urn:jboss:jsr-303", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="deployment")
+ at XmlType(name="constraintsType", propOrder={"beans"})
+public class ConstraintsMetaData
+{
+ private Set<BeanMetaData> beans;
+
+ public Set<BeanMetaData> getBeans()
+ {
+ return beans;
+ }
+
+ @XmlElement(name = "bean")
+ public void setBeans(Set<BeanMetaData> beans)
+ {
+ this.beans = beans;
+ }
+}
Added: projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ParameterMetaData.java
===================================================================
--- projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ParameterMetaData.java (rev 0)
+++ projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/ParameterMetaData.java 2008-05-06 22:59:23 UTC (rev 73091)
@@ -0,0 +1,58 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jsr303.xml.metadata;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlValue;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at XmlType(name="parameterType")
+public class ParameterMetaData
+{
+ private String name;
+ private Object value;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ @XmlAttribute
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+
+ @XmlValue
+ public void setValue(Object value)
+ {
+ this.value = value;
+ }
+}
\ No newline at end of file
Added: projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/PropertyMetaData.java
===================================================================
--- projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/PropertyMetaData.java (rev 0)
+++ projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/metadata/PropertyMetaData.java 2008-05-06 22:59:23 UTC (rev 73091)
@@ -0,0 +1,70 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jsr303.xml.metadata;
+
+import java.util.Set;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at XmlType(name="propertyType", propOrder={"constraints"})
+public class PropertyMetaData
+{
+ private String name;
+ private Set<ConstraintMetaData> constraints;
+ private boolean ignoreOnClass;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ @XmlAttribute
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public Set<ConstraintMetaData> getConstraints()
+ {
+ return constraints;
+ }
+
+ @XmlElement(name = "constraint")
+ public void setConstraints(Set<ConstraintMetaData> constraints)
+ {
+ this.constraints = constraints;
+ }
+
+ public boolean isIgnoreOnClass()
+ {
+ return ignoreOnClass;
+ }
+
+ public void setIgnoreOnClass(boolean ignoreOnClass)
+ {
+ this.ignoreOnClass = ignoreOnClass;
+ }
+}
\ No newline at end of file
Added: projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/parser/ConstraintsParser.java
===================================================================
--- projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/parser/ConstraintsParser.java (rev 0)
+++ projects/jboss-jsr303/trunk/xml/src/main/org/jboss/jsr303/xml/parser/ConstraintsParser.java 2008-05-06 22:59:23 UTC (rev 73091)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jsr303.xml.parser;
+
+import java.io.InputStream;
+
+import org.jboss.jsr303.xml.metadata.ConstraintsMetaData;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ConstraintsParser
+{
+ private static UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
+ private static DefaultSchemaResolver resolver = (DefaultSchemaResolver)SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+
+ static
+ {
+ resolver.addClassBinding("urn:jboss:jsr-303", ConstraintsMetaData.class);
+ }
+
+ public static ConstraintsMetaData parseConstraintsMetaData(InputStream inputStream) throws Exception
+ {
+ Unmarshaller unmarshaller = factory.newUnmarshaller();
+ Object parsed = unmarshaller.unmarshal(inputStream, resolver);
+ return ConstraintsMetaData.class.cast(parsed);
+ }
+}
More information about the jboss-cvs-commits
mailing list