[jboss-cvs] JBossAS SVN: r94018 - in projects/bootstrap/trunk: api-as and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 25 02:33:20 EDT 2009


Author: ALRubinger
Date: 2009-09-25 02:33:19 -0400 (Fri, 25 Sep 2009)
New Revision: 94018

Modified:
   projects/bootstrap/trunk/api-as/pom.xml
   projects/bootstrap/trunk/api-as/src/main/java/org/jboss/bootstrap/api/as/server/JBossASServerFactory.java
   projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/GenericFactory.java
   projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/SecurityActions.java
   projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/ServerFactory.java
Log:
[JBBOOT-109] Refit the JBossASServerFactory and parents to pave the way for embedded-api to become a bootstrap component and take advantage

Modified: projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/GenericFactory.java
===================================================================
--- projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/GenericFactory.java	2009-09-25 06:26:46 UTC (rev 94017)
+++ projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/GenericFactory.java	2009-09-25 06:33:19 UTC (rev 94018)
@@ -65,7 +65,7 @@
     * @throws Exception If some error occurred in constructing the instance
     */
    final static <T> T createInstance(final String implClassName, final ClassLoader cl, final Class<T> expectedType)
-         throws IllegalArgumentException, Exception
+         throws IllegalArgumentException, InstantiationException
    {
       // Precondition checks
       if (implClassName == null || implClassName.length() == 0)

Modified: projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/SecurityActions.java
===================================================================
--- projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/SecurityActions.java	2009-09-25 06:26:46 UTC (rev 94017)
+++ projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/SecurityActions.java	2009-09-25 06:33:19 UTC (rev 94018)
@@ -62,46 +62,61 @@
     * @throws IllegalArgumentException If the class was not specified
     * @throws PrivilegedActionException 
     */
-   static Object newInstance(final Class<?> clazz, final ClassLoader cl) throws IllegalArgumentException, Exception
+   static Object newInstance(final Class<?> clazz, final ClassLoader cl) throws IllegalArgumentException,
+         InstantiationException
    {
 
       // Whether to set the CL
       final boolean setDefiningCl = cl != null;
 
       // Make new instance
-      return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>()
+      try
       {
-
-         public Object run() throws Exception
+         return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>()
          {
-            // Initialize
-            Thread current = null;
-            ClassLoader oldCl = null;
 
-            // If necessary, set the TCCL
-            if (setDefiningCl)
+            public Object run() throws Exception
             {
-               current = Thread.currentThread();
-               oldCl = current.getContextClassLoader();
-               current.setContextClassLoader(cl);
-            }
+               // Initialize
+               Thread current = null;
+               ClassLoader oldCl = null;
 
-            try
-            {
-               // Create the instance
-               return clazz.newInstance();
-            }
-            finally
-            {
-               // Reset the TCCL if necessary
+               // If necessary, set the TCCL
                if (setDefiningCl)
                {
-                  current.setContextClassLoader(oldCl);
+                  current = Thread.currentThread();
+                  oldCl = current.getContextClassLoader();
+                  current.setContextClassLoader(cl);
                }
+
+               try
+               {
+                  // Create the instance
+                  return clazz.newInstance();
+               }
+               finally
+               {
+                  // Reset the TCCL if necessary
+                  if (setDefiningCl)
+                  {
+                     current.setContextClassLoader(oldCl);
+                  }
+               }
             }
+
+         });
+      }
+      catch (final PrivilegedActionException pae)
+      {
+         // Return an InstanciationException outright
+         final Throwable cause = pae.getCause();
+         if (cause instanceof InstantiationException)
+         {
+            throw (InstantiationException) cause;
          }
-
-      });
+         // Otherwise wrap in some runtime exception
+         throw new RuntimeException("Error in instanciation", cause);
+      }
    }
 
    /**

Modified: projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/ServerFactory.java
===================================================================
--- projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/ServerFactory.java	2009-09-25 06:26:46 UTC (rev 94017)
+++ projects/bootstrap/trunk/api/src/main/java/org/jboss/bootstrap/api/factory/ServerFactory.java	2009-09-25 06:33:19 UTC (rev 94018)
@@ -56,10 +56,11 @@
     * @param implClassName The fully-qualified name of the implementation class
     * @throws IllegalArgumentException If the implementation class name is null, blank, 
     *       can not be found on the ClassLoader, or is not assignable to {@link Server} 
-    * @throws Exception If some error occurred in constructing the Server
+    * @throws InstantiationException If some error occurred in constructing the Server
     * @return The newly-created Server
     */
