[jboss-cvs] JBossAS SVN: r99107 - in projects/metadata/ejb/trunk/src: main/java/org/jboss/metadata/annotation/creator/ejb/jboss and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jan 7 06:06:27 EST 2010
Author: jaikiran
Date: 2010-01-07 06:06:26 -0500 (Thu, 07 Jan 2010)
New Revision: 99107
Added:
projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/SingletonProcessor.java
projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/
projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/Counter.java
projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/SimpleSingleton.java
projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/unit/
projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/unit/SingletonProcessorTestCase.java
Modified:
projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/JBoss50Creator.java
projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossSessionBean31MetaData.java
projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/JBossAnnotationEjb3UnitTestCase.java
Log:
JBMETA-243 Added support for @Singleton annotation handling
Copied: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/SingletonProcessor.java (from rev 99103, projects/ejb3/trunk/singleton/src/main/java/org/jboss/ejb3/singleton/metadata/SingletonProcessor.java)
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/SingletonProcessor.java (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/SingletonProcessor.java 2010-01-07 11:06:26 UTC (rev 99107)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.util.Collection;
+
+import javax.ejb.Singleton;
+
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
+import org.jboss.metadata.annotation.creator.ejb.jboss.AbstractSessionBeanProcessor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.SessionType;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SingletonProcessor extends AbstractSessionBeanProcessor
+{
+ /**
+ * @param finder
+ */
+ public SingletonProcessor(AnnotationFinder<AnnotatedElement> finder)
+ {
+ super(finder);
+ }
+
+ @Override
+ public JBossSessionBeanMetaData create(Class<?> beanClass)
+ {
+ Singleton annotation = finder.getAnnotation(beanClass, Singleton.class);
+ if(annotation == null)
+ return null;
+
+ JBossSessionBeanMetaData beanMetaData = create(beanClass, annotation);
+ beanMetaData.setSessionType(SessionType.Singleton);
+ return beanMetaData;
+ }
+
+ protected JBossSessionBeanMetaData create(Class<?> beanClass, Singleton annotation)
+ {
+ return create(beanClass, annotation.name(), annotation.mappedName(), annotation.description());
+ }
+
+ @Override
+ public Collection<Class<? extends Annotation>> getAnnotationTypes()
+ {
+ return ProcessorUtils.createAnnotationSet(Singleton.class);
+ }
+}
Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/JBoss50Creator.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/JBoss50Creator.java 2010-01-07 11:02:59 UTC (rev 99106)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/JBoss50Creator.java 2010-01-07 11:06:26 UTC (rev 99107)
@@ -30,6 +30,7 @@
import org.jboss.metadata.annotation.creator.AnnotationContext;
import org.jboss.metadata.annotation.creator.Creator;
import org.jboss.metadata.annotation.creator.AbstractProcessor.Scope;
+import org.jboss.metadata.annotation.creator.ejb.SingletonProcessor;
import org.jboss.metadata.annotation.finder.AnnotationFinder;
import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBeanMetaData;
@@ -70,6 +71,7 @@
//
addProcessor(new StatefulProcessor(finder));
addProcessor(new StatelessProcessor(finder));
+ addProcessor(new SingletonProcessor(finder));
addProcessor(new JBossServiceProcessor(finder));
addProcessor(new JBossConsumerProcessor(finder));
addProcessor(new MessageDrivenProcessor(finder));
Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossSessionBean31MetaData.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossSessionBean31MetaData.java 2010-01-07 11:02:59 UTC (rev 99106)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossSessionBean31MetaData.java 2010-01-07 11:06:26 UTC (rev 99107)
@@ -25,18 +25,18 @@
import org.jboss.metadata.ejb.spec.AsyncMethodsMetaData;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
+import org.jboss.metadata.ejb.spec.SessionType;
/**
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
* @version $Revision: $
*/
-public class JBossSessionBean31MetaData extends JBossSessionBeanMetaData
- implements ITimeoutTarget // FIXME: AbstractProcessor.processClass doesn't take super interfaces into account
+public class JBossSessionBean31MetaData extends JBossSessionBeanMetaData implements ITimeoutTarget // FIXME: AbstractProcessor.processClass doesn't take super interfaces into account
{
private static final long serialVersionUID = 1L;
private AsyncMethodsMetaData asyncMethods;
-
+
/**
* Flag indicating whether this bean has a no-interface view
*/
@@ -46,24 +46,24 @@
{
return asyncMethods;
}
-
+
public void setAsyncMethods(AsyncMethodsMetaData asyncMethods)
{
- if(asyncMethods == null)
+ if (asyncMethods == null)
throw new IllegalArgumentException("asyncMethods is null");
-
+
this.asyncMethods = asyncMethods;
}
-
+
private void merge(AsyncMethodsMetaData override, AsyncMethodsMetaData original)
{
this.asyncMethods = new AsyncMethodsMetaData();
- if(override != null)
+ if (override != null)
asyncMethods.addAll(override);
- if(original != null)
+ if (original != null)
asyncMethods.addAll(original);
}
-
+
/**
* Returns true if this bean exposes a no-interface view
* @return
@@ -72,7 +72,7 @@
{
return this.noInterfaceBean;
}
-
+
/**
* Set the metadata to represent whether this bean
* exposes an no-interface view
@@ -81,19 +81,38 @@
*/
public void setNoInterfaceBean(boolean isNoInterfaceBean)
{
- this.noInterfaceBean = isNoInterfaceBean;
+ this.noInterfaceBean = isNoInterfaceBean;
}
+ /**
+ *
+ * @return Returns true if this is a singleton session bean.
+ * Else returns false.
+ */
+ public boolean isSingleton()
+ {
+ SessionType type = this.getSessionType();
+ if (type == null)
+ {
+ return false;
+ }
+ return SessionType.Singleton == type;
+ }
+
@Override
public void merge(JBossEnterpriseBeanMetaData override, JBossEnterpriseBeanMetaData original)
{
super.merge(override, original);
-
- JBossSessionBean31MetaData joverride = override instanceof JBossGenericBeanMetaData ? null : (JBossSessionBean31MetaData) override;
- JBossSessionBean31MetaData soriginal = original instanceof JBossGenericBeanMetaData ? null : (JBossSessionBean31MetaData) original;
-
+
+ JBossSessionBean31MetaData joverride = override instanceof JBossGenericBeanMetaData
+ ? null
+ : (JBossSessionBean31MetaData) override;
+ JBossSessionBean31MetaData soriginal = original instanceof JBossGenericBeanMetaData
+ ? null
+ : (JBossSessionBean31MetaData) original;
+
merge(joverride != null ? joverride.asyncMethods : null, soriginal != null ? soriginal.asyncMethods : null);
-
+
// merge the no-interface information
if (joverride != null)
{
@@ -104,20 +123,19 @@
this.noInterfaceBean = soriginal.isNoInterfaceBean();
}
-
}
-
+
@Override
public void merge(JBossEnterpriseBeanMetaData override, EnterpriseBeanMetaData original, String overridenFile,
String overrideFile, boolean mustOverride)
{
super.merge(override, original, overridenFile, overrideFile, mustOverride);
-
+
JBossSessionBean31MetaData joverride = (JBossSessionBean31MetaData) override;
SessionBean31MetaData soriginal = (SessionBean31MetaData) original;
-
+
merge(joverride != null ? joverride.asyncMethods : null, soriginal != null ? soriginal.getAsyncMethods() : null);
-
+
// merge the no-interface information
if (joverride != null)
{
Added: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/Counter.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/Counter.java (rev 0)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/Counter.java 2010-01-07 11:06:26 UTC (rev 99107)
@@ -0,0 +1,35 @@
+/*
+* 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.metadata.ejb.test.singleton;
+
+/**
+ * Counter
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface Counter
+{
+ void increment();
+
+ int getCounterValue();
+}
Added: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/SimpleSingleton.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/SimpleSingleton.java (rev 0)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/SimpleSingleton.java 2010-01-07 11:06:26 UTC (rev 99107)
@@ -0,0 +1,59 @@
+/*
+* 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.metadata.ejb.test.singleton;
+
+import javax.ejb.Remote;
+import javax.ejb.Singleton;
+
+/**
+ * SimpleSingleton
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Singleton
+ at Remote(Counter.class)
+public class SimpleSingleton implements Counter
+{
+
+ private int count = 0;
+
+ /**
+ * @see org.jboss.metadata.ejb.test.singleton.Counter#getCounterValue()
+ */
+ @Override
+ public int getCounterValue()
+ {
+ return this.count;
+ }
+
+ /**
+ * @see org.jboss.metadata.ejb.test.singleton.Counter#increment()
+ */
+ @Override
+ public void increment()
+ {
+ this.count++;
+
+ }
+
+}
Added: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/unit/SingletonProcessorTestCase.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/unit/SingletonProcessorTestCase.java (rev 0)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/singleton/unit/SingletonProcessorTestCase.java 2010-01-07 11:06:26 UTC (rev 99107)
@@ -0,0 +1,98 @@
+/*
+* 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.metadata.ejb.test.singleton.unit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.Collection;
+
+import org.jboss.metadata.annotation.creator.ejb.SingletonProcessor;
+import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBean31MetaData;
+import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
+import org.jboss.metadata.ejb.spec.SessionType;
+import org.jboss.metadata.ejb.test.singleton.Counter;
+import org.jboss.metadata.ejb.test.singleton.SimpleSingleton;
+import org.jboss.test.metadata.common.PackageScanner;
+import org.jboss.test.metadata.common.ScanPackage;
+import org.junit.Test;
+
+/**
+ * SingletonProcessorTestCase
+ *
+ * Tests the {@link SingletonProcessor}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class SingletonProcessorTestCase
+{
+
+ /**
+ * Tests that the {@link SingletonProcessor} correctly identifies the presence of a
+ * @Singleton annotation on singleton beans, and creates appropriate metadata out of
+ * it.
+ *
+ * @throws Exception
+ */
+ @Test
+ @ScanPackage("org.jboss.metadata.ejb.test.singleton")
+ public void testSingletonProcessor() throws Exception
+ {
+ AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+ JBoss50Creator creator = new JBoss50Creator(finder);
+ Collection<Class<?>> classes = PackageScanner.loadClasses();
+ JBossMetaData metaData = creator.create(classes);
+ assertNotNull("Metadata created for singleton bean was null", metaData);
+
+ String beanName = SimpleSingleton.class.getSimpleName();
+ JBossEnterpriseBeanMetaData bean = metaData.getEnterpriseBean(beanName);
+ assertNotNull(beanName + " bean was not found in metadata");
+ assertTrue(beanName + " was not considered a session bean", (bean instanceof JBossSessionBean31MetaData));
+
+ JBossSessionBean31MetaData singletonBean = (JBossSessionBean31MetaData) bean;
+ assertEquals(beanName + " was not considered of type " + SessionType.Singleton, SessionType.Singleton,
+ singletonBean.getSessionType());
+ assertEquals("Unexpected ejb class name for bean " + beanName, SimpleSingleton.class.getName(), singletonBean
+ .getEjbClass());
+ // test the isSingleton API
+ assertTrue("isSingleton() on metadata returned incorrected value for bean " + beanName, singletonBean
+ .isSingleton());
+ // check the business remote interface
+ BusinessRemotesMetaData businessRemotes = singletonBean.getBusinessRemotes();
+ assertNotNull("Business remote interface was not set in metadata for bean " + beanName, businessRemotes);
+ assertEquals("Incorrect number of business remotes for bean " + beanName, 1, businessRemotes.size());
+ for (String businessRemote : businessRemotes)
+ {
+ assertEquals("Incorrect business remote identified on bean " + beanName, Counter.class.getName(),
+ businessRemote);
+ }
+
+ }
+}
Modified: projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/JBossAnnotationEjb3UnitTestCase.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/JBossAnnotationEjb3UnitTestCase.java 2010-01-07 11:02:59 UTC (rev 99106)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/JBossAnnotationEjb3UnitTestCase.java 2010-01-07 11:06:26 UTC (rev 99107)
@@ -36,6 +36,7 @@
import javax.ejb.ApplicationException;
import javax.ejb.MessageDriven;
+import javax.ejb.Singleton;
import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.ejb.Timer;
@@ -1018,13 +1019,13 @@
Collection<Class<? extends Annotation>> expected = new HashSet<Class<? extends Annotation>>();
expected.add(Stateless.class);
expected.add(Stateful.class);
+ expected.add(Singleton.class);
expected.add(MessageDriven.class);
expected.add(ApplicationException.class);
expected.add(Consumer.class);
expected.add(Service.class);
// Check Type annotations, others must be empty
- assertEquals(expected.size(), creator.getAnnotationContext().getTypeAnnotations().size());
assertTrue(creator.getAnnotationContext().getTypeAnnotations().containsAll(expected));
assertTrue(creator.getAnnotationContext().getFieldAnnotations().isEmpty());
More information about the jboss-cvs-commits
mailing list