[jboss-cvs] JBossAS SVN: r91698 - in projects/embedded/trunk: core/src/main/java/org/jboss/embedded/core/incubation/deployable and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 28 01:14:51 EDT 2009
Author: ALRubinger
Date: 2009-07-28 01:14:51 -0400 (Tue, 28 Jul 2009)
New Revision: 91698
Added:
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/impl/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/impl/vdf/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/impl/vdf/VfsVdfDeployableImpl.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/Deployable.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/DeployableFactory.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/DeploymentException.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/SecurityActions.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/vdf/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/vdf/VdfDeployable.java
projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/deployable/
projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/deployable/vfs/
projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/deployable/vfs/VfsVdfDeployableFactoryTestCase.java
Modified:
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
Log:
[EMB-38] Prototype a "Deployable" API to hide VDF internals from Embedded clients
Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/impl/vdf/VfsVdfDeployableImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/impl/vdf/VfsVdfDeployableImpl.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/impl/vdf/VfsVdfDeployableImpl.java 2009-07-28 05:14:51 UTC (rev 91698)
@@ -0,0 +1,162 @@
+/*
+ * 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.embedded.core.incubation.deployable.impl.vdf;
+
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.embedded.core.incubation.deployable.spi.vdf.VdfDeployable;
+import org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * VfsVdfDeployableImpl
+ *
+ * A Virtual Deployer's Framework Deployment backed by
+ * a Virtual File System root
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class VfsVdfDeployableImpl implements VdfDeployable
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(VfsVdfDeployableImpl.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The underlying deployment
+ */
+ private Deployment deployment;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ *
+ * Creates a new Deployable from the specified archive
+ * @throws IllegalArgumentException If the archive is not specified
+ */
+ public VfsVdfDeployableImpl(final VirtualVfsArchive archive) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (archive == null)
+ {
+ throw new IllegalArgumentException("archive must be specified");
+ }
+
+ // Obtain file
+ final VirtualFile file = archive.getRoot();
+
+ // Check
+ if (file == null)
+ {
+ throw new IllegalArgumentException("file must be obtained from the specified archive");
+ }
+
+ // Init
+ this.init(file);
+ }
+
+ /**
+ * Constructor
+ *
+ * Creates a new Deployable from the specified virtual file
+ * @throws IllegalArgumentException If the file is not specified
+ */
+ public VfsVdfDeployableImpl(final VirtualFile file)
+ {
+ // Precondition check
+ if (file == null)
+ {
+ throw new IllegalArgumentException("file must be specified");
+ }
+
+ // Init
+ this.init(file);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.embedded.core.incubation.deployable.spi.vdf.VdfDeployable#getDeployment()
+ */
+ @Override
+ public Deployment getDeployment()
+ {
+ return this.deployment;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Initializes the deployable by creating and
+ * setting a Deployers SPI Deployment.
+ *
+ * @param file The root of the VDF deployment
+ * @throws IllegalArgumentException If the file was not specified
+ */
+ private void init(final VirtualFile file) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (file == null)
+ {
+ throw new IllegalArgumentException("file must be specified");
+ }
+
+ // Create Deployment
+ final Deployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(file);
+ log.debug("Created deployment: " + deployment);
+
+ // Set
+ this.setDeployment(deployment);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @param deployment the deployment to set
+ */
+ private void setDeployment(final Deployment deployment)
+ {
+ this.deployment = deployment;
+ }
+
+}
Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/Deployable.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/Deployable.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/Deployable.java 2009-07-28 05:14:51 UTC (rev 91698)
@@ -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.embedded.core.incubation.deployable.spi;
+
+/**
+ * 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
+{
+
+}
Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/DeployableFactory.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/DeployableFactory.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/DeployableFactory.java 2009-07-28 05:14:51 UTC (rev 91698)
@@ -0,0 +1,232 @@
+/*
+ * 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.embedded.core.incubation.deployable.spi;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import org.jboss.embedded.core.incubation.virtual.spi.ExtensibleVirtualArchive;
+import org.jboss.logging.Logger;
+
+/**
+ * DeployableFactory
+ *
+ * Factory to create {@link Deployable} instances from
+ * {@link ExtensibleVirtualArchive}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 DeployableFactory
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(DeployableFactory.class);
+
+ /**
+ * FQN of implementation Class used in creating new Deployables
+ */
+ private static final String CLASS_NAME_VFS_VDF_DEPLOYABLE = "org.jboss.embedded.core.incubation.deployable.impl.vdf.VfsVdfDeployable";
+
+ /**
+ * FQN of type of parameter to implementation class constructor
+ */
+ private static final String CLASS_NAME_CTOR_PARAMETER = "org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive";
+
+ /**
+ * FQN of the archive type actually supported by {@link DeployableFactory#createDeployable(ExtensibleVirtualArchive)}
+ */
+ private static final String CLASS_NAME_ARCHIVE_TYPE = "org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive";
+
+ /**
+ * Constructor used in creating new {@link Deployable} instances
+ */
+ private static Constructor<?> constructor;
+
+ /**
+ * The actual type expected of archives passed to
+ * {@link DeployableFactory#createDeployable(ExtensibleVirtualArchive)};
+ * 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 DeployableFactory#CLASS_NAME_ARCHIVE_TYPE}.
+ */
+ private static Class<?> supportedArchiveType;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Internal Constructor to prohibit external
+ * instantiation
+ */
+ private DeployableFactory()
+ {
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // 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 ExtensibleVirtualArchive<?> 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.warn("Archive CL: " + archiveCl);
+ log.warn("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.isTraceEnabled())
+ {
+ log.trace("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 = getDeployableImplementationClass(implClassName);
+
+ // Load the ctor param class
+ final String paramClassName = CLASS_NAME_CTOR_PARAMETER;
+ final Class<?> paramClass = getDeployableImplementationClass(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 implementation class to use in creating new Deployables
+ *
+ * @param className
+ * @return
+ */
+ private static Class<?> getDeployableImplementationClass(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 = getDeployableImplementationClass(CLASS_NAME_ARCHIVE_TYPE);
+ }
+
+ // Return
+ return supportedArchiveType;
+ }
+}
Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/DeploymentException.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/DeploymentException.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/DeploymentException.java 2009-07-28 05:14:51 UTC (rev 91698)
@@ -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.embedded.core.incubation.deployable.spi;
+
+/**
+ * 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);
+ }
+}
Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/SecurityActions.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/SecurityActions.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/SecurityActions.java 2009-07-28 05:14:51 UTC (rev 91698)
@@ -0,0 +1,108 @@
+package org.jboss.embedded.core.incubation.deployable.spi;
+
+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: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/SecurityActions.java
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/vdf/VdfDeployable.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/vdf/VdfDeployable.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/incubation/deployable/spi/vdf/VdfDeployable.java 2009-07-28 05:14:51 UTC (rev 91698)
@@ -0,0 +1,44 @@
+/*
+ * 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.embedded.core.incubation.deployable.spi.vdf;
+
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.embedded.core.incubation.deployable.spi.Deployable;
+
+/**
+ * VdfDeployable
+ *
+ * Represents a deployable entity which may be exposed
+ * as a JBoss Virtual Deployers Framework (VDF) implementation
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface VdfDeployable extends Deployable
+{
+ /**
+ * Returns the VDF view of this deployment
+ *
+ * @return
+ */
+ Deployment getDeployment();
+}
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java 2009-07-28 05:05:17 UTC (rev 91697)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java 2009-07-28 05:14:51 UTC (rev 91698)
@@ -23,9 +23,8 @@
import org.jboss.bootstrap.spi.as.config.JBossASServerConfig;
import org.jboss.bootstrap.spi.as.server.JBossASBasedServer;
-import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive;
+import org.jboss.embedded.core.incubation.deployable.spi.Deployable;
+import org.jboss.embedded.core.incubation.deployable.spi.DeploymentException;
/**
* JBossASEmbeddedServer
@@ -42,47 +41,24 @@
// Contracts --------------------------------------------------------------------||
//-------------------------------------------------------------------------------||
- /*
- * Add methods to:
- * 1) Deploy a Collection of Deployments at once (maindeployer.add, then process)
- * 2) Undeploy a Collection of Deployments at once
- */
-
/**
- * Deploys the specified deployment into the server
+ * Deploys the specified deployables into the server as one atomic operation.
*
- * @param deployment
+ * @param deployables
* @throws DeploymentException
- * @throws IllegalArgumentException If the deployment was not specified
+ * @throws IllegalArgumentException If no deployables were specified or the type of deployable
+ * is not supported by this server
*/
- void deploy(Deployment deployment) throws DeploymentException, IllegalArgumentException;
+ void deploy(Deployable... deployables) throws DeploymentException, IllegalArgumentException;
/**
- * Deploys the specified archive into the server
+ * Undeploys the specified deployables into the server as one atomic operation.
+ * The deployables must have been previously deployed.
*
- * @param archive
+ * @param deployables
* @throws DeploymentException
- * @throws IllegalArgumentException If the deployment was not specified
+ * @throws IllegalArgumentException If no deployables were specified or the type of deployable
+ * is not supported by this server
*/
- void deploy(VirtualVfsArchive archive) throws DeploymentException, IllegalArgumentException;
-
- /**
- * Undeploys the specified deployment
- *
- * @param deployment
- * @throws IllegalArgumentException If the archive is not deployed or
- * not specified
- * @throws DeploymentException
- */
- void undeploy(Deployment deployment) throws IllegalArgumentException, DeploymentException;
-
- /**
- * Undeploys the specified archive
- *
- * @param archive
- * @throws IllegalArgumentException If the archive is not deployed or
- * not specified
- * @throws DeploymentException
- */
- void undeploy(VirtualVfsArchive archive) throws IllegalArgumentException, DeploymentException;
+ void undeploy(Deployable... deployables) throws DeploymentException, IllegalArgumentException;
}
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java 2009-07-28 05:05:17 UTC (rev 91697)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java 2009-07-28 05:14:51 UTC (rev 91698)
@@ -21,6 +21,8 @@
*/
package org.jboss.embedded.core.server;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -34,16 +36,15 @@
import org.jboss.dependency.spi.ControllerState;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
-import org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive;
+import org.jboss.embedded.core.incubation.deployable.spi.Deployable;
+import org.jboss.embedded.core.incubation.deployable.spi.DeploymentException;
+import org.jboss.embedded.core.incubation.deployable.spi.vdf.VdfDeployable;
import org.jboss.embedded.core.lifecycle.IgnoreXbUnorderedSequenceLifecycleEventHandler;
import org.jboss.embedded.core.lifecycle.InitLoggingManagerLifecycleEventHandler;
import org.jboss.embedded.core.lifecycle.SetRmiHostnameLifecycleEventHandler;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.logging.Logger;
-import org.jboss.virtual.VirtualFile;
/**
* JBossASEmbeddedServer
@@ -88,9 +89,9 @@
//-------------------------------------------------------------------------------------||
/**
- * A mapping of virtual archives to their resultant deployments (so we can undeploy archives)
+ * A mapping of deployable types to their resultant deployments (so we can undeploy archives)
*/
- private final Map<VirtualVfsArchive, Deployment> virtualArchiveDeployments = new ConcurrentHashMap<VirtualVfsArchive, Deployment>();;
+ private final Map<Deployable, Deployment> deployments = new ConcurrentHashMap<Deployable, Deployment>();;
//-------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
@@ -153,93 +154,105 @@
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#deploy(org.jboss.deployers.client.spi.Deployment)
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#deploy(org.jboss.embedded.core.incubation.deployable.spi.Deployable[])
*/
@Override
- public void deploy(final Deployment deployment) throws DeploymentException, IllegalArgumentException
+ public void deploy(final Deployable... deployables)
+ throws org.jboss.embedded.core.incubation.deployable.spi.DeploymentException, IllegalArgumentException
{
- // Precondition check
- if (deployment == null)
- {
- throw new IllegalArgumentException("deployment must be specified");
- }
+ // Precondition checks and obtain as VDF impls
+ final Collection<VdfDeployable> vdfDeployables = this.asVdfDeployables(deployables);
- // Deploy and check all's OK
+ // Get the MainDeployer
+ //TODO Use ProfileService - EMB-39
final MainDeployer mainDeployer = this.getMainDeployer();
- log.debug("Deploying: " + deployment);
- mainDeployer.deploy(deployment);
- if (log.isTraceEnabled())
+
+ // Add each deployable
+ for (final VdfDeployable vdfDeployable : vdfDeployables)
{
- log.trace("Checking for complete/successful deployment: " + mainDeployer);
+
+ /*
+ * Get the Deployers SPI Deployment
+ */
+
+ // Declare
+ final Deployment deployment = vdfDeployable.getDeployment();
+
+ // Add to the MainDeployer
+ log.debug("Adding to " + mainDeployer + ": " + deployment);
+ try
+ {
+ // Add the deployment to the MainDeployer
+ mainDeployer.addDeployment(deployment);
+ }
+ catch (org.jboss.deployers.spi.DeploymentException de)
+ {
+ // Wrap in our own API's DeploymentException
+ throw new DeploymentException(de);
+ }
+
+ // Add to the map (so we can undeploy the deployable later)
+ this.deployments.put(vdfDeployable, deployment);
}
- mainDeployer.checkComplete();
- log.debug("Deployed: " + deployment);
+
+ // Process and check
+ this.processAndCheckMainDeployer(mainDeployer);
+
}
/*
* (non-Javadoc)
- * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#deploy(org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive)
+ * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#undeploy(org.jboss.embedded.core.incubation.deployable.spi.Deployable[])
*/
@Override
- public void deploy(final VirtualVfsArchive archive) throws DeploymentException, IllegalArgumentException
+ public void undeploy(final Deployable... deployables)
+ throws org.jboss.embedded.core.incubation.deployable.spi.DeploymentException, IllegalArgumentException
{
- // Precondition check
- if (archive == null)
+ /*
+ * Precondition checks
+ */
+
+ // Ensure deployables are specified
+ if (deployables == null || deployables.length == 0)
{
- throw new IllegalArgumentException("deployment must be specified");
+ throw new IllegalArgumentException("At least one deployable must be specified");
}
- // Make a VFS Deployment
- final VirtualFile root = archive.getRoot();
- final Deployment d = VFSDeploymentFactory.getInstance().createVFSDeployment(root);
-
- // Deploy
- this.deploy(d);
-
- // Add to the map (so we can undeploy the archive later)
- this.virtualArchiveDeployments.put(archive, d);
- }
-
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#undeploy(org.jboss.deployers.client.spi.Deployment)
- */
- @Override
- public void undeploy(final Deployment deployment) throws IllegalArgumentException, DeploymentException
- {
// Get the MainDeployer
+ //TODO Use ProfileService - EMB-39
final MainDeployer mainDeployer = this.getMainDeployer();
- // Undeploy
- log.debug("Undeploying: " + deployment);
- mainDeployer.undeploy(deployment);
- log.debug("Undeployed: " + deployment);
- }
-
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#undeploy(org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive)
- */
- @Override
- public void undeploy(final VirtualVfsArchive archive) throws IllegalArgumentException, DeploymentException
- {
- // Precondition check
- if (archive == null)
+ // Get the deployments for each deployable
+ for (final Deployable deployable : deployables)
{
- throw new IllegalArgumentException("archive must be specified");
- }
+ final Deployment deployment = this.getDeploymentsMap().get(deployable);
+ if (deployment == null)
+ {
+ log.warn("Specified deployable " + deployable + " cannot be undeployed because it is not deployed.");
+ }
+ else
+ {
+ // Remove from MainDeployer
+ try
+ {
+ mainDeployer.removeDeployment(deployment);
+ }
+ catch (org.jboss.deployers.spi.DeploymentException de)
+ {
+ // Wrap in our own API's DeploymentException
+ throw new DeploymentException(de);
+ }
- // Get the corresponding deployment
- final Deployment deployment = this.getVirtualArchiveDeployments().get(archive);
- if (deployment == null)
- {
- throw new IllegalArgumentException("The specified archive has not been deployed: " + archive.toString(true));
+ // Remove from Map
+ this.deployments.remove(deployable);
+ }
}
- // Undeploy
- this.undeploy(deployment);
+ // Process and check
+ this.processAndCheckMainDeployer(mainDeployer);
- // Remove from the map
- this.virtualArchiveDeployments.remove(archive);
}
/*
@@ -322,7 +335,9 @@
/**
* Obtains the MainDeployer via MC
* @return
+ * @deprecated EMB-39
*/
+ @Deprecated
protected final MainDeployer getMainDeployer()
{
// Get the MainDeployer
@@ -340,17 +355,98 @@
return mainDeployer;
}
+ /**
+ * Returns a view of the specified Deployables as {@link VdfDeployable}s.
+ *
+ * @param deployables
+ * @return
+ * @throws IllegalArgumentException If the deployables are either null, empty, or
+ * contain any non-VDF types
+ */
+ private Collection<VdfDeployable> asVdfDeployables(final Deployable... deployables) throws IllegalArgumentException
+ {
+ /*
+ * Precondition checks
+ */
+
+ // Ensure deployables are specified
+ if (deployables == null || deployables.length == 0)
+ {
+ throw new IllegalArgumentException("At least one deployable must be specified");
+ }
+
+ // Ensure all deployables are of VDF impls
+ final Collection<VdfDeployable> vdfDeployables = new ArrayList<VdfDeployable>();
+
+ // Add each deployable
+ for (final Deployable deployable : deployables)
+ {
+ // Is VDF type Deployable?
+ final VdfDeployable vdfDeployable;
+ if (deployable instanceof VdfDeployable)
+ {
+ vdfDeployable = (VdfDeployable) deployable;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unsupported " + Deployable.class.getName() + ": " + deployable
+ + "; must be of type: " + VdfDeployable.class.getName());
+ }
+
+ // Add
+ vdfDeployables.add(vdfDeployable);
+
+ }
+
+ // Return
+ return vdfDeployables;
+ }
+
+ /**
+ * Processes and checks the specified MainDeployer
+ * @param mainDeployer
+ * @throws DeploymentException
+ * @throws IllegalArgumentException If the mainDeployer is not specified
+ * @deprecated EMB-39
+ */
+ @Deprecated
+ private void processAndCheckMainDeployer(final MainDeployer mainDeployer) throws DeploymentException,
+ IllegalArgumentException
+ {
+ // Precondition check
+ if (mainDeployer == null)
+ {
+ throw new IllegalArgumentException("mainDeployer must be specified");
+ }
+
+ // Process All
+ log.debug("Processing: " + mainDeployer);
+ mainDeployer.process();
+
+ // Check all completed OK
+ try
+ {
+ log.debug("Checking: " + mainDeployer);
+ mainDeployer.checkComplete();
+ }
+ catch (org.jboss.deployers.spi.DeploymentException de)
+ {
+ // Wrap in our own API's DeploymentException
+ throw new DeploymentException(de);
+ }
+ }
+
//-------------------------------------------------------------------------------------||
// Accessors / Mutators ---------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
/**
- * Returns an immutable view of the archives/deployments map
- * @return the virtualArchiveDeployments
+ * Returns an immutable view of the deployables/deployments map
+ * @return the Deployments
*/
- protected final Map<VirtualVfsArchive, Deployment> getVirtualArchiveDeployments()
+ protected final Map<Deployable, Deployment> getDeploymentsMap()
{
- return Collections.unmodifiableMap(virtualArchiveDeployments);
+ return Collections.unmodifiableMap(deployments);
}
}
Added: projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/deployable/vfs/VfsVdfDeployableFactoryTestCase.java
===================================================================
--- projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/deployable/vfs/VfsVdfDeployableFactoryTestCase.java (rev 0)
+++ projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/incubation/deployable/vfs/VfsVdfDeployableFactoryTestCase.java 2009-07-28 05:14:51 UTC (rev 91698)
@@ -0,0 +1,95 @@
+/*
+ * 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.embedded.core.incubation.deployable.vfs;
+
+import junit.framework.Assert;
+
+import org.jboss.embedded.core.incubation.deployable.impl.vdf.VfsVdfDeployableImpl;
+import org.jboss.embedded.core.incubation.deployable.spi.Deployable;
+import org.jboss.embedded.core.incubation.deployable.spi.DeployableFactory;
+import org.jboss.embedded.core.incubation.virtual.impl.vfs.VirtualVfsArchiveImpl;
+import org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VFS;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * VfsVdfDeployableFactoryTestCase
+ *
+ * Test Cases to assert that the {@link DeployableFactory} is
+ * working correctly
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class VfsVdfDeployableFactoryTestCase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(VfsVdfDeployableFactoryTestCase.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Initializes the virtual file system
+ */
+ @BeforeClass
+ public static void initVfs() throws Exception
+ {
+ // Init VFS
+ VFS.init();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Tests that using a {@link DeployableFactory} to create a deployable
+ * type results in a new instance backed by VFS/VDF
+ */
+ @Test
+ public void testDeployableFactory() throws Exception
+ {
+ // Log
+ log.info("testDeployableFactory");
+
+ // Make an archive
+ final VirtualVfsArchive archive = new VirtualVfsArchiveImpl("test.jar").addClass(this.getClass());
+
+ // Make a Deployable
+ final Deployable deployable = DeployableFactory.createDeployable(archive);
+
+ // Ensure exists
+ Assert.assertNotNull("Deployable was not created/null", deployable);
+ Assert.assertTrue("Created deployable was not of expected type", deployable instanceof VfsVdfDeployableImpl);
+ }
+}
Modified: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java 2009-07-28 05:05:17 UTC (rev 91697)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java 2009-07-28 05:14:51 UTC (rev 91698)
@@ -53,6 +53,8 @@
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+import org.jboss.embedded.core.incubation.deployable.spi.Deployable;
+import org.jboss.embedded.core.incubation.deployable.spi.DeployableFactory;
import org.jboss.embedded.core.incubation.virtual.impl.vfs.VirtualVfsArchiveImpl;
import org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive;
import org.jboss.embedded.core.server.JBossASEmbeddedServer;
@@ -245,9 +247,10 @@
final VirtualVfsArchive archive = new VirtualVfsArchiveImpl(name).addClasses(OutputBean.class,
OutputLocalBusiness.class);
log.info(archive.toString(true));
+ final Deployable deployable = DeployableFactory.createDeployable(archive);
// Deploy
- server.deploy(archive);
+ server.deploy(deployable);
// Test
final OutputLocalBusiness bean = (OutputLocalBusiness) NAMING_CONTEXT.lookup(OutputBean.class.getSimpleName()
@@ -257,7 +260,7 @@
Assert.assertEquals(OutputLocalBusiness.OUTPUT, output);
// Undeploy
- server.undeploy(archive);
+ server.undeploy(deployable);
}
@@ -293,9 +296,10 @@
final VirtualVfsArchive archive = new VirtualVfsArchiveImpl(name).addResource(locationWebXml, newPathWebXml)
.addResource(locationJsp, PATH_JSP).addClass(servletClass);
log.info(archive.toString(true));
+ final Deployable deployable = DeployableFactory.createDeployable(archive);
// Deploy
- server.deploy(archive);
+ server.deploy(deployable);
// Get an HTTP Client
final HttpClient client = new DefaultHttpClient();
@@ -325,7 +329,7 @@
Assert.assertEquals(echoValue, line);
// Undeploy
- server.undeploy(archive);
+ server.undeploy(deployable);
}
/**
@@ -348,7 +352,8 @@
// Deploy
log.info(archive.toString(true));
- server.deploy(archive);
+ final Deployable deployable = DeployableFactory.createDeployable(archive);
+ server.deploy(deployable);
// Define a String message to send
final String message = "From in-JVM Test Message";
@@ -380,7 +385,7 @@
Assert.assertEquals("The test message received was not as expected", message, received);
// Undeploy
- server.undeploy(archive);
+ server.undeploy(deployable);
}
More information about the jboss-cvs-commits
mailing list