[jboss-cvs] JBossAS SVN: r60707 - in projects/microcontainer/branches/2_0/deployers/src: resources/tests and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 20 01:44:19 EST 2007


Author: scott.stark at jboss.org
Date: 2007-02-20 01:44:19 -0500 (Tue, 20 Feb 2007)
New Revision: 60707

Added:
   projects/microcontainer/branches/2_0/deployers/src/resources/tests/jaxp/
   projects/microcontainer/branches/2_0/deployers/src/resources/tests/jaxp/somebean.jbean
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/SomeBean.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/TestXmlDeployer.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/test/
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/test/JAXPDeployerUnitTestCase.java
Modified:
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/JAXPDeployer.java
Log:
JBMICROCONT-144, check for a Document attachment to allow for management overrides.

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/JAXPDeployer.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/JAXPDeployer.java	2007-02-20 06:06:03 UTC (rev 60706)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/JAXPDeployer.java	2007-02-20 06:44:19 UTC (rev 60707)
@@ -33,11 +33,17 @@
 import org.xml.sax.InputSource;
 
 /**
- * SchemaResolverDeployer.
+ * JAXPDeployer is an abstract deployer that overrides parse to run a jaxp
+ * parse of the VirtualFile passed to parse.
  * 
+ * 
+ * @see #parse(DeploymentUnit, VirtualFile, T)
+ * @see #doParse(DeploymentUnit, VirtualFile)
+ * 
  * @param <T> the expected type 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
  */
 public abstract class JAXPDeployer<T> extends AbstractParsingDeployer<T>
 {
@@ -145,10 +151,18 @@
     */
    protected T parse(DeploymentUnit unit, VirtualFile file, T root) throws Exception
    {
-      Document document = doParse(unit, file);
+      // First look for an existing Document attachment 
+      Document document = unit.getAttachment(Document.class);
+      if( document == null )
+      {
+         // Next parse the metadata file
+         document = doParse(unit, file);
+      }
+
+      // Transform the document into a T instance
       return parse(unit, file, document);
    }
-   
+
    /**
     * Do the parsing
     * 


Property changes on: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/JAXPDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/microcontainer/branches/2_0/deployers/src/resources/tests/jaxp/somebean.jbean
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/resources/tests/jaxp/somebean.jbean	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/resources/tests/jaxp/somebean.jbean	2007-02-20 06:44:19 UTC (rev 60707)
@@ -0,0 +1 @@
+<somebean name="bean1" version="1.0" />
\ No newline at end of file

Added: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/SomeBean.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/SomeBean.java	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/SomeBean.java	2007-02-20 06:44:19 UTC (rev 60707)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.jaxp.support;
+
+/**
+ * A bean created by the JAXPDeployer parse.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class SomeBean
+{
+   private String name;
+   private String version;
+
+   public String getName()
+   {
+      return name;
+   }
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   public String getVersion()
+   {
+      return version;
+   }
+   public void setVersion(String version)
+   {
+      this.version = version;
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/SomeBean.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/TestXmlDeployer.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/TestXmlDeployer.java	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/TestXmlDeployer.java	2007-02-20 06:44:19 UTC (rev 60707)
@@ -0,0 +1,44 @@
+package org.jboss.test.deployers.jaxp.support;
+
+import org.jboss.deployers.plugins.deployers.helpers.JAXPDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.virtual.VirtualFile;
+import org.w3c.dom.Document;
+
+public class TestXmlDeployer extends JAXPDeployer<SomeBean>
+{
+   private SomeBean lastBean;
+
+   public TestXmlDeployer()
+   {
+      super(SomeBean.class);
+   }
+
+   public SomeBean getLastBean()
+   {
+      return lastBean;
+   }
+
+   @Override
+   protected SomeBean parse(DeploymentUnit unit, VirtualFile file, Document doc)
+      throws Exception
+   {
+      String name = doc.getDocumentElement().getAttribute("name");
+      String version = doc.getDocumentElement().getAttribute("version");
+
+      SomeBean bean = new SomeBean();
+      bean.setName(name);
+      bean.setVersion(version);
+      lastBean = bean;
+      return bean;
+   }
+
+   @Override
+   public void deploy(DeploymentUnit unit)
+      throws DeploymentException
+   {
+      createMetaData(unit, null, ".jbean");
+   }
+
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/support/TestXmlDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/test/JAXPDeployerUnitTestCase.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/test/JAXPDeployerUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/test/JAXPDeployerUnitTestCase.java	2007-02-20 06:44:19 UTC (rev 60707)
@@ -0,0 +1,126 @@
+/*
+* 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.jaxp.test;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.plugins.deployment.MainDeployerImpl;
+import org.jboss.deployers.plugins.structure.vfs.file.FileStructure;
+import org.jboss.deployers.plugins.structure.vfs.jar.JARStructure;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.deployers.spi.structure.DeploymentState;
+import org.jboss.test.deployers.BaseDeployersTest;
+import org.jboss.test.deployers.jaxp.support.SomeBean;
+import org.jboss.test.deployers.jaxp.support.TestXmlDeployer;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Tests of the JAXPDeployer.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class JAXPDeployerUnitTestCase extends BaseDeployersTest
+{
+   public static Test suite()
+   {
+      return new TestSuite(JAXPDeployerUnitTestCase.class);
+   }
+
+   private MainDeployerImpl main;
+   private TestXmlDeployer deployer;
+
+   public JAXPDeployerUnitTestCase(String name) throws Throwable
+   {
+      super(name);
+   }
+
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      try
+      {
+         main = new MainDeployerImpl();
+         main.addStructureDeployer(new JARStructure());
+         main.addStructureDeployer(new FileStructure());
+         
+         deployer = new TestXmlDeployer();
+         deployer.create();
+         main.addDeployer(deployer);
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException(t);
+      }
+   }
+
+   public void testDocOverride() throws Exception
+   {
+      DeploymentContext context = createDeploymentContext("/jaxp", "somebean.jbean");
+      assertDeploy(context, null, null);
+      SomeBean bean = deployer.getLastBean();
+      assertNotNull(bean);
+      assertEquals("bean.name", bean.getName(), "bean1");
+      assertEquals("bean.version", bean.getVersion(), "1.0");
+
+      // Now deploy with an overriden Document
+      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+      DocumentBuilder builder = factory.newDocumentBuilder();
+      DOMImplementation dom = builder.getDOMImplementation();
+      Document doc = dom.createDocument(null, "somebean", null);
+      Element root = doc.getDocumentElement();
+      root.setAttribute("name", "bean1.1");
+      root.setAttribute("version", "1.1");
+      assertDeploy(context, Document.class, doc);
+
+      bean = deployer.getLastBean();
+      assertNotNull(bean);
+      assertEquals("bean.name", bean.getName(), "bean1.1");
+      assertEquals("bean.version", bean.getVersion(), "1.1");
+
+      assertUndeploy(context);
+   }
+
+   protected <T> void assertDeploy(DeploymentContext context, Class<T> clazz, T mo)
+      throws Exception
+   {
+      main.addDeploymentContext(context);
+      if( mo != null )
+         context.getTransientManagedObjects().addAttachment(clazz, mo);
+      main.process();
+      assertEquals("DeploymentState", DeploymentState.DEPLOYED, context.getState());
+   }
+
+   protected void assertUndeploy(DeploymentContext context)
+      throws Exception
+   {
+      main.removeDeploymentContext(context.getName());
+      main.process();
+      assertEquals("DeploymentState", DeploymentState.UNDEPLOYED, context.getState());
+   }
+}


Property changes on: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/jaxp/test/JAXPDeployerUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list