[jboss-cvs] JBossAS SVN: r66822 - in trunk/varia: src/main/org/jboss/varia/deployment and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 7 12:37:36 EST 2007


Author: alesj
Date: 2007-11-07 12:37:35 -0500 (Wed, 07 Nov 2007)
New Revision: 66822

Added:
   trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellDeployer.java
   trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellScriptDeployer.java
   trunk/varia/src/resources/beanshell/
   trunk/varia/src/resources/beanshell/bsh-deployers-beans.xml
Modified:
   trunk/varia/build.xml
   trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScript.java
   trunk/varia/src/main/org/jboss/varia/deployment/BeanShellSubDeployer.java
Log:
Porting BSH deployers to new VFS based deployers.

Modified: trunk/varia/build.xml
===================================================================
--- trunk/varia/build.xml	2007-11-07 15:50:57 UTC (rev 66821)
+++ trunk/varia/build.xml	2007-11-07 17:37:35 UTC (rev 66822)
@@ -509,6 +509,7 @@
         <include name="org/jboss/varia/deployment/BeanShell**"/>
         <include name="org/jboss/varia/deployment/Script**"/>
         <include name="org/jboss/varia/deployment/Test**"/>
+        <include name="org/jboss/varia/deployment/Legacy**"/>
       </fileset>
     </jar>
 

Modified: trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScript.java
===================================================================
--- trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScript.java	2007-11-07 15:50:57 UTC (rev 66821)
+++ trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScript.java	2007-11-07 17:37:35 UTC (rev 66822)
@@ -28,6 +28,7 @@
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.net.URL;
 
 import javax.management.Attribute;
 import javax.management.AttributeNotFoundException;
@@ -75,20 +76,33 @@
 
    // Constructors --------------------------------------------------
 
