[jboss-cvs] JBossAS SVN: r109761 - in projects/metadata/ejb/trunk/src: main/java/org/jboss/metadata/ejb/jboss and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 7 13:18:48 EST 2010


Author: wolfc
Date: 2010-12-07 13:18:47 -0500 (Tue, 07 Dec 2010)
New Revision: 109761

Added:
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulTimeoutProcessor.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/AbstractTimeoutMetaData.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/StatefulTimeoutMetaData.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/TimeUnitAdapter.java
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta321/
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta321/AnnotatedStatefulTimeoutBean.java
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta321/unit/
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta321/unit/StatefulTimeoutTestCase.java
   projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta321/
   projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta321/ejb-jar.xml
Removed:
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/TimeUnitAdatper.java
Modified:
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulProcessor.java
   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/spec/AccessTimeoutMetaData.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionBean31MetaData.java
Log:
JBMETA-321: added stateful timeout parsing and processing

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulProcessor.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulProcessor.java	2010-12-07 18:08:51 UTC (rev 109760)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulProcessor.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -59,6 +59,8 @@
 
       addTypeProcessor(new AccessTimeoutClassProcessor(finder));      
       addMethodProcessor(new AccessTimeoutMethodProcessor(finder));
+
+      addTypeProcessor(new StatefulTimeoutProcessor(finder));
    }
 
    @Override

Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulTimeoutProcessor.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulTimeoutProcessor.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulTimeoutProcessor.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (c) 2010, Red Hat, Inc., 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.jboss;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBean31MetaData;
+import org.jboss.metadata.ejb.spec.StatefulTimeoutMetaData;
+
+import javax.ejb.StatefulTimeout;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.util.Collection;
+
+import static org.jboss.metadata.annotation.creator.ProcessorUtils.createAnnotationSet;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class StatefulTimeoutProcessor extends AbstractFinderUser
+   implements Processor<JBossSessionBean31MetaData, Class<?>>
+{
+   protected StatefulTimeoutProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   @Override
+   public Collection<Class<? extends Annotation>> getAnnotationTypes()
+   {
+      return createAnnotationSet(StatefulTimeout.class);
+   }
+
+   @Override
+   public void process(JBossSessionBean31MetaData metaData, Class<?> type)
+   {
+      StatefulTimeout annotation = finder.getAnnotation(type, StatefulTimeout.class);
+      if(annotation == null)
+         return;
+
+      metaData.setStatefulTimeout(new StatefulTimeoutMetaData(annotation.value(), annotation.unit()));
+   }
+}

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-12-07 18:08:51 UTC (rev 109760)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossSessionBean31MetaData.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -31,6 +31,7 @@
 import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
 import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
 import org.jboss.metadata.ejb.spec.SessionType;
+import org.jboss.metadata.ejb.spec.StatefulTimeoutMetaData;
 import org.jboss.metadata.ejb.spec.TimerMetaData;
 import org.jboss.metadata.merge.MergeUtil;
 
@@ -99,6 +100,8 @@
    private NamedMethodMetaData afterBeginMethod;
    private NamedMethodMetaData beforeCompletionMethod;
    private NamedMethodMetaData afterCompletionMethod;
+   
+   private StatefulTimeoutMetaData statefulTimeout;
 
    public AsyncMethodsMetaData getAsyncMethods()
    {
@@ -351,6 +354,16 @@
       this.afterCompletionMethod = method;
    }
 
+   public StatefulTimeoutMetaData getStatefulTimeout()
+   {
+      return statefulTimeout;
+   }
+
+   public void setStatefulTimeout(StatefulTimeoutMetaData statefulTimeout)
+   {
+      this.statefulTimeout = statefulTimeout;
+   }
+   
    /**
     * {@inheritDoc}
     */
@@ -397,6 +410,8 @@
 
       this.beanLevelAccessTimeout = override(joverride != null ? joverride.getAccessTimeout() : null, soriginal != null ? soriginal.getAccessTimeout() : null);
 
