[jboss-cvs] JBossAS SVN: r66861 - in trunk/varia/src: resources/beanshell and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 8 06:57:51 EST 2007


Author: alesj
Date: 2007-11-08 06:57:51 -0500 (Thu, 08 Nov 2007)
New Revision: 66861

Added:
   trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScriptClient.java
   trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellScriptClient.java
Modified:
   trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScript.java
   trunk/varia/src/resources/beanshell/bsh-deployers-beans.xml
Log:
Optional BeanShellScriptClient.

Modified: trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScript.java
===================================================================
--- trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScript.java	2007-11-08 11:38:49 UTC (rev 66860)
+++ trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScript.java	2007-11-08 11:57:51 UTC (rev 66861)
@@ -22,6 +22,7 @@
 package org.jboss.varia.deployment;
 
 import java.io.InputStream;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -90,6 +91,20 @@
       init(url);
    }
 
+   BeanShellScript(String name, InputStream stream)
+         throws DeploymentException
+   {
+      try
+      {
+         this.name = name;
+         loadScript (stream);
+      }
+      catch (Exception e)
+      {
+         throw new DeploymentException (e);
+      }
+   }
+
    protected void init(URL url)
          throws DeploymentException
    {
@@ -324,12 +339,10 @@
 
    protected void loadScript (java.net.URL url) throws Exception
    {
-      Interpreter interpreter = new Interpreter ();
-      interpreter.setClassLoader(Thread.currentThread().getContextClassLoader());
       InputStream stream = url.openStream();
       try
       {
-         interpreter.eval (new java.io.InputStreamReader (stream));
+         loadScript(stream);
       }
       finally
       {
@@ -337,9 +350,27 @@
          {
             stream.close();
          }
-         catch (Exception strange) { log.info(strange); }
+         catch (IOException e)
+         {
+            log.info(e);
+         }
       }
+   }
 
+   /**
+    * Load script.
+    * Stream should/must be closed/handled
+    * by the client invoking this method.
+    *
+    * @param stream the stream
+    * @throws Exception for any error
+    */
+   protected void loadScript (InputStream stream) throws Exception
+   {
+      Interpreter interpreter = new Interpreter ();
+      interpreter.setClassLoader(Thread.currentThread().getContextClassLoader());
+      interpreter.eval (new java.io.InputStreamReader (stream));
+
       scriptService = (ScriptService)interpreter.getInterface(ScriptService.class);
 
       // We now load the script preferences

Added: trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScriptClient.java
===================================================================
--- trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScriptClient.java	                        (rev 0)
+++ trunk/varia/src/main/org/jboss/varia/deployment/BeanShellScriptClient.java	2007-11-08 11:57:51 UTC (rev 66861)
@@ -0,0 +1,50 @@
+/*
+* 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.spi.DeploymentException;
+
+/**
+ * Old client style bean shell client interface.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface BeanShellScriptClient
+{
+   /**
+    * Create bean shell script deployment.
+    *
+    * @param bshScript the script
+    * @param scriptName the script name
+    * @return deployment name
+    * @throws DeploymentException for any error
+    */
+   String createScriptDeployment(String bshScript, String scriptName) throws DeploymentException;
+
+   /**
+    * Remove script deployment.
+    *
+    * @param scriptName the script name
+    * @throws DeploymentException for any exception
+    */
+   void removeScriptDeployment(String scriptName) throws DeploymentException;
+}

Added: trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellScriptClient.java
===================================================================
--- trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellScriptClient.java	                        (rev 0)
+++ trunk/varia/src/main/org/jboss/varia/deployment/LegacyBeanShellScriptClient.java	2007-11-08 11:57:51 UTC (rev 66861)
@@ -0,0 +1,100 @@
+/*
+* 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.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.jboss.deployers.client.plugins.deployment.AbstractDeployment;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.logging.Logger;
+
+/**
+ * Old client style bean shell invocation client.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at ManagementObject
+public class LegacyBeanShellScriptClient implements BeanShellScriptClient
+{
+   protected Logger log = Logger.getLogger(getClass());
+   private DeployerClient deployer;
+
+   public LegacyBeanShellScriptClient(DeployerClient deployer)
+   {
+      if (deployer == null)
+         throw new IllegalArgumentException("Null client deployer.");
+      this.deployer = deployer;
+   }
+
+   protected BeanShellScript createBeanShellScript(String bshScript, String scriptName)
+         throws org.jboss.deployment.DeploymentException
+   {
+      InputStream stream = new ByteArrayInputStream(bshScript.getBytes());
+      try
+      {
+         return new BeanShellScript(this + ": " + scriptName, stream);
+      }
+      finally
+      {
+         try
+         {
+            stream.close();
+         }
+         catch (IOException ignored)
+         {
+         }
+      }
+   }
+
+   @ManagementOperation
+   public String createScriptDeployment(String bshScript, String scriptName) throws DeploymentException
+   {
+      if (bshScript == null)
+         throw new IllegalArgumentException("Null bean shell script.");
+
+      if (scriptName == null)
+         throw new IllegalArgumentException("Null script name.");
+
+      BeanShellScript script = createBeanShellScript(bshScript, scriptName);
+      Deployment deployment = new AbstractDeployment(scriptName);
+      MutableAttachments mutableAttachments = ((MutableAttachments)deployment.getPredeterminedManagedObjects());
+      mutableAttachments.addAttachment(BeanShellScript.class, script);
+
+      deployer.addDeployment(deployment);
+      deployer.process();
+
+      return deployment.getName();
+   }
+
+   @ManagementOperation
+   public void removeScriptDeployment(String scriptName) throws DeploymentException
+   {
+      deployer.removeDeployment(scriptName);
+   }
+}

Modified: trunk/varia/src/resources/beanshell/bsh-deployers-beans.xml
===================================================================
--- trunk/varia/src/resources/beanshell/bsh-deployers-beans.xml	2007-11-08 11:38:49 UTC (rev 66860)
+++ trunk/varia/src/resources/beanshell/bsh-deployers-beans.xml	2007-11-08 11:57:51 UTC (rev 66861)
@@ -13,4 +13,10 @@
    	<constructor><parameter><inject bean="JMXKernel" property="serviceController"/></parameter></constructor>
    </bean>
 
+<!--
+   <bean name="BSHScriptClient" class="org.jboss.varia.deployment.LegacyBeanShellScriptClient">
+      <constructor><parameter><inject bean="MainDeployer"/></parameter></constructor>
+   </bean>
+-->
+
 </deployment>




More information about the jboss-cvs-commits mailing list