[jboss-cvs] JBossAS SVN: r71345 - in projects/microcontainer/trunk/kernel/src: main/org/jboss/beans/metadata/spi/factory and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 27 08:54:59 EDT 2008


Author: alesj
Date: 2008-03-27 08:54:59 -0400 (Thu, 27 Mar 2008)
New Revision: 71345

Added:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/factory/AbstractBeanFactory.java
Modified:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/factory/GenericBeanFactory.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/AbstractKernelTest.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/MyBeanFactory.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigureFromStringTestCase.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateTestCase.java
Log:
Introducing AbstractBeanFactory.
Fixing date assumption of locale being US.

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/factory/GenericBeanFactory.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/factory/GenericBeanFactory.java	2008-03-27 12:12:13 UTC (rev 71344)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/factory/GenericBeanFactory.java	2008-03-27 12:54:59 UTC (rev 71345)
@@ -21,20 +21,12 @@
 */
 package org.jboss.beans.metadata.plugins.factory;
 
-import java.util.List;
 import java.util.Map;
 
 import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.beans.info.spi.BeanAccessMode;
-import org.jboss.beans.metadata.spi.ClassLoaderMetaData;
-import org.jboss.beans.metadata.spi.ConstructorMetaData;
-import org.jboss.beans.metadata.spi.LifecycleMetaData;
-import org.jboss.beans.metadata.spi.ParameterMetaData;
 import org.jboss.beans.metadata.spi.ValueMetaData;
-import org.jboss.beans.metadata.spi.factory.BeanFactory;
+import org.jboss.beans.metadata.spi.factory.AbstractBeanFactory;
 import org.jboss.joinpoint.spi.Joinpoint;
-import org.jboss.joinpoint.spi.JoinpointException;
-import org.jboss.joinpoint.spi.MethodJoinpoint;
 import org.jboss.joinpoint.spi.TargettedJoinpoint;
 import org.jboss.kernel.plugins.config.Configurator;
 import org.jboss.kernel.spi.config.KernelConfigurator;
@@ -45,41 +37,18 @@
 /**
  * Bean factory metadata.
  * 
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision$
  */
