[jboss-cvs] JBossAS SVN: r97042 - in projects/fresh/trunk: fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 26 12:06:39 EST 2009


Author: alesj
Date: 2009-11-26 12:06:39 -0500 (Thu, 26 Nov 2009)
New Revision: 97042

Added:
   projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/ExecutableAnnotationDeployer.java
   projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/ExecutableClassesDeployer.java
   projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/PickupExecutablesDeployer.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/ExecutableFactory.java
Modified:
   projects/fresh/trunk/fresh-deployers/pom.xml
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/ExecutableRegistry.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/impl/DefaultExecutableRegistry.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/impl/LazyExecutableRegistry.java
Log:
[FRESH-19]; fresh deployers.

Modified: projects/fresh/trunk/fresh-deployers/pom.xml
===================================================================
--- projects/fresh/trunk/fresh-deployers/pom.xml	2009-11-26 16:47:57 UTC (rev 97041)
+++ projects/fresh/trunk/fresh-deployers/pom.xml	2009-11-26 17:06:39 UTC (rev 97042)
@@ -15,6 +15,13 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.jboss.fresh</groupId>
+            <artifactId>fresh-shell</artifactId>
+        </dependency>
+
+        <!-- Other MC deps -->
+
+        <dependency>
             <groupId>org.jboss.deployers</groupId>
             <artifactId>jboss-deployers-vfs</artifactId>
             <scope>provided</scope>

Added: projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/ExecutableAnnotationDeployer.java
===================================================================
--- projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/ExecutableAnnotationDeployer.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/ExecutableAnnotationDeployer.java	2009-11-26 17:06:39 UTC (rev 97042)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.fresh.deployers.exe;
+
+import java.util.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
+import org.jboss.deployers.spi.annotations.Element;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.fresh.annotations.Executable;
+import org.jboss.fresh.shell.ExecutableRegistry;
+
+/**
+ * Pick up all classes that are marked with @Executable.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ExecutableAnnotationDeployer extends PickupExecutablesDeployer<AnnotationEnvironment>
+{
+   public ExecutableAnnotationDeployer(ExecutableRegistry registry)
+   {
+      super(registry, AnnotationEnvironment.class);
+   }
+
+   /**
+    * Handle classes that are marked with @Executable.
+    *
+    * @param env the annotation environment
+    * @param deploy are we in deploy phase
+    */
+   protected void handleExecutable(AnnotationEnvironment env, boolean deploy)
+   {
+      Set<Element<Executable,Class<?>>> elements = env.classIsAnnotatedWith(Executable.class);
+      for (Element elt : elements)
+      {
+         Class<?> owner = elt.getOwner();
+         if (deploy)
+            getRegistry().registerExecutable(owner);
+         else
+            getRegistry().unregisterExecutable(owner);
+      }
+   }
+
+   public void deploy(DeploymentUnit unit, AnnotationEnvironment env) throws DeploymentException
+   {
+      handleExecutable(env, true);
+   }
+
+   @Override
+   public void undeploy(DeploymentUnit unit, AnnotationEnvironment env)
+   {
+      handleExecutable(env, false);
+   }
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/ExecutableClassesDeployer.java
===================================================================
--- projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/ExecutableClassesDeployer.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/ExecutableClassesDeployer.java	2009-11-26 17:06:39 UTC (rev 97042)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.fresh.deployers.exe;
+
+import java.util.Set;
+import java.util.HashSet;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.visitor.ClassFilter;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.fresh.shell.Executable;
+import org.jboss.fresh.shell.ExecutableRegistry;
+
+/**
+ * Pick up all classes that extend Executable.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ExecutableClassesDeployer extends PickupExecutablesDeployer<Module>
+{
+   public ExecutableClassesDeployer(ExecutableRegistry registry)
+   {
+      super(registry, Module.class);
+   }
+
+   public void deploy(DeploymentUnit unit, Module module) throws DeploymentException
+   {
+      ExecutableClassVisitor visitor = new ExecutableClassVisitor();
+      module.visit(visitor);
+      unit.addAttachment(Executable.class.getName() + "s", visitor.getExecutables());
+   }
+
+   @SuppressWarnings({"unchecked"})
+   @Override
+   public void undeploy(DeploymentUnit unit, Module deployment)
+   {
+      Set<Class<?>> executables = unit.getAttachment(Executable.class.getName() + "s", Set.class);
+      for (Class<?> clazz : executables)
+      {
+         getRegistry().unregisterExecutable(clazz);
+      }
+   }
+
+   private class ExecutableClassVisitor implements ResourceVisitor
+   {
+      private Set<Class<?>> executables = new HashSet<Class<?>>();
+
+      public ResourceFilter getFilter()
+      {
+         return ClassFilter.INSTANCE;
+      }
+
+      public void visit(ResourceContext resource)
+      {
+         Class<?> clazz = resource.loadClass();
+         if (Executable.class.isAssignableFrom(clazz))
+         {
+            getRegistry().registerExecutable(clazz);
+            executables.add(clazz);
+         }
+      }
+
+      public Set<Class<?>> getExecutables()
+      {
+         return executables;
+      }
+   }
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/PickupExecutablesDeployer.java
===================================================================
--- projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/PickupExecutablesDeployer.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-deployers/src/main/java/org/jboss/fresh/deployers/exe/PickupExecutablesDeployer.java	2009-11-26 17:06:39 UTC (rev 97042)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.fresh.deployers.exe;
+
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.fresh.shell.ExecutableRegistry;
+
+/**
+ * Pick up all classes that are either:
+ * - annotated with @Executable
+ * - implement ExecutableFactory
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class PickupExecutablesDeployer<T> extends AbstractSimpleRealDeployer<T>
+{
+   private ExecutableRegistry registry;
+
+   protected PickupExecutablesDeployer(ExecutableRegistry registry, Class<T> input)
+   {
+      super(input);
+      setStage(DeploymentStages.PRE_REAL);
+
+      if (registry == null)
+         throw new IllegalArgumentException("Null registry");      
+      this.registry = registry;
+   }
+
+   protected ExecutableRegistry getRegistry()
+   {
+      return registry;
+   }
+}

Copied: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/ExecutableFactory.java (from rev 97034, projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/Executable.java)
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/ExecutableFactory.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/ExecutableFactory.java	2009-11-26 17:06:39 UTC (rev 97042)
@@ -0,0 +1,9 @@
+package org.jboss.fresh.shell;
+
+/**
+ * Factory.
+ */
+public interface ExecutableFactory
+{
+   Executable create();
+}
\ No newline at end of file

