[jboss-svn-commits] JBoss Common SVN: r3435 - in tmpdpl/trunk: api/src/main/java/org/jboss/tmpdpl/api/container and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Aug 6 00:29:37 EDT 2009
Author: ALRubinger
Date: 2009-08-06 00:29:37 -0400 (Thu, 06 Aug 2009)
New Revision: 3435
Added:
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/Container.java
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/DeploymentException.java
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/Deployable.java
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/SecurityActions.java
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/VfsVdfDeployableFactory.java
Removed:
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/Deployable.java
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/DeploymentException.java
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/SecurityActions.java
tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/VfsVdfDeployableFactory.java
Modified:
tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableFactoryTestCase.java
tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImplTestCase.java
tmpdpl/trunk/spi-vdf/src/main/java/org/jboss/tmpdpl/spi/vdf/VdfDeployable.java
Log:
[TMPDPL-2] Add a Container API to deploy/undeploy Deployable types
Deleted: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/Deployable.java
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/Deployable.java 2009-08-06 03:26:22 UTC (rev 3434)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/Deployable.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -1,39 +0,0 @@
-/*
- * 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.tmpdpl.api;
-
-/**
- * Deployable
- *
- * Represents an entity which is eligible for deployment into an
- * Embedded Server.
- *
- * In practice, this is a marker interface, where an embedded server may
- * support a finite set of the children of this type.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public interface Deployable
-{
-
-}
Deleted: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/DeploymentException.java
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/DeploymentException.java 2009-08-06 03:26:22 UTC (rev 3434)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/DeploymentException.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -1,79 +0,0 @@
-/*
- * 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.tmpdpl.api;
-
-/**
- * DeploymentException
- *
- * Indicates a problem encountered during deployment to the server
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class DeploymentException extends Exception
-{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- //-------------------------------------------------------------------------------------||
- // Constructors -----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- *
- */
- public DeploymentException()
- {
- super();
- }
-
- /**
- * @param message
- * @param cause
- */
- public DeploymentException(String message, Throwable cause)
- {
- super(message, cause);
- }
-
- /**
- * @param message
- */
- public DeploymentException(String message)
- {
- super(message);
- }
-
- /**
- * @param cause
- */
- public DeploymentException(Throwable cause)
- {
- super(cause);
- }
-}
Deleted: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/SecurityActions.java
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/SecurityActions.java 2009-08-06 03:26:22 UTC (rev 3434)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/SecurityActions.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -1,108 +0,0 @@
-package org.jboss.tmpdpl.api;
-
-import java.lang.reflect.Constructor;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-
-/**
- * SecurityActions
- *
- * A set of privileged actions that are not to leak out
- * of this package
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-class SecurityActions
-{
-
- //-------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------||
- //-------------------------------------------------------------------------------||
-
- /**
- * No external instantiation
- */
- private SecurityActions()
- {
-
- }
-
- //-------------------------------------------------------------------------------||
- // Utility Methods --------------------------------------------------------------||
- //-------------------------------------------------------------------------------||
-
- /**
- * Obtains the Thread Context ClassLoader
- */
- static ClassLoader getThreadContextClassLoader()
- {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
- {
- public ClassLoader run()
- {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- }
-
- /**
- * Obtains the constructor for the specified class with the specified param types
- * according to the contract of {@link Class#getConstructor(Class...)}
- *
- * @param clazz
- * @param paramTypes
- * @return
- * @throws NoSuchMethodException
- * @throws SecurityException
- * @throws IllegalArgumentException If the class or param types were not specified
- */
- static Constructor<?> getConstructor(final Class<?> clazz, final Class<?>... paramTypes)
- throws NoSuchMethodException, SecurityException, IllegalArgumentException
- {
- // Precondition checks
- if (clazz == null)
- {
- throw new IllegalArgumentException("class must be specified");
- }
- if (paramTypes == null)
- {
- throw new IllegalArgumentException("param types must be specified");
- }
-
- try
- {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>()
- {
-
- @Override
- public Constructor<?> run() throws Exception
- {
- return clazz.getConstructor(paramTypes);
- }
- });
- }
- catch (final PrivilegedActionException pae)
- {
- // Throw nsme and se
- final Throwable unwrapped = pae.getCause();
- if (unwrapped instanceof NoSuchMethodException)
- {
- final NoSuchMethodException nsme = (NoSuchMethodException) unwrapped;
- throw nsme;
- }
- if (unwrapped instanceof SecurityException)
- {
- final SecurityException se = (SecurityException) unwrapped;
- throw se;
- }
-
- // Throw the cause as encountered
- throw new RuntimeException("Error in obtaining constructor", unwrapped);
-
- }
- }
-
-}
Deleted: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/VfsVdfDeployableFactory.java
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/VfsVdfDeployableFactory.java 2009-08-06 03:26:22 UTC (rev 3434)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/VfsVdfDeployableFactory.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -1,228 +0,0 @@
-/*
- * 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.tmpdpl.api;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.jboss.declarchive.api.Archive;
-
-/**
- * VfsVdfDeployableFactory
- *
- * Factory to create {@link Deployable} instances from
- * {@link VfsArchive}s. This removes the API
- * dependency upon internals for the client view and additionally
- * acts as a convenience mechanism.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class VfsVdfDeployableFactory
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(VfsVdfDeployableFactory.class.getName());
-
- /**
- * FQN of implementation Class used in creating new Deployables
- */
- private static final String CLASS_NAME_VFS_VDF_DEPLOYABLE = "org.jboss.tmpdpl.impl.vdf.VfsVdfDeployableImpl";
-
- /**
- * FQN of the archive type actually supported by {@link VfsVdfDeployableFactory#createDeployable(VirtualArchive)}
- */
- private static final String CLASS_NAME_ARCHIVE_TYPE = "org.jboss.declarchive.spi.vfs.VfsArchive";
-
- /**
- * Constructor used in creating new {@link Deployable} instances
- */
- private static Constructor<?> constructor;
-
- /**
- * The actual type expected of archives passed to
- * {@link VfsVdfDeployableFactory#createDeployable(Archive)};
- * used here to do runtime type checking so we hide the internals and don't
- * leak out APIs to the client. Will have FQN of {@link VfsVdfDeployableFactory#CLASS_NAME_ARCHIVE_TYPE}.
- */
- private static Class<?> supportedArchiveType;
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Internal Constructor to prohibit external
- * instantiation
- */
- private VfsVdfDeployableFactory()
- {
- }
-
- //-------------------------------------------------------------------------------------||
- // Functional Methods -----------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Creates a {@link Deployable} from the specified archive
- *
- * @param archive
- * @throws IllegalArgumentException If the archive is not specified or an unsupported type
- */
- public static Deployable createDeployable(final Archive archive) throws IllegalArgumentException
- {
- // Precondition check
- final Class<?> supportedArchiveType = getSupportedArchiveType();
- if (!supportedArchiveType.isAssignableFrom(archive.getClass()))
- {
- final ClassLoader archiveCl = archive.getClass().getClassLoader();
- final ClassLoader supportedCl = supportedArchiveType.getClassLoader();
- log.log(Level.WARNING, "Archive CL: " + archiveCl);
- log.log(Level.WARNING, "Expected CL: " + supportedCl);
- throw new IllegalArgumentException("Specified archive must be of type " + supportedArchiveType.getName()
- + "; was instead: " + archive);
- }
-
- // Get the implementation ctor
- final Constructor<?> constructor = getConstructor();
-
- // Make a new instance
- final Object obj;
- try
- {
- obj = constructor.newInstance(archive);
- if (log.isLoggable(Level.FINER))
- {
- log.log(Level.FINER, "Created: " + obj);
- }
- }
- catch (final InstantiationException e)
- {
- throw new RuntimeException("Error in creating new " + Deployable.class.getName(), e);
- }
- catch (final IllegalAccessException e)
- {
- throw new RuntimeException("Error in creating new " + Deployable.class.getName(), e);
- }
- catch (final InvocationTargetException e)
- {
- throw new RuntimeException("Error in creating new " + Deployable.class.getName(), e);
- }
-
- // Cast
- final Deployable deployable;
- try
- {
- deployable = Deployable.class.cast(obj);
- }
- catch (final ClassCastException cce)
- {
- throw new RuntimeException("New instance should be of type " + Deployable.class.getName(), cce);
- }
-
- // Return
- return deployable;
- }
-
- //-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Obtains the constructor used in creating new Deployable instances.
- * Uses a cached copy unless not yet initialized.
- */
- private synchronized static Constructor<?> getConstructor()
- {
- // If we haven't yet cached the ctor
- if (constructor == null)
- {
- // Load the impl class
- final String implClassName = CLASS_NAME_VFS_VDF_DEPLOYABLE;
- final Class<?> implClass = getClass(implClassName);
-
- // Load the ctor param class
- final String paramClassName = CLASS_NAME_ARCHIVE_TYPE;
- final Class<?> paramClass = getClass(paramClassName);
-
- // Get and set the ctor
- try
- {
- constructor = SecurityActions.getConstructor(implClass, paramClass);
- }
- catch (final NoSuchMethodException nsme)
- {
- throw new RuntimeException("Could not find constructor to be used in factory creation of a new "
- + Deployable.class.getSimpleName(), nsme);
- }
-
- }
-
- // Return
- return constructor;
- }
-
- /**
- * Obtains the class with the specified name from the TCCL
- *
- * @param className
- * @return
- */
- private static Class<?> getClass(final String className)
- {
- final ClassLoader cl = SecurityActions.getThreadContextClassLoader();
- try
- {
- return Class.forName(className, false, cl);
- }
- catch (ClassNotFoundException cnfe)
- {
- throw new RuntimeException("Could not find implementation class \"" + className + "\" in " + cl, cnfe);
- }
- }
-
- /**
- * Obtains the Class representing supported archive types to be used
- * in creation of new Deployables
- * @return
- */
- private synchronized static Class<?> getSupportedArchiveType()
- {
- // If not yet initialized/cached
- if (supportedArchiveType == null)
- {
- // Load and set
- supportedArchiveType = getClass(CLASS_NAME_ARCHIVE_TYPE);
- }
-
- // Return
- return supportedArchiveType;
- }
-}
Added: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/Container.java
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/Container.java (rev 0)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/Container.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -0,0 +1,82 @@
+/*
+ * 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.tmpdpl.api.container;
+
+import org.jboss.declarchive.api.Archive;
+import org.jboss.tmpdpl.api.deployable.Deployable;
+
+/**
+ * Container
+ *
+ * An entity capable of deploying/undeploying {@link Deployable} types
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Container
+{
+ //-------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Deploys the specified deployables into the server as one atomic operation.
+ *
+ * @param deployables
+ * @throws DeploymentException
+ * @throws IllegalArgumentException If no deployables were specified or the type of deployable
+ * is not supported by this server
+ */
+ void deploy(Deployable... deployables) throws DeploymentException, IllegalArgumentException;
+
+ /**
+ * Deploys the specified archives into the server as one atomic operation.
+ *
+ * @param archives
+ * @throws DeploymentException
+ * @throws IllegalArgumentException If no archives were specified or the type of archive
+ * is not supported by this server
+ */
+ void deploy(Archive... archives) throws DeploymentException, IllegalArgumentException;
+
+ /**
+ * Undeploys the specified deployables from the server as one atomic operation.
+ * The deployables must have been previously deployed.
+ *
+ * @param deployables
+ * @throws DeploymentException
+ * @throws IllegalArgumentException If no deployables were specified or the type of deployable
+ * is not supported by this server
+ */
+ void undeploy(Deployable... deployables) throws DeploymentException, IllegalArgumentException;
+
+ /**
+ * Undeploys the specified archives from the server as one atomic operation.
+ * The archives must have been previously deployed.
+ *
+ * @param archives
+ * @throws DeploymentException
+ * @throws IllegalArgumentException If no archives were specified or the type of archive
+ * is not supported by this server
+ */
+ void undeploy(Archive... archives) throws DeploymentException, IllegalArgumentException;
+}
Copied: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/DeploymentException.java (from rev 3434, tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/DeploymentException.java)
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/DeploymentException.java (rev 0)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/DeploymentException.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -0,0 +1,79 @@
+/*
+ * 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.tmpdpl.api.container;
+
+/**
+ * DeploymentException
+ *
+ * Indicates a problem encountered during deployment to the target {@link Container}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class DeploymentException extends Exception
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ *
+ */
+ public DeploymentException()
+ {
+ super();
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public DeploymentException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ /**
+ * @param message
+ */
+ public DeploymentException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public DeploymentException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Copied: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/Deployable.java (from rev 3434, tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/Deployable.java)
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/Deployable.java (rev 0)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/Deployable.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -0,0 +1,39 @@
+/*
+ * 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.tmpdpl.api.deployable;
+
+/**
+ * Deployable
+ *
+ * Represents an entity which is eligible for deployment into an
+ * Embedded Server.
+ *
+ * In practice, this is a marker interface, where an embedded server may
+ * support a finite set of the children of this type.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Deployable
+{
+
+}
Copied: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/SecurityActions.java (from rev 3434, tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/SecurityActions.java)
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/SecurityActions.java (rev 0)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/SecurityActions.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -0,0 +1,108 @@
+package org.jboss.tmpdpl.api.deployable;
+
+import java.lang.reflect.Constructor;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * SecurityActions
+ *
+ * A set of privileged actions that are not to leak out
+ * of this package
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * No external instantiation
+ */
+ private SecurityActions()
+ {
+
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+
+ /**
+ * Obtains the constructor for the specified class with the specified param types
+ * according to the contract of {@link Class#getConstructor(Class...)}
+ *
+ * @param clazz
+ * @param paramTypes
+ * @return
+ * @throws NoSuchMethodException
+ * @throws SecurityException
+ * @throws IllegalArgumentException If the class or param types were not specified
+ */
+ static Constructor<?> getConstructor(final Class<?> clazz, final Class<?>... paramTypes)
+ throws NoSuchMethodException, SecurityException, IllegalArgumentException
+ {
+ // Precondition checks
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("class must be specified");
+ }
+ if (paramTypes == null)
+ {
+ throw new IllegalArgumentException("param types must be specified");
+ }
+
+ try
+ {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>()
+ {
+
+ @Override
+ public Constructor<?> run() throws Exception
+ {
+ return clazz.getConstructor(paramTypes);
+ }
+ });
+ }
+ catch (final PrivilegedActionException pae)
+ {
+ // Throw nsme and se
+ final Throwable unwrapped = pae.getCause();
+ if (unwrapped instanceof NoSuchMethodException)
+ {
+ final NoSuchMethodException nsme = (NoSuchMethodException) unwrapped;
+ throw nsme;
+ }
+ if (unwrapped instanceof SecurityException)
+ {
+ final SecurityException se = (SecurityException) unwrapped;
+ throw se;
+ }
+
+ // Throw the cause as encountered
+ throw new RuntimeException("Error in obtaining constructor", unwrapped);
+
+ }
+ }
+
+}
Property changes on: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/SecurityActions.java
___________________________________________________________________
Name: svn:executable
+ *
Copied: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/VfsVdfDeployableFactory.java (from rev 3434, tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/VfsVdfDeployableFactory.java)
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/VfsVdfDeployableFactory.java (rev 0)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/VfsVdfDeployableFactory.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -0,0 +1,228 @@
+/*
+ * 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.tmpdpl.api.deployable;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Archive;
+
+/**
+ * VfsVdfDeployableFactory
+ *
+ * Factory to create {@link Deployable} instances from
+ * {@link VfsArchive}s. This removes the API
+ * dependency upon internals for the client view and additionally
+ * acts as a convenience mechanism.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class VfsVdfDeployableFactory
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(VfsVdfDeployableFactory.class.getName());
+
+ /**
+ * FQN of implementation Class used in creating new Deployables
+ */
+ private static final String CLASS_NAME_VFS_VDF_DEPLOYABLE = "org.jboss.tmpdpl.impl.vdf.VfsVdfDeployableImpl";
+
+ /**
+ * FQN of the archive type actually supported by {@link VfsVdfDeployableFactory#createDeployable(VirtualArchive)}
+ */
+ private static final String CLASS_NAME_ARCHIVE_TYPE = "org.jboss.declarchive.spi.vfs.VfsArchive";
+
+ /**
+ * Constructor used in creating new {@link Deployable} instances
+ */
+ private static Constructor<?> constructor;
+
+ /**
+ * The actual type expected of archives passed to
+ * {@link VfsVdfDeployableFactory#createDeployable(Archive)};
+ * used here to do runtime type checking so we hide the internals and don't
+ * leak out APIs to the client. Will have FQN of {@link VfsVdfDeployableFactory#CLASS_NAME_ARCHIVE_TYPE}.
+ */
+ private static Class<?> supportedArchiveType;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Internal Constructor to prohibit external
+ * instantiation
+ */
+ private VfsVdfDeployableFactory()
+ {
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Functional Methods -----------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a {@link Deployable} from the specified archive
+ *
+ * @param archive
+ * @throws IllegalArgumentException If the archive is not specified or an unsupported type
+ */
+ public static Deployable createDeployable(final Archive archive) throws IllegalArgumentException
+ {
+ // Precondition check
+ final Class<?> supportedArchiveType = getSupportedArchiveType();
+ if (!supportedArchiveType.isAssignableFrom(archive.getClass()))
+ {
+ final ClassLoader archiveCl = archive.getClass().getClassLoader();
+ final ClassLoader supportedCl = supportedArchiveType.getClassLoader();
+ log.log(Level.WARNING, "Archive CL: " + archiveCl);
+ log.log(Level.WARNING, "Expected CL: " + supportedCl);
+ throw new IllegalArgumentException("Specified archive must be of type " + supportedArchiveType.getName()
+ + "; was instead: " + archive);
+ }
+
+ // Get the implementation ctor
+ final Constructor<?> constructor = getConstructor();
+
+ // Make a new instance
+ final Object obj;
+ try
+ {
+ obj = constructor.newInstance(archive);
+ if (log.isLoggable(Level.FINER))
+ {
+ log.log(Level.FINER, "Created: " + obj);
+ }
+ }
+ catch (final InstantiationException e)
+ {
+ throw new RuntimeException("Error in creating new " + Deployable.class.getName(), e);
+ }
+ catch (final IllegalAccessException e)
+ {
+ throw new RuntimeException("Error in creating new " + Deployable.class.getName(), e);
+ }
+ catch (final InvocationTargetException e)
+ {
+ throw new RuntimeException("Error in creating new " + Deployable.class.getName(), e);
+ }
+
+ // Cast
+ final Deployable deployable;
+ try
+ {
+ deployable = Deployable.class.cast(obj);
+ }
+ catch (final ClassCastException cce)
+ {
+ throw new RuntimeException("New instance should be of type " + Deployable.class.getName(), cce);
+ }
+
+ // Return
+ return deployable;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the constructor used in creating new Deployable instances.
+ * Uses a cached copy unless not yet initialized.
+ */
+ private synchronized static Constructor<?> getConstructor()
+ {
+ // If we haven't yet cached the ctor
+ if (constructor == null)
+ {
+ // Load the impl class
+ final String implClassName = CLASS_NAME_VFS_VDF_DEPLOYABLE;
+ final Class<?> implClass = getClass(implClassName);
+
+ // Load the ctor param class
+ final String paramClassName = CLASS_NAME_ARCHIVE_TYPE;
+ final Class<?> paramClass = getClass(paramClassName);
+
+ // Get and set the ctor
+ try
+ {
+ constructor = SecurityActions.getConstructor(implClass, paramClass);
+ }
+ catch (final NoSuchMethodException nsme)
+ {
+ throw new RuntimeException("Could not find constructor to be used in factory creation of a new "
+ + Deployable.class.getSimpleName(), nsme);
+ }
+
+ }
+
+ // Return
+ return constructor;
+ }
+
+ /**
+ * Obtains the class with the specified name from the TCCL
+ *
+ * @param className
+ * @return
+ */
+ private static Class<?> getClass(final String className)
+ {
+ final ClassLoader cl = SecurityActions.getThreadContextClassLoader();
+ try
+ {
+ return Class.forName(className, false, cl);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new RuntimeException("Could not find implementation class \"" + className + "\" in " + cl, cnfe);
+ }
+ }
+
+ /**
+ * Obtains the Class representing supported archive types to be used
+ * in creation of new Deployables
+ * @return
+ */
+ private synchronized static Class<?> getSupportedArchiveType()
+ {
+ // If not yet initialized/cached
+ if (supportedArchiveType == null)
+ {
+ // Load and set
+ supportedArchiveType = getClass(CLASS_NAME_ARCHIVE_TYPE);
+ }
+
+ // Return
+ return supportedArchiveType;
+ }
+}
Modified: tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableFactoryTestCase.java
===================================================================
--- tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableFactoryTestCase.java 2009-08-06 03:26:22 UTC (rev 3434)
+++ tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableFactoryTestCase.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -27,8 +27,8 @@
import org.jboss.declarchive.api.Archive;
import org.jboss.declarchive.impl.vfs.MemoryArchiveImpl;
-import org.jboss.tmpdpl.api.Deployable;
-import org.jboss.tmpdpl.api.VfsVdfDeployableFactory;
+import org.jboss.tmpdpl.api.deployable.Deployable;
+import org.jboss.tmpdpl.api.deployable.VfsVdfDeployableFactory;
import org.jboss.virtual.VFS;
import org.junit.BeforeClass;
import org.junit.Test;
Modified: tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImplTestCase.java
===================================================================
--- tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImplTestCase.java 2009-08-06 03:26:22 UTC (rev 3434)
+++ tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImplTestCase.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -25,7 +25,7 @@
import org.jboss.declarchive.impl.vfs.MemoryArchiveImpl;
import org.jboss.declarchive.spi.vfs.VfsArchive;
-import org.jboss.tmpdpl.api.Deployable;
+import org.jboss.tmpdpl.api.deployable.Deployable;
import org.jboss.virtual.VFS;
import org.junit.Assert;
import org.junit.BeforeClass;
Modified: tmpdpl/trunk/spi-vdf/src/main/java/org/jboss/tmpdpl/spi/vdf/VdfDeployable.java
===================================================================
--- tmpdpl/trunk/spi-vdf/src/main/java/org/jboss/tmpdpl/spi/vdf/VdfDeployable.java 2009-08-06 03:26:22 UTC (rev 3434)
+++ tmpdpl/trunk/spi-vdf/src/main/java/org/jboss/tmpdpl/spi/vdf/VdfDeployable.java 2009-08-06 04:29:37 UTC (rev 3435)
@@ -22,7 +22,7 @@
package org.jboss.tmpdpl.spi.vdf;
import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.tmpdpl.api.Deployable;
+import org.jboss.tmpdpl.api.deployable.Deployable;
/**
* VdfDeployable
More information about the jboss-svn-commits
mailing list