[jboss-cvs] JBossAS SVN: r57228 - in trunk/ejb3/src: main/org/jboss/ejb3/metamodel resources/test/dd test/org/jboss/ejb3/test/dd/unit

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 27 05:12:21 EDT 2006


Author: wolfc
Date: 2006-09-27 05:12:12 -0400 (Wed, 27 Sep 2006)
New Revision: 57228

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDD.java
   trunk/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDDObjectFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/metamodel/LifecycleCallback.java
   trunk/ejb3/src/resources/test/dd/application-client-test1.xml
   trunk/ejb3/src/test/org/jboss/ejb3/test/dd/unit/ApplicationClientXmlTestCase.java
Log:
EJBTHREE-718: parser

Added: trunk/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDD.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDD.java	2006-09-27 08:59:22 UTC (rev 57227)
+++ trunk/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDD.java	2006-09-27 09:12:12 UTC (rev 57228)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.ejb3.metamodel;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.security.auth.callback.CallbackHandler;
+
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.EjbRef;
+import org.jboss.metamodel.descriptor.EnvEntry;
+import org.jboss.metamodel.descriptor.EnvironmentRefGroup;
+import org.jboss.metamodel.descriptor.MessageDestinationRef;
+import org.jboss.metamodel.descriptor.PersistenceUnitRef;
+import org.jboss.metamodel.descriptor.ResourceEnvRef;
+import org.jboss.metamodel.descriptor.ResourceRef;
+
+/**
+ * This represents a application client deployment descriptor.
+ * 
+ * FIXME: should not extend EnviromentRefGroup, but InjectionHandler wants this
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ApplicationClientDD extends EnvironmentRefGroup
+{
+   private static final Logger log = Logger.getLogger(ApplicationClientDD.class);
+   
+   private String displayName;
+   
+//   protected HashMap<String, EnvEntry> envEntries = new HashMap<String, EnvEntry>();
+//   protected HashMap<String, EjbRef> ejbRefs = new HashMap<String, EjbRef>();
+//   // TODO: javaee:service-refGroup
+//   protected HashMap<String, ResourceRef> resourceRefs = new HashMap<String, ResourceRef>();
+//   protected HashMap<String, ResourceEnvRef> resourceEnvRefs = new HashMap<String, ResourceEnvRef>();
+//   protected HashMap<String, MessageDestinationRef> messageDestinationRefs = new HashMap<String, MessageDestinationRef>();
+//   protected List<PersistenceUnitRef> persistenceUnitRefs = new ArrayList<PersistenceUnitRef>();
+   
+   private List<LifecycleCallback> postConstructs = new ArrayList<LifecycleCallback>();
+   private List<LifecycleCallback> preDestroys = new ArrayList<LifecycleCallback>();
+   private String callbackHandlerClass = null;
+   
+   private int version = 5;
+   private boolean metadataComplete = false;
+   
+   public String getDisplayName()
+   {
+      return displayName;
+   }
+   
+   public void setDisplayName(String displayName)
+   {
+      this.displayName = displayName;
+   }
+   
+   public boolean isMetaDataComplete()
+   {
+      return metadataComplete;
+   }
+   
+   public void setMetadataComplete(boolean metadataComplete)
+   {
+      this.metadataComplete = metadataComplete;
+   }
+   
+   public List<LifecycleCallback> getPostConstructs()
+   {
+      return postConstructs;
+   }
+   
+   public List<LifecycleCallback> getPreDestroys()
+   {
+      return preDestroys;
+   }
+   
+   public int getVersion()
+   {
+      return version;
+   }
+   
+   public void setVersion(int version)
+   {
+      this.version = version;
+   }
+}

Added: trunk/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDDObjectFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDDObjectFactory.java	2006-09-27 08:59:22 UTC (rev 57227)
+++ trunk/ejb3/src/main/org/jboss/ejb3/metamodel/ApplicationClientDDObjectFactory.java	2006-09-27 09:12:12 UTC (rev 57228)
@@ -0,0 +1,169 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.ejb3.metamodel;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.DDObjectFactory;
+import org.jboss.metamodel.descriptor.EnvEntry;
+import org.jboss.util.xml.JBossEntityResolver;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.xml.sax.Attributes;
+
+/**
+ * A JBossXB object factory for parsing application client descriptor files.
+ * 
+ * http://java.sun.com/xml/ns/javaee/application-client_5.xsd
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ApplicationClientDDObjectFactory extends DDObjectFactory
+{
+   private static final Logger log = Logger.getLogger(ApplicationClientDDObjectFactory.class);
+   
+   private ApplicationClientDDObjectFactory()
+   {
+      
+   }
+   
+   public static ApplicationClientDD parse(URL ddResource) throws JBossXBException, IOException
+   {
+      if(ddResource == null)
+         return null;
+      
+      log.debug("found application-client.xml " + ddResource);
+      
+      ApplicationClientDDObjectFactory factory = new ApplicationClientDDObjectFactory();
+      UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+      unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, true);
+      Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+      JBossEntityResolver entityResolver = new JBossEntityResolver();
+      unmarshaller.setEntityResolver(entityResolver);
+
+      ApplicationClientDD dd = (ApplicationClientDD) unmarshaller.unmarshal(ddResource.openStream(), factory, null);
+      
+      return dd;
+   }
+   
+   /**
+    * Called when parsing character is complete.
+    */
+   public void addChild(ApplicationClientDD parent, EnvEntry entry, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addEnvEntry(entry);
+   }
+
+   public void addChild(ApplicationClientDD parent, LifecycleCallback lifecycleCallback, UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      if(localName.equals("post-construct"))
+         parent.getPostConstructs().add(lifecycleCallback);
+      else if(localName.equals("pre-destroy"))
+         parent.getPreDestroys().add(lifecycleCallback);
+      else
+         throw new IllegalArgumentException(localName);
+   }
+   
+   public Object completeRoot(Object root, UnmarshallingContext ctx, String uri, String name)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public Object newChild(ApplicationClientDD parent, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs)
+   {
+      Object child = super.newEnvRefGroupChild(localName);
+      if(child != null) return child;
+      
+      if(localName.equals("post-construct") || localName.equals("pre-destroy"))
+      {
+         child = new LifecycleCallback();
+      }
+      
+      // ignore things like display-name & description
+      
+      return child;
+   }
+   
+   public Object newRoot(Object root, UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs)
+   {
+      final ApplicationClientDD dd;
+      if(root == null)
+         root = dd = new ApplicationClientDD();
+      else
+         dd = (ApplicationClientDD) root;
+      
+      if(attrs.getLength() > 0)
+      {
+         for (int i = 0; i < attrs.getLength(); ++i)
+         {
+            if (attrs.getLocalName(i).equals("version"))
+            {
+               dd.setVersion(Integer.parseInt(attrs.getValue(i)));
+            }
+            else if(attrs.getLocalName(i).equals("metadata-complete"))
+            {
+               dd.setMetadataComplete(Boolean.parseBoolean(attrs.getValue(i)));
+            }
+            else if(attrs.getLocalName(i).equals("schemaLocation"))
+            {
+               // ignore
+            }
+            else
+               throw new IllegalArgumentException(attrs.getLocalName(i));
+         }
+      }
+      
+      return root;
+   }
+
+   /**
+    * Called when a child element with simple content is read for DD.
+    */
+   public void setValue(ApplicationClientDD dd, UnmarshallingContext navigator, String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("display-name"))
+      {
+         dd.setDisplayName(getValue(localName, value));
+      }
+//      else if(localName.equals("description"))
+//      {
+//         // ignore
+//      }
+//      else
+//         throw new IllegalArgumentException(localName);
+   }
+   
+   public void setValue(LifecycleCallback lifecycleCallback, UnmarshallingContext navigator, String namespaceURI, String localName, String value)
+   {
+      if(localName.equals("lifecycle-callback-class"))
+         lifecycleCallback.setLifecycleCallbackClass(value);
+      else if(localName.equals("lifecycle-callback-method"))
+         lifecycleCallback.setLifecycleCallbackMethod(value);
+      else
+         throw new IllegalArgumentException(localName);
+   }
+}