Modified: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/ExecutableRegistry.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/ExecutableRegistry.java	2009-11-26 16:47:57 UTC (rev 97041)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/ExecutableRegistry.java	2009-11-26 17:06:39 UTC (rev 97042)
@@ -22,6 +22,8 @@
 package org.jboss.fresh.shell;
 
 /**
+ * Executable registry.
+ *
  * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
 public interface ExecutableRegistry
@@ -33,4 +35,37 @@
     * @return found Executable instance or null if not matching to command
     */
    Executable getExecutable(String command);
+
+   /**
+    * Get executable.
+    *
+    * Note: expected type can be null, if we don't know the actual type.
+    * If returned instance is not an Executable instance,
+    * then it should have proper annotations.
+    *
+    * @param command the command
+    * @param expectedType the expected type
+    * @param <T> exact executable type
+    * @return the executable object
+    */
+   <T> T getExecutable(String command, Class<T> expectedType);
+
+   /**
+    * Register an executable object.
+    *
+    * The executable param can either be:
+    * - class who's super class is Executable
+    * - implement ExecutableFacotry
+    * - have proper annotations
+    *
+    * @param executable an executable object
+    */
+   void registerExecutable(Object executable);
+
+   /**
+    * Unregister executable.
+    *
+    * @param executable the executable
+    */
+   void unregisterExecutable(Object executable);
 }

Modified: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/impl/DefaultExecutableRegistry.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/impl/DefaultExecutableRegistry.java	2009-11-26 16:47:57 UTC (rev 97041)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/impl/DefaultExecutableRegistry.java	2009-11-26 17:06:39 UTC (rev 97042)
@@ -91,4 +91,19 @@
          return null;
       }
    }
+
+   public <T> T getExecutable(String command, Class<T> expectedType)
+   {
+      return null; // TODO - FRESH-21
+   }
+
+   public void registerExecutable(Object executable)
+   {
+      // TODO - FRESH-21
+   }
+
+   public void unregisterExecutable(Object executable)
+   {
+      // TODO - FRESH-21
+   }
 }

Modified: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/impl/LazyExecutableRegistry.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/impl/LazyExecutableRegistry.java	2009-11-26 16:47:57 UTC (rev 97041)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/impl/LazyExecutableRegistry.java	2009-11-26 17:06:39 UTC (rev 97042)
@@ -47,6 +47,11 @@
 
    public Executable getExecutable(String command)
    {
+      return getDelegate().getExecutable(command);
+   }
+
+   protected ExecutableRegistry getDelegate()
+   {
       if (delegate == null)
       {
          ControllerContext context;
@@ -65,12 +70,26 @@
 
          delegate = (ExecutableRegistry)context.getTarget();
       }
-
-      return delegate.getExecutable(command);
+      return delegate;
    }
 
    public void setExecutableRegistryName(String executableRegistryName)
    {
       this.executableRegistryName = executableRegistryName;
    }
+
+   public <T> T getExecutable(String command, Class<T> expectedType)
+   {
+      return getDelegate().getExecutable(command, expectedType);
+   }
+
+   public void registerExecutable(Object executable)
+   {
+      getDelegate().registerExecutable(executable);
+   }
+
+   public void unregisterExecutable(Object executable)
+   {
+      getDelegate().unregisterExecutable(executable);
+   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list