+      this.statefulTimeout = override(joverride != null ? joverride.getStatefulTimeout() : null, soriginal != null ? soriginal.getStatefulTimeout() : null);
+
       if (joverride != null)
       {
          this.noInterfaceBean = joverride.isNoInterfaceBean();
@@ -458,6 +473,8 @@
       
       this.beanLevelAccessTimeout = override(joverride != null ? joverride.getAccessTimeout() : null, soriginal != null ? soriginal.getAccessTimeout() : null);
 
+      this.statefulTimeout = override(joverride != null ? joverride.getStatefulTimeout() : null, soriginal != null ? soriginal.getStatefulTimeout() : null);
+
       if (joverride != null)
       {
          this.noInterfaceBean = joverride.isNoInterfaceBean();
@@ -537,5 +554,4 @@
          MergeUtil.merge(this.timers, overrideTimers, originalTimers);
       }
    }
-
 }

Copied: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/AbstractTimeoutMetaData.java (from rev 109725, projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/AccessTimeoutMetaData.java)
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/AbstractTimeoutMetaData.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/AbstractTimeoutMetaData.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (c) 2010, Red Hat, Inc., 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.ejb.spec;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import java.io.Serializable;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Metadata for {@link javax.ejb.AccessTimeout}'s xml equivalent
+ *
+ * @author Jaikiran Pai
+ */
+public abstract class AbstractTimeoutMetaData implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+
+   private long timeout;
+
+   private TimeUnit unit;
+
+   protected AbstractTimeoutMetaData()
+   {
+   }
+
+   protected AbstractTimeoutMetaData(long timeout, TimeUnit unit)
+   {
+      this.timeout = timeout;
+      this.unit = unit;
+   }
+
+   @XmlElement(name = "timeout", required = true)
+   public void setTimeout(long timeout)
+   {
+      this.timeout = timeout;
+   }
+
+   public long getTimeout()
+   {
+      return this.timeout;
+   }
+
+   @XmlElement(name = "unit", required = true)
+   @XmlJavaTypeAdapter(TimeUnitAdapter.class)
+   public void setUnit(TimeUnit timeUnit)
+   {
+      this.unit = timeUnit;
+   }
+
+   public TimeUnit getUnit()
+   {
+      return this.unit;
+   }
+}

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/AccessTimeoutMetaData.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/AccessTimeoutMetaData.java	2010-12-07 18:08:51 UTC (rev 109760)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/AccessTimeoutMetaData.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -21,13 +21,8 @@
 */
 package org.jboss.metadata.ejb.spec;
 
-import java.io.Serializable;
-import java.util.concurrent.TimeUnit;
-
 import javax.ejb.AccessTimeout;
-import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
 /**
  * Metadata for {@link AccessTimeout}'s xml equivalent
@@ -35,40 +30,8 @@
  * @author Jaikiran Pai
  * @version $Revision: $
  */
- at XmlType(name = "access-timeoutType", propOrder =
-{"timeout", "unit"})
-public class AccessTimeoutMetaData implements Serializable
+ at XmlType(name = "access-timeoutType", propOrder = {"timeout", "unit"})
+public class AccessTimeoutMetaData extends AbstractTimeoutMetaData
 {
-
-   /**
-    * 
-    */
    private static final long serialVersionUID = 1L;
-
-   private long timeout;
-
-   private TimeUnit unit;
-
-   @XmlElement(name = "timeout", required = true)
-   public void setTimeout(long timeout)
-   {
-      this.timeout = timeout;
-   }
-
-   public long getTimeout()
-   {
-      return this.timeout;
-   }
-
-   @XmlElement(name = "unit", required = true)
-   @XmlJavaTypeAdapter(TimeUnitAdatper.class)
-   public void setUnit(TimeUnit timeUnit)
-   {
-      this.unit = timeUnit;
-   }
-
-   public TimeUnit getUnit()
-   {
-      return this.unit;
-   }
 }

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionBean31MetaData.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionBean31MetaData.java	2010-12-07 18:08:51 UTC (rev 109760)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/SessionBean31MetaData.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -44,7 +44,7 @@
  */
 @XmlType(name = "session-beanType", propOrder =
 {"descriptionGroup", "ejbName", "mappedName", "home", "remote", "localHome", "local", "businessLocals",
-      "businessRemotes", "localBean", "serviceEndpoint", "ejbClass", "sessionType", "timeoutMethod", "timers", "initOnStartup",
+      "businessRemotes", "localBean", "serviceEndpoint", "ejbClass", "sessionType", "statefulTimeout", "timeoutMethod", "timers", "initOnStartup",
       "concurrencyManagementType", "concurrentMethods", "dependsOnMetaData", "initMethods", "removeMethods", "asyncMethods", "transactionType",
       "afterBeginMethod", "beforeCompletionMethod", "afterCompletionMethod",
       "aroundInvokes", "environmentRefsGroup", "postActivates", "prePassivates", "securityRoleRefs", "securityIdentity"})