Added: trunk/ejb3/src/main/org/jboss/ejb3/metamodel/LifecycleCallback.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/metamodel/LifecycleCallback.java	2006-09-27 08:59:22 UTC (rev 57227)
+++ trunk/ejb3/src/main/org/jboss/ejb3/metamodel/LifecycleCallback.java	2006-09-27 09:12:12 UTC (rev 57228)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.ejb3.metamodel;
+
+/**
+ * The lifecycle-callback type specifies a method on a
+ * class to be called when a lifecycle event occurs.
+ * Note that each class may have only one lifecycle callback
+ * method for any given event and that the method may not
+ * be overloaded.
+ * 
+ * If the lifefycle-callback-class element is missing then
+ * the class defining the callback is assumed to be the
+ * component class in scope at the place in the descriptor
+ * in which the callback definition appears.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class LifecycleCallback
+{
+   private String lifecycleCallbackClass;
+   private String lifecycleCallbackMethod;
+   
+   public String getLifecycleCallbackClass()
+   {
+      return lifecycleCallbackClass;
+   }
+   
+   public void setLifecycleCallbackClass(String lifecycleCallbackClass)
+   {
+      this.lifecycleCallbackClass = lifecycleCallbackClass;
+   }
+   
+   public String getLifecycleCallbackMethod()
+   {
+      return lifecycleCallbackMethod;
+   }
+   
+   public void setLifecycleCallbackMethod(String lifecycleCallbackMethod)
+   {
+      this.lifecycleCallbackMethod = lifecycleCallbackMethod;
+   }
+}

Added: trunk/ejb3/src/resources/test/dd/application-client-test1.xml
===================================================================
--- trunk/ejb3/src/resources/test/dd/application-client-test1.xml	2006-09-27 08:59:22 UTC (rev 57227)
+++ trunk/ejb3/src/resources/test/dd/application-client-test1.xml	2006-09-27 09:12:12 UTC (rev 57228)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application-client xmlns="http://java.sun.com/xml/ns/javaee"
+                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+                    http://java.sun.com/xml/ns/javaee/application-client_5.xsd"
+                    version="5">
+	<display-name>Test1</display-name>
+	<description>application client dd test</description>
+
+	<env-entry>
+		<env-entry-name>envTest</env-entry-name>
+		<env-entry-type>java.lang.String</env-entry-type>
+		<env-entry-value>Hello world</env-entry-value>
+	</env-entry>
+	
+	<post-construct>
+		<lifecycle-callback-method>postConstruct</lifecycle-callback-method>
+	</post-construct>
+	
+	<pre-destroy>
+		<lifecycle-callback-method>preDestroy</lifecycle-callback-method>
+	</pre-destroy>
+	
+	<callback-handler>org.jboss.ejb3.test.applicationclient.client.TestCallbackHandler</callback-handler>
+</application-client>
\ No newline at end of file

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/dd/unit/ApplicationClientXmlTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/dd/unit/ApplicationClientXmlTestCase.java	2006-09-27 08:59:22 UTC (rev 57227)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/dd/unit/ApplicationClientXmlTestCase.java	2006-09-27 09:12:12 UTC (rev 57228)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.ejb3.test.dd.unit;
+
+import java.net.URL;
+import java.util.Iterator;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jboss.ejb3.metamodel.ApplicationClientDD;
+import org.jboss.ejb3.metamodel.ApplicationClientDDObjectFactory;
+import org.jboss.ejb3.metamodel.LifecycleCallback;
+import org.jboss.metamodel.descriptor.EnvEntry;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ApplicationClientXmlTestCase extends TestCase
+{
+   public void testUnmarshalDDXsd() throws Exception
+   {
+      URL xmlUrl = getResourceUrl("dd/application-client-test1.xml");
+      assertNotNull(xmlUrl);
+      ApplicationClientDD dd = ApplicationClientDDObjectFactory.parse(xmlUrl);
+      assertNotNull(dd);
+      
+      assertEquals("Test1", dd.getDisplayName());
+      //assertEquals("application client dd test", dd.getDescription());
+      
+      assertEquals(1, dd.getEnvEntries().size());
+      
+      {
+         Iterator<EnvEntry> i = dd.getEnvEntries().iterator();
+         
+         EnvEntry ee = i.next();
+         assertEquals("envTest", ee.getEnvEntryName());
+         assertEquals("java.lang.String", ee.getEnvEntryType());
+         assertEquals("Hello world", ee.getEnvEntryValue());
+      }
+      
+      assertEquals(1, dd.getPostConstructs().size());
+      
+      {
+         Iterator<LifecycleCallback> i = dd.getPostConstructs().iterator();
+         LifecycleCallback lc = i.next();
+         assertNull(lc.getLifecycleCallbackClass());
+         assertEquals("postConstruct", lc.getLifecycleCallbackMethod());
+      }
+      
+      assertEquals(1, dd.getPreDestroys().size());
+      
+      {
+         Iterator<LifecycleCallback> i = dd.getPreDestroys().iterator();
+         LifecycleCallback lc = i.next();
+         assertNull(lc.getLifecycleCallbackClass());
+         assertEquals("preDestroy", lc.getLifecycleCallbackMethod());
+      }
+   }
+   
+   private static URL getResourceUrl(String name)
+   {
+      URL url = Thread.currentThread().getContextClassLoader().getResource(name);
+      if (url == null)
+      {
+         throw new IllegalStateException("Resource not found: " + name);
+      }
+      return url;
+   }
+
+   public static Test suite() throws Exception
+   {
+      return new TestSuite(ApplicationClientXmlTestCase.class);
+   }
+   
+}




More information about the jboss-cvs-commits mailing list