-public class GenericBeanFactory implements BeanFactory, KernelControllerContextAware
+public class GenericBeanFactory extends AbstractBeanFactory implements KernelControllerContextAware
 {
    /** The log */
    private static final Logger log = Logger.getLogger(GenericBeanFactory.class);
-   
-   /** The configurator */
-   protected KernelConfigurator configurator;
-   
+
    /** Our context */
    protected KernelControllerContext context;
-   
-   /** The bean class name */
-   protected String bean;
 
-   /** The access mode */
-   protected BeanAccessMode accessMode;
-
-   /** The classloader */
-   protected ClassLoaderMetaData classLoader;
-   
-   /** The constructor metadata */
-   protected ConstructorMetaData constructor;
-   
-   /** The properties Map<propertyName, ValueMetaData> */
-   protected Map<String, ValueMetaData> properties;
-
-   /** The create lifecycle method */
-   protected LifecycleMetaData create;
-
-   /** The start lifecycle method */
-   protected LifecycleMetaData start;
-
    /**
     * Create a new generic bean factory
     * 
@@ -87,7 +56,7 @@
     */
    public GenericBeanFactory(KernelConfigurator configurator)
    {
-      this.configurator = configurator;
+      super(configurator);
    }
    
    /**
@@ -147,179 +116,4 @@
    {
       this.context = null;
    }
-
-   /**
-    * Get the bean name
-    * 
-    * @return the bean
-    */
-   public String getBean()
-   {
-      return bean;
-   }
-   
-   /**
-    * Set the bean name
-    * 
-    * @param bean the bean name
-    */
-   public void setBean(String bean)
-   {
-      this.bean = bean;
-   }
-
-   /**
-    * Get the access mode.
-    *
-    * @return the access mode
-    */
-   public BeanAccessMode getAccessMode()
-   {
-      return accessMode;
-   }
-
-   /**
-    * Set the access mode.
-    *
-    * @param accessMode the access mode.
-    */
-   public void setAccessMode(BeanAccessMode accessMode)
-   {
-      this.accessMode = accessMode;
-   }
-
-   /**
-    * Get the classLoader.
-    * 
-    * @return the classLoader.
-    */
-   public ClassLoaderMetaData getClassLoader()
-   {
-      return classLoader;
-   }
-
-   /**
-    * Set the classLoader.
-    * 
-    * @param classLoader the classLoader.
-    */
-   public void setClassLoader(ClassLoaderMetaData classLoader)
-   {
-      this.classLoader = classLoader;
-   }
-
-   /**
-    * Get the constructor metadata
-    * 
-    * @return the contructor metadata
-    */
-   public ConstructorMetaData getConstructor()
-   {
-      return constructor;
-   }
-   
-   /**
-    * Set the constructor metadata
-    * 
-    * @param constructor the constructor metadata
-    */
-   public void setConstructor(ConstructorMetaData constructor)
-   {
-      this.constructor = constructor;
-   }
-   
-   /**
-    * Get the properties
-    * 
-    * @return the properties Map<propertyName, ValueMetaData>
-    */
-   public Map<String, ValueMetaData> getProperties()
-   {
-      return properties;
-   }
-   
-   /**
-    * Set the properties
-    * 
-    * @param properties the properties Map<propertyName, ValueMetaData>
-    */
-   public void setProperties(Map<String, ValueMetaData> properties)
-   {
-      this.properties = properties;
-   }
-
-   /**
-    * Get the create.
-    * 
-    * @return the create.
-    */
-   public LifecycleMetaData getCreate()
-   {
-      return create;
-   }
-
-   /**
-    * Set the create.
-    * 
-    * @param create the create.
-    */
-   public void setCreate(LifecycleMetaData create)
-   {
-      this.create = create;
-   }
-
-   /**
-    * Get the start.
-    * 
-    * @return the start.
-    */
-   public LifecycleMetaData getStart()
-   {
-      return start;
-   }
-
-   /**
-    * Set the start.
-    * 
-    * @param start the start.
-    */
-   public void setStart(LifecycleMetaData start)
-   {
-      this.start = start;
-   }
-
-   /**
-    * Invoke a lifecycle method
-    * 
-    * @param methodName the default method name
-    * @param lifecycle the lifecycle
-    * @param info the bean info
-    * @param cl the classloader
-    * @param target the target
-    * @throws Throwable for any error
-    */
-   protected void invokeLifecycle(String methodName, LifecycleMetaData lifecycle, BeanInfo info, ClassLoader cl, Object target) throws Throwable
-   {
-      if (lifecycle == null || lifecycle.isIgnored() == false)
-      {
-         String method = methodName;
-         if (lifecycle != null && lifecycle.getMethodName() != null)
-            method = lifecycle.getMethodName();
-         List<ParameterMetaData> parameters = null;
-         if (lifecycle != null)
-            parameters = lifecycle.getParameters();
-         MethodJoinpoint joinpoint;
-         try
-         {
-            joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true);
-         }
-         catch (JoinpointException ignored)
-         {
-            return;
-         }
-         joinpoint.setTarget(target);
-         joinpoint.dispatch();
-      }
-   }
-
 }