+   @Deprecated
    public BeanShellScript(final DeploymentInfo di)
       throws DeploymentException
    {
+      this.deploymentInfo = di;
+      init(deploymentInfo.url);
+   }
+
+   public BeanShellScript(final URL url)
+         throws DeploymentException
+   {
+      init(url);
+   }
+
+   protected void init(URL url)
+         throws DeploymentException
+   {
       try
       {
-         this.deploymentInfo = di;
-         String name = deploymentInfo.url.toString();
+         String name = url.toString();
          if (name.endsWith("/"))
          {
             name = name.substring(0, name.length() - 1);
          }
          this.name = name;
 
-         loadScript (di.url);
+         loadScript (url);
       }
       catch (Exception e)
       {

Modified: trunk/varia/src/main/org/jboss/varia/deployment/BeanShellSubDeployer.java
===================================================================
--- trunk/varia/src/main/org/jboss/varia/deployment/BeanShellSubDeployer.java	2007-11-07 15:50:57 UTC (rev 66821)
+++ trunk/varia/src/main/org/jboss/varia/deployment/BeanShellSubDeployer.java	2007-11-07 17:37:35 UTC (rev 66822)
@@ -48,6 +48,7 @@
  * @jmx.mbean name="jboss.system:service=BeanShellSubDeployer"
  *            extends="org.jboss.deployment.SubDeployerMBean"
  */
+ at Deprecated
 public class BeanShellSubDeployer extends SubDeployerSupport
    implements BeanShellSubDeployerMBean
 {
@@ -258,8 +259,14 @@
       {
          File scriptFile = File.createTempFile(scriptName, ".bsh");
          FileWriter fw = new FileWriter(scriptFile);
-         fw.write(bshScript);
-         fw.close();
+         try
+         {
+            fw.write(bshScript);
+         }
+         finally
+         {
+            fw.close();
+         }
 
          URL scriptURL = scriptFile.toURL();
          mainDeployer.deploy(scriptURL);

Added: trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellDeployer.java
===================================================================
--- trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellDeployer.java	                        (rev 0)
+++ trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellDeployer.java	2007-11-07 17:37:35 UTC (rev 66822)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.varia.deployment;
+
+import org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * .bsh file deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LegacyBeanShellDeployer extends AbstractVFSParsingDeployer<BeanShellScript>
+{
+   public LegacyBeanShellDeployer()
+   {
+      super(BeanShellScript.class);
+      setSuffix(".bsh");
+   }
+
+   protected BeanShellScript parse(VFSDeploymentUnit vfsDeploymentUnit, VirtualFile virtualFile, BeanShellScript root) throws Exception
+   {
+      if (log.isTraceEnabled())
+         log.trace("Parsing bean shell file to create script instance: " + virtualFile);
+
+      return new BeanShellScript(virtualFile.toURL());
+   }
+}

Added: trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellScriptDeployer.java
===================================================================
--- trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellScriptDeployer.java	                        (rev 0)
+++ trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellScriptDeployer.java	2007-11-07 17:37:35 UTC (rev 66822)
@@ -0,0 +1,147 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.varia.deployment;
+
+import java.util.Arrays;
+import java.util.Collection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.mx.util.ObjectNameConverter;
+import org.jboss.system.ServiceController;
+import org.jboss.system.microcontainer.LifecycleDependencyItem;
+import org.jboss.system.microcontainer.ServiceControllerContext;
+
+/**
+ * Old mbean style bean shell script deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LegacyBeanShellScriptDeployer extends AbstractSimpleRealDeployer<BeanShellScript>
+{
+   public static final String BASE_SCRIPT_OBJECT_NAME = "jboss.scripts:type=BeanShell";
+   /** The service controller */
+   private ServiceController serviceController;
+   /** The default controller mode */
+   private ControllerMode mode = ControllerMode.AUTOMATIC;
+
+   public LegacyBeanShellScriptDeployer(ServiceController serviceController)
+   {
+      super(BeanShellScript.class);
+      if (serviceController == null)
+         throw new IllegalArgumentException("Null service controller.");
+      this.serviceController = serviceController;
+   }
+
+   /**
+    * Get the bean shell script name.
+    *
+    * @param script the script
+    * @param deploymentUnit the deployment unit
+    * @return get script's object name
+    * @throws MalformedObjectNameException for any error
+    */
+   protected ObjectName getBshScriptName(BeanShellScript script, DeploymentUnit deploymentUnit)
+         throws MalformedObjectNameException
+   {
+      ObjectName bshScriptName = script.getPreferedObjectName();
+      if (bshScriptName == null)
+      {
+         bshScriptName = ObjectNameConverter.convert(BASE_SCRIPT_OBJECT_NAME + ",url=" + deploymentUnit.getSimpleName());
+      }
+      return bshScriptName;
+   }
+
+   public void deploy(DeploymentUnit deploymentUnit, BeanShellScript script) throws DeploymentException
+   {
+      try
+      {
+         Controller controller = serviceController.getKernel().getController();
+         ObjectName bshScriptName = getBshScriptName(script, deploymentUnit);
+         ServiceControllerContext context = new ServiceControllerContext(serviceController, bshScriptName, script);
+         context.setMode(mode);
+         ObjectName[] depends = script.getDependsServices();
+         if (depends != null)
+            addDependencies(context, Arrays.asList(depends));
+
+         if (log.isTraceEnabled())
+            log.trace("Installing bean shell script: " + bshScriptName);
+
+         controller.install(context);
+      }
+      catch (Throwable t)
+      {
+         throw DeploymentException.rethrowAsDeploymentException("Unable to deploy bean shell script.", t);
+      }
+   }
+
+   public void undeploy(DeploymentUnit deploymentUnit, BeanShellScript script)
+   {
+      try
+      {
+         ObjectName bshScriptName = getBshScriptName(script, deploymentUnit);
+         Controller controller = serviceController.getKernel().getController();
+
+         if (log.isTraceEnabled())
+            log.trace("Uninstalling bean shell script: " + bshScriptName);
+
+         controller.uninstall(bshScriptName.getCanonicalName());
+      }
+      catch (Throwable t)
+      {
+         log.error("Exception while undeploying bean shell script: " + t);
+      }
+   }
+
+   /**
+    * Add the passed lifecycle dependencies to the context
+    *
+    * @param context the context
+    * @param depends the dependencies
+    */
+   private void addDependencies(ServiceControllerContext context, Collection<ObjectName> depends)
+   {
+      DependencyInfo info = context.getDependencyInfo();
+      for (ObjectName other : depends)
+      {
+         info.addIDependOn(new LifecycleDependencyItem(context.getName(), other.getCanonicalName(), ControllerState.CREATE));
+         info.addIDependOn(new LifecycleDependencyItem(context.getName(), other.getCanonicalName(), ControllerState.START));
+      }
+   }
+
+   /**
+    * Set the mode.
+    *
+    * @param mode the controller mode
+    */
+   public void setMode(String mode)
+   {
+      this.mode = new ControllerMode(mode);
+   }
+}

Added: trunk/varia/src/resources/beanshell/bsh-deployers-beans.xml
===================================================================
--- trunk/varia/src/resources/beanshell/bsh-deployers-beans.xml	                        (rev 0)
+++ trunk/varia/src/resources/beanshell/bsh-deployers-beans.xml	2007-11-07 17:37:35 UTC (rev 66822)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+    BSH  Deployer
+-->
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <!-- BSH parser -->
+   <bean name="BSHParserDeployer" class="org.jboss.varia.deployment.LegacyBeanShellDeployer" />
+
+   <!-- BSH script deployer -->
+   <bean name="BSHScriptDeployer" class="org.jboss.varia.deployment.LegacyBeanShellScriptDeployer">
+   	<constructor><parameter><inject bean="JMXKernel" property="serviceController"/></parameter></constructor>
+   </bean>
+
+</deployment>




More information about the jboss-cvs-commits mailing list