[jboss-cvs] JBossAS SVN: r75397 - in projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency: plugins/graph and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 4 17:34:40 EDT 2008


Author: alesj
Date: 2008-07-04 17:34:40 -0400 (Fri, 04 Jul 2008)
New Revision: 75397

Added:
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/AbstractLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyDepthLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyLeavesFirstLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyWidthLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/DefaultLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/DepthLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/LeavesFirstLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/LocalLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ParentOnlyLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/Search.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/TopLevelLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/WidthLookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/GraphController.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/LookupStrategy.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/SearchInfo.java
Modified:
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/ScopedController.java
Log:
Initial search/lookup contract.

Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java	2008-07-04 16:14:24 UTC (rev 75396)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -47,6 +47,9 @@
 import org.jboss.dependency.spi.DependencyInfo;
 import org.jboss.dependency.spi.DependencyItem;
 import org.jboss.dependency.spi.LifecycleCallbackItem;
+import org.jboss.dependency.spi.graph.GraphController;
+import org.jboss.dependency.spi.graph.SearchInfo;
+import org.jboss.dependency.spi.graph.LookupStrategy;
 import org.jboss.util.JBossObject;
 
 /**
@@ -56,7 +59,7 @@
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision$
  */
-public class AbstractController extends JBossObject implements Controller, ControllerStateModel
+public class AbstractController extends JBossObject implements Controller, ControllerStateModel, GraphController
 {
    /** The lock */
    private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
@@ -257,7 +260,7 @@
     *
     * @return the parent controller
     */
-   protected AbstractController getParentController()
+   public AbstractController getParentController()
    {
       return parentController;
    }
@@ -346,6 +349,18 @@
       }
    }
 