\ No newline at end of file

Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/factory/AbstractBeanFactory.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/factory/AbstractBeanFactory.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/factory/AbstractBeanFactory.java	2008-03-27 12:54:59 UTC (rev 71345)
@@ -0,0 +1,259 @@
+/*
+* 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.beans.metadata.spi.factory;
+
+import java.util.Map;
+import java.util.List;
+
+import org.jboss.beans.info.spi.BeanAccessMode;
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.metadata.spi.ClassLoaderMetaData;
+import org.jboss.beans.metadata.spi.ConstructorMetaData;
+import org.jboss.beans.metadata.spi.LifecycleMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.joinpoint.spi.MethodJoinpoint;
+import org.jboss.joinpoint.spi.JoinpointException;
+
+/**
+ * SPI contract of bean factory we can create from GenericBeanFactoryMetaData.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractBeanFactory implements BeanFactory
+{
+   /** The configurator */
+   protected KernelConfigurator configurator;
+
+   /** The bean class name */
+   protected String bean;
+
+   /** The access mode */
+   protected BeanAccessMode accessMode;
+
+   /** The classloader */
+   protected ClassLoaderMetaData classLoader;
+
+   /** The constructor metadata */
+   protected ConstructorMetaData constructor;
+
+   /** The properties Map<propertyName, ValueMetaData> */
+   protected Map<String, ValueMetaData> properties;
+
+   /** The create lifecycle method */
+   protected LifecycleMetaData create;
+
+   /** The start lifecycle method */
+   protected LifecycleMetaData start;
+
+   protected AbstractBeanFactory(KernelConfigurator configurator)
+   {
+      if (configurator == null)
+         throw new IllegalArgumentException("Null configurator");
+      this.configurator = configurator;
+   }
+
+   /**
+    * Get the configurator.
+    *
+    * @return the configurator
+    */
+   protected KernelConfigurator getConfigurator()
+   {
+      return configurator;
+   }
+
+   /**
+    * Get the bean name
+    *
+    * @return the bean
+    */
+   public String getBean()
+   {
+      return bean;
+   }
+
+   /**
+    * Set the bean name
+    *
+    * @param bean the bean name
+    */
+   public void setBean(String bean)
+   {
+      this.bean = bean;
+   }
+
+   /**
+    * Get the access mode.
+    *
+    * @return the access mode
+    */
+   public BeanAccessMode getAccessMode()
+   {
+      return accessMode;
+   }
+
+   /**
+    * Set the access mode.
+    *
+    * @param accessMode the access mode.
+    */
+   public void setAccessMode(BeanAccessMode accessMode)
+   {
+      this.accessMode = accessMode;
+   }
+
+   /**
+    * Get the classLoader.
+    *
+    * @return the classLoader.
+    */
+   public ClassLoaderMetaData getClassLoader()
+   {
+      return classLoader;
+   }
+
+   /**
+    * Set the classLoader.
+    *
+    * @param classLoader the classLoader.
+    */
+   public void setClassLoader(ClassLoaderMetaData classLoader)
+   {
+      this.classLoader = classLoader;
+   }
+
+   /**
+    * Get the constructor metadata
+    *
+    * @return the contructor metadata
+    */
+   public ConstructorMetaData getConstructor()
+   {
+      return constructor;
+   }
+
+   /**
+    * Set the constructor metadata
+    *
+    * @param constructor the constructor metadata
+    */
+   public void setConstructor(ConstructorMetaData constructor)
+   {
+      this.constructor = constructor;
+   }
+
+   /**
+    * Get the properties
+    *
+    * @return the properties Map<propertyName, ValueMetaData>
+    */
+   public Map<String, ValueMetaData> getProperties()
+   {
+      return properties;
+   }
+
+   /**
+    * Set the properties
+    *
+    * @param properties the properties Map<propertyName, ValueMetaData>
+    */
+   public void setProperties(Map<String, ValueMetaData> properties)
+   {
+      this.properties = properties;
+   }
+
+   /**
+    * Get the create.
+    *
+    * @return the create.
+    */
+   public LifecycleMetaData getCreate()
+   {
+      return create;
+   }
+
+   /**
+    * Set the create.
+    *
+    * @param create the create.
+    */
+   public void setCreate(LifecycleMetaData create)
+   {
+      this.create = create;
+   }
+
+   /**
+    * Get the start.
+    *
+    * @return the start.
+    */
+   public LifecycleMetaData getStart()
+   {
+      return start;
+   }
+
+   /**
+    * Set the start.
+    *
+    * @param start the start.
+    */
+   public void setStart(LifecycleMetaData start)
+   {
+      this.start = start;
+   }
+
+   /**
+    * Invoke a lifecycle method
+    *
+    * @param methodName the default method name
+    * @param lifecycle the lifecycle
+    * @param info the bean info
+    * @param cl the classloader
+    * @param target the target
+    * @throws Throwable for any error
+    */
+   protected void invokeLifecycle(String methodName, LifecycleMetaData lifecycle, BeanInfo info, ClassLoader cl, Object target) throws Throwable
+   {
+      if (lifecycle == null || lifecycle.isIgnored() == false)
+      {
+         String method = methodName;
+         if (lifecycle != null && lifecycle.getMethodName() != null)
+            method = lifecycle.getMethodName();
+         List<ParameterMetaData> parameters = null;
+         if (lifecycle != null)
+            parameters = lifecycle.getParameters();
+         MethodJoinpoint joinpoint;
+         try
+         {
+            joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true);
+         }
+         catch (JoinpointException ignored)
+         {
+            return;
+         }
+         joinpoint.setTarget(target);
+         joinpoint.dispatch();
+      }
+   }
+}

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/AbstractKernelTest.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/AbstractKernelTest.java	2008-03-27 12:12:13 UTC (rev 71344)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/AbstractKernelTest.java	2008-03-27 12:54:59 UTC (rev 71345)
@@ -25,6 +25,7 @@
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.Locale;
 
 import org.jboss.kernel.Kernel;
 import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
