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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 8 08:46:07 EDT 2008


Author: alesj
Date: 2008-07-08 08:46:07 -0400 (Tue, 08 Jul 2008)
New Revision: 75493

Added:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Search.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchPropertyAnnotationPlugin.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchValueMetaData.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/ScopeTester.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SearchInjection.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/BasicSearchAnnotationSupportTestCase.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/SearchTestSuite.java
Modified:
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractDependencyItem.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/AbstractLookupStrategy.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/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/GraphController.java
   projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/LookupStrategy.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractDependencyValueMetaData.java
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractValueMetaData.java
   projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationsTestSuite.java
Log:
Initial Search support.

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-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -349,7 +349,7 @@
       }
    }
 
-   public ControllerContext getContext(Object name, ControllerState state, SearchInfo info) throws Throwable
+   public ControllerContext getContext(Object name, ControllerState state, SearchInfo info)
    {
       if (info == null)
          throw new IllegalArgumentException("Null search info.");

Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractDependencyItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractDependencyItem.java	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractDependencyItem.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -235,7 +235,17 @@
    public String toHumanReadableString()
    {
       StringBuilder builder = new StringBuilder();
-      builder.append("Depends on '").append(getIDependOn());
+      toHumanReadableString(builder);
       return builder.toString();
    }
+
+   /**
+    * Add info to builder.
+    *
+    * @param builder the string builder
+    */
+   protected void toHumanReadableString(StringBuilder builder)
+   {
+      builder.append("Depends on '").append(getIDependOn());
+   }
 }

Modified: 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	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/AbstractLookupStrategy.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -54,7 +54,7 @@
       return this;
    }
 
-   public ControllerContext getContext(Controller controller, Object name, ControllerState state) throws Throwable
+   public ControllerContext getContext(Controller controller, Object name, ControllerState state)
    {
       if (controller instanceof AbstractController == false)
          throw new IllegalArgumentException("Can only handle AbstractController: " + controller);
@@ -69,7 +69,6 @@
     * @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;
+   protected abstract ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state);
 }
\ No newline at end of file

Modified: 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	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/DefaultLookupStrategy.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -33,7 +33,7 @@
  */
 public class DefaultLookupStrategy implements LookupStrategy
 {
-   public ControllerContext getContext(Controller controller, Object name, ControllerState state) throws Throwable
+   public ControllerContext getContext(Controller controller, Object name, ControllerState state)
    {
       return controller.getContext(name, state);
    }

Modified: 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	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/DepthLookupStrategy.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -46,7 +46,7 @@
       this.checkCurrent = checkCurrent;
    }
 
-   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state)
    {
       return getContextInternal(controller, name, state, checkCurrent);
    }
@@ -59,9 +59,8 @@
     * @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
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state, boolean check)
    {
       ControllerContext context;
       if (check)

Modified: 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	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/LeavesFirstLookupStrategy.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -46,7 +46,7 @@
       this.checkCurrent = checkCurrent;
    }
 
-   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state)
    {
       return getContextInternal(controller, name, state, checkCurrent);
    }
