[jboss-cvs] JBossAS SVN: r88139 - in projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as: server and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 4 02:36:24 EDT 2009
Author: ALRubinger
Date: 2009-05-04 02:36:24 -0400 (Mon, 04 May 2009)
New Revision: 88139
Added:
projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/config/JBossASServerConfigFactory.java
projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/config/SecurityActions.java
projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/server/JBossASServerFactory.java
projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/server/SecurityActions.java
Log:
[JBBOOT-59] Create an SPI-backed Server Factory for AS
Added: projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/config/JBossASServerConfigFactory.java
===================================================================
--- projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/config/JBossASServerConfigFactory.java (rev 0)
+++ projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/config/JBossASServerConfigFactory.java 2009-05-04 06:36:24 UTC (rev 88139)
@@ -0,0 +1,109 @@
+/*
+ * 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.bootstrap.spi.as.config;
+
+import org.jboss.bootstrap.spi.config.ServerConfig;
+import org.jboss.bootstrap.spi.factory.ServerConfigFactory;
+
+/**
+ * JBossASServerConfigFactory
+ *
+ * Factory of {@link JBossASServerConfig} implementations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class JBossASServerConfigFactory
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The FQN of the default implementation class to create
+ */
+ public static final String DEFAULT_AS_SERVER_CONFIG_IMPL_CLASS_NAME = "org.jboss.bootstrap.impl.as.config.BasicJBossASServerConfig";
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor, should not be called
+ */
+ private JBossASServerConfigFactory()
+ {
+ // No external access
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Factory Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a JBossASServerConfig from the default implementation class name
+ * {@link JBossASServerConfigFactory#DEFAULT_AS_SERVER_CONFIG_IMPL_CLASS_NAME}, using the
+ * Thread Context ClassLoader. The returned config will additionally be created using
+ * the TCCL.
+ *
+ * @return The newly-created config
+ */
+ public static JBossASServerConfig createServerConfig()
+ {
+ return createServerConfig(SecurityActions.getTccl());
+ }
+
+ /**
+ * Creates a JBossASServerConfig from the default implementation class name
+ * {@link JBossASServerConfigFactory#DEFAULT_AS_SERVER_CONFIG_IMPL_CLASS_NAME}, using the
+ * specified ClassLoader. The returned config will additionally be created using
+ * the ClassLoader denoted.
+ *
+ * @throws IllegalArgumentException If the ClassLoader is null
+ * @return The newly-created config
+ */
+ public static JBossASServerConfig createServerConfig(final ClassLoader cl) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException(ClassLoader.class.getSimpleName() + " is required.");
+ }
+
+ // Get the config
+ ServerConfig<?> config = null;
+ try
+ {
+ config = ServerConfigFactory.createServerConfig(DEFAULT_AS_SERVER_CONFIG_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 configuration", e);
+ }
+
+ // Cast
+ return JBossASServerConfig.class.cast(config);
+ }
+}
Added: projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/config/SecurityActions.java
===================================================================
--- projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/config/SecurityActions.java (rev 0)
+++ projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/config/SecurityActions.java 2009-05-04 06:36:24 UTC (rev 88139)
@@ -0,0 +1,73 @@
+/*
+ * 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.bootstrap.spi.as.config;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ *
+ * Utility class for security actions, so as to provide
+ * some centralization without leaking privileged actions
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * In place to prevent instanciation
+ */
+ private SecurityActions()
+ {
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ *
+ * @return
+ */
+ static ClassLoader getTccl()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+
+ public ClassLoader run()
+ {
+ // Return the TCCL
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ });
+ }
+}
Added: projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/server/JBossASServerFactory.java
===================================================================
--- projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/server/JBossASServerFactory.java (rev 0)
+++ projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/server/JBossASServerFactory.java 2009-05-04 06:36:24 UTC (rev 88139)
@@ -0,0 +1,220 @@
+/*
+ * 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.bootstrap.spi.as.server;
+
+import org.jboss.bootstrap.spi.as.config.JBossASServerConfig;
+import org.jboss.bootstrap.spi.as.config.JBossASServerConfigFactory;
+import org.jboss.bootstrap.spi.factory.ServerFactory;
+import org.jboss.bootstrap.spi.server.Server;
+
+/**
+ * JBossASServerFactory
+ *
+ * Factory of {@link JBossASServer} implementations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class JBossASServerFactory
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The FQN of the default server implementation class to create
+ */
+ public static final String DEFAULT_AS_SERVER_IMPL_CLASS_NAME = "org.jboss.bootstrap.impl.as.server.JBossASServerImpl";
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor, should not be used
+ */
+ private JBossASServerFactory()
+ {
+ // No external access
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Factory Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * 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.
+ *
+ * @return The newly-created Server
+ */
+ public static JBossASServer createServer()
+ {
+ return createServer(SecurityActions.getTccl());
+ }
+
+ /**
+ * 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.
+ *
+ * @throws IllegalArgumentException If the ClassLoader is null
+ * @return The newly-created Server
+ */
+ public static JBossASServer createServer(final ClassLoader cl) throws IllegalArgumentException
+ {
+ try
+ {
+ return createServer(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);
+ }
+ }
+
+ /**
+ * 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.
+ *
+ * @throws IllegalArgumentException If the ClassLoader is null
+ * @return The newly-created Server populated with a default configuration
+ */
+ public static JBossASServer createServerWithDefaultConfiguration(final ClassLoader cl)
+ throws IllegalArgumentException
+ {
+ 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);
+ }
+ }
+
+ /**
+ * 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 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
+ {
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException(ClassLoader.class.getSimpleName() + " is required.");
+ }
+ if (implClassName == null || implClassName.length() == 0)
+ {
+ throw new IllegalArgumentException("Implementation class name must be specified");
+ }
+
+ // Get the server
+ final Server<?, ?> server = ServerFactory.createServer(implClassName, cl);
+
+ // Cast
+ final Class<JBossASServer> targetClass = JBossASServer.class;
+ JBossASServer asServer = null;
+ try
+ {
+ asServer = targetClass.cast(server);
+ }
+ catch (ClassCastException cce)
+ {
+ // Catch, explain giving some context, throw new
+ throw new ClassCastException("Specified server implementation class, " + implClassName
+ + " must be assignable to " + targetClass.getName());
+ }
+
+ // Set a default config
+ final JBossASServerConfig config = JBossASServerConfigFactory.createServerConfig(cl);
+ asServer.setConfiguration(config);
+
+ // 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;
+ }
+}
Added: projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/server/SecurityActions.java
===================================================================
--- projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/server/SecurityActions.java (rev 0)
+++ projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/server/SecurityActions.java 2009-05-04 06:36:24 UTC (rev 88139)
@@ -0,0 +1,73 @@
+/*
+ * 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.bootstrap.spi.as.server;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ *
+ * Utility class for security actions, so as to provide
+ * some centralization without leaking privileged actions
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * In place to prevent instanciation
+ */
+ private SecurityActions()
+ {
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ *
+ * @return
+ */
+ static ClassLoader getTccl()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+
+ public ClassLoader run()
+ {
+ // Return the TCCL
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ });
+ }
+}
More information about the jboss-cvs-commits
mailing list