weaver 2004/01/19 13:54:28
Modified: portal/src/java/org/apache/jetspeed/deployment/impl
DeployPortletAppEventListener.java
Log:
added undeploy support
Revision Changes Path
1.4 +73 -31
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployPortletAppEventListener.java
Index: DeployPortletAppEventListener.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployPortletAppEventListener.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DeployPortletAppEventListener.java 16 Jan 2004 19:41:21 -0000 1.3
+++ DeployPortletAppEventListener.java 19 Jan 2004 21:54:28 -0000 1.4
@@ -6,8 +6,11 @@
*/
package org.apache.jetspeed.deployment.impl;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -35,28 +38,28 @@
*/
public class DeployPortletAppEventListener implements DeploymentEventListener
{
-
-
protected static final Log log = LogFactory.getLog("deployment");
private String webAppDir;
private String dbAalias;
private Deployment pam;
-
-
+ private Map appNameToFile;
- public DeployPortletAppEventListener(String webAppDir, String dbAlias,
Deployment pam)
- {
- this.webAppDir = webAppDir;
- this.dbAalias = dbAlias;
- this.pam = pam;
- }
-
- public DeployPortletAppEventListener(String webAppDir, Deployment pam)
- {
- this.webAppDir = webAppDir;
- this.pam = pam;
- }
+ public DeployPortletAppEventListener(String webAppDir, String dbAlias,
Deployment pam)
+ {
+ this.webAppDir = webAppDir;
+ this.dbAalias = dbAlias;
+ this.pam = pam;
+ this.appNameToFile = new HashMap();
+
+ }
+
+ public DeployPortletAppEventListener(String webAppDir, Deployment pam)
+ {
+ this.webAppDir = webAppDir;
+ this.pam = pam;
+ this.appNameToFile = new HashMap();
+ }
/**
* @see
org.apache.jetspeed.deployment.DeploymentEventListener#invoke(org.apache.jetspeed.deployment.DeploymentEvent)
@@ -76,41 +79,80 @@
}
else
{
- log.info("Loading portlet application from web archive
"+handler.getPath());
+ log.info("Loading portlet application from web archive " +
handler.getPath());
SAXBuilder builder = new SAXBuilder();
Document portletXml = builder.build(portletXmlStream);
Element portletApp = portletXml.getRootElement();
String id = portletApp.getAttributeValue("id");
- if(id == null)
+ if (id == null)
{
- throw new
PortletApplicationException("<portlet-app> requires a unique \"id\" attribute.");
+ throw new PortletApplicationException("<portlet-app>
requires a unique \"id\" attribute.");
}
-
-
if(JetspeedPortletRegistry.getPortletApplicationByIndetifier(id) != null)
+
+ if
(JetspeedPortletRegistry.getPortletApplicationByIndetifier(id) != null)
{
- log.info("Portlet application
\""+id+"\"" +" already been registered. Skipping initial deployment.");
- return;
+ log.info("Portlet application \"" + id + "\"" + " already
been registered. Skipping initial deployment.");
+ // still need to register the filename to the app name so
undeploy works correctly
+
appNameToFile.put(handler.getFile().getName(), id);
+ return;
}
-
- log.info("Preparing to deploy portlet app \""+id+"\"");
- if(dbAalias != null)
+
+ log.info("Preparing to deploy portlet app \"" + id + "\"");
+ if (dbAalias != null)
{
- pam.deploy(webAppDir,
handler.getPath(), id, dbAalias, 0);
+ pam.deploy(webAppDir, handler.getPath(), id, dbAalias, 0);
}
else
{
- pam.deploy(webAppDir,
handler.getPath(), id);
+ pam.deploy(webAppDir, handler.getPath(), id);
}
+
+ appNameToFile.put(handler.getFile().getName(),
id);
+ log.info("Portlet app \"" + id + "\" " + "successfuly
deployed.");
- log.info("Portlet app \""+id+"\"
"+"successfuly deployed.");
}
+
}
catch (Exception e1)
{
- String msg = "Error deploying portlet app: " + e1.toString();
+ String msg = "Error deploying portlet app: " + e1.toString();
throw new DeploymentException(msg, e1);
}
+ }
+ else if (event.getEventType().equals(DeploymentEvent.EVENT_TYPE_UNDEPLOY))
+ {
+ String paName = null;
+ try
+ {
+ FSObjectHandler handler = (FSObjectHandler) event.getHandler();
+ File fileThatWasRemoved = handler.getFile();
+ String fileName = fileThatWasRemoved.getName();
+ paName = (String) appNameToFile.get(fileName);
+ if(paName == null)
+ {
+ String msg = "Unable to locate application name for archive
\""+fileName+"\"";
+ log.warn(msg);
+ throw new DeploymentException(msg);
+ }
+ log.info("Preparing to undeploy portlet application
\""+paName+"\"");
+ pam.undeploy(webAppDir, paName);
+ log.info("Portlet application \""+paName+"\""+" was successfuly
undeployed.");
+ }
+ catch (Exception e)
+ {
+ String msg = "Error undeploying portlet app
"+paName+": " + e.toString();
+ if(e instanceof DeploymentException)
+ {
+ throw (DeploymentException) e;
+ }
+ else
+ {
+ throw new DeploymentException(msg, e);
+ }
+
+ }
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]