[jboss-cvs] JBossAS SVN: r72365 - in projects/metadata/trunk/src: test/java/org/jboss/test/metadata/annotation and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 17 11:11:24 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-04-17 11:11:24 -0400 (Thu, 17 Apr 2008)
New Revision: 72365
Added:
projects/metadata/trunk/src/main/java/org/jboss/metadata/client/spec/AnnotationMergedView.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/AnnotationClientUnitTestCase.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/basic/
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/basic/Client.java
projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/basic/ResourceIF.java
projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/annotation/client/
projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/annotation/client/AnnotationClient_testXmlMerge.xml
Log:
JBMETA-18, add annotation merge util for client app metadata
Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/client/spec/AnnotationMergedView.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/client/spec/AnnotationMergedView.java (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/client/spec/AnnotationMergedView.java 2008-04-17 15:11:24 UTC (rev 72365)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.metadata.client.spec;
+
+import org.jboss.metadata.javaee.spec.RemoteEnvironmentRefsGroupMetaData;
+
+/**
+ * Create a merged ApplicationClient5MetaData view from an xml + annotation views
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class AnnotationMergedView
+{
+ public static void merge(ApplicationClient5MetaData merged, ApplicationClientMetaData xml, ApplicationClientMetaData annotation)
+ {
+ if(xml != null)
+ {
+ if(xml.getVersion() != null)
+ merged.setVersion(xml.getVersion());
+ merged.setDTD("", xml.getDtdPublicId(), xml.getDtdSystemId());
+ if(xml.getCallbackHandler() != null)
+ merged.setCallbackHandler(xml.getCallbackHandler());
+ merged.setMetadataComplete(xml.isMetadataComplete());
+
+ if(xml.getMessageDestinations() != null)
+ merged.setMessageDestinations(xml.getMessageDestinations());
+ }
+
+ // Merge the remote env
+ RemoteEnvironmentRefsGroupMetaData environmentRefsGroup = new RemoteEnvironmentRefsGroupMetaData();
+ RemoteEnvironmentRefsGroupMetaData xmlEnv = xml != null ? xml.getJndiEnvironmentRefsGroup() : null;
+ RemoteEnvironmentRefsGroupMetaData annEnv = annotation != null ? annotation.getJndiEnvironmentRefsGroup() : null;
+ environmentRefsGroup.merge(xmlEnv, annEnv, "application.xml", "annotations", false);
+ merged.setJndiEnvironmentRefsGroup(environmentRefsGroup);
+ }
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/AnnotationClientUnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/AnnotationClientUnitTestCase.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/AnnotationClientUnitTestCase.java 2008-04-17 15:11:24 UTC (rev 72365)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.metadata.annotation.client;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.Collection;
+
+import org.jboss.metadata.annotation.creator.client.ApplicationClient5MetaDataCreator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.client.jboss.JBossClient5DTDMetaData;
+import org.jboss.metadata.client.spec.AnnotationMergedView;
+import org.jboss.metadata.client.spec.ApplicationClient14DTDMetaData;
+import org.jboss.metadata.client.spec.ApplicationClient14MetaData;
+import org.jboss.metadata.client.spec.ApplicationClient5MetaData;
+import org.jboss.metadata.ejb.jboss.JBoss50DTDMetaData;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.spec.EjbJar20MetaData;
+import org.jboss.metadata.ejb.spec.EjbJar21MetaData;
+import org.jboss.metadata.ejb.spec.EjbJar30MetaData;
+import org.jboss.metadata.javaee.spec.AnnotatedEJBReferenceMetaData;
+import org.jboss.metadata.javaee.spec.AnnotatedEJBReferencesMetaData;
+import org.jboss.metadata.javaee.spec.EJBReferenceMetaData;
+import org.jboss.metadata.javaee.spec.EnvironmentEntryMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
+import org.jboss.metadata.javaee.spec.MessageDestinationMetaData;
+import org.jboss.metadata.javaee.spec.ResourceEnvironmentReferenceMetaData;
+import org.jboss.metadata.javaee.spec.ResourceReferenceMetaData;
+import org.jboss.test.metadata.annotation.client.basic.ResourceIF;
+import org.jboss.test.metadata.common.PackageScanner;
+import org.jboss.test.metadata.common.ScanPackage;
+import org.jboss.test.metadata.javaee.AbstractJavaEEMetaDataTest;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.omg.CORBA.ORB;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class AnnotationClientUnitTestCase extends AbstractJavaEEMetaDataTest
+{
+ public static SchemaBindingResolver initResolver()
+ {
+ DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+
+ resolver.addClassBindingForLocation("application-client_1_3.dtd", ApplicationClient14DTDMetaData.class);
+ resolver.addClassBindingForLocation("application-client_1_4.xsd", ApplicationClient14MetaData.class);
+ resolver.addClassBindingForLocation("application-client_5.xsd", ApplicationClient5MetaData.class);
+ resolver.addClassBindingForLocation("jboss-client", JBossClient5DTDMetaData.class);
+ return resolver;
+ }
+
+ public AnnotationClientUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ @ScanPackage("org.jboss.test.metadata.annotation.client.basic")
+ public void testApplicationClientProcessor()
+ throws Exception
+ {
+ AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+
+ Collection<Class<?>> classes = PackageScanner.loadClasses();
+ System.out.println("Processing classes: "+classes);
+ ApplicationClient5MetaDataCreator creator = new ApplicationClient5MetaDataCreator(finder);
+ ApplicationClient5MetaData clientMD = creator.create(classes);
+ System.out.println(clientMD.getAnnotatedEjbReferences());
+ assertEquals(3, clientMD.getAnnotatedEjbReferences().size());
+ AnnotatedEJBReferenceMetaData resourceMethodBean = clientMD.getAnnotatedEjbReferences().get("resourceMethodBean");
+ assertNotNull(resourceMethodBean);
+ assertEquals(ResourceIF.class, resourceMethodBean.getBeanInterface());
+ assertEquals("ResourceOnMethodBean", resourceMethodBean.getLink());
+ AnnotatedEJBReferenceMetaData resourceClassBean = clientMD.getAnnotatedEjbReferences().get("ejb/resourceClassBean");
+ assertNotNull(resourceClassBean);
+ assertEquals("ResourcesOnClassBean", resourceClassBean.getLink());
+ assertEquals("refs/resources/ResourcesOnClassBean", resourceClassBean.getMappedName());
+ assertEquals("refs/resources/ResourcesOnClassBean", resourceClassBean.getJndiName());
+
+ // ORB maps to a resource-env-ref
+ ResourceEnvironmentReferenceMetaData orbRes = clientMD.getResourceEnvironmentReferenceByName("orb");
+ System.out.println(clientMD.getResourceEnvironmentReferences());
+ assertNotNull(orbRes);
+ assertEquals(ORB.class.getName(), orbRes.getType());
+ }
+ @ScanPackage("org.jboss.test.metadata.annotation.client.basic")
+ public void testXmlMerge()
+ throws Exception
+ {
+ AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+ Collection<Class<?>> classes = PackageScanner.loadClasses();
+ System.out.println("Processing classes: "+classes);
+ ApplicationClient5MetaDataCreator creator = new ApplicationClient5MetaDataCreator(finder);
+ ApplicationClient5MetaData clientMD = creator.create(classes);
+
+ ApplicationClient5MetaData xmlMD = super.unmarshal(ApplicationClient5MetaData.class);
+ ApplicationClient5MetaData merged = new ApplicationClient5MetaData();
+ AnnotationMergedView.merge(merged, xmlMD, clientMD);
+
+ EnvironmentEntryMetaData msg = merged.getEnvironmentEntryByName("msg");
+ assertNotNull(msg);
+ assertEquals("java.lang.String", msg.getType());
+ assertEquals("how are you?", msg.getValue());
+
+ LifecycleCallbacksMetaData postConstructs = merged.getPostConstructs();
+ assertNotNull(postConstructs);
+ assertEquals(1, postConstructs.size());
+ LifecycleCallbackMetaData pc0 = postConstructs.get(0);
+ assertEquals("postConstruct", pc0.getMethodName());
+
+ LifecycleCallbacksMetaData preDestroys = merged.getPreDestroys();
+ assertNotNull(preDestroys);
+ assertEquals(1, preDestroys.size());
+ LifecycleCallbackMetaData pd0 = preDestroys.get(0);
+ assertEquals("preDestroy", pd0.getMethodName());
+
+ assertEquals("org.jboss.ejb3.test.applicationclient.client.TestCallbackHandler", merged.getCallbackHandler());
+
+ // ORB maps to a resource-env-ref
+ ResourceEnvironmentReferenceMetaData orbRes = merged.getResourceEnvironmentReferenceByName("orb");
+ System.out.println(clientMD.getResourceEnvironmentReferences());
+ assertNotNull(orbRes);
+ assertEquals(ORB.class.getName(), orbRes.getType());
+ ResourceEnvironmentReferenceMetaData messageReplier = merged.getResourceEnvironmentReferenceByName("messageReplier");
+ assertNotNull(messageReplier);
+ assertEquals("javax.jms.Queue", messageReplier.getType());
+
+ MessageDestinationMetaData md = merged.getMessageDestinationByName("MY-QUEUE");
+ assertNotNull(md);
+ assertEquals("queue/testQueue", md.getJndiName());
+ assertEquals("queue/testQueue", md.getMappedName());
+ }
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/basic/Client.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/basic/Client.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/basic/Client.java 2008-04-17 15:11:24 UTC (rev 72365)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.metadata.annotation.client.basic;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+
+import org.omg.CORBA.ORB;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class Client
+{
+ @EJB(beanName = "ResourceOnMethodBean")
+ private static ResourceIF resourceMethodBean;
+
+ @EJB(beanName = "ResourceOnFieldBean")
+ private static ResourceIF resourceFieldBean;
+
+ @EJB(name="ejb/resourceClassBean", beanName = "ResourcesOnClassBean", mappedName="refs/resources/ResourcesOnClassBean")
+ private static ResourceIF resourceClassBean;
+
+ @Resource
+ private static ORB orb;
+}
Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/basic/ResourceIF.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/basic/ResourceIF.java (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/client/basic/ResourceIF.java 2008-04-17 15:11:24 UTC (rev 72365)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.metadata.annotation.client.basic;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public interface ResourceIF
+{
+
+}
Added: projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/annotation/client/AnnotationClient_testXmlMerge.xml
===================================================================
--- projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/annotation/client/AnnotationClient_testXmlMerge.xml (rev 0)
+++ projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/annotation/client/AnnotationClient_testXmlMerge.xml 2008-04-17 15:11:24 UTC (rev 72365)
@@ -0,0 +1,35 @@
+<?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/javaee
+ http://java.sun.com/xml/ns/javaee/application-client_5.xsd"
+ version="5" id="appclient-test">
+ <description>application client unit test</description>
+ <display-name>appclient-test-client</display-name>
+
+ <env-entry>
+ <env-entry-name>msg</env-entry-name>
+ <env-entry-type>java.lang.String</env-entry-type>
+ <env-entry-value>how are you?</env-entry-value>
+ </env-entry>
+
+ <resource-env-ref>
+ <resource-env-ref-name>messageReplier</resource-env-ref-name>
+ <resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
+ </resource-env-ref>
+
+ <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>
+
+ <message-destination>
+ <message-destination-name>MY-QUEUE</message-destination-name>
+ <mapped-name>queue/testQueue</mapped-name>
+ </message-destination>
+</application-client>
More information about the jboss-cvs-commits
mailing list