[jboss-cvs] JBossAS SVN: r94206 - in projects/kernel/trunk/dependency/src: main/java/org/jboss/dependency/plugins/helpers and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 1 05:49:39 EDT 2009


Author: alesj
Date: 2009-10-01 05:49:39 -0400 (Thu, 01 Oct 2009)
New Revision: 94206

Added:
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/helpers/
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java
   projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/InjectionControllerContextActions.java
   projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/SCTester.java
   projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/StatelessControllerTestCase.java
Modified:
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
   projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java
Log:
[JBKERNEL-56]; add stateless controller.

Modified: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2009-10-01 09:46:52 UTC (rev 94205)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2009-10-01 09:49:39 UTC (rev 94206)
@@ -485,7 +485,7 @@
          for (int i = states.size()-1; i>=0; --i)
          {
             ControllerState state = states.get(i);
-            result.addAll(contextsByState.get(state));
+            result.addAll(getContextsByState(state));
          }
          result.addAll(errorContexts.values());
          return result;
@@ -1039,7 +1039,7 @@
          {
             ControllerState state = states.get(i);
             ControllerState nextState = states.get(i + 1);
-            Set<ControllerContext> stillUnresolved = contextsByState.get(state);
+            Set<ControllerContext> stillUnresolved = getContextsByState(state);
             if (stillUnresolved.isEmpty() == false)
             {
                for (ControllerContext ctx : stillUnresolved)
@@ -1079,7 +1079,7 @@
    protected boolean resolveContexts(ControllerState fromState, ControllerState toState, boolean trace)
    {
       boolean resolutions = false;
-      Set<ControllerContext> unresolved = contextsByState.get(fromState);
+      Set<ControllerContext> unresolved = getContextsByState(fromState);
       Set<ControllerContext> resolved = resolveContexts(unresolved, toState, trace);
       if (resolved.isEmpty() == false)
       {

Copied: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java (from rev 91450, projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java)
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java	                        (rev 0)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java	2009-10-01 09:49:39 UTC (rev 94206)
@@ -0,0 +1,88 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.dependency.plugins.helpers;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.plugins.AbstractController;
+
+/**
+ * Stateless controller.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class StatelessController extends AbstractController implements Controller
+{
+   private Controller controller;
+
+   public StatelessController(Controller controller)
+   {
+      if (controller == null)
+         throw new IllegalArgumentException("Null controller");
+
+      this.controller = controller;
+      for (ControllerState state : controller.getStates())
+         addState(state, null);
+   }
+
+   public void enableOnDemand(ControllerContext context) throws Throwable
+   {
+      // ignore
+   }
+
+   @Override
+   protected void registerControllerContext(ControllerContext context)
+   {
+      // do nothing
+   }
+
+   @Override
+   public void install(ControllerContext context) throws Throwable
+   {
+      super.install(context);
+   }
+
+   public ControllerContext uninstall(Object name)
+   {
+      return null;
+   }
+
+   public ControllerContext getContext(Object name, ControllerState state)
+   {
+      return controller.getContext(name, state);
+   }
+
+   public ControllerContext getInstalledContext(Object name)
+   {
+      return controller.getInstalledContext(name);
+   }
+
+   public boolean isShutdown()
+   {
+      return controller.isShutdown();
+   }
+
+   public void shutdown()
+   {
+   }
+}
\ No newline at end of file


Property changes on: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/InjectionControllerContextActions.java (from rev 94115, projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/MockControllerContextActions.java)
===================================================================
--- projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/InjectionControllerContextActions.java	                        (rev 0)
+++ projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/InjectionControllerContextActions.java	2009-10-01 09:49:39 UTC (rev 94206)
@@ -0,0 +1,80 @@
+/*
+* 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.test.dependency.controller.support;
+
+import java.lang.reflect.Method;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerContextActions;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.reflect.plugins.introspection.ReflectionUtils;
+
+/**
+ * Actions that only do injection
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class InjectionControllerContextActions implements ControllerContextActions
+{
+   private Object inject;
+   private String method;
+
+   public InjectionControllerContextActions(Object inject, String method)
+   {
+      this.inject = inject;
+      this.method = method;
+   }
+
+   protected void inject(ControllerContext context, ControllerState state, boolean nullify) throws Throwable
+   {
+      if (ControllerState.CONFIGURED.equals(state))
+      {
+         Object target = context.getTarget();
+         Controller controller = context.getController();
+         ControllerContext other = controller.getInstalledContext(inject);
+         Object injectee = other.getTarget();
+         Method m = ReflectionUtils.findMethod(target.getClass(), method, injectee.getClass());
+         if (nullify)
+            injectee = null;
+
+         ReflectionUtils.invoke(m, target, new Object[]{injectee});
+      }
+   }
+
+   public void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
+   {
+      inject(context, toState, false);
+   }
+
+   public void uninstall(ControllerContext context, ControllerState fromState, ControllerState toState)
+   {
+      try
+      {
+         inject(context, toState, false);
+      }
+      catch (Throwable ignored)
+      {
+      }
+   }
+}
\ No newline at end of file

Copied: projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/SCTester.java (from rev 94115, projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/Synchronizer.java)
===================================================================
--- projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/SCTester.java	                        (rev 0)
+++ projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/SCTester.java	2009-10-01 09:49:39 UTC (rev 94206)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test.dependency.controller.support;
+
+/**
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SCTester
+{
+   private Object injectee;
+
+   public Object getInjectee()
+   {
+      return injectee;
+   }
+
+   public void setInjectee(Object injectee)
+   {
+      this.injectee = injectee;
+   }
+}
\ No newline at end of file

Modified: projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java
===================================================================
--- projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java	2009-10-01 09:46:52 UTC (rev 94205)
+++ projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java	2009-10-01 09:49:39 UTC (rev 94206)
@@ -29,6 +29,7 @@
  * Controller Test Suite.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision$
  */
 public class ControllerTestSuite extends TestSuite
@@ -63,6 +64,7 @@
       suite.addTest(SelfDependencyTestCase.suite());
       suite.addTest(ShutdownControllerTestCase.suite());
       suite.addTest(StateConsistencyUnitTestCase.suite());
+      suite.addTest(StatelessControllerTestCase.suite());
 
       return suite;
    }

Added: projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/StatelessControllerTestCase.java
===================================================================
--- projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/StatelessControllerTestCase.java	                        (rev 0)
+++ projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/StatelessControllerTestCase.java	2009-10-01 09:49:39 UTC (rev 94206)
@@ -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.test.dependency.controller.test;
+
+import junit.framework.Test;
+import org.jboss.dependency.plugins.AbstractControllerContext;
+import org.jboss.dependency.plugins.AbstractDependencyInfo;
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.dependency.plugins.helpers.StatelessController;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.dependency.controller.support.InjectionControllerContextActions;
+import org.jboss.test.dependency.controller.support.MockControllerContextActions;
+import org.jboss.test.dependency.controller.support.SCTester;
+
+/**
+ * Test stateless controller.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class StatelessControllerTestCase extends AbstractDependencyTest
+{
+   private MockControllerContextActions actions = new MockControllerContextActions();
+
+   public StatelessControllerTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(StatelessControllerTestCase.class);
+   }
+
+   /**
+    * Default setup with security manager enabled
+    *
+    * @param clazz the class
+    * @return the delegate
+    * @throws Exception for any error
+    */
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      return new AbstractTestDelegate(clazz);
+   }
+
+   protected ControllerContext prepareTopController(Object name, Object target) throws Throwable
+   {
+      ControllerContext context = new AbstractControllerContext(name, actions, new AbstractDependencyInfo(), target);
+      assertInstall(context, ControllerState.INSTALLED);
+      return context;
+   }
+
+   public void testInjection() throws Throwable
+   {
+      Object injectee = new Object();
+      prepareTopController("injectee", injectee);
+
+      StatelessController sc = new StatelessController(controller);
+      DependencyInfo info = new AbstractDependencyInfo();
+      info.addIDependOn(new AbstractDependencyItem("bean", "injectee", ControllerState.CONFIGURED, ControllerState.INSTALLED));
+      SCTester target = new SCTester();
+      ControllerContext context = new AbstractControllerContext("bean", new InjectionControllerContextActions("injectee", "setInjectee"), info, target);
+      sc.install(context);
+      assertEquals(ControllerState.INSTALLED, context.getState());
+      assertEquals(injectee, target.getInjectee());
+      assertNull(controller.getContext("bean", null));
+      assertNull(sc.getContext("bean", null));
+   }
+}




More information about the jboss-cvs-commits mailing list