-   public static Server<?, ?> createServer(final String implClassName) throws IllegalArgumentException, Exception
+   public static Server<?, ?> createServer(final String implClassName) throws IllegalArgumentException,
+         InstantiationException
    {
       return createServer(implClassName, SecurityActions.getTccl());
    }
@@ -74,11 +75,11 @@
     * @throws IllegalArgumentException If the ClassLoader is null, implementation class 
     *       name is null, blank, can not be found on the ClassLoader, 
     *       or is not assignable to {@link Server}.
-    * @throws Exception If some error occurred in constructing the Server
+    * @throws InstantiationException If some error occurred in constructing the Server
     * @return The newly-created Server
     */
    public static Server<?, ?> createServer(final String implClassName, final ClassLoader cl)
-         throws IllegalArgumentException, Exception
+         throws IllegalArgumentException, InstantiationException
    {
       return GenericFactory.createInstance(implClassName, cl, Server.class);
    }

Modified: projects/bootstrap/trunk/api-as/pom.xml
===================================================================
--- projects/bootstrap/trunk/api-as/pom.xml	2009-09-25 06:26:46 UTC (rev 94017)
+++ projects/bootstrap/trunk/api-as/pom.xml	2009-09-25 06:33:19 UTC (rev 94018)
@@ -25,7 +25,7 @@
   <!-- Properties -->
   <properties>
 
-    <version.org.jboss.bootstrap_jboss.bootstrap.api>2.0.0-alpha-1</version.org.jboss.bootstrap_jboss.bootstrap.api>
+    <version.org.jboss.bootstrap_jboss.bootstrap.api>2.0.0-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.api>
 
   </properties>
 

Modified: projects/bootstrap/trunk/api-as/src/main/java/org/jboss/bootstrap/api/as/server/JBossASServerFactory.java
===================================================================
--- projects/bootstrap/trunk/api-as/src/main/java/org/jboss/bootstrap/api/as/server/JBossASServerFactory.java	2009-09-25 06:26:46 UTC (rev 94017)
+++ projects/bootstrap/trunk/api-as/src/main/java/org/jboss/bootstrap/api/as/server/JBossASServerFactory.java	2009-09-25 06:33:19 UTC (rev 94018)
@@ -78,19 +78,6 @@
 
    /**
     * Creates a JBossASServer from the default implementation class name
-    * {@link JBossASServerFactory#DEFAULT_AS_SERVER_IMPL_CLASS_NAME}, using the 
-    * Thread Context ClassLoader.  The returned server will additionally be created using
-    * the TCCL.  As a convenience, the server will contain a default configuration.
-    * 
-    * @return The newly-created Server populated with a default configuration
-    */
-   public static JBossASServer createServerWithDefaultConfiguration()
-   {
-      return createServerWithDefaultConfiguration(SecurityActions.getTccl());
-   }
-
-   /**
-    * Creates a JBossASServer from the default implementation class name
     * {@link JBossASServerFactory#DEFAULT_AS_SERVER_IMPL_CLASS_NAME}, using the
     * specified ClassLoader.  The returned server will additionally be created using
     * the ClassLoader denoted.
@@ -112,27 +99,20 @@
    }
 
    /**
-    * Creates a JBossASServer from the default implementation class name
-    * {@link JBossASServerFactory#DEFAULT_AS_SERVER_IMPL_CLASS_NAME}, using the
-    * specified ClassLoader.  The returned server will additionally be created using
-    * the ClassLoader denoted. As a convenience, the server will contain a 
-    * default configuration.
+    * Creates a JBossASServer from the specified implementation class name
+    * using the specified ClassLoader.  The returned server will additionally 
+    * be created using the ClassLoader denoted. 
     * 
-    * @throws IllegalArgumentException If the ClassLoader is null
-    * @return The newly-created Server populated with a default configuration
+    * @param implClassName The FQN of the class used to create the new server instance
+    * @param cl The ClassLoader used to create the new server instance
+    * @throws IllegalArgumentException If the ClassLoader or server implementation class is null
+    * @throws Exception If there was an error in creating the Server
+    * @return The newly-created Server
     */
