[jboss-cvs] JBossAS SVN: r73708 - in projects/jboss-deployers/trunk: deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 27 08:16:37 EDT 2008
Author: alesj
Date: 2008-05-27 08:16:37 -0400 (Tue, 27 May 2008)
New Revision: 73708
Added:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployerHelper.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleJBossXBDeployer.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleObjectModelFactoryDeployer.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java
Removed:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java
Modified:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleSchemaResolverDeployer.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/ObjectModelFactoryDeployer.java
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/vfs/deployer/merge/support/MultiRarDeployer.java
Log:
Refactoring to make (Multiple)OMFD easier to implement.
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/merge/support/MultiRarDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/merge/support/MultiRarDeployer.java 2008-05-27 11:37:31 UTC (rev 73707)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/merge/support/MultiRarDeployer.java 2008-05-27 12:16:37 UTC (rev 73708)
@@ -35,7 +35,7 @@
*/
public class MultiRarDeployer extends MultipleSchemaResolverDeployer<RarDeploymentMetaData>
{
- private static Map<String, Class<?>> getMappings()
+ private static Map<String, Class<?>> getCustomMappings()
{
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
mappings.put("rar.xml", RarMetaData.class);
@@ -47,7 +47,7 @@
public MultiRarDeployer()
{
- super(RarDeploymentMetaData.class, getMappings());
+ super(RarDeploymentMetaData.class, getCustomMappings());
}
protected RarDeploymentMetaData mergeMetaData(VFSDeploymentUnit unit, Map<Class<?>, List<Object>> metadata) throws Exception
Deleted: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java 2008-05-27 11:37:31 UTC (rev 73707)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java 2008-05-27 12:16:37 UTC (rev 73708)
@@ -1,185 +0,0 @@
-/*
-* 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.spi.deployer;
-
-import java.io.InputStream;
-
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.xb.annotations.JBossXmlSchema;
-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;
-
-/**
- * JBossXB deployer.
- *
- * @param <T> the expected type
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- */
-public abstract class JBossXBDeployer<T> extends AbstractVFSParsingDeployer<T>
-{
- /** Unmarshaller factory */
- private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
-
- /** The singleton schema resolver */
- private static DefaultSchemaResolver resolver = (DefaultSchemaResolver)SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
-
- /** Whether the Unmarshaller will use schema validation */
- private boolean useSchemaValidation = true;
-
- /** Whether to validate */
- private boolean useValidation = true;
-
- /**
- * Create a new SchemaResolverDeployer.
- *
- * @param output the output
- * @throws IllegalArgumentException for a null output
- */
- protected JBossXBDeployer(Class<T> output)
- {
- super(output);
- }
-
- /**
- * Get the useSchemaValidation.
- *
- * @return the useSchemaValidation.
- */
- public boolean isUseSchemaValidation()
- {
- return useSchemaValidation;
- }
-
- /**
- * Set the useSchemaValidation.
- *
- * @param useSchemaValidation the useSchemaValidation.
- */
- public void setUseSchemaValidation(boolean useSchemaValidation)
- {
- this.useSchemaValidation = useSchemaValidation;
- }
-
- /**
- * Get the useValidation.
- *
- * @return the useValidation.
- */
- public boolean isUseValidation()
- {
- return useValidation;
- }
-
- /**
- * Set the useValidation.
- *
- * @param useValidation the useValidation.
- */
- public void setUseValidation(boolean useValidation)
- {
- this.useValidation = useValidation;
- }
-
- /**
- * Add class binding.
- *
- * @param namespace the namespace
- * @param metadata the metadata
- */
- protected void addClassBinding(String namespace, Class<?> metadata)
- {
- resolver.addClassBinding(namespace, metadata);
- }
-
- /**
- * Remove class binding.
- *
- * @param namespace the namespace
- */
- protected void removeClassBinding(String namespace)
- {
- resolver.removeClassBinding(namespace);
- }
-
- /**
- * Find the namespace on class/package
- *
- * @param metadata the metadata class
- * @return jboss xml schema namespace
- */
- protected static String findNamespace(Class<?> metadata)
- {
- JBossXmlSchema jBossXmlSchema = metadata.getAnnotation(JBossXmlSchema.class);
- if (jBossXmlSchema == null)
- {
- Package pckg = metadata.getPackage();
- if (pckg != null)
- jBossXmlSchema = pckg.getAnnotation(JBossXmlSchema.class);
- }
- return jBossXmlSchema != null ? jBossXmlSchema.namespace() : null;
- }
-
- /**
- * Parse the file to create metadata instance.
- *
- * @param expectedType the expected type
- * @param file the file
- * @return new metadata instance
- * @throws Exception for any error
- */
- protected <U> U parse(Class<U> expectedType, VirtualFile file) throws Exception
- {
- if (expectedType == null)
- throw new IllegalArgumentException("Null expected type");
- if (file == null)
- throw new IllegalArgumentException("Null file");
-
- log.debug("Parsing file: "+file+" for type: " + expectedType);
- Unmarshaller unmarshaller = factory.newUnmarshaller();
- unmarshaller.setSchemaValidation(isUseSchemaValidation());
- unmarshaller.setValidation(isUseValidation());
- InputStream is = openStreamAndValidate(file);
- Object parsed = null;
- try
- {
- parsed = unmarshaller.unmarshal(is, resolver);
- log.debug("Parsed file: "+file+" to: "+parsed);
- }
- finally
- {
- try
- {
- is.close();
- }
- catch (Exception ignored)
- {
- }
- }
- if (parsed == null)
- throw new DeploymentException("The xml " + file.getPathName() + " is not well formed!");
-
- return expectedType.cast(parsed);
- }
-}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java (from rev 73696, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/ObjectModelFactoryDeployer.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java 2008-05-27 12:16:37 UTC (rev 73708)
@@ -0,0 +1,96 @@
+/*
+* 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.spi.deployer;
+
+/**
+ * JBoss XB deployer.
+ *
+ * @param <T> the expected type
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class JBossXBDeployer<T> extends AbstractVFSParsingDeployer<T>
+{
+ /** The helper */
+ private JBossXBDeployerHelper<T> helper;
+
+ /**
+ * Create a new SchemaResolverDeployer.
+ *
+ * @param output the output
+ * @throws IllegalArgumentException for a null output
+ */
+ public JBossXBDeployer(Class<T> output)
+ {
+ super(output);
+ this.helper = new JBossXBDeployerHelper<T>(output);
+ }
+
+ /**
+ * Get the helper.
+ *
+ * @return the helper
+ */
+ protected JBossXBDeployerHelper<T> getHelper()
+ {
+ return helper;
+ }
+
+ /**
+ * Get the useSchemaValidation.
+ *
+ * @return the useSchemaValidation.
+ */
+ public boolean isUseSchemaValidation()
+ {
+ return helper.isUseSchemaValidation();
+ }
+
+ /**
+ * Set the useSchemaValidation.
+ *
+ * @param useSchemaValidation the useSchemaValidation.
+ */
+ public void setUseSchemaValidation(boolean useSchemaValidation)
+ {
+ helper.setUseSchemaValidation(useSchemaValidation);
+ }
+
+ /**
+ * Get the useValidation.
+ *
+ * @return the useValidation.
+ */
+ public boolean isUseValidation()
+ {
+ return helper.isUseValidation();
+ }
+
+ /**
+ * Set the useValidation.
+ *
+ * @param useValidation the useValidation.
+ */
+ public void setUseValidation(boolean useValidation)
+ {
+ helper.setUseValidation(useValidation);
+ }
+}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployerHelper.java (from rev 73696, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployerHelper.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployerHelper.java 2008-05-27 12:16:37 UTC (rev 73708)
@@ -0,0 +1,264 @@
+/*
+* 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.spi.deployer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.xb.annotations.JBossXmlSchema;
+import org.jboss.xb.binding.ObjectModelFactory;
+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;
+
+/**
+ * JBossXB deployer.
+ *
+ * @param <T> the expected type
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class JBossXBDeployerHelper<T>
+{
+ /** The log */
+ private Logger log = Logger.getLogger(JBossXBDeployerHelper.class);
+
+ /** Unmarshaller factory */
+ private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
+
+ /** The singleton schema resolver */
+ private static DefaultSchemaResolver resolver = (DefaultSchemaResolver)SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+
+ /** The output */
+ private Class<T> output;
+
+ /** Whether the Unmarshaller will use schema validation */
+ private boolean useSchemaValidation = true;
+
+ /** Whether to validate */
+ private boolean useValidation = true;
+
+ /**
+ * Create a new SchemaResolverDeployer.
+ *
+ * @param output the output
+ * @throws IllegalArgumentException for a null output
+ */
+ protected JBossXBDeployerHelper(Class<T> output)
+ {
+ if (output == null)
+ throw new IllegalArgumentException("Null output.");
+ this.output = output;
+ }
+
+ /**
+ * Get the useSchemaValidation.
+ *
+ * @return the useSchemaValidation.
+ */
+ public boolean isUseSchemaValidation()
+ {
+ return useSchemaValidation;
+ }
+
+ /**
+ * Set the useSchemaValidation.
+ *
+ * @param useSchemaValidation the useSchemaValidation.
+ */
+ public void setUseSchemaValidation(boolean useSchemaValidation)
+ {
+ this.useSchemaValidation = useSchemaValidation;
+ }
+
+ /**
+ * Get the useValidation.
+ *
+ * @return the useValidation.
+ */
+ public boolean isUseValidation()
+ {
+ return useValidation;
+ }
+
+ /**
+ * Set the useValidation.
+ *
+ * @param useValidation the useValidation.
+ */
+ public void setUseValidation(boolean useValidation)
+ {
+ this.useValidation = useValidation;
+ }
+
+ /**
+ * Add class binding.
+ *
+ * @param namespace the namespace
+ * @param metadata the metadata
+ */
+ public static void addClassBinding(String namespace, Class<?> metadata)
+ {
+ resolver.addClassBinding(namespace, metadata);
+ }
+
+ /**
+ * Remove class binding.
+ *
+ * @param namespace the namespace
+ */
+ public static void removeClassBinding(String namespace)
+ {
+ resolver.removeClassBinding(namespace);
+ }
+
+ /**
+ * Find the namespace on class/package
+ *
+ * @param metadata the metadata class
+ * @return jboss xml schema namespace
+ */
+ public static String findNamespace(Class<?> metadata)
+ {
+ JBossXmlSchema jBossXmlSchema = metadata.getAnnotation(JBossXmlSchema.class);
+ if (jBossXmlSchema == null)
+ {
+ Package pckg = metadata.getPackage();
+ if (pckg != null)
+ jBossXmlSchema = pckg.getAnnotation(JBossXmlSchema.class);
+ }
+ return jBossXmlSchema != null ? jBossXmlSchema.namespace() : null;
+ }
+
+ /**
+ * Parse file to output metadata.
+ *
+ * @param file the file to parse
+ * @return new metadata instance
+ * @throws Exception for any error
+ */
+ public T parse(VirtualFile file) throws Exception
+ {
+ return parse(output, file);
+ }
+
+ /**
+ * Parse the file to create metadata instance.
+ *
+ * @param expectedType the expected type
+ * @param file the file
+ * @return new metadata instance
+ * @throws Exception for any error
+ */
+ public <U> U parse(Class<U> expectedType, VirtualFile file) throws Exception
+ {
+ if (expectedType == null)
+ throw new IllegalArgumentException("Null expected type");
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+
+ log.debug("Parsing file: "+file+" for type: " + expectedType);
+ Unmarshaller unmarshaller = factory.newUnmarshaller();
+ unmarshaller.setSchemaValidation(isUseSchemaValidation());
+ unmarshaller.setValidation(isUseValidation());
+ InputStream is = openStreamAndValidate(file);
+ Object parsed = null;
+ try
+ {
+ parsed = unmarshaller.unmarshal(is, resolver);
+ log.debug("Parsed file: "+file+" to: "+parsed);
+ }
+ finally
+ {
+ try
+ {
+ is.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ if (parsed == null)
+ throw new DeploymentException("The xml " + file.getPathName() + " is not well formed!");
+
+ return expectedType.cast(parsed);
+ }
+
+ /**
+ * Parse the file using object model factory.
+ *
+ * @param expectedType the expected type
+ * @param file the file to parse
+ * @param root the previous root
+ * @param omf the object model factory
+ * @return new metadata instance
+ * @throws Exception for any error
+ */
+ public <U> U parseWithObjectModelFactory(Class<U> expectedType, VirtualFile file, U root, ObjectModelFactory omf) throws Exception
+ {
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+
+ log.debug("Parsing file: "+file+" for deploymentType: " + expectedType);
+
+ Unmarshaller unmarshaller = factory.newUnmarshaller();
+ unmarshaller.setSchemaValidation(isUseSchemaValidation());
+ unmarshaller.setValidation(isUseValidation());
+ Object parsed = null;
+ try
+ {
+ URL url = file.toURL();
+ parsed = unmarshaller.unmarshal(url.toString(), omf, root);
+ }
+ catch (Throwable t)
+ {
+ DeploymentException.rethrowAsDeploymentException("Error parsing meta data " + file.getPathName(), t);
+ }
+ if (parsed == null)
+ throw new DeploymentException("The xml " + file.getPathName() + " is not well formed!");
+
+ return expectedType.cast(parsed);
+ }
+
+ /**
+ * Open stream and validate if not null.
+ *
+ * @param file the virtual file
+ * @return non-null input stream
+ * @throws Exception for any error or if file's stream is null
+ */
+ protected static InputStream openStreamAndValidate(VirtualFile file) throws Exception
+ {
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+
+ InputStream inputStream = SecurityActions.openStream(file);
+ if (inputStream == null)
+ throw new IOException("Null file stream: " + file);
+
+ return inputStream;
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployerHelper.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Added: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleJBossXBDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleJBossXBDeployer.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleJBossXBDeployer.java 2008-05-27 12:16:37 UTC (rev 73708)
@@ -0,0 +1,97 @@
+/*
+* 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.spi.deployer;
+
+import java.util.Map;
+
+/**
+ * MultipleObjectModelFactoryDeployer.
+ *
+ * @param <T> the expected type
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class MultipleJBossXBDeployer<T> extends MultipleVFSParsingDeployer<T>
+{
+ /** The helper */
+ private JBossXBDeployerHelper<T> helper;
+
+ public MultipleJBossXBDeployer(Class<T> output, Map<String, Class<?>> mappings)
+ {
+ this(output, mappings, null, null);
+ }
+
+ public MultipleJBossXBDeployer(Class<T> output, Map<String, Class<?>> mappings, String suffix, Class<?> suffixClass)
+ {
+ super(output, mappings, suffix, suffixClass);
+ this.helper = new JBossXBDeployerHelper<T>(output);
+ }
+
+ /**
+ * Get the helper.
+ *
+ * @return the helper
+ */
+ protected JBossXBDeployerHelper<T> getHelper()
+ {
+ return helper;
+ }
+
+ /**
+ * Get the useSchemaValidation.
+ *
+ * @return the useSchemaValidation.
+ */
+ public boolean isUseSchemaValidation()
+ {
+ return helper.isUseSchemaValidation();
+ }
+
+ /**
+ * Set the useSchemaValidation.
+ *
+ * @param useSchemaValidation the useSchemaValidation.
+ */
+ public void setUseSchemaValidation(boolean useSchemaValidation)
+ {
+ helper.setUseSchemaValidation(useSchemaValidation);
+ }
+
+ /**
+ * Get the useValidation.
+ *
+ * @return the useValidation.
+ */
+ public boolean isUseValidation()
+ {
+ return helper.isUseValidation();
+ }
+
+ /**
+ * Set the useValidation.
+ *
+ * @param useValidation the useValidation.
+ */
+ public void setUseValidation(boolean useValidation)
+ {
+ helper.setUseValidation(useValidation);
+ }
+}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleObjectModelFactoryDeployer.java (from rev 73696, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleSchemaResolverDeployer.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleObjectModelFactoryDeployer.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleObjectModelFactoryDeployer.java 2008-05-27 12:16:37 UTC (rev 73708)
@@ -0,0 +1,64 @@
+/*
+* 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.spi.deployer;
+
+import java.util.Map;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.xb.binding.ObjectModelFactory;
+
+/**
+ * MultipleObjectModelFactoryDeployer.
+ *
+ * @param <T> the expected type
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class MultipleObjectModelFactoryDeployer<T> extends MultipleJBossXBDeployer<T>
+{
+ public MultipleObjectModelFactoryDeployer(Class<T> output, Map<String, Class<?>> mappings)
+ {
+ super(output, mappings);
+ }
+
+ public MultipleObjectModelFactoryDeployer(Class<T> output, Map<String, Class<?>> mappings, String suffix, Class<?> suffixClass)
+ {
+ super(output, mappings, suffix, suffixClass);
+ }
+
+ protected <U> U parse(Class<U> expectedType, VirtualFile file, Object root) throws Exception
+ {
+ U tRoot;
+ if (expectedType.isInstance(root))
+ tRoot = expectedType.cast(root);
+ else
+ tRoot = null;
+ return getHelper().parseWithObjectModelFactory(expectedType, file, tRoot, getObjectModelFactory(tRoot));
+ }
+
+ /**
+ * Get the object model factory
+ *
+ * @param root - possibly null pre-existing root
+ * @return the object model factory
+ */
+ protected abstract ObjectModelFactory getObjectModelFactory(Object root);
+}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleSchemaResolverDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleSchemaResolverDeployer.java 2008-05-27 11:37:31 UTC (rev 73707)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleSchemaResolverDeployer.java 2008-05-27 12:16:37 UTC (rev 73708)
@@ -22,16 +22,12 @@
package org.jboss.deployers.vfs.spi.deployer;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.ArrayList;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.virtual.VirtualFile;
import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.virtual.VirtualFile;
/**
* MultipleSchemaResolverDeployer.
@@ -39,10 +35,8 @@
* @param <T> the expected type
* @author <a href="ales.justin at jboss.com">Ales Justin</a>
*/
-public abstract class MultipleSchemaResolverDeployer<T> extends JBossXBDeployer<T>
+public abstract class MultipleSchemaResolverDeployer<T> extends MultipleJBossXBDeployer<T>
{
- private Map<String, Class<?>> mappings;
- private Class<?> suffixClass;
private Set<Class<?>> excluded;
private Set<String> namespaces;
@@ -58,15 +52,7 @@
public MultipleSchemaResolverDeployer(Class<T> output, Map<String, Class<?>> mappings, String suffix, Class<?> suffixClass, Set<Class<?>> excluded)
{
- super(output);
- if (mappings == null || mappings.isEmpty())
- throw new IllegalArgumentException("Illegal mappings");
- this.mappings = mappings;
- setNames(mappings.keySet());
- setSuffix(suffix);
- if (suffix != null && suffixClass == null)
- throw new IllegalArgumentException("Null suffix class");
- this.suffixClass = suffixClass;
+ super(output, mappings, suffix, suffixClass);
if (excluded == null)
excluded = Collections.emptySet();
this.excluded = excluded;
@@ -78,12 +64,12 @@
*/
public void create()
{
- for (Class<?> metadata : mappings.values())
+ for (Class<?> metadata : getMappings().values())
{
registerMetaDataClass(metadata);
}
- if (suffixClass != null)
- registerMetaDataClass(suffixClass);
+ if (getSuffixClass() != null)
+ registerMetaDataClass(getSuffixClass());
}
/**
@@ -96,14 +82,14 @@
{
if (excluded.contains(metadata) == false)
{
- String namespace = findNamespace(metadata);
+ String namespace = JBossXBDeployerHelper.findNamespace(metadata);
if (namespace == null || JBossXmlConstants.DEFAULT.equals(namespace))
throw new IllegalArgumentException(
"Registering schema with JBossXB is enabled, but cannot find namespace on class or package: " + metadata +
", perhaps missing @JBossXmlSchema or using default namespace attribute."
);
- addClassBinding(namespace, metadata);
+ JBossXBDeployerHelper.addClassBinding(namespace, metadata);
namespaces.add(namespace);
}
}
@@ -114,104 +100,12 @@
public void destroy()
{
for (String namespace : namespaces)
- removeClassBinding(namespace);
+ JBossXBDeployerHelper.removeClassBinding(namespace);
namespaces.clear();
}
- /**
- * Match file to mapping metadata class.
- *
- * @param file the file
- * @return matching metadata class
- */
- protected Class<?> matchFileToClass(VirtualFile file)
+ protected <U> U parse(Class<U> expectedType, VirtualFile file, Object root) throws Exception
{
- String fileName = file.getName();
- Class<?> result = mappings.get(fileName);
- if (result == null)
- {
- if (getSuffix() != null && fileName.endsWith(getSuffix()))
- result = suffixClass;
- }
-
- if (result == null)
- throw new IllegalArgumentException(
- "Should not be here, file '" + file +
- "' must macth some mapping " + mappings + " or suffix " + getSuffix()
- );
-
- return result;
+ return getHelper().parse(expectedType, file);
}
-
- @SuppressWarnings("unchecked")
- protected T parse(VFSDeploymentUnit unit, VirtualFile file, T root) throws Exception
- {
- Class<?> expectedClass = matchFileToClass(file);
- if (getOutput().isAssignableFrom(expectedClass) == false)
- throw new IllegalArgumentException("Matched " + expectedClass + " which is not assignable to output " + getOutput());
-
- return (T)parse(expectedClass, file);
- }
-
- protected T mergeFiles(VFSDeploymentUnit unit, T root, List<VirtualFile> files, Set<String> missingFiles) throws Exception
- {
- Map<Class<?> , List<Object>> metadata = new HashMap<Class<?>, List<Object>>();
- for (VirtualFile file : files)
- {
- Class<?> clazz = matchFileToClass(file);
- List<Object> instances = metadata.get(clazz);
- if (instances == null)
- {
- instances = new ArrayList<Object>();
- metadata.put(clazz, instances);
- }
- Object instance = parse(clazz, file);
- instances.add(instance);
- }
- return mergeMetaData(unit, root, metadata, missingFiles);
- }
-
- /**
- * Merge metadatas into single piece of metatdata
- *
- * @param unit the unit
- * @param root possibly null pre-existing root
- * @param metadata the metadatas
- * @param missingFiles file names that are missing matching file
- * @return merged metadata
- * @throws Exception for any error
- */
- protected T mergeMetaData(VFSDeploymentUnit unit, T root, Map<Class<?>, List<Object>> metadata, Set<String> missingFiles) throws Exception
- {
- return mergeMetaData(unit, metadata);
- }
-
- /**
- * Merge metadatas into single piece of metatdata
- *
- * @param unit the unit
- * @param metadata the metadatas
- * @return merged metadata
- * @throws Exception for any error
- */
- protected abstract T mergeMetaData(VFSDeploymentUnit unit, Map<Class<?>, List<Object>> metadata) throws Exception;
-
-
- /**
- * Get single metadata instance from metadata.
- *
- * @param metadata the metadatas map
- * @param clazz metadata class
- * @return matching metadata instance
- */
- protected <S> S getInstance(Map<Class<?>, List<Object>> metadata, Class<S> clazz)
- {
- List<Object> instances = metadata.get(clazz);
- if (instances == null || instances.isEmpty())
- return null;
- else if (instances.size() > 1)
- throw new IllegalArgumentException("Expecting single instance: " + metadata);
-
- return clazz.cast(instances.iterator().next());
- }
}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java (from rev 73696, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/JBossXBDeployer.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java 2008-05-27 12:16:37 UTC (rev 73708)
@@ -0,0 +1,193 @@
+/*
+* 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.spi.deployer;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Multiple VFS parsing deployer.
+ *
+ * @param <T> the expected type
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class MultipleVFSParsingDeployer<T> extends AbstractVFSParsingDeployer<T>
+{
+ private Map<String, Class<?>> mappings;
+ private Class<?> suffixClass;
+
+ public MultipleVFSParsingDeployer(Class<T> output, Map<String, Class<?>> mappings)
+ {
+ this(output, mappings, null, null);
+ }
+
+ public MultipleVFSParsingDeployer(Class<T> output, Map<String, Class<?>> mappings, String suffix, Class<?> suffixClass)
+ {
+ super(output);
+ if (mappings == null || mappings.isEmpty())
+ throw new IllegalArgumentException("Illegal mappings");
+ this.mappings = mappings;
+ setNames(mappings.keySet());
+ setSuffix(suffix);
+ if (suffix != null && suffixClass == null)
+ throw new IllegalArgumentException("Null suffix class");
+ this.suffixClass = suffixClass;
+ }
+
+ /**
+ * Match file to mapping metadata class.
+ *
+ * @param file the file
+ * @return matching metadata class
+ */
+ protected Class<?> matchFileToClass(VirtualFile file)
+ {
+ String fileName = file.getName();
+ Class<?> result = mappings.get(fileName);
+ if (result == null)
+ {
+ if (getSuffix() != null && fileName.endsWith(getSuffix()))
+ result = suffixClass;
+ }
+
+ if (result == null)
+ throw new IllegalArgumentException(
+ "Should not be here, file '" + file +
+ "' must macth some mapping " + mappings + " or suffix " + getSuffix()
+ );
+
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected T parse(VFSDeploymentUnit unit, VirtualFile file, T root) throws Exception
+ {
+ Class<?> expectedType = matchFileToClass(file);
+ if (getOutput().isAssignableFrom(expectedType) == false)
+ throw new IllegalArgumentException("Matched " + expectedType + " which is not assignable to output " + getOutput());
+ if (root != null && expectedType.isInstance(root) == false)
+ throw new IllegalArgumentException("Illegal root type: " + root + ", expecting " + expectedType);
+
+ return (T)parse(expectedType, file, root);
+ }
+
+ /**
+ * Parse file to produce expected class metadata.
+ *
+ * Root doesn't have U signature, since it conflicts
+ * with its usage in the parse(VFSDeployment unit, VirtualFile file, T root) method.
+ *
+ * @param expectedType the expected class
+ * @param file the file to parse
+ * @param root the previous root
+ * @return new metadata instance
+ * @throws Exception for any error
+ */
+ protected abstract <U> U parse(Class<U> expectedType, VirtualFile file, Object root) throws Exception;
+
+ protected T mergeFiles(VFSDeploymentUnit unit, T root, List<VirtualFile> files, Set<String> missingFiles) throws Exception
+ {
+ Map<Class<?> , List<Object>> metadata = new HashMap<Class<?>, List<Object>>();
+ for (VirtualFile file : files)
+ {
+ Class<?> clazz = matchFileToClass(file);
+ List<Object> instances = metadata.get(clazz);
+ if (instances == null)
+ {
+ instances = new ArrayList<Object>();
+ metadata.put(clazz, instances);
+ }
+ Object instance = parse(clazz, file, root);
+ instances.add(instance);
+ }
+ return mergeMetaData(unit, root, metadata, missingFiles);
+ }
+
+ /**
+ * Merge metadatas into single piece of metatdata
+ *
+ * @param unit the unit
+ * @param root possibly null pre-existing root
+ * @param metadata the metadatas
+ * @param missingFiles file names that are missing matching file
+ * @return merged metadata
+ * @throws Exception for any error
+ */
+ protected T mergeMetaData(VFSDeploymentUnit unit, T root, Map<Class<?>, List<Object>> metadata, Set<String> missingFiles) throws Exception
+ {
+ return mergeMetaData(unit, metadata);
+ }
+
+ /**
+ * Merge metadatas into single piece of metatdata
+ *
+ * @param unit the unit
+ * @param metadata the metadatas
+ * @return merged metadata
+ * @throws Exception for any error
+ */
+ protected abstract T mergeMetaData(VFSDeploymentUnit unit, Map<Class<?>, List<Object>> metadata) throws Exception;
+
+ /**
+ * Get single metadata instance from metadata.
+ *
+ * @param metadata the metadatas map
+ * @param clazz metadata class
+ * @return matching metadata instance
+ */
+ protected <S> S getInstance(Map<Class<?>, List<Object>> metadata, Class<S> clazz)
+ {
+ List<Object> instances = metadata.get(clazz);
+ if (instances == null || instances.isEmpty())
+ return null;
+ else if (instances.size() > 1)
+ throw new IllegalArgumentException("Expecting single instance: " + metadata);
+
+ return clazz.cast(instances.iterator().next());
+ }
+
+ /**
+ * Get mappings.
+ *
+ * @return the mappings
+ */
+ public Map<String, Class<?>> getMappings()
+ {
+ return mappings;
+ }
+
+ /**
+ * Get suffix class.
+ *
+ * @return the suffix mathing class
+ */
+ public Class<?> getSuffixClass()
+ {
+ return suffixClass;
+ }
+}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/ObjectModelFactoryDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/ObjectModelFactoryDeployer.java 2008-05-27 11:37:31 UTC (rev 73707)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/ObjectModelFactoryDeployer.java 2008-05-27 12:16:37 UTC (rev 73708)
@@ -21,14 +21,9 @@
*/
package org.jboss.deployers.vfs.spi.deployer;
-import java.net.URL;
-
-import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.virtual.VirtualFile;
import org.jboss.xb.binding.ObjectModelFactory;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.UnmarshallerFactory;
/**
* ObjectModelFactoryDeployer extends the AbstractParsingDeployer to add an
@@ -39,19 +34,11 @@
* @param <T> the expected type
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author Scott.Stark at jboss.org
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public abstract class ObjectModelFactoryDeployer<T> extends AbstractVFSParsingDeployer<T>
+public abstract class ObjectModelFactoryDeployer<T> extends JBossXBDeployer<T>
{
- /** Unmarshaller factory */
- private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
-
- /** Whether the Unmarshaller will use schema validation */
- private boolean useSchemaValidation = true;
-
- /** Whether to validate */
- private boolean useValidation = true;
-
/**
* Create a new SchemaResolverDeployer.
*
@@ -63,72 +50,10 @@
super(output);
}
- /**
- * Get the useSchemaValidation.
- *
- * @return the useSchemaValidation.
- */
- public boolean isUseSchemaValidation()
- {
- return useSchemaValidation;
- }
-
- /**
- * Set the useSchemaValidation.
- *
- * @param useSchemaValidation the useSchemaValidation.
- */
- public void setUseSchemaValidation(boolean useSchemaValidation)
- {
- this.useSchemaValidation = useSchemaValidation;
- }
-
- /**
- * Get the useValidation.
- *
- * @return the useValidation.
- */
- public boolean isUseValidation()
- {
- return useValidation;
- }
-
- /**
- * Set the useValidation.
- *
- * @param useValidation the useValidation.
- */
- public void setUseValidation(boolean useValidation)
- {
- this.useValidation = useValidation;
- }
-
@Override
protected T parse(VFSDeploymentUnit unit, VirtualFile file, T root) throws Exception
{
- if (file == null)
- throw new IllegalArgumentException("Null file");
-
- log.debug("Parsing file: "+file+" for deploymentType: " + getOutput());
-
- Unmarshaller unmarshaller = factory.newUnmarshaller();
- unmarshaller.setSchemaValidation(isUseSchemaValidation());
- unmarshaller.setValidation(isUseValidation());
- Object parsed = null;
- try
- {
- ObjectModelFactory factory = getObjectModelFactory(root);
- URL url = file.toURL();
- parsed = unmarshaller.unmarshal(url.toString(), factory, root);
- }
- catch (Throwable t)
- {
- DeploymentException.rethrowAsDeploymentException("Error parsing meta data " + file.getPathName(), t);
- }
- if (parsed == null)
- throw new DeploymentException("The xml " + file.getPathName() + " is not well formed!");
-
- return getOutput().cast(parsed);
+ return getHelper().parseWithObjectModelFactory(getOutput(), file, root, getObjectModelFactory(root));
}
/**
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-05-27 11:37:31 UTC (rev 73707)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/SchemaResolverDeployer.java 2008-05-27 12:16:37 UTC (rev 73708)
@@ -90,14 +90,14 @@
{
if (isRegisterWithJBossXB())
{
- namespace = findNamespace(getOutput());
+ namespace = JBossXBDeployerHelper.findNamespace(getOutput());
if (namespace == null || JBossXmlConstants.DEFAULT.equals(namespace))
throw new IllegalArgumentException(
"RegisterWithJBossXB is enabled, but cannot find namespace on class or package: " + getOutput() +
", perhaps missing @JBossXmlSchema or using default namespace attribute."
);
- addClassBinding(namespace, getOutput());
+ JBossXBDeployerHelper.addClassBinding(namespace, getOutput());
}
}
@@ -109,7 +109,7 @@
if (isRegisterWithJBossXB())
{
// namespace should exist, since we got past create
- removeClassBinding(namespace);
+ JBossXBDeployerHelper.removeClassBinding(namespace);
}
}
@@ -117,6 +117,6 @@
{
if (file == null)
throw new IllegalArgumentException("Null file");
- return parse(getOutput(), file);
+ return getHelper().parse(file);
}
}
More information about the jboss-cvs-commits
mailing list