@@ -99,6 +99,8 @@
    private NamedMethodMetaData afterBeginMethod;
    private NamedMethodMetaData beforeCompletionMethod;
    private NamedMethodMetaData afterCompletionMethod;
+
+   private StatefulTimeoutMetaData statefulTimeout;
    
    /**
     * Returns the init-on-startup value of the session bean metadata.
@@ -413,6 +415,8 @@
       this.concurrentMethods = new ConcurrentMethodsMetaData();
       this.concurrentMethods.merge(override != null ? override.getConcurrentMethods() : null, original != null ? original.getConcurrentMethods() : null);
 
+      this.statefulTimeout = override(override != null ? override.getStatefulTimeout() : null, original != null ? original.getStatefulTimeout() : null);
+
       if (override != null)
       {
          if (override.localBean != null)
@@ -485,4 +489,14 @@
          MergeUtil.merge(this.timers, overrideTimers, originalTimers);
       }
    }
+
+   public StatefulTimeoutMetaData getStatefulTimeout()
+   {
+      return statefulTimeout;
+   }
+
+   public void setStatefulTimeout(StatefulTimeoutMetaData statefulTimeout)
+   {
+      this.statefulTimeout = statefulTimeout;
+   }
 }

Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/StatefulTimeoutMetaData.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/StatefulTimeoutMetaData.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/StatefulTimeoutMetaData.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (c) 2010, Red Hat, Inc., 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.ejb.spec;
+
+import javax.xml.bind.annotation.XmlType;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at XmlType(name = "stateful-timeoutType", propOrder = {"timeout", "unit"})
+public class StatefulTimeoutMetaData extends AbstractTimeoutMetaData
+{
+   private static final long serialVersionUID = -467025454498279681L;
+
+   public StatefulTimeoutMetaData()
+   {
+   }
+
+   public StatefulTimeoutMetaData(long timeout, TimeUnit unit)
+   {
+      super(timeout, unit);
+   }
+}

Copied: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/TimeUnitAdapter.java (from rev 109725, projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/TimeUnitAdatper.java)
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/TimeUnitAdapter.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/TimeUnitAdapter.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -0,0 +1,75 @@
+/*
+* 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.spec;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import java.util.Locale;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Responsible for converting the String value of {@link TimeUnit} to
+ * the corresponding {@link TimeUnit}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class TimeUnitAdapter extends XmlAdapter<String, TimeUnit>
+{
+
+   /**
+    * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
+    */
+   @Override
+   public String marshal(TimeUnit val) throws Exception
+   {
+      switch (val)
+      {
+         case DAYS :
+            return "Days";
+         case HOURS :
+            return "Hours";
+         case MICROSECONDS :
+            return "Microseconds";
+         case MILLISECONDS :
+            return "Milliseconds";
+         case MINUTES :
+            return "Minutes";
+         case NANOSECONDS :
+            return "Nanoseconds";
+         case SECONDS :
+            return "Seconds";
+         default :
+            return null;
+      }
+   }
+
+   /**
+    * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
+    */
+   @Override
+   public TimeUnit unmarshal(String val) throws Exception
+   {
+      String timeUnit = val.toUpperCase(Locale.ENGLISH);
+      return TimeUnit.valueOf(timeUnit);
+   }
+
+}