-   public static JBossASServer createServerWithDefaultConfiguration(final ClassLoader cl)
-         throws IllegalArgumentException
+   public static JBossASServer createServer(final String implClassName, final ClassLoader cl)
+         throws IllegalArgumentException, Exception
    {
-      try
-      {
-         return createServerWithDefaultConfiguration(DEFAULT_AS_SERVER_IMPL_CLASS_NAME, cl);
-      }
-      catch (Exception e)
-      {
-         // An exception here is likely our fault, so throw a RuntimeException
-         throw new RuntimeException("Error in creating the Server", e);
-      }
+      return createServer(implClassName, cl, JBossASServer.class);
    }
 
    /**
@@ -140,12 +120,16 @@
     * using the specified ClassLoader.  The returned server will additionally 
     * be created using the ClassLoader denoted. 
     * 
+    * @param implClassName The FQN of the class used to create the new server instance
+    * @param cl The ClassLoader used to create the new server instance
+    * @param expectedType The expected runtime type of the new server instance
+    * @param <T> Expected runtime type of the newly-created server instance
     * @throws IllegalArgumentException If the ClassLoader or server implementation class is null
     * @throws Exception If there was an error in creating the Server
     * @return The newly-created Server
     */
-   public static JBossASServer createServer(final String implClassName, final ClassLoader cl)
-         throws IllegalArgumentException, Exception
+   public static <T extends JBossASBasedServer<T, JBossASServerConfig>> T createServer(final String implClassName,
+         final ClassLoader cl, final Class<T> expectedType) throws IllegalArgumentException, InstantiationException
    {
       // Precondition check
       if (cl == null)
@@ -161,17 +145,16 @@
       final Server<?, ?> server = ServerFactory.createServer(implClassName, cl);
 
       // Cast
-      final Class<JBossASServer> targetClass = JBossASServer.class;
-      JBossASServer asServer = null;
+      final T asServer;
       try
       {
-         asServer = targetClass.cast(server);
+         asServer = expectedType.cast(server);
       }
-      catch (ClassCastException cce)
+      catch (final ClassCastException cce)
       {
          // Catch, explain giving some context, throw new
          throw new ClassCastException("Specified server implementation class, " + implClassName
-               + " must be assignable to " + targetClass.getName());
+               + " must be assignable to " + expectedType.getName());
       }
 
       // Set a default config
@@ -181,40 +164,4 @@
       // Return
       return asServer;
    }
-
-   /**
-    * Creates a JBossASServer from the specified implementation class name
-    * using the specified ClassLoader.  The returned server will additionally 
-    * be created using the ClassLoader denoted. As a convenience, the server 
-    * will contain a default configuration.
-    * 
-    * @throws IllegalArgumentException If the ClassLoader or server implementation class is null
-    * @throws Exception If there was an error in creating the Server
-    * @return The newly-created Server populated with a default configuration
-    */
-   public static JBossASServer createServerWithDefaultConfiguration(final String implClassName, final ClassLoader cl)
-         throws IllegalArgumentException, Exception
-   {
-      // Make the server, applying a default config
-      return applyDefaultConfiguration(createServer(implClassName, cl), cl);
-   }
-
-   //-------------------------------------------------------------------------------------||
-   // Internal Helper Methods ------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Sets a new, default configuration upon the specified server
-    * 
-    * @param server The server upon which we'll set a new config
-    * @param cl The ClassLoader used to create the new config
-    * @return The same server instance passed in, with a set config
-    */
-   private static JBossASServer applyDefaultConfiguration(final JBossASServer server, final ClassLoader cl)
-   {
-      // Set a default config
-      final JBossASServerConfig config = JBossASServerConfigFactory.createServerConfig(cl);
-      server.setConfiguration(config);
-      return server;
-   }
 }




More information about the jboss-cvs-commits mailing list