[jboss-svn-commits] JBoss Portal SVN: r5682 - in trunk: common/src/main/org/jboss/portal/common/net core/src/main/org/jboss/portal/core/deployment/jboss portlet/src/main/org/jboss/portal/portlet/deployment/jboss server/src/main/org/jboss/portal/server/deployment/jboss theme/src/main/org/jboss/portal/theme/deployment/jboss
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Nov 20 09:45:08 EST 2006
Author: julien at jboss.com
Date: 2006-11-20 09:44:48 -0500 (Mon, 20 Nov 2006)
New Revision: 5682
Added:
trunk/common/src/main/org/jboss/portal/common/net/URLFilter.java
trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentContext.java
trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentFactoryContext.java
trunk/server/src/main/org/jboss/portal/server/deployment/jboss/PortalDeploymentInfoContext.java
Modified:
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeploymentFactory.java
trunk/portlet/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java
trunk/server/src/main/org/jboss/portal/server/deployment/jboss/AbstractDeploymentFactory.java
trunk/server/src/main/org/jboss/portal/server/deployment/jboss/Deployment.java
trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentFactory.java
trunk/server/src/main/org/jboss/portal/server/deployment/jboss/PortalDeploymentInfo.java
trunk/server/src/main/org/jboss/portal/server/deployment/jboss/ServerDeployer.java
trunk/server/src/main/org/jboss/portal/server/deployment/jboss/ServerDeployerMBean.java
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeploymentFactory.java
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeploymentFactory.java
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeploymentFactory.java
Log:
improve the deployment layer to have responsibities more well defined
Added: trunk/common/src/main/org/jboss/portal/common/net/URLFilter.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/net/URLFilter.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/common/src/main/org/jboss/portal/common/net/URLFilter.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.net;
+
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface URLFilter
+{
+ /**
+ * Return true if the factory accept to create a deployment for this url.
+ */
+ boolean acceptFile(URL url);
+
+ /**
+ * Return true if the directory should be visited.
+ */
+ boolean acceptDir(URL url);
+}
Modified: trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeploymentFactory.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeploymentFactory.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeploymentFactory.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -51,7 +51,7 @@
/** . */
protected PortalObjectContainer portalObjectContainer;
- public boolean accept(URL url)
+ public boolean acceptFile(URL url)
{
String urlAsFile = url.getFile();
Matcher matcher = URL_PATTERN.matcher(urlAsFile);
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -126,7 +126,7 @@
return apiFactory;
}
- public boolean accept(URL url)
+ public boolean acceptFile(URL url)
{
String urlAsFile = url.getFile();
Matcher matcher = urlPattern.matcher(urlAsFile);
Modified: trunk/server/src/main/org/jboss/portal/server/deployment/jboss/AbstractDeploymentFactory.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/jboss/AbstractDeploymentFactory.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/jboss/AbstractDeploymentFactory.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -23,6 +23,7 @@
package org.jboss.portal.server.deployment.jboss;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.net.URLFilter;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import java.net.URL;
@@ -31,7 +32,7 @@
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public abstract class AbstractDeploymentFactory extends AbstractJBossService implements DeploymentFactory
+public abstract class AbstractDeploymentFactory extends AbstractJBossService implements DeploymentFactory, URLFilter
{
/** The server deployer. */
@@ -106,7 +107,12 @@
*/
public void registerFactory()
{
- deployer.registerFactory(this);
+ deployer.registerFactory(
+ name,
+ this,
+ this,
+ setupURL
+ );
}
/**
@@ -115,7 +121,7 @@
*/
public void unregisterFactory()
{
- deployer.unregisterFactory(this);
+ deployer.unregisterFactory(name);
}
public URL getSetupURL()
Modified: trunk/server/src/main/org/jboss/portal/server/deployment/jboss/Deployment.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/jboss/Deployment.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/jboss/Deployment.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -45,7 +45,7 @@
/** The deployment URL. */
protected final URL url;
- /** The web app abstraction. */
+ /** The optional web app abstraction. */
protected final PortalWebApp pwa;
/** The JMX server. */
Added: trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentContext.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentContext.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentContext.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -0,0 +1,128 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.server.deployment.jboss;
+
+import org.jboss.portal.server.deployment.PortalWebApp;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.deployment.DeploymentException;
+import org.jboss.logging.Logger;
+
+import javax.management.MBeanServer;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeploymentContext
+{
+
+ /** . */
+ private static final Logger log = Logger.getLogger(DeploymentContext.class);
+
+ /** The factory that takes care of this deployment. */
+ private final DeploymentFactoryContext factoryCtx;
+
+ /** The deployment URL. */
+ private final URL url;
+
+ /** The provided deployment. */
+ private Deployment deployment;
+
+ /** The deployment short name. */
+ private String name;
+
+ /** . */
+ private PortalWebApp pwa;
+
+ /** . */
+ private MBeanServer server;
+
+ public DeploymentContext(DeploymentFactoryContext factoryCtx, PortalWebApp pwa, URL url, MBeanServer server)
+ {
+ this.factoryCtx = factoryCtx;
+ this.pwa = pwa;
+ this.url = url;
+ this.server = server;
+ }
+
+ public URL getURL()
+ {
+ return url;
+ }
+
+ public DeploymentFactoryContext getFactoryContext()
+ {
+ return factoryCtx;
+ }
+
+ public void create() throws DeploymentException
+ {
+ log.debug("Instantiating deployment for url " + url + " by factory " + factoryCtx.getName());
+ deployment = factoryCtx.getFactory().newInstance(url, pwa, server);
+ name = Tools.getShortNameOf(deployment.getClass());
+
+ //
+ log.debug("Create step for deployment " + name + " for url " + url);
+ deployment.create();
+ }
+
+ public void start() throws DeploymentException
+ {
+ if (deployment == null)
+ {
+ log.debug("Cannot start deployment of factory " + factoryCtx.getName() + " for url " + url + " because it is null");
+ }
+ else
+ {
+ log.debug("Start step for deployment " + name + " for url " + url);
+ deployment.start();
+ }
+ }
+
+ public void stop() throws DeploymentException
+ {
+ if (deployment == null)
+ {
+ log.debug("Cannot stop deployment of factory " + factoryCtx.getName() + " for url " + url + " because it is null");
+ }
+ else
+ {
+ log.debug("Stop step for deployment " + name + " for url " + url);
+ deployment.stop();
+ }
+ }
+
+ public void destroy() throws DeploymentException
+ {
+ if (deployment == null)
+ {
+ log.debug("Cannot destroy deployment of factory " + factoryCtx.getName() + " for url " + url + " because it is null");
+ }
+ else
+ {
+ log.debug("Destroy step for deployment " + name + " for url " + url);
+ deployment.destroy();
+ }
+ }
+}
Modified: trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentFactory.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentFactory.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentFactory.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -36,29 +36,14 @@
*/
public interface DeploymentFactory
{
-
- String getName();
-
- /** Return true if the factory accept to create a deployment for this url. */
- boolean accept(URL url);
-
- /** Return true if the directory should be visited. */
- boolean acceptDir(URL url);
-
/**
* Create a new instance of the deployment.
*
- * @param url the URL of the file to deploy
- * @param pwa the web application that contains the file to deploy
+ * @param url the URL of the file to deploy
+ * @param pwa the web application that contains the file to deploy or null if it does not exist
* @param mbeanServer the JMX mbean server
- * @return a deployment
+ * @return a deployment ready to be processed
* @throws DeploymentException if the deployment cannot be created
*/
Deployment newInstance(URL url, PortalWebApp pwa, MBeanServer mbeanServer) throws DeploymentException;
-
- /**
- * Returns an URL that must be processed just after this has been registered. If the method returns null then no
- * processing is done. This method should always return the same value.
- */
- URL getSetupURL();
}
Added: trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentFactoryContext.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentFactoryContext.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/jboss/DeploymentFactoryContext.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -0,0 +1,74 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.server.deployment.jboss;
+
+import org.jboss.portal.common.net.URLFilter;
+
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeploymentFactoryContext
+{
+ /** . */
+ private String name;
+
+ /** . */
+ private URLFilter filter;
+
+ /** . */
+ private DeploymentFactory factory;
+
+ /** . */
+ private URL setupURL;
+
+ public DeploymentFactoryContext(String name, URLFilter filter, DeploymentFactory factory, URL setupURL)
+ {
+ this.name = name;
+ this.filter = filter;
+ this.factory = factory;
+ this.setupURL = setupURL;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public URLFilter getFilter()
+ {
+ return filter;
+ }
+
+ public DeploymentFactory getFactory()
+ {
+ return factory;
+ }
+
+ public URL getSetupURL()
+ {
+ return setupURL;
+ }
+}
Modified: trunk/server/src/main/org/jboss/portal/server/deployment/jboss/PortalDeploymentInfo.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/jboss/PortalDeploymentInfo.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/jboss/PortalDeploymentInfo.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -25,21 +25,22 @@
import org.apache.log4j.Logger;
import org.jboss.deployment.DeploymentException;
import org.jboss.deployment.DeploymentInfo;
+import org.jboss.portal.server.deployment.PortalWebApp;
+import org.jboss.portal.common.util.SetMap;
import org.jboss.portal.common.net.URLNavigator;
import org.jboss.portal.common.net.URLVisitor;
-import org.jboss.portal.common.util.SetMap;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.server.deployment.PortalWebApp;
import javax.management.MBeanServer;
-import java.io.IOException;
import java.net.URL;
-import java.util.HashSet;
+import java.util.Set;
import java.util.Iterator;
+import java.util.HashSet;
import java.util.LinkedList;
-import java.util.Set;
+import java.io.IOException;
/**
+ * Extends the JBoss AS deployment info to have more contextual information.
+ *
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision$
*/
@@ -49,6 +50,12 @@
/** The serialVersionUID */
private static final long serialVersionUID = 4911467978162887964L;
+ /** . */
+ private final Logger log;
+
+ /** The optional web application containing that deployment info. */
+ public final PortalWebApp pwa;
+
public PortalDeploymentInfo(URL url, MBeanServer server) throws DeploymentException
{
this(url, null, null, server);
@@ -63,7 +70,6 @@
{
super(url, parent, server);
this.pwa = pwa;
- this.deployements = new SetMap();
this.log = Logger.getLogger(ServerDeployer.class.getName());
}
@@ -71,174 +77,4 @@
{
this(url, parent, parent.pwa, server);
}
-
- private final Logger log;
-
- public final PortalWebApp pwa;
-
- public final SetMap deployements;
-
- private class FactoryVisitor implements URLVisitor
- {
- private DeploymentFactory factory;
- private Set ctxs = new HashSet();
- private LinkedList blah = new LinkedList();
-
- public FactoryVisitor(DeploymentFactory factory)
- {
- this.factory = factory;
- }
-
- public void startDir(URL url, String name)
- {
- log.debug("Trying factory " + factory.getName() + " to accept dir " + url);
- boolean accepted = factory.acceptDir(url);
- if (accepted)
- {
- log.debug("Factory " + factory.getName() + " accepted dir " + url);
- }
- else
- {
- log.debug("Factory " + factory.getName() + " did not accept dir " + url);
- }
- blah.addLast(Boolean.valueOf(accepted));
- }
-
- public void endDir(URL url, String name)
- {
- blah.removeLast();
- }
-
- public void file(URL url, String name)
- {
- Boolean accepted = Boolean.TRUE;
- if (blah.size() > 0)
- {
- accepted = (Boolean)blah.getLast();
- }
- if (accepted.booleanValue())
- {
- log.debug("Trying factory " + factory.getName() + " to accept file " + url);
- if (factory.accept(url))
- {
- log.debug("Factory " + factory.getName() + " accepted file " + url);
- DeploymentContext ctx = new DeploymentContext(factory, url);
- ctxs.add(ctx);
- }
- }
- }
- }
-
- public Set add(DeploymentFactory factory) throws DeploymentException
- {
- FactoryVisitor visitor = new FactoryVisitor(factory);
- try
- {
- URLNavigator.visit(url, visitor);
- }
- catch (IOException e)
- {
- throw new DeploymentException(e);
- }
- for (Iterator i = visitor.ctxs.iterator(); i.hasNext();)
- {
- DeploymentContext ctx = (DeploymentContext)i.next();
- deployements.put(ctx.url, ctx);
- }
- return visitor.ctxs;
- }
-
- public Set remove(DeploymentFactory factory)
- {
- Set removed = new HashSet();
- for (Iterator i = new HashSet(deployements.keySet()).iterator(); i.hasNext();)
- {
- URL childURL = (URL)i.next();
- for (Iterator j = deployements.iterator(childURL); j.hasNext();)
- {
- DeploymentContext deploymentContext = (DeploymentContext)j.next();
- if (deploymentContext.factory == factory)
- {
- j.remove();
- removed.add(deploymentContext);
- }
- }
- }
- return removed;
- }
-
- public class DeploymentContext
- {
- /** The factory that takes care of this deployment. */
- private final DeploymentFactory factory;
-
- /** The deployment URL. */
- private final URL url;
-
- /** The provided deployment. */
- private Deployment deployment;
-
- /** The deployment short name. */
- private String name;
-
- public DeploymentContext(DeploymentFactory factory, URL url)
- {
- if (factory == null)
- {
- throw new IllegalArgumentException();
- }
- this.factory = factory;
- this.url = url;
- }
-
- public void create() throws DeploymentException
- {
- log.debug("Instantiating deployment for url " + url + " by factory " + factory.getName());
- deployment = factory.newInstance(url, pwa, getServer());
- name = Tools.getShortNameOf(deployment.getClass());
-
- //
- log.debug("Create step for deployment " + name + " for url " + url);
- deployment.create();
- }
-
- public void start() throws DeploymentException
- {
- if (deployment == null)
- {
- log.debug("Cannot start deployment of factory " + factory.getName() + " for url " + url + " because it is null");
- }
- else
- {
- log.debug("Start step for deployment " + name + " for url " + url);
- deployment.start();
- }
- }
-
- public void stop() throws DeploymentException
- {
- if (deployment == null)
- {
- log.debug("Cannot stop deployment of factory " + factory.getName() + " for url " + url + " because it is null");
- }
- else
- {
- log.debug("Stop step for deployment " + name + " for url " + url);
- deployment.stop();
- }
- }
-
- public void destroy() throws DeploymentException
- {
- if (deployment == null)
- {
- log.debug("Cannot destroy deployment of factory " + factory.getName() + " for url " + url + " because it is null");
- }
- else
- {
- log.debug("Destroy step for deployment " + name + " for url " + url);
- deployment.destroy();
- }
- }
- }
}
Added: trunk/server/src/main/org/jboss/portal/server/deployment/jboss/PortalDeploymentInfoContext.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/jboss/PortalDeploymentInfoContext.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/jboss/PortalDeploymentInfoContext.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -0,0 +1,240 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.server.deployment.jboss;
+
+import org.jboss.portal.common.util.SetMap;
+import org.jboss.portal.common.net.URLNavigator;
+import org.jboss.portal.common.net.URLVisitor;
+import org.jboss.deployment.DeploymentException;
+import org.jboss.logging.Logger;
+
+import java.util.Iterator;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.LinkedList;
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortalDeploymentInfoContext
+{
+
+ /** . */
+ private static final Logger log = Logger.getLogger(PortalDeploymentInfoContext.class);
+
+ /** . */
+ private final PortalDeploymentInfo pdi;
+
+ /** The various deployments that this deployment info generated. */
+ private final SetMap deployments;
+
+ public PortalDeploymentInfoContext(PortalDeploymentInfo pdi)
+ {
+ this.pdi = pdi;
+ this.deployments = new SetMap();
+ }
+
+ public PortalDeploymentInfo getInfo()
+ {
+ return pdi;
+ }
+
+ public void add(DeploymentFactoryContext factoryCtx, boolean proceedLifcycle) throws DeploymentException
+ {
+ try
+ {
+ FactoryVisitor visitor = new FactoryVisitor(factoryCtx);
+ URLNavigator.visit(pdi.url, visitor);
+
+ // Record the different deployment contexts created by this factory
+ for (Iterator i = visitor.ctxs.iterator(); i.hasNext();)
+ {
+ DeploymentContext ctx = (DeploymentContext)i.next();
+ deployments.put(ctx.getURL(), ctx);
+
+ //
+ if (proceedLifcycle)
+ {
+ try
+ {
+ ctx.create();
+ ctx.start();
+ }
+ catch (DeploymentException e)
+ {
+ log.error("Failed to deploy url " + pdi.url);
+ }
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ throw new DeploymentException(e);
+ }
+ }
+
+ public void remove(DeploymentFactoryContext factoryContext, boolean proceedLifcycle)
+ {
+ for (Iterator i = new HashSet(deployments.keySet()).iterator(); i.hasNext();)
+ {
+ URL childURL = (URL)i.next();
+ for (Iterator j = deployments.iterator(childURL); j.hasNext();)
+ {
+ DeploymentContext deploymentContext = (DeploymentContext)j.next();
+ if (deploymentContext.getFactoryContext().getName().equals(factoryContext.getName()))
+ {
+ j.remove();
+
+ //
+ if (proceedLifcycle)
+ {
+ DeploymentContext ctx = (DeploymentContext)j.next();
+ try
+ {
+ ctx.stop();
+ ctx.destroy();
+ }
+ catch (DeploymentException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private class FactoryVisitor implements URLVisitor
+ {
+
+ /** . */
+ private final Set ctxs;
+
+ /** . */
+ private final LinkedList blah;
+
+ /** . */
+ private final DeploymentFactoryContext factoryCtx;
+
+ public FactoryVisitor(DeploymentFactoryContext factoryCtx)
+ {
+ this.factoryCtx = factoryCtx;
+ this.blah = new LinkedList();
+ this.ctxs = new HashSet();
+ }
+
+ public void startDir(URL url, String name)
+ {
+ log.debug("Trying factory " + factoryCtx.getName() + " to accept dir " + url);
+ boolean accepted = factoryCtx.getFilter().acceptDir(url);
+ if (accepted)
+ {
+ log.debug("Factory " + factoryCtx.getName() + " accepted dir " + url);
+ }
+ else
+ {
+ log.debug("Factory " + factoryCtx.getName() + " did not accept dir " + url);
+ }
+ blah.addLast(Boolean.valueOf(accepted));
+ }
+
+ public void endDir(URL url, String name)
+ {
+ blah.removeLast();
+ }
+
+ public void file(URL url, String name)
+ {
+ Boolean accepted = Boolean.TRUE;
+ if (blah.size() > 0)
+ {
+ accepted = (Boolean)blah.getLast();
+ }
+ if (accepted.booleanValue())
+ {
+ log.debug("Trying factory " + factoryCtx.getName() + " to accept file " + url);
+ if (factoryCtx.getFilter().acceptFile(url))
+ {
+ log.debug("Factory " + factoryCtx.getName() + " accepted file " + url);
+ DeploymentContext ctx = new DeploymentContext(factoryCtx, pdi.pwa, url, pdi.getServer());
+ ctxs.add(ctx);
+ }
+ }
+ }
+ }
+
+ public void create() throws DeploymentException
+ {
+ for (Iterator i = deployments.keySet().iterator(); i.hasNext();)
+ {
+ URL url = (URL)i.next();
+ for (Iterator j = deployments.iterator(url); j.hasNext();)
+ {
+ DeploymentContext ctx = (DeploymentContext)j.next();
+ ctx.create();
+ }
+ }
+ }
+
+ public void start() throws DeploymentException
+ {
+ for (Iterator i = deployments.keySet().iterator(); i.hasNext();)
+ {
+ URL url = (URL)i.next();
+ for (Iterator j = deployments.iterator(url); j.hasNext();)
+ {
+ DeploymentContext ctx = (DeploymentContext)j.next();
+ ctx.start();
+ }
+ }
+ }
+
+ public void stop() throws DeploymentException
+ {
+ for (Iterator i = deployments.keySet().iterator(); i.hasNext();)
+ {
+ URL url = (URL)i.next();
+ for (Iterator j = deployments.iterator(url); j.hasNext();)
+ {
+ DeploymentContext ctx = (DeploymentContext)j.next();
+ ctx.stop();
+ }
+ }
+ }
+
+ public void destroy() throws DeploymentException
+ {
+ for (Iterator i = deployments.keySet().iterator(); i.hasNext();)
+ {
+ URL url = (URL)i.next();
+ for (Iterator j = deployments.iterator(url); j.hasNext();)
+ {
+ DeploymentContext ctx = (DeploymentContext)j.next();
+ ctx.destroy();
+ }
+ }
+ }
+}
Modified: trunk/server/src/main/org/jboss/portal/server/deployment/jboss/ServerDeployer.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/jboss/ServerDeployer.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/jboss/ServerDeployer.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -28,6 +28,7 @@
import org.jboss.deployment.SubDeployerSupport;
import org.jboss.mx.loading.RepositoryClassLoader;
import org.jboss.portal.common.util.URLTools;
+import org.jboss.portal.common.net.URLFilter;
import org.jboss.portal.server.Server;
import org.jboss.portal.server.deployment.PortalWebApp;
@@ -35,7 +36,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -53,22 +53,22 @@
/** The server. */
private Server portalServer;
- /** The factories. */
- private Set factories;
+ /** The factory contexts. */
+ private Map factoryContexts;
- /** The portal deployment info map. */
- private Map diMap;
+ /** The portal deployment info context map. */
+ private Map infoContexts;
public ServerDeployer()
{
log = Logger.getLogger(ServerDeployer.class);
- factories = Collections.synchronizedSet(new HashSet());
- diMap = Collections.synchronizedMap(new HashMap());
+ factoryContexts = Collections.synchronizedMap(new HashMap());
+ infoContexts = Collections.synchronizedMap(new HashMap());
}
public Set getFactories()
{
- return new HashSet(factories);
+ return null;
}
/** This should never be called for server deployment. */
@@ -92,19 +92,30 @@
return this;
}
- public void registerFactory(DeploymentFactory factory)
+ public void registerFactory(String name, URLFilter filter, DeploymentFactory factory, URL setupURL)
{
- log.debug("Registering factory " + factory.getName());
+ log.debug("Registering factory " + name);
+ // Check against dual registration
+ if (factoryContexts.containsKey(name))
+ {
+ throw new IllegalArgumentException("Attempty to register a factory twice " + name);
+ }
+
+ // Add the factory
+ DeploymentFactoryContext factoryCtx = new DeploymentFactoryContext(name, filter, factory, setupURL);
+ factoryContexts.put(name, factoryCtx);
+ log.debug("Added factory " + name);
+
// Process the setup URL
- URL setupURL = factory.getSetupURL();
if (setupURL != null && URLTools.exists(setupURL))
{
try
{
- log.debug("Found valid setup url to deploy provided by factory " + factory.getName() + " : " + setupURL);
+ log.debug("Found valid setup url to deploy provided by factory " + name + " : " + setupURL);
PortalDeploymentInfo pdi = new PortalDeploymentInfo(setupURL, server);
pdi.deployer = this;
+ infoContexts.put(pdi.url, new PortalDeploymentInfoContext(pdi));
mainDeployer.deploy(pdi);
}
catch (DeploymentException e)
@@ -113,72 +124,43 @@
}
}
- // Add the factory
- log.debug("Added factory " + factory.getName());
- factories.add(factory);
-
//
- for (Iterator i = new ArrayList(diMap.values()).iterator(); i.hasNext();)
+ for (Iterator i = new ArrayList(infoContexts.values()).iterator(); i.hasNext();)
{
- PortalDeploymentInfo pdi = (PortalDeploymentInfo)i.next();
+ PortalDeploymentInfoContext pdiCtx = (PortalDeploymentInfoContext)i.next();
try
{
- log.debug("Adding factory " + factory.getName() + " to pdi " + pdi.url);
- Set added = pdi.add(factory);
-
- //
- for (Iterator j = added.iterator(); j.hasNext();)
- {
- PortalDeploymentInfo.DeploymentContext ctx = (PortalDeploymentInfo.DeploymentContext)j.next();
- try
- {
- ctx.create();
- ctx.start();
- }
- catch (DeploymentException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
+ log.debug("Adding factory " + name + " to pdi " + pdiCtx.getInfo().url);
+ pdiCtx.add(factoryCtx, true);
}
catch (DeploymentException e)
{
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ log.error("Failed to deploy url " + pdiCtx.getInfo().url);
}
}
}
- public void unregisterFactory(DeploymentFactory factory)
+ public void unregisterFactory(String name)
{
- log.debug("Unregistering factory " + factory.getName());
- for (Iterator i = new ArrayList(diMap.values()).iterator(); i.hasNext();)
+ log.debug("Unregistering factory " + name);
+
+ //
+ DeploymentFactoryContext factoryCtx = (DeploymentFactoryContext)factoryContexts.remove(name);
+ if (factoryCtx == null)
{
- PortalDeploymentInfo pdi = (PortalDeploymentInfo)i.next();
- Set removed = pdi.remove(factory);
- for (Iterator j = removed.iterator(); j.hasNext();)
- {
- PortalDeploymentInfo.DeploymentContext ctx = (PortalDeploymentInfo.DeploymentContext)j.next();
- try
- {
- ctx.stop();
- ctx.destroy();
- }
- catch (DeploymentException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
+ throw new IllegalArgumentException("Cannot unregister non existing factory " + name);
}
- // Remove the factory
- log.debug("Removed factory " + factory.getName());
- factories.remove(factory);
+ for (Iterator i = new ArrayList(infoContexts.values()).iterator(); i.hasNext();)
+ {
+ PortalDeploymentInfoContext pdiCtx = (PortalDeploymentInfoContext)i.next();
+ pdiCtx.remove(factoryCtx, true);
+ }
- // Undeploy the setup url if any
- URL setupURL = factory.getSetupURL();
+ URL setupURL = factoryCtx.getSetupURL();
if (setupURL != null && URLTools.exists(setupURL))
{
- log.debug("Found valid setup url to undeploy provided by factory " + factory.getName() + " : " + setupURL);
+ log.debug("Found valid setup url to undeploy provided by factory " + name + " : " + setupURL);
if (mainDeployer.isDeployed(setupURL))
{
try
@@ -189,22 +171,29 @@
{
log.error("Failed to un deploy setup url " + setupURL);
}
+ finally
+ {
+ infoContexts.remove(setupURL);
+ }
}
else
{
- log.warn("Unknown setup url by main deployer provided by factory " + factory.getName() + " : " + setupURL);
+ log.warn("Unknown setup url by main deployer provided by factory " + name + " : " + setupURL);
}
}
+
+ // Log the removal
+ log.debug("Removed factory " + name);
}
protected void processNestedDeployments(DeploymentInfo di) throws DeploymentException
{
// We only list if it is a directory
- PortalDeploymentInfo pdi = (PortalDeploymentInfo)di;
- for (Iterator j = factories.iterator(); j.hasNext();)
+ PortalDeploymentInfoContext pdiCtx = (PortalDeploymentInfoContext)infoContexts.get(di.url);
+ for (Iterator j = factoryContexts.values().iterator(); j.hasNext();)
{
- DeploymentFactory factory = (DeploymentFactory)j.next();
- pdi.add(factory);
+ DeploymentFactoryContext factoryCtx = (DeploymentFactoryContext)j.next();
+ pdiCtx.add(factoryCtx, false);
}
}
@@ -215,68 +204,38 @@
public void create(DeploymentInfo di) throws DeploymentException
{
- // Put it in the map
- diMap.put(di.url, di);
+ PortalDeploymentInfoContext pdiCtx = (PortalDeploymentInfoContext)infoContexts.get(di.url);
+ pdiCtx.create();
- PortalDeploymentInfo pdi = (PortalDeploymentInfo)di;
- for (Iterator i = pdi.deployements.keySet().iterator(); i.hasNext();)
- {
- URL url = (URL)i.next();
- for (Iterator j = pdi.deployements.iterator(url); j.hasNext();)
- {
- PortalDeploymentInfo.DeploymentContext ctx = (PortalDeploymentInfo.DeploymentContext)j.next();
- ctx.create();
- }
- }
+ //
super.create(di);
}
public void start(DeploymentInfo di) throws DeploymentException
{
- PortalDeploymentInfo pdi = (PortalDeploymentInfo)di;
- for (Iterator i = pdi.deployements.keySet().iterator(); i.hasNext();)
- {
- URL url = (URL)i.next();
- for (Iterator j = pdi.deployements.iterator(url); j.hasNext();)
- {
- PortalDeploymentInfo.DeploymentContext ctx = (PortalDeploymentInfo.DeploymentContext)j.next();
- ctx.start();
- }
- }
+ PortalDeploymentInfoContext pdiCtx = (PortalDeploymentInfoContext)infoContexts.get(di.url);
+ pdiCtx.start();
+
+ //
super.start(di);
}
public void stop(DeploymentInfo di) throws DeploymentException
{
- PortalDeploymentInfo pdi = (PortalDeploymentInfo)di;
- for (Iterator i = pdi.deployements.keySet().iterator(); i.hasNext();)
- {
- URL url = (URL)i.next();
- for (Iterator j = pdi.deployements.iterator(url); j.hasNext();)
- {
- PortalDeploymentInfo.DeploymentContext ctx = (PortalDeploymentInfo.DeploymentContext)j.next();
- ctx.stop();
- }
- }
+ PortalDeploymentInfoContext pdiCtx = (PortalDeploymentInfoContext)infoContexts.get(di.url);
+ pdiCtx.stop();
+
+ //
super.stop(di);
}
public void destroy(DeploymentInfo di) throws DeploymentException
{
- PortalDeploymentInfo pdi = (PortalDeploymentInfo)di;
- for (Iterator i = pdi.deployements.keySet().iterator(); i.hasNext();)
- {
- URL url = (URL)i.next();
- for (Iterator j = pdi.deployements.iterator(url); j.hasNext();)
- {
- PortalDeploymentInfo.DeploymentContext ctx = (PortalDeploymentInfo.DeploymentContext)j.next();
- ctx.destroy();
- }
- }
- super.destroy(di);
+ PortalDeploymentInfoContext pdiCtx = (PortalDeploymentInfoContext)infoContexts.get(di.url);
+ pdiCtx.destroy();
//
- diMap.remove(di.url);
+ super.destroy(di);
}
public void deploy(PortalWebApp pwa) throws DeploymentException
@@ -289,25 +248,36 @@
URL url = Deployment.findWEBINFURL(pwa.getURL());
// Create our deployment info object and pass it to main deployer
- PortalDeploymentInfo di = new PortalDeploymentInfo(url, null, pwa, server);
- di.ucl = rcl;
- di.deployer = this;
+ PortalDeploymentInfo pdi = new PortalDeploymentInfo(url, null, pwa, server);
+ pdi.ucl = rcl;
+ pdi.deployer = this;
+ // Put it in the map
+ infoContexts.put(pdi.url, new PortalDeploymentInfoContext(pdi));
+
// And let JBoss deploy it
- mainDeployer.deploy(di);
+ mainDeployer.deploy(pdi);
}
public void undeploy(PortalWebApp pwa) throws DeploymentException
{
+ URL url = Deployment.findWEBINFURL(pwa.getURL());
+
+ //
try
{
- URL url = Deployment.findWEBINFURL(pwa.getURL());
+ // Undeploy
mainDeployer.undeploy(url);
}
catch (Exception e)
{
log.error("Error when undeploying portal web app", e);
}
+ finally
+ {
+ // Remove it in the map
+ infoContexts.remove(url);
+ }
}
/** Instrument the portal web app. */
@@ -323,5 +293,4 @@
log.error("Cannot instrument the web application", e);
}
}
-
}
Modified: trunk/server/src/main/org/jboss/portal/server/deployment/jboss/ServerDeployerMBean.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/jboss/ServerDeployerMBean.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/jboss/ServerDeployerMBean.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -26,6 +26,7 @@
import org.jboss.deployment.SubDeployerMBean;
import org.jboss.portal.server.Server;
import org.jboss.portal.server.deployment.PortalWebApp;
+import org.jboss.portal.common.net.URLFilter;
import java.net.URL;
import java.util.Set;
@@ -61,12 +62,24 @@
Set getFactories();
/**
+ *
+ *
+ * @param name the factory name
+ * @param filter filter urls
+ * @param factory create deployment
+ * @param setupURL an optional setup URL
*/
- void registerFactory(DeploymentFactory factory);
+ void registerFactory(
+ String name,
+ URLFilter filter,
+ DeploymentFactory factory,
+ URL setupURL);
/**
+ *
+ * @param name the factory name to unregister
*/
- void unregisterFactory(DeploymentFactory factory);
+ void unregisterFactory(String name);
/** Locate a deployment info factory based on the url. If no factory is found it returns null. */
Modified: trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeploymentFactory.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeploymentFactory.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeploymentFactory.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -46,7 +46,7 @@
private LayoutService layoutService;
- public boolean accept(URL url)
+ public boolean acceptFile(URL url)
{
String urlAsFile = url.getFile();
Matcher matcher = URL_PATTERN.matcher(urlAsFile);
Modified: trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeploymentFactory.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeploymentFactory.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeploymentFactory.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -45,7 +45,7 @@
protected static final Pattern URL_PATTERN2 = Pattern.compile(".*-strategies\\.xml");
private LayoutService layoutService;
- public boolean accept(URL url)
+ public boolean acceptFile(URL url)
{
String urlAsFile = url.getFile();
return URL_PATTERN.matcher(urlAsFile).matches() || URL_PATTERN2.matcher(urlAsFile).matches();
Modified: trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeploymentFactory.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeploymentFactory.java 2006-11-20 14:12:35 UTC (rev 5681)
+++ trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeploymentFactory.java 2006-11-20 14:44:48 UTC (rev 5682)
@@ -45,7 +45,7 @@
private ThemeService themeService;
- public boolean accept(URL url)
+ public boolean acceptFile(URL url)
{
String urlAsFile = url.getFile();
Matcher matcher = URL_PATTERN.matcher(urlAsFile);
More information about the jboss-svn-commits
mailing list