Deleted: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/TimeUnitAdatper.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/TimeUnitAdatper.java	2010-12-07 18:08:51 UTC (rev 109760)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/spec/TimeUnitAdatper.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -1,76 +0,0 @@
-/*
-* 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.spec;
-
-import java.util.Locale;
-import java.util.concurrent.TimeUnit;
-
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-
-/**
- * Responsible for converting the String value of {@link TimeUnit} to
- * the corresponding {@link TimeUnit}
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
-public class TimeUnitAdatper extends XmlAdapter<String, TimeUnit>
-{
-
-   /**
-    * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
-    */
-   @Override
-   public String marshal(TimeUnit val) throws Exception
-   {
-      switch (val)
-      {
-         case DAYS :
-            return "Days";
-         case HOURS :
-            return "Hours";
-         case MICROSECONDS :
-            return "Microseconds";
-         case MILLISECONDS :
-            return "Milliseconds";
-         case MINUTES :
-            return "Minutes";
-         case NANOSECONDS :
-            return "Nanoseconds";
-         case SECONDS :
-            return "Seconds";
-         default :
-            return null;
-      }
-   }
-
-   /**
-    * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
-    */
-   @Override
-   public TimeUnit unmarshal(String val) throws Exception
-   {
-      String timeUnit = val.toUpperCase(Locale.ENGLISH);
-      return TimeUnit.valueOf(timeUnit);
-   }
-
-}

Added: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta321/AnnotatedStatefulTimeoutBean.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta321/AnnotatedStatefulTimeoutBean.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta321/AnnotatedStatefulTimeoutBean.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (c) 2010, Red Hat, Inc., 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.ejb.test.jbmeta321;
+
+import javax.ejb.Stateful;
+import javax.ejb.StatefulTimeout;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Stateful
+ at StatefulTimeout(value=5, unit=TimeUnit.DAYS)
+public class AnnotatedStatefulTimeoutBean
+{
+}