@@ -59,9 +59,8 @@
     * @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
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state, boolean check)
    {
       Set<AbstractController> children = controller.getControllers();
       for (AbstractController child : children)

Modified: 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	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/LocalLookupStrategy.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -33,7 +33,7 @@
  */
 public class LocalLookupStrategy extends AbstractLookupStrategy
 {
-   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state)
    {
       if (controller instanceof ScopedController)
       {

Modified: 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	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ParentOnlyLookupStrategy.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -33,7 +33,7 @@
  */
 public class ParentOnlyLookupStrategy extends AbstractLookupStrategy
 {
-   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state)
    {
       AbstractController parent = controller.getParentController();
       if (parent != null)

Modified: 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	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/TopLevelLookupStrategy.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -32,7 +32,7 @@
  */
 public class TopLevelLookupStrategy extends AbstractLookupStrategy
 {
-   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state)
    {
       AbstractController parent = controller.getParentController();
       while (parent != null)

Modified: 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	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/WidthLookupStrategy.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -46,7 +46,7 @@
       this.checkCurrent = checkCurrent;
    }
 
-   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state) throws Throwable
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state)
    {
       return getContextInternal(controller, name, state, checkCurrent);
    }
@@ -59,9 +59,8 @@
     * @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
+   protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state, boolean check)
    {
       ControllerContext context;
       if (check)

Modified: 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	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/GraphController.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -41,7 +41,6 @@
     * @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;
+   ControllerContext getContext(Object name, ControllerState state, SearchInfo info);
 }

Modified: 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	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/LookupStrategy.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -39,7 +39,6 @@
     * @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;
+   ControllerContext getContext(Controller controller, Object name, ControllerState state);
 }

Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Search.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Search.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/Search.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -0,0 +1,68 @@
+/*
+* 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.beans.metadata.api.annotations;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Do a search over GraphController for matching context.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Target(ElementType.METHOD)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface Search
+{
+   /**
+    * Get bean.
+    * Default is no bean.
+    *
+    * @return bean name
+    */
+   String bean();
+
+   /**
+    * Get dependent state.
+    * Default is Installed.
+    *
+    * @return dependent state.
+    */
+   String dependentState() default "";
+
+   /**
+    * Get search type.
+    *
+    * @return the search type
+    */
+   String type();
+
+   /**
+    * Get property.
+    * Default is no property.
+    *
+    * @return property name
+    */
+   String property() default "";
+}

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractDependencyValueMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractDependencyValueMetaData.java	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractDependencyValueMetaData.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -195,7 +195,7 @@
       if (lookup == null)
          return null;
 
-      Object result = lookup.getTarget();
+      Object result;
       if (property != null)
       {
          if (lookup instanceof AttributeDispatchContext)
@@ -208,6 +208,11 @@
                   "Cannot use property attribute, context is not AttributeDispatchContext: " + lookup +
                   ", metadata: " + this);
       }
+      else
+      {
+         result = lookup.getTarget();
+      }
+      
       return info != null ? info.convertValue(result) : result;
    }
 

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractValueMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractValueMetaData.java	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractValueMetaData.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -103,9 +103,9 @@
       visitor.initialVisit(this);
    }
 
-   public void describeVisit(MetaDataVisitor vistor)
+   public void describeVisit(MetaDataVisitor visitor)
    {
-      vistor.describeVisit(this);
+      visitor.describeVisit(this);
    }
 
    public TypeInfo getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable

Copied: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchPropertyAnnotationPlugin.java (from rev 75212, projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/InjectAnnotationPlugin.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchPropertyAnnotationPlugin.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchPropertyAnnotationPlugin.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -0,0 +1,70 @@
+/*
+* 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.kernel.plugins.annotations;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.beans.metadata.api.annotations.Search;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Search value annotation plugin.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SearchPropertyAnnotationPlugin extends PropertyAnnotationPlugin<Search>
+{
+   public final static SearchPropertyAnnotationPlugin INSTANCE = new SearchPropertyAnnotationPlugin();
+
+   private static final Map<String, org.jboss.dependency.plugins.graph.Search> types;
+
+   static
+   {
+      types = new HashMap<String,org.jboss.dependency.plugins.graph.Search>();
+      for (org.jboss.dependency.plugins.graph.Search search : org.jboss.dependency.plugins.graph.Search.values())
+      {
+         types.put(search.type().toUpperCase(), search);
+      }
+   }
+
+   protected SearchPropertyAnnotationPlugin()
+   {
+      super(Search.class);
+   }
+
+   public ValueMetaData createValueMetaData(Search search)
+   {
+      String searchType = search.type();
+      org.jboss.dependency.plugins.graph.Search type = types.get(searchType.toUpperCase());
+      if (type == null)
+         throw new IllegalArgumentException("No such search type: " + searchType + ", available: " + types.keySet());
+      
+      return new SearchValueMetaData(
+            search.bean(),
+            new ControllerState(search.dependentState()),
+            type,
+            search.property()
+      );
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchValueMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchValueMetaData.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchValueMetaData.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -0,0 +1,157 @@
+/*
+* 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.kernel.plugins.annotations;
+
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.spi.MetaDataVisitor;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.dependency.spi.dispatch.AttributeDispatchContext;
+import org.jboss.dependency.spi.graph.GraphController;
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * Search value metadata.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SearchValueMetaData extends AbstractValueMetaData
+{
+   private ControllerState state;
+   private org.jboss.dependency.plugins.graph.Search search;
+   private String property;
+
+   private ControllerContext context;
+
+   public SearchValueMetaData(Object value, ControllerState state, org.jboss.dependency.plugins.graph.Search search, String property)
+   {
+      super(value);
+      if (search == null)
+         throw new IllegalArgumentException("Null search type");
+      
+      this.state = state;
+      this.search = search;
+      this.property = property;
+   }
+
+   public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
+   {
+      Controller controller = context.getController();
+      // we're here, so it must be GraphController instance
+      GraphController gc = (GraphController)controller;
+      ControllerContext context = gc.getContext(getUnderlyingValue(), state, search);
+
+      Object result;
+      if (property != null && property.length() > 0)
+      {
+         if (context instanceof AttributeDispatchContext)
+         {
+            AttributeDispatchContext adc = (AttributeDispatchContext)context;
+            result = adc.get(property);
+         }
+         else
+            throw new IllegalArgumentException(
+                  "Cannot use property attribute, context is not AttributeDispatchContext: " + context +
+                  ", metadata: " + this);
+      }
+      else
+      {
+         result = context.getTarget();
+      }
+
+      return info != null ? info.convertValue(result) : result;
+   }
+
+   public void initialVisit(MetaDataVisitor visitor)
+   {
+      context = visitor.getControllerContext();
+
+      super.initialVisit(visitor);
+   }
+
+   public void describeVisit(MetaDataVisitor visitor)
+   {
+      Object name = context.getName();
+      Object iDependOn = getUnderlyingValue();
+
+      ControllerState whenRequired = visitor.getContextState();
+      ControllerState dependentState = state;
+      if (dependentState == null)
+         dependentState = ControllerState.INSTALLED;
+
+      DependencyItem item = new SearchDependencyItem(name, iDependOn, whenRequired, dependentState);
+      visitor.addDependency(item);
+
+      super.describeVisit(visitor);
+   }
+
+   public void toString(JBossStringBuilder buffer)
+   {
+      super.toString(buffer);
+      buffer.append("search=").append(search);
+   }
+
+   public void toShortString(JBossStringBuilder buffer)
+   {
+      super.toShortString(buffer);
+      buffer.append("search=").append(search);
+   }
+
+   private class SearchDependencyItem extends AbstractDependencyItem
+   {
+      private SearchDependencyItem(Object name, Object iDependOn, ControllerState whenRequired, ControllerState dependentState)
+      {
+         super(name, iDependOn, whenRequired, dependentState);
+      }
+
+      public boolean resolve(Controller controller)
+      {
+         if (controller instanceof GraphController)
+         {
+            GraphController gc = (GraphController)controller;
+            ControllerContext context = gc.getContext(getIDependOn(), getDependentState(), search);
+            if (context != null)
+            {
+               setIDependOn(context.getName());
+               addDependsOnMe(controller, context);
+               setResolved(true);
+            }
+            else
+            {
+               setResolved(false);
+            }
+            return isResolved();
+         }
+         return false;
+      }
+
+      protected void toHumanReadableString(StringBuilder builder)
+      {
+         super.toHumanReadableString(builder);
+         builder.append("search=").append(search);
+      }
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/ScopeTester.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/ScopeTester.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/ScopeTester.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -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.test.kernel.annotations.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ScopeTester
+{
+   private String scope;
+
+   public ScopeTester(String scope)
+   {
+      this.scope = scope;
+   }
+
+   public String getScope()
+   {
+      return scope;
+   }
+}

Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SearchInjection.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SearchInjection.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/support/SearchInjection.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -0,0 +1,119 @@
+/*
+* 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.kernel.annotations.support;
+
+import org.jboss.beans.metadata.api.annotations.Search;
+import org.jboss.metadata.plugins.scope.ApplicationScope;
+import org.jboss.metadata.plugins.scope.DeploymentScope;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at ApplicationScope("main")
+ at DeploymentScope("core")
+public class SearchInjection
+{
+   private ScopeTester top;
+   private ScopeTester parent;
+   private ScopeTester local;
+   private ScopeTester normal;
+   private ScopeTester withChildren;
+   private ScopeTester childrenOnly;
+   private ScopeTester leaves;
+
+   public ScopeTester getTop()
+   {
+      return top;
+   }
+
+   @Search(bean = "bean", type = "toplevel")
+   public void setTop(ScopeTester top)
+   {
+      this.top = top;
+   }
+
+   public ScopeTester getParent()
+   {
+      return parent;
+   }
+
+   @Search(bean = "bean", type = "parentonly")
+   public void setParent(ScopeTester parent)
+   {
+      this.parent = parent;
+   }
+
+   public ScopeTester getLocal()
+   {
+      return local;
+   }
+
+   @Search(bean = "bean", type = "local")
+   public void setLocal(ScopeTester local)
+   {
+      this.local = local;
+   }
+
+   public ScopeTester getNormal()
+   {
+      return normal;
+   }
+
+   @Search(bean = "bean", type = "<default>")
+   public void setNormal(ScopeTester normal)
+   {
+      this.normal = normal;
+   }
+
+   public ScopeTester getWithChildren()
+   {
+      return withChildren;
+   }
+
+   @Search(bean = "bean", type = "depth")
+   public void setWithChildren(ScopeTester withChildren)
+   {
+      this.withChildren = withChildren;
+   }
+
+   public ScopeTester getChildrenOnly()
+   {
+      return childrenOnly;
+   }
+
+   @Search(bean = "bean", type = "ChildrenOnlyDepth")
+   public void setChildrenOnly(ScopeTester childrenOnly)
+   {
+      this.childrenOnly = childrenOnly;
+   }
+
+   public ScopeTester getLeaves()
+   {
+      return leaves;
+   }
+
+   @Search(bean = "bean", type = "leavesfirst")
+   public void setLeaves(ScopeTester leaves)
+   {
+      this.leaves = leaves;
+   }
+}
\ No newline at end of file

Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationsTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationsTestSuite.java	2008-07-08 09:49:47 UTC (rev 75492)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/AnnotationsTestSuite.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -29,6 +29,7 @@
 import org.jboss.test.kernel.annotations.test.inheritance.AnnotationsInheritanceTestSuite;
 import org.jboss.test.kernel.annotations.test.override.AnnotationsOverrideTestSuite;
 import org.jboss.test.kernel.annotations.test.wb.WBTestSuite;
+import org.jboss.test.kernel.annotations.test.search.SearchTestSuite;
 
 /**
  * Annotations tests.
@@ -52,6 +53,7 @@
       suite.addTest(AnnotationFieldTestSuite.suite());
       suite.addTest(AnnotationFactoryTestSuite.suite());
       suite.addTest(WBTestSuite.suite());
+      suite.addTest(SearchTestSuite.suite());
 
       return suite;
    }

Copied: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/BasicSearchAnnotationSupportTestCase.java (from rev 75212, projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/BasicFieldAnnotationSupportTestCase.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/BasicSearchAnnotationSupportTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/BasicSearchAnnotationSupportTestCase.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -0,0 +1,125 @@
+/*
+* 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.kernel.annotations.test.search;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.UUID;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.api.annotations.Aliases;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.plugins.annotations.AbstractBeanAnnotationAdapter;
+import org.jboss.kernel.plugins.annotations.BasicBeanAnnotationAdapter;
+import org.jboss.kernel.plugins.annotations.BeanAnnotationAdapter;
+import org.jboss.kernel.plugins.annotations.SearchPropertyAnnotationPlugin;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.metadata.plugins.scope.ApplicationScope;
+import org.jboss.metadata.plugins.scope.DeploymentScope;
+import org.jboss.metadata.plugins.scope.InstanceScope;
+import org.jboss.test.kernel.annotations.support.ScopeTester;
+import org.jboss.test.kernel.annotations.support.SearchInjection;
+import org.jboss.test.kernel.annotations.test.AbstractBeanAnnotationAdapterTest;
+
+/**
+ * Basic search annotation IoC support
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BasicSearchAnnotationSupportTestCase extends AbstractBeanAnnotationAdapterTest
+{
+   public BasicSearchAnnotationSupportTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(BasicSearchAnnotationSupportTestCase.class);
+   }
+
+   protected BeanAnnotationAdapter getBeanAnnotationAdapterClass()
+   {
+      AbstractBeanAnnotationAdapter adapter = BasicBeanAnnotationAdapter.INSTANCE;
+      adapter.addAnnotationPlugin(SearchPropertyAnnotationPlugin.INSTANCE);
+      return adapter;
+   }
+
+   public void testSearchTypes() throws Throwable
+   {
+      List<ControllerContext> contexts = new ArrayList<ControllerContext>();
+      try
+      {
+         contexts.add(install("top", null, null, -1));
+         contexts.add(install("parent", "main", null, -1));
+         contexts.add(install("local", "main", "core", -1));
+         contexts.add(install("child", "main", "core", 1));
+
+         runAnnotationsOnClass(SearchInjection.class);
+      }
+      finally
+      {
+         ListIterator<ControllerContext> iter = contexts.listIterator(contexts.size());
+         while (iter.hasPrevious())
+         {
+            getController().uninstall(iter.previous().getName());
+         }
+      }
+   }
+
+   protected void doTestAfterInstall(Object target)
+   {
+      SearchInjection si = (SearchInjection)target;
+      assertScopeTester(si.getTop(), "top");
+      assertScopeTester(si.getParent(), "parent");
+      assertScopeTester(si.getLocal(), "local");
+      assertScopeTester(si.getNormal(), "local");
+      assertScopeTester(si.getWithChildren(), "local");
+      assertScopeTester(si.getChildrenOnly(), "child");
+      assertScopeTester(si.getLeaves(), "child");      
+   }
+
+   protected void assertScopeTester(ScopeTester tester, String scope)
+   {
+      assertNotNull(scope, tester);
+      assertEquals(scope, tester.getScope());
+   }
+
+   protected ControllerContext install(String scope, String app, String deployment, int id) throws Throwable
+   {
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(UUID.randomUUID().toString(), ScopeTester.class.getName());
+      builder.addConstructorParameter(String.class.getName(), scope);
+      builder.addAnnotation("@" + Aliases.class.getName() + "({\"bean\"})");
+
+      if (app != null)
+         builder.addAnnotation("@" + ApplicationScope.class.getName() + "(\"" + app + "\")");
+      if (deployment != null)
+         builder.addAnnotation("@" + DeploymentScope.class.getName() + "(\"" + deployment + "\")");
+      if (id > 0)
+         builder.addAnnotation("@" + InstanceScope.class.getName() + "(\"id-" + Integer.toString(id) + "\")");
+
+      KernelController controller = getController();
+      return controller.install(builder.getBeanMetaData());
+   }
+}
\ No newline at end of file

Copied: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/SearchTestSuite.java (from rev 75212, projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/field/AnnotationFieldTestSuite.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/SearchTestSuite.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/SearchTestSuite.java	2008-07-08 12:46:07 UTC (rev 75493)
@@ -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.test.kernel.annotations.test.search;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Search annotation tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SearchTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Search Tests");
+
+      suite.addTest(BasicSearchAnnotationSupportTestCase.suite());
+
+      return suite;
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list