+   public ControllerContext getContext(Object name, ControllerState state, SearchInfo info) throws Throwable
+   {
+      if (info == null)
+         throw new IllegalArgumentException("Null search info.");
+
+      LookupStrategy strategy = info.getStrategy();
+      if (strategy == null)
+         throw new IllegalArgumentException("AbstractController doesn't implement this search info: " + info);
+
+      return strategy.getContext(this, name, state);
+   }
+
    /**
     * Get all the contexts.
     * In state decending order.

Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/ScopedController.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/ScopedController.java	2008-07-04 16:14:24 UTC (rev 75396)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/ScopedController.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -22,10 +22,13 @@
 package org.jboss.dependency.plugins;
 
 import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
 
 /**
  * Scoped controller.
- * Not other scoping logic except add/remove controller context.
+ *
+ * The only scoping logic is local lookup and
+ * add/remove of controller context.
  * Subclasses should provide parent lookup after looking
  * at the current scoped instance.
  *
@@ -41,6 +44,19 @@
    }
 
    /**
+    * Get the context only in this scope.
+    * No hierarchy lookup.
+    *
+    * @param name the context name
+    * @param state the controller state
+    * @return found context or null if not available
+    */
+   public ControllerContext getContextLocally(Object name, ControllerState state)
+   {
+      return super.getContext(name, state);
+   }
+
+   /**
     * Is controller scoped.
     *
     * @return true if scoped

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/AbstractLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/AbstractLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/AbstractLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,75 @@
+/*
+* 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.dependency.plugins.graph;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.graph.LookupStrategy;
+import org.jboss.dependency.spi.graph.SearchInfo;
+
+/**
+ * Abstract lookup strategy.
+ * Only working on AbstractController controller instances.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractLookupStrategy implements LookupStrategy, SearchInfo
+{
+   private String type;
+
+   public String type()
+   {
+      if (type == null)
+      {
+         String simpleName = getClass().getSimpleName();
+         int p = simpleName.indexOf("Strategy");
+         type = simpleName.substring(0, p);
+      }
+      return type;
+   }
+
+   public LookupStrategy getStrategy()
+   {
+      return this;
+   }
+
+   public ControllerContext getContext(Controller controller, Object name, ControllerState state) throws Throwable
+   {
+      if (controller instanceof AbstractController == false)
+         throw new IllegalArgumentException("Can only handle AbstractController: " + controller);
+
+      return getContextInternal((AbstractController)controller, name, state);
+   }
+
+   /**
+    * Get context based on this strategy.
+    *
+    * @param controller the current abstract controller
+    * @param name the name of the context
+    * @param state the context's state
+    * @return context or null if not available
+    * @throws Throwable for any error
+    */
+   protected abstract ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable;
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyDepthLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyDepthLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyDepthLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,35 @@
+/*
+* 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.dependency.plugins.graph;
+
+/**
+ * Children only - depth search.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ChildrenOnlyDepthLookupStrategy extends DepthLookupStrategy
+{
+   public ChildrenOnlyDepthLookupStrategy()
+   {
+      super(false);
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyLeavesFirstLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyLeavesFirstLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyLeavesFirstLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,35 @@
+/*
+* 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.dependency.plugins.graph;
+
+/**
+ *  Children only - leaves first.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ChildrenOnlyLeavesFirstLookupStrategy extends LeavesFirstLookupStrategy
+{
+   public ChildrenOnlyLeavesFirstLookupStrategy()
+   {
+      super(false);
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyWidthLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyWidthLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ChildrenOnlyWidthLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,35 @@
+/*
+* 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.dependency.plugins.graph;
+
+/**
+ * Children only - width search.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ChildrenOnlyWidthLookupStrategy extends WidthLookupStrategy
+{
+   public ChildrenOnlyWidthLookupStrategy()
+   {
+      super(false);
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/DefaultLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/DefaultLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/DefaultLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,40 @@
+/*
+* 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.dependency.plugins.graph;
+
+import org.jboss.dependency.spi.graph.LookupStrategy;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Default lookup.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DefaultLookupStrategy implements LookupStrategy
+{
+   public ControllerContext getContext(Controller controller, Object name, ControllerState state) throws Throwable
+   {
+      return controller.getContext(name, state);
+   }
+}

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/DepthLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/DepthLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/DepthLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,90 @@
+/*
+* 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.dependency.plugins.graph;
+
+import java.util.Set;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Depth search.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DepthLookupStrategy extends AbstractLookupStrategy
+{
+   private boolean checkCurrent;
+
+   public DepthLookupStrategy()
+   {
+      this(true);
+   }
+
+   protected DepthLookupStrategy(boolean checkCurrent)
+   {
+      this.checkCurrent = checkCurrent;
+   }
+
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   {
+      return getContextInternal(controller, name, state, checkCurrent);
+   }
+
+   /**
+    * Get context based on this strategy.
+    *
+    * @param controller the current abstract controller
+    * @param name the name of the context
+    * @param state the context's state
+    * @param check check current
+    * @return context or null if not available
+    * @throws Throwable for any error
+    */
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state, boolean check) throws Throwable
+   {
+      ControllerContext context;
+      if (check)
+      {
+         context = controller.getContext(name, state);
+         if (context != null)
+            return context;
+      }
+
+      Set<AbstractController> children = controller.getControllers();
+      for (AbstractController child : children)
+      {
+         // check child first
+         context = child.getContext(name, state);
+         if (context != null)
+            return context;
+
+         // then its children
+         context = getContextInternal(child, name, state, false);
+         if (context != null)
+            return context;
+      }
+
+      return null;
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/LeavesFirstLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/LeavesFirstLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/LeavesFirstLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,79 @@
+/*
+* 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.dependency.plugins.graph;
+
+import java.util.Set;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ *  Leaves first.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LeavesFirstLookupStrategy extends AbstractLookupStrategy
+{
+   private boolean checkCurrent;
+
+   public LeavesFirstLookupStrategy()
+   {
+      this(true);
+   }
+
+   protected LeavesFirstLookupStrategy(boolean checkCurrent)
+   {
+      this.checkCurrent = checkCurrent;
+   }
+
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   {
+      return getContextInternal(controller, name, state, checkCurrent);
+   }
+
+   /**
+    * Get context based on this strategy.
+    *
+    * @param controller the current abstract controller
+    * @param name the name of the context
+    * @param state the context's state
+    * @param check check current
+    * @return context or null if not available
+    * @throws Throwable for any error
+    */
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state, boolean check) throws Throwable
+   {
+      Set<AbstractController> children = controller.getControllers();
+      for (AbstractController child : children)
+      {
+         ControllerContext context = getContextInternal(child, name, state, true);
+         if (context != null)
+            return context;
+      }
+
+      if (check)
+         return controller.getContext(name, state);
+
+      return null;
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/LocalLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/LocalLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/LocalLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,46 @@
+/*
+* 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.dependency.plugins.graph;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.dependency.plugins.ScopedController;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Check only current scope.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LocalLookupStrategy extends AbstractLookupStrategy
+{
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   {
+      if (controller instanceof ScopedController)
+      {
+         ScopedController scopedController = (ScopedController)controller;
+         return scopedController.getContextLocally(name, state);
+      }
+      else
+         return controller.getContext(name, state);
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ParentOnlyLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ParentOnlyLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ParentOnlyLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,44 @@
+/*
+* 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.dependency.plugins.graph;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Check only parent.
+ * Return null if there is no parent.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ParentOnlyLookupStrategy extends AbstractLookupStrategy
+{
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   {
+      AbstractController parent = controller.getParentController();
+      if (parent != null)
+         return parent.getContext(name, state);
+      else
+         return null;
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/Search.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/Search.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/Search.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,76 @@
+/*
+* 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.dependency.plugins.graph;
+
+import org.jboss.dependency.spi.graph.LookupStrategy;
+import org.jboss.dependency.spi.graph.SearchInfo;
+
+/**
+ * Search enum.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public enum Search implements SearchInfo
+{
+   DEFAULT(new DefaultSearchInfoWrapper()),
+   LOCAL(new LocalLookupStrategy()),
+   TOP(new TopLevelLookupStrategy()),
+   PARENT(new ParentOnlyLookupStrategy()),
+   DEPTH(new DepthLookupStrategy()),
+   LEAVES(new LeavesFirstLookupStrategy()),
+   WIDTH(new WidthLookupStrategy()),
+   CHILD_ONLY_DEPTH(new ChildrenOnlyDepthLookupStrategy()),
+   CHILD_ONLY_LEAVES(new ChildrenOnlyLeavesFirstLookupStrategy()),
+   CHILD_ONLY_WIDTH(new ChildrenOnlyWidthLookupStrategy());
+
+   private SearchInfo info;
+
+   Search(SearchInfo info)
+   {
+      this.info = info;
+   }
+
+   public String type()
+   {
+      return info.type();
+   }
+
+   public LookupStrategy getStrategy()
+   {
+      return info.getStrategy();
+   }
+
+   private static class DefaultSearchInfoWrapper implements SearchInfo
+   {
+      private DefaultLookupStrategy strategy = new DefaultLookupStrategy();
+
+      public String type()
+      {
+         return "<DEFAULT>";
+      }
+
+      public LookupStrategy getStrategy()
+      {
+         return strategy;
+      }
+   }
+}

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/TopLevelLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/TopLevelLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/TopLevelLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,45 @@
+/*
+* 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.dependency.plugins.graph;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.plugins.AbstractController;
+
+/**
+ * Check only top level.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TopLevelLookupStrategy extends AbstractLookupStrategy
+{
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   {
+      AbstractController parent = controller.getParentController();
+      while (parent != null)
+      {
+         controller = parent;
+         parent = controller.getParentController();
+      }
+      return controller.getContext(name, state);
+   }
+}

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/WidthLookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/WidthLookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/WidthLookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,91 @@
+/*
+* 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.dependency.plugins.graph;
+
+import java.util.Set;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Width search.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class WidthLookupStrategy extends AbstractLookupStrategy
+{
+   private boolean checkCurrent;
+
+   public WidthLookupStrategy()
+   {
+      this(true);
+   }
+
+   protected WidthLookupStrategy(boolean checkCurrent)
+   {
+      this.checkCurrent = checkCurrent;
+   }
+
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   {
+      return getContextInternal(controller, name, state, checkCurrent);
+   }
+
+   /**
+    * Get context based on this strategy.
+    *
+    * @param controller the current abstract controller
+    * @param name the name of the context
+    * @param state the context's state
+    * @param check check current
+    * @return context or null if not available
+    * @throws Throwable for any error
+    */
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state, boolean check) throws Throwable
+   {
+      ControllerContext context;
+      if (check)
+      {
+         context = controller.getContext(name, state);
+         if (context != null)
+            return context;
+      }
+
+      Set<AbstractController> children = controller.getControllers();
+      for (AbstractController child : children)
+      {
+         context = child.getContext(name, state);
+         if (context != null)
+            return context;
+      }
+
+      for(AbstractController child : children)
+      {
+         context = getContextInternal(child, name, state, false);
+         if (context != null)
+            return context;
+      }
+
+      return null;
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/GraphController.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/GraphController.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/GraphController.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,47 @@
+/*
+* 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.dependency.spi.graph;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Graph controller.
+ *
+ * Either GraphController itself understands
+ * SearchInfo, or delegates work to LookupStrategy.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface GraphController
+{
+   /**
+    * Get the context.
+    *
+    * @param name the context name
+    * @param state the required state
+    * @param info the seatch info
+    * @return found context or null if not available
+    * @throws Throwable for any error
+    */
+   ControllerContext getContext(Object name, ControllerState state, SearchInfo info) throws Throwable;
+}

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/LookupStrategy.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/LookupStrategy.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/LookupStrategy.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,45 @@
+/*
+* 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.dependency.spi.graph;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Context lookup strategy.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface LookupStrategy
+{
+   /**
+    * Get context based on this strategy.
+    *
+    * @param controller the current controller
+    * @param name the name of the context
+    * @param state the context's state
+    * @return context or null if not available
+    * @throws Throwable for any error
+    */
+   ControllerContext getContext(Controller controller, Object name, ControllerState state) throws Throwable;
+}

Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/SearchInfo.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/SearchInfo.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/SearchInfo.java	2008-07-04 21:34:40 UTC (rev 75397)
@@ -0,0 +1,54 @@
+/*
+* 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.dependency.spi.graph;
+
+/**
+ * Search info.
+ *
+ * Holding the type or/and lookup strategy.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface SearchInfo
+{
+   /**
+    * The search type.
+    *
+    * If there is no supported lookup strategy
+    * GraphController implementation might
+    * return context on itself.
+    *
+    * @return
+    */
+   String type();
+
+   /**
+    * Get the lookup strategy.
+    *
+    * Might be null, but then we expect the GraphController
+    * to implement this search type.
+    * Otherwise error should be thown by GraphController.
+    *
+    * @return the strategy or null depending on GraphContorller
+    */
+   LookupStrategy getStrategy();
+}




More information about the jboss-cvs-commits mailing list