Added: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta321/unit/StatefulTimeoutTestCase.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta321/unit/StatefulTimeoutTestCase.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/jbmeta321/unit/StatefulTimeoutTestCase.java	2010-12-07 18:18:47 UTC (rev 109761)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (c) 2010, Red Hat, Inc., 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.ejb.test.jbmeta321.unit;
+
+import junit.framework.Assert;
+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.JBoss51MetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBean31MetaData;
+import org.jboss.metadata.ejb.spec.EjbJar31MetaData;
+import org.jboss.metadata.ejb.spec.EjbJarMetaData;
+import org.jboss.metadata.ejb.spec.SessionBean31MetaData;
+import org.jboss.metadata.ejb.spec.StatefulTimeoutMetaData;
+import org.jboss.metadata.ejb.test.jbmeta321.AnnotatedStatefulTimeoutBean;
+import org.jboss.test.metadata.common.PackageScanner;
+import org.jboss.test.metadata.common.ScanPackage;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.resolver.MultiClassSchemaResolver;
+import org.jboss.xb.binding.resolver.MutableSchemaResolver;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.lang.reflect.AnnotatedElement;
+import java.net.URL;
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class StatefulTimeoutTestCase
+{
+   private static MutableSchemaResolver schemaBindingResolver;
+
+   private static UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+
+   @BeforeClass
+   public static void beforeClass()
+   {
+      schemaBindingResolver = new MultiClassSchemaResolver();
+      schemaBindingResolver.mapLocationToClass("ejb-jar_3_1.xsd", EjbJar31MetaData.class);
+   }
+
+   @Test
+   @ScanPackage("org.jboss.metadata.ejb.test.jbmeta321")
+   public void testAnnotations()
+   {
+      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 bean was null", metaData);
+
+      JBossSessionBean31MetaData bean = (JBossSessionBean31MetaData) metaData.getEnterpriseBean(AnnotatedStatefulTimeoutBean.class.getSimpleName());
+      Assert.assertNotNull("Session bean metadata was null", bean);
+
+      assertNotNull(bean.getStatefulTimeout());
+      assertEquals(5, bean.getStatefulTimeout().getTimeout());
+      assertEquals(TimeUnit.DAYS, bean.getStatefulTimeout().getUnit());
+   }
+
+   @Test
+   public void testMerge() throws Exception
+   {
+      EjbJarMetaData ejb31 = unmarshal(EjbJarMetaData.class, "/org/jboss/metadata/ejb/test/jbmeta321/ejb-jar.xml");
+
+      SessionBean31MetaData original = (SessionBean31MetaData) ejb31.getEnterpriseBean("Test");
+
+      SessionBean31MetaData bean = new SessionBean31MetaData();
+      bean.merge(null, original);
+
+      assertNotNull(bean.getStatefulTimeout());
+      assertEquals(10, bean.getStatefulTimeout().getTimeout());
+      assertEquals(TimeUnit.HOURS, bean.getStatefulTimeout().getUnit());
+   }
+
+   @Test
+   public void testOverride() throws Exception
+   {
+      EjbJarMetaData ejb31 = unmarshal(EjbJarMetaData.class, "/org/jboss/metadata/ejb/test/jbmeta321/ejb-jar.xml");
+
+      SessionBean31MetaData original = (SessionBean31MetaData) ejb31.getEnterpriseBean("Test");
+
+      SessionBean31MetaData override = new SessionBean31MetaData();
+      override.setStatefulTimeout(new StatefulTimeoutMetaData(1, TimeUnit.MINUTES));
+
+      SessionBean31MetaData bean = new SessionBean31MetaData();
+      bean.merge(override, original);
+
+      assertNotNull(bean.getStatefulTimeout());
+      assertEquals(1, bean.getStatefulTimeout().getTimeout());
+      assertEquals(TimeUnit.MINUTES, bean.getStatefulTimeout().getUnit());
+   }
+
+   @Test
+   public void testOverride2() throws Exception
+   {
+      EjbJarMetaData ejb31 = unmarshal(EjbJarMetaData.class, "/org/jboss/metadata/ejb/test/jbmeta321/ejb-jar.xml");
+
+      SessionBean31MetaData original = (SessionBean31MetaData) ejb31.getEnterpriseBean("Test");
+
+      JBoss51MetaData overrideJar = new JBoss51MetaData();
+      overrideJar.setEnterpriseBeans(new JBossEnterpriseBeansMetaData());
+      JBossSessionBean31MetaData override = new JBossSessionBean31MetaData();
+      override.setEnterpriseBeansMetaData(overrideJar.getEnterpriseBeans());
+      override.setStatefulTimeout(new StatefulTimeoutMetaData(3, TimeUnit.MILLISECONDS));
+
+      JBossSessionBean31MetaData bean = new JBossSessionBean31MetaData();
+      // Q&D
+      bean.setEnterpriseBeansMetaData(overrideJar.getEnterpriseBeans());
+      bean.merge(override, original);
+
+      assertNotNull(bean.getStatefulTimeout());
+      assertEquals(3, bean.getStatefulTimeout().getTimeout());
+      assertEquals(TimeUnit.MILLISECONDS, bean.getStatefulTimeout().getUnit());
+   }
+
+   @Test
+   public void testParse() throws Exception
+   {
+      EjbJarMetaData ejb31 = unmarshal(EjbJarMetaData.class, "/org/jboss/metadata/ejb/test/jbmeta321/ejb-jar.xml");
+
+      SessionBean31MetaData bean = (SessionBean31MetaData) ejb31.getEnterpriseBean("Test");
+
+      assertNotNull(bean.getStatefulTimeout());
+      assertEquals(10, bean.getStatefulTimeout().getTimeout());
+      assertEquals(TimeUnit.HOURS, bean.getStatefulTimeout().getUnit());
+   }
+
+   private static <T> T unmarshal(Class<T> type, String resource) throws JBossXBException
+   {
+      Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+      unmarshaller.setValidation(false);
+      URL url = type.getResource(resource);
+      if (url == null)
+         throw new IllegalArgumentException("Failed to find resource " + resource);
+      return type.cast(unmarshaller.unmarshal(url.toString(), schemaBindingResolver));
+   }   
+}

Added: projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta321/ejb-jar.xml
===================================================================
--- projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta321/ejb-jar.xml	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/resources/org/jboss/metadata/ejb/test/jbmeta321/ejb-jar.xml	2010-12-07 18:18:47 UTC (rev 109761)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ejb-jar 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/ejb-jar_3_1.xsd"
+      version="3.1">
+   <enterprise-beans>
+      <session>
+         <ejb-name>Test</ejb-name>
+         <stateful-timeout>
+            <timeout>10</timeout>
+            <unit>Hours</unit>
+         </stateful-timeout>
+      </session>
+   </enterprise-beans>
+</ejb-jar>
\ No newline at end of file



More information about the jboss-cvs-commits mailing list