[jboss-cvs] JBossAS SVN: r75394 - in projects/jboss-reflect/trunk/src: main/org/jboss/reflect/plugins/javassist and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 4 12:04:55 EDT 2008


Author: alesj
Date: 2008-07-04 12:04:55 -0400 (Fri, 04 Jul 2008)
New Revision: 75394

Added:
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoNumberTest.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/IntrospectionNumberUnitTestCase.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/JavassistNumberUnitTestCase.java
Modified:
   projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java
   projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
   projects/jboss-reflect/trunk/src/main/org/jboss/reflect/spi/NumberInfo.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AbstractClassInfoTest.java
   projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoTestSuite.java
Log:
[JBREFLECT-28]; use 3 phase instantiation of NumberInfo.

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java	2008-07-04 14:49:13 UTC (rev 75393)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java	2008-07-04 16:04:55 UTC (rev 75394)
@@ -302,12 +302,13 @@
          return primitive;
 
       NumberInfo number = NumberInfo.valueOf(clazz.getName());
-      if (number != null)
+      if (number != null && number.getPhase() != NumberInfo.Phase.INITIALIZING)
       {
          synchronized (number)
          {
-            if (number.isInitialized() == false)
+            if (number.getPhase() != NumberInfo.Phase.COMPLETE)
             {
+               number.initializing();
                number.setDelegate(get(clazz));
             }
          }
@@ -332,12 +333,13 @@
             return primitive;
 
          NumberInfo number = NumberInfo.valueOf(name);
-         if (number != null)
+         if (number != null && number.getPhase() != NumberInfo.Phase.INITIALIZING)
          {
             synchronized (number)
             {
-               if (number.isInitialized() == false)
+               if (number.getPhase() != NumberInfo.Phase.COMPLETE)
                {
+                  number.initializing();
                   number.setDelegate(get(type));
                }
             }
@@ -358,12 +360,13 @@
          return primitive;
 
       NumberInfo number = NumberInfo.valueOf(name);
-      if (number != null)
+      if (number != null && number.getPhase() != NumberInfo.Phase.INITIALIZING)
       {
          synchronized (number)
          {
-            if (number.isInitialized() == false)
+            if (number.getPhase() != NumberInfo.Phase.COMPLETE)
             {
+               number.initializing();
                number.setDelegate(resolveComplexTypeInfo(cl, name));
             }
          }

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2008-07-04 14:49:13 UTC (rev 75393)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2008-07-04 16:04:55 UTC (rev 75394)
@@ -261,13 +261,14 @@
          return primitive;
 
       NumberInfo number = NumberInfo.valueOf(clazz.getName());
-      if (number != null)
+      if (number != null && number.getPhase() != NumberInfo.Phase.INITIALIZING)
       {
          synchronized (number)
          {
-            if (number.isInitialized() == false)
+            if (number.getPhase() != NumberInfo.Phase.COMPLETE)
             {
-               number.setDelegate((TypeInfo) get(clazz));
+               number.initializing();
+               number.setDelegate((TypeInfo)get(clazz));
             }
          }
          return number;
@@ -288,12 +289,13 @@
          return primitive;
 
       NumberInfo number = NumberInfo.valueOf(name);
-      if (number != null)
+      if (number != null && number.getPhase() != NumberInfo.Phase.INITIALIZING)
       {
          synchronized (number)
          {
-            if (number.isInitialized() == false)
+            if (number.getPhase() != NumberInfo.Phase.COMPLETE)
             {
+               number.initializing();
                number.setDelegate((TypeInfo) get(Class.forName(name, false, cl)));
             }
          }

Modified: projects/jboss-reflect/trunk/src/main/org/jboss/reflect/spi/NumberInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/org/jboss/reflect/spi/NumberInfo.java	2008-07-04 14:49:13 UTC (rev 75393)
+++ projects/jboss-reflect/trunk/src/main/org/jboss/reflect/spi/NumberInfo.java	2008-07-04 16:04:55 UTC (rev 75394)
@@ -36,6 +36,16 @@
  */
 public class NumberInfo extends PrimitiveInfo implements ClassInfo
 {
+   /**
+    * The phase enum
+    */
+   public enum Phase
+   {
+      INSTANTIATED,
+      INITIALIZING,
+      COMPLETE
+   }
+
    /** serialVersionUID */
    private static final long serialVersionUID = 1L;
 
@@ -92,6 +102,8 @@
 
    private transient ClassInfo delegate;
 
+   private transient Phase phase;
+
    /**
     * Get the primitive info for a type
     *
@@ -133,15 +145,23 @@
    }
 
    /**
-    * Whether the delegate is initialized
-    * 
-    * @return true when there is a delegate
+    * Get the phase.
+    *
+    * @return the current phase
     */
-   public boolean isInitialized()
+   public Phase getPhase()
    {
-      return (delegate != null);
+      return phase;
    }
 
+   /**
+    * Are we currently initializing delegate.
+    */
+   public void initializing()
+   {
+      phase = Phase.INITIALIZING;
+   }
+
    @Override
    public boolean equals(Object obj)
    {

Modified: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AbstractClassInfoTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AbstractClassInfoTest.java	2008-07-04 14:49:13 UTC (rev 75393)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/AbstractClassInfoTest.java	2008-07-04 16:04:55 UTC (rev 75394)
@@ -69,13 +69,13 @@
       TypeInfoFactory factory = getTypeInfoFactory();
       getLog().debug("Using typeInfoFactory: " + factory);
       
-      TypeInfo info = factory.getTypeInfo(clazz);
+      TypeInfo info = factory.getTypeInfo(clazz.getName(), getClass().getClassLoader());
       getLog().debug("Got: " + info + " from " + clazz);
       assertNotNull(info);
       assertEquals(info, expected);
 
       ClassLoader cl = getClass().getClassLoader();
-      info = factory.getTypeInfo(clazz.getName(), getClass().getClassLoader());
+      info = factory.getTypeInfo(clazz);
       getLog().debug("Got: " + info + " from " + clazz.getName() + " cl=" + cl);
       assertNotNull(info);
       assertEquals(info, expected);

Copied: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoNumberTest.java (from rev 71434, projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoPrimitiveTest.java)
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoNumberTest.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoNumberTest.java	2008-07-04 16:04:55 UTC (rev 75394)
@@ -0,0 +1,94 @@
+/*
+* 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.test.classinfo.test;
+
+import org.jboss.reflect.spi.NumberInfo;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * ClassInfoNumberTest.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class ClassInfoNumberTest extends AbstractClassInfoTest
+{
+   public ClassInfoNumberTest(String name)
+   {
+      super(name);
+   }
+
+   public void testByte() throws Throwable
+   {
+      testNumber(Byte.class, NumberInfo.BYTE_OBJECT, new String[] { "1", "2" }, new Byte[] { 1, 2 });
+   }
+
+   public void testDouble() throws Throwable
+   {
+      testNumber(Double.class, NumberInfo.DOUBLE_OBJECT, new String[] { "1.2", "3.14" }, new Double[] { 1.2, 3.14 });
+   }
+
+   public void testFloat() throws Throwable
+   {
+      testNumber(Float.class, NumberInfo.FLOAT_OBJECT, new String[] { "1.0e10", "4.2e5" }, new Float[] { 1.0e10f, 4.2e5f });
+   }
+
+   public void testInt() throws Throwable
+   {
+      testNumber(Integer.class, NumberInfo.INT_OBJECT, new String[] { "1", "2" }, new Integer[] { 1, 2 });
+   }
+
+   public void testLong() throws Throwable
+   {
+      testNumber(Long.class, NumberInfo.LONG_OBJECT, new String[] { "1", "2" }, new Long[] { 1l, 2l });
+   }
+
+   public void testShort() throws Throwable
+   {
+      testNumber(Short.class, NumberInfo.SHORT_OBJECT, new String[] { "1", "2" }, new Short[] { 1, 2 });
+   }
+
+/*
+   public void testAtomicInt() throws Throwable
+   {
+      testNumber(AtomicInteger.class, NumberInfo.ATOMIC_INT, new String[] { "1", "2" }, new AtomicInteger[] {new AtomicInteger(1), new AtomicInteger(2)});
+   }
+
+   public void testAtomicLong() throws Throwable
+   {
+      testNumber(AtomicLong.class, NumberInfo.ATOMIC_INT, new String[] { "1", "2" }, new AtomicLong[] {new AtomicLong(1), new AtomicLong(2)});
+   }
+*/
+
+   protected <T> void testNumber(Class<T> clazz, NumberInfo number, String[] values, T[] types) throws Throwable
+   {
+      TypeInfo info = testBasics(clazz, number);
+      assertFalse(info.isArray());
+      assertFalse(info.isEnum());
+      assertFalse(info.isPrimitive());
+
+      if (values == null)
+         return;
+
+      testArray(clazz, info);
+      testValues(clazz, info, values, types);
+   }
+}
\ No newline at end of file

Modified: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoTestSuite.java
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoTestSuite.java	2008-07-04 14:49:13 UTC (rev 75393)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/ClassInfoTestSuite.java	2008-07-04 16:04:55 UTC (rev 75394)
@@ -44,6 +44,8 @@
 
       suite.addTest(IntrospectionPrimitiveUnitTestCase.suite());
       suite.addTest(JavassistPrimitiveUnitTestCase.suite());
+      suite.addTest(IntrospectionNumberUnitTestCase.suite());
+      suite.addTest(JavassistNumberUnitTestCase.suite());
       suite.addTest(IntrospectionArrayUnitTestCase.suite());
       suite.addTest(JavassistArrayUnitTestCase.suite());
       suite.addTest(IntrospectionEnumUnitTestCase.suite());

Copied: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/IntrospectionNumberUnitTestCase.java (from rev 71434, projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/IntrospectionPrimitiveUnitTestCase.java)
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/IntrospectionNumberUnitTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/IntrospectionNumberUnitTestCase.java	2008-07-04 16:04:55 UTC (rev 75394)
@@ -0,0 +1,50 @@
+/*
+* 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.test.classinfo.test;
+
+import junit.framework.Test;
+
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * IntrospectionNumberUnitTestCase.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class IntrospectionNumberUnitTestCase extends ClassInfoNumberTest
+{
+   public IntrospectionNumberUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(IntrospectionNumberUnitTestCase.class);
+   }
+
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new IntrospectionTypeInfoFactory();
+   }
+}
\ No newline at end of file

Added: projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/JavassistNumberUnitTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/JavassistNumberUnitTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/tests/org/jboss/test/classinfo/test/JavassistNumberUnitTestCase.java	2008-07-04 16:04:55 UTC (rev 75394)
@@ -0,0 +1,49 @@
+/*
+* 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.test.classinfo.test;
+
+import junit.framework.Test;
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * JavassistNumberUnitTestCase.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class JavassistNumberUnitTestCase extends ClassInfoNumberTest
+{
+   public JavassistNumberUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(JavassistNumberUnitTestCase.class);
+   }
+
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new JavassistTypeInfoFactory();
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list