[jboss-cvs] JBossAS SVN: r71307 - in projects/jboss-deployers/trunk: deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/xb and 16 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 26 12:33:59 EDT 2008
Author: alesj
Date: 2008-03-26 12:33:59 -0400 (Wed, 26 Mar 2008)
New Revision: 71307
Added:
projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/xb/
projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/xb/SchemaResolverDeployerMetaData.java
projects/jboss-deployers/trunk/deployers-vfs/src/resources/schema/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/schema/jboss-deployers-2.0.xsd
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/Common.xml
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/test/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/test/MyMetaData-foobar.xml
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/test/SchemaResolverXBTestCase.xml
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/JBossXBDeployersTestSuite.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/XBDeployersTest.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/XBDeployersTestDelegate.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/support/
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/support/TestMetaData.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/test/
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/test/SchemaResolverXBTestCase.java
Modified:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/SchemaResolverDeployer.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/DeployersVFSTestSuite.java
Log:
Adding automated schema registration to SchemaResolverDeployer.
Adding jbossxb-parser element to ease the SchemaResolverDeployer usage.
Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/xb/SchemaResolverDeployerMetaData.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/xb/SchemaResolverDeployerMetaData.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/xb/SchemaResolverDeployerMetaData.java 2008-03-26 16:33:59 UTC (rev 71307)
@@ -0,0 +1,190 @@
+/*
+* 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.deployers.vfs.plugins.xb;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.deployers.vfs.spi.deployer.SchemaResolverDeployer;
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * Shortcut for defining new schema resolver deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at JBossXmlSchema(namespace="urn:jboss:deployers:2.0", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="jbossxb-parser")
+ at XmlType(name="parserType")
+public class SchemaResolverDeployerMetaData implements Serializable, BeanMetaDataFactory
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ private String name;
+ private String metadata;
+ private String suffix;
+ private String fileName;
+ private boolean useSchemaValidation = true;
+ private boolean useValidation = true;
+ private boolean registerWithJBossXB;
+ private String jarExtension;
+ private boolean includeDeploymentFile;
+ private boolean buildManagedObject;
+
+ @XmlTransient
+ public List<BeanMetaData> getBeans()
+ {
+ if (getSuffix() == null && getFileName() == null)
+ throw new IllegalArgumentException("Both suffix and file-name are null!");
+
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(getName(), SchemaResolverDeployer.class.getName());
+ builder.addConstructorParameter(Class.class.getName(), getMetadata());
+ builder.addPropertyMetaData("suffix", getSuffix());
+ builder.addPropertyMetaData("name", getFileName());
+ builder.addPropertyMetaData("useSchemaValidation", isUseSchemaValidation());
+ builder.addPropertyMetaData("useValidation", isUseValidation());
+ builder.addPropertyMetaData("registerWithJBossXB", isRegisterWithJBossXB());
+ builder.addPropertyMetaData("includeDeploymentFile", isIncludeDeploymentFile());
+ builder.addPropertyMetaData("buildManagedObject", isBuildManagedObject());
+ return Collections.singletonList(builder.getBeanMetaData());
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ @XmlAttribute(required = true)
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getMetadata()
+ {
+ return metadata;
+ }
+
+ @XmlAttribute(required = true)
+ public void setMetadata(String metadata)
+ {
+ this.metadata = metadata;
+ }
+
+ public String getSuffix()
+ {
+ return suffix;
+ }
+
+ @XmlAttribute
+ public void setSuffix(String suffix)
+ {
+ this.suffix = suffix;
+ }
+
+ public String getFileName()
+ {
+ return fileName;
+ }
+
+ @XmlAttribute(name = "file-name")
+ public void setFileName(String fileName)
+ {
+ this.fileName = fileName;
+ }
+
+ public boolean isUseSchemaValidation()
+ {
+ return useSchemaValidation;
+ }
+
+ @XmlAttribute(name = "use-schema-validation")
+ public void setUseSchemaValidation(boolean useSchemaValidation)
+ {
+ this.useSchemaValidation = useSchemaValidation;
+ }
+
+ public boolean isUseValidation()
+ {
+ return useValidation;
+ }
+
+ @XmlAttribute(name = "use-validation")
+ public void setUseValidation(boolean useValidation)
+ {
+ this.useValidation = useValidation;
+ }
+
+ public boolean isRegisterWithJBossXB()
+ {
+ return registerWithJBossXB;
+ }
+
+ @XmlAttribute(name = "register-with-jbossxb")
+ public void setRegisterWithJBossXB(boolean registerWithJBossXB)
+ {
+ this.registerWithJBossXB = registerWithJBossXB;
+ }
+
+ public String getJarExtension()
+ {
+ return jarExtension;
+ }
+
+ @XmlAttribute(name = "jar-extension")
+ public void setJarExtension(String jarExtension)
+ {
+ this.jarExtension = jarExtension;
+ }
+
+ public boolean isIncludeDeploymentFile()
+ {
+ return includeDeploymentFile;
+ }
+
+ @XmlAttribute(name = "include-deployment-file")
+ public void setIncludeDeploymentFile(boolean includeDeploymentFile)
+ {
+ this.includeDeploymentFile = includeDeploymentFile;
+ }
+
+ public boolean isBuildManagedObject()
+ {
+ return buildManagedObject;
+ }
+
+ @XmlAttribute(name = "build-managed-object")
+ public void setBuildManagedObject(boolean buildManagedObject)
+ {
+ this.buildManagedObject = buildManagedObject;
+ }
+}
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/schema/jboss-deployers-2.0.xsd
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/schema/jboss-deployers-2.0.xsd (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/schema/jboss-deployers-2.0.xsd 2008-03-26 16:33:59 UTC (rev 71307)
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="urn:jboss:classloader:1.0"
+ xmlns="urn:jboss:classloader:1.0"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="1.0">
+
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[
+ An xml schema for the deployers xml that can be used in a -beans.xml
+ to create a schema resolver deployer.
+
+ Typical usage:
+ <jbossxb-parser xmlns="urn:jboss:deployers:2.0"
+ name="FooParser"
+ class="com.foo.MetaData"
+ suffix="-foo.xml"/> ]]>
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:element name="jbossxb-parser" type="parserType">
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[
+ The root classloader element
+ ]]>
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+
+ <xsd:complexType name="parserType">
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[
+ This parser element/type has a bunch of attributes.
+ To see which they are, check the SchemaResolverDeployer class.
+ ]]>
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:attribute name="name" type="xsd:string" required="true" />
+ <xsd:attribute name="metadata" type="xsd:string" required="true" />
+ <xsd:attribute name="suffix" type="xsd:string" required="false" />
+ <xsd:attribute name="file-name" type="xsd:string" required="false" />
+ <xsd:attribute name="use-schema-validation" type="xsd:boolean" required="false" />
+ <xsd:attribute name="use-validation" type="xsd:boolean" required="false" />
+ <xsd:attribute name="register-with-jbossxb" type="xsd:boolean" required="false" />
+ <xsd:attribute name="jar-extension" type="xsd:string" required="false" />
+ <xsd:attribute name="include-deployment-file" type="xsd:boolean" required="false" />
+ <xsd:attribute name="build-managed-object" type="xsd:boolean" required="false" />
+ </xsd:complexType>
+</xsd:schema>
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/Common.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/Common.xml (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/Common.xml 2008-03-26 16:33:59 UTC (rev 71307)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="SchemaResolverConfig" class="org.jboss.xb.binding.sunday.unmarshalling.SchemaResolverConfig">
+ <property name="bindingClasses">
+ <map keyClass="java.lang.String" valueClass="java.lang.String">
+ <entry>
+ <key>urn:jboss:deployers:2.0</key>
+ <value>org.jboss.deployers.vfs.plugins.xb.SchemaResolverDeployerMetaData</value>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
+</deployment>
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/test/MyMetaData-foobar.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/test/MyMetaData-foobar.xml (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/test/MyMetaData-foobar.xml 2008-03-26 16:33:59 UTC (rev 71307)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jboss-test xmlns="urn:jboss:mytest:1.0" name="mymetadata"/>
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/test/SchemaResolverXBTestCase.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/test/SchemaResolverXBTestCase.xml (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/org/jboss/test/deployers/vfs/xb/test/SchemaResolverXBTestCase.xml 2008-03-26 16:33:59 UTC (rev 71307)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <jbossxb-parser xmlns="urn:jboss:deployers:2.0"
+ name="deployer"
+ metadata="org.jboss.test.deployers.vfs.xb.support.TestMetaData"
+ suffix="-foobar.xml"
+ register-with-jbossxb="true"
+ />
+
+</deployment>
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/DeployersVFSTestSuite.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/DeployersVFSTestSuite.java 2008-03-26 16:33:54 UTC (rev 71306)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/DeployersVFSTestSuite.java 2008-03-26 16:33:59 UTC (rev 71307)
@@ -35,6 +35,7 @@
import org.jboss.test.deployers.vfs.structurebuilder.VFSStructureBuilderTestSuite;
import org.jboss.test.deployers.vfs.managed.VFSManagedTestSuite;
import org.jboss.test.deployers.vfs.matchers.VFSMatchersTestSuite;
+import org.jboss.test.deployers.vfs.xb.JBossXBDeployersTestSuite;
/**
* Deployers VFS Test Suite.
@@ -63,6 +64,7 @@
suite.addTest(NonMetadataDeployersTestSuite.suite());
suite.addTest(ClassLoaderTestSuite.suite());
suite.addTest(VFSMatchersTestSuite.suite());
+ suite.addTest(JBossXBDeployersTestSuite.suite());
return suite;
}
Added: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/JBossXBDeployersTestSuite.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/JBossXBDeployersTestSuite.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/JBossXBDeployersTestSuite.java 2008-03-26 16:33:59 UTC (rev 71307)
@@ -0,0 +1,49 @@
+/*
+* 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.test.deployers.vfs.xb;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.jboss.test.deployers.vfs.xb.test.SchemaResolverXBTestCase;
+
+/**
+ * JBossXB deployers extensions.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class JBossXBDeployersTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("JBossXB Deployers Tests");
+
+ suite.addTest(SchemaResolverXBTestCase.suite());
+
+ return suite;
+ }
+}
\ No newline at end of file
Added: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/XBDeployersTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/XBDeployersTest.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/XBDeployersTest.java 2008-03-26 16:33:59 UTC (rev 71307)
@@ -0,0 +1,48 @@
+/*
+* 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.test.deployers.vfs.xb;
+
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class XBDeployersTest extends MicrocontainerTest
+{
+ public XBDeployersTest(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Get the test delegate
+ *
+ * @param clazz the test class
+ * @return the delegate
+ * @throws Exception for any error
+ */
+ public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+ {
+ return new XBDeployersTestDelegate(clazz);
+ }
+}
Added: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/XBDeployersTestDelegate.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/XBDeployersTestDelegate.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/XBDeployersTestDelegate.java 2008-03-26 16:33:59 UTC (rev 71307)
@@ -0,0 +1,48 @@
+/*
+* 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.test.deployers.vfs.xb;
+
+import java.net.URL;
+
+import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class XBDeployersTestDelegate extends MicrocontainerTestDelegate
+{
+ protected XBDeployersTestDelegate(Class<?> clazz) throws Exception
+ {
+ super(clazz);
+ }
+
+ protected void deploy() throws Exception
+ {
+ String common = "/org/jboss/test/deployers/vfs/xb/Common.xml";
+ URL url = getClass().getResource(common);
+ if (url == null)
+ throw new IllegalStateException(common + " not found");
+ deploy(url);
+
+ super.deploy();
+ }
+}
\ No newline at end of file
Added: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/support/TestMetaData.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/support/TestMetaData.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/support/TestMetaData.java 2008-03-26 16:33:59 UTC (rev 71307)
@@ -0,0 +1,50 @@
+/*
+* 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.test.deployers.vfs.xb.support;
+
+import java.io.Serializable;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlAttribute;
+
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at JBossXmlSchema(namespace="urn:jboss:mytest:1.0", elementFormDefault=XmlNsForm.QUALIFIED)
+ at XmlRootElement(name="jboss-test")
+public class TestMetaData implements Serializable
+{
+ private String name;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ @XmlAttribute(required = true)
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
Added: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/test/SchemaResolverXBTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/test/SchemaResolverXBTestCase.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/xb/test/SchemaResolverXBTestCase.java 2008-03-26 16:33:59 UTC (rev 71307)
@@ -0,0 +1,76 @@
+/*
+* 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.test.deployers.vfs.xb.test;
+
+import java.net.URL;
+import java.util.Collections;
+
+import junit.framework.Test;
+import org.jboss.deployers.vfs.plugins.structure.AbstractVFSDeploymentContext;
+import org.jboss.deployers.vfs.plugins.structure.AbstractVFSDeploymentUnit;
+import org.jboss.deployers.vfs.spi.deployer.SchemaResolverDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
+import org.jboss.test.deployers.vfs.xb.XBDeployersTest;
+import org.jboss.test.deployers.vfs.xb.support.TestMetaData;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Schema resolver JBossXB test case.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SchemaResolverXBTestCase extends XBDeployersTest
+{
+ public SchemaResolverXBTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(SchemaResolverXBTestCase.class);
+ }
+
+ public void testJBossXBParser() throws Throwable
+ {
+ SchemaResolverDeployer<?> deployer = assertBean("deployer", SchemaResolverDeployer.class);
+ assertEquals(TestMetaData.class, deployer.getOutput());
+ assertEquals("-foobar.xml", deployer.getSuffix());
+ assertTrue(deployer.isRegisterWithJBossXB());
+
+ String common = "/org/jboss/test/deployers/vfs/xb/test";
+ URL url = getClass().getResource(common);
+ assertNotNull(url);
+ VirtualFile file = VFS.getRoot(url);
+ assertNotNull(file);
+
+ VFSDeploymentContext context = new AbstractVFSDeploymentContext(file, "");
+ context.setMetaDataLocations(Collections.singletonList(file));
+ AbstractVFSDeploymentUnit unit = new AbstractVFSDeploymentUnit(context);
+ deployer.deploy(unit);
+
+ TestMetaData metaData = unit.getAttachment(TestMetaData.class);
+ assertNotNull(metaData);
+ assertEquals("mymetadata", metaData.getName());
+ }
+}
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/SchemaResolverDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/SchemaResolverDeployer.java 2008-03-26 16:33:54 UTC (rev 71306)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/SchemaResolverDeployer.java 2008-03-26 16:33:59 UTC (rev 71307)
@@ -30,11 +30,13 @@
import org.jboss.xb.binding.UnmarshallerFactory;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
+import org.jboss.xb.annotations.JBossXmlSchema;
/**
* SchemaResolverDeployer.
*
* @param <T> the expected type
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author Scott.Stark at jboss.org
* @version $Revision 1.1 $
@@ -53,6 +55,9 @@
/** Whether to validate */
private boolean useValidation = true;
+ /** Whether we register with jbossxb */
+ private boolean registerWithJBossXB;
+
/**
* Create a new SchemaResolverDeployer.
*
@@ -104,6 +109,58 @@
this.useValidation = useValidation;
}
+ /**
+ * Get the registerWithJBossXB.
+ *
+ * @return the registerWithJBossXB
+ */
+ public boolean isRegisterWithJBossXB()
+ {
+ return registerWithJBossXB;
+ }
+
+ /**
+ * Set the registerWithJBossXB.
+ *
+ * @param registerWithJBossXB the registerWithJBossXB
+ */
+ public void setRegisterWithJBossXB(boolean registerWithJBossXB)
+ {
+ this.registerWithJBossXB = registerWithJBossXB;
+ }
+
+ /**
+ * Check if we need to register schema to jbossxb.
+ */
+ public void create()
+ {
+ if (isRegisterWithJBossXB())
+ {
+ SingletonSchemaResolverFactory schemaResolverFactory = SingletonSchemaResolverFactory.getInstance();
+ schemaResolverFactory.addJaxbSchema(findNamespace(), getOutput().getName());
+ }
+ }
+
+ /**
+ * Find the namespace on class/package
+ *
+ * @return jboss xml schema namespace
+ */
+ protected String findNamespace()
+ {
+ Class<T> metadata = getOutput();
+ JBossXmlSchema jBossXmlSchema = metadata.getAnnotation(JBossXmlSchema.class);
+ if (jBossXmlSchema == null)
+ {
+ Package pckg = metadata.getPackage();
+ jBossXmlSchema = pckg.getAnnotation(JBossXmlSchema.class);
+ }
+ if (jBossXmlSchema == null)
+ throw new IllegalArgumentException("RegisterWithJBossXB equals true, but cannot find @JBossXmlSchema on class or package.");
+
+ return jBossXmlSchema.namespace();
+ }
+
protected T parse(VFSDeploymentUnit unit, VirtualFile file, T root) throws Exception
{
if (file == null)
More information about the jboss-cvs-commits
mailing list