@@ -42,13 +43,45 @@
  */
 public class AbstractKernelTest extends AbstractTestCaseWithSetup
 {
-   private static DateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
-   
+   private static DateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US);
+   private Locale locale;
+
    public AbstractKernelTest(String name)
    {
       super(name);
    }
-   
+
+   protected void setUp() throws Exception
+   {
+      // set locales
+      locale = Locale.getDefault();
+      setLocale(Locale.US);
+
+      super.setUp();
+   }
+
+   protected void setLocale(Locale locale)
+   {
+      SecurityManager sm = suspendSecurity();
+      try
+      {
+         Locale.setDefault(locale);
+      }
+      finally
+      {
+         resumeSecurity(sm);
+      }
+   }
+
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+
+      // reset locale
+      setLocale(locale);
+      locale = null;
+   }
+
    protected Kernel bootstrap() throws Throwable
    {
       BasicBootstrap bootstrap = new BasicBootstrap();
@@ -69,14 +102,20 @@
 
    protected Date createDate(String date)
    {
+      Locale locale = Locale.getDefault();
       try
       {
+         setLocale(Locale.US);
          return dateFormat.parse(date);
       }
       catch (Exception e)
       {
          throw new NestedRuntimeException(e);
       }
+      finally
+      {
+         setLocale(locale);   
+      }
    }
 
    protected Date createDate(int year, int month, int day)

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/MyBeanFactory.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/MyBeanFactory.java	2008-03-27 12:12:13 UTC (rev 71344)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/MyBeanFactory.java	2008-03-27 12:54:59 UTC (rev 71345)
@@ -21,13 +21,13 @@
 */
 package org.jboss.test.kernel.config.support;
 
-import org.jboss.beans.metadata.plugins.factory.GenericBeanFactory;
+import org.jboss.beans.metadata.spi.factory.AbstractBeanFactory;
 import org.jboss.kernel.spi.config.KernelConfigurator;
 
 /**
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class MyBeanFactory extends GenericBeanFactory
+public class MyBeanFactory extends AbstractBeanFactory
 {
    public MyBeanFactory(KernelConfigurator configurator)
    {

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigureFromStringTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigureFromStringTestCase.java	2008-03-27 12:12:13 UTC (rev 71344)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigureFromStringTestCase.java	2008-03-27 12:54:59 UTC (rev 71345)
@@ -52,7 +52,7 @@
    
    AbstractBeanMetaData metaData;
    
-   String stringValue =  new String("StringValue");
+   String stringValue =  "StringValue";
    Byte byteValue = new Byte("12");
    Boolean booleanValue = Boolean.TRUE;
    // TODO character
@@ -152,7 +152,7 @@
 
       metaData = new AbstractBeanMetaData();
       HashSet<PropertyMetaData> attributes = new HashSet<PropertyMetaData>();
-      attributes.add(new AbstractPropertyMetaData("AString", stringValue.toString()));
+      attributes.add(new AbstractPropertyMetaData("AString", stringValue));
       attributes.add(new AbstractPropertyMetaData("AByte", byteValue.toString()));
       attributes.add(new AbstractPropertyMetaData("ABoolean", booleanValue.toString()));
       // TODO character 

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateTestCase.java	2008-03-27 12:12:13 UTC (rev 71344)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/GenericFactoryInstantiateTestCase.java	2008-03-27 12:54:59 UTC (rev 71345)
@@ -138,7 +138,6 @@
       }
    }
 
-   @SuppressWarnings("deprecation")
    protected BeanFactory configureFromIllegalClass() throws Throwable
    {
       GenericBeanFactoryMetaData factory = new GenericBeanFactoryMetaData("Factory", "org.jboss.test.NoSuchClass");
@@ -153,7 +152,6 @@
       assertEquals("foobar", factory.createBean());
    }
 
-   @SuppressWarnings("deprecation")
    protected BeanFactory configureFromDefinedFactoryClass() throws Throwable
    {
       GenericBeanFactoryMetaData factory = new GenericBeanFactoryMetaData("Factory", SimpleBean.class.getName());




More information about the jboss-cvs-commits mailing list