[jboss-cvs] JBossAS SVN: r75677 - in projects/microcontainer/trunk: dependency/src/main/org/jboss/dependency/plugins/graph and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jul 11 06:43:49 EDT 2008
Author: alesj
Date: 2008-07-11 06:43:47 -0400 (Fri, 11 Jul 2008)
New Revision: 75677
Added:
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ScopeKeySearchInfo.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/ScopeKeySearchTestCase.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
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/AbstractLookupStrategy.java
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/Search.java
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/SearchInfo.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchPropertyAnnotationPlugin.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractKernelController.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ScopedKernelController.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/SearchTestSuite.java
Log:
Adding info parameters to SearchInfo.
New ScopeKey search strategy + tests.
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-11 10:16:13 UTC (rev 75676)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -370,7 +370,7 @@
throw new IllegalArgumentException("AbstractController doesn't implement this search info: " + info);
if (log.isTraceEnabled())
- log.trace("Executing search " + info.type());
+ log.trace("Executing search " + info.getType());
return strategy.getContext(this, name, state);
}
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-11 10:16:13 UTC (rev 75676)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/ScopedController.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -23,6 +23,8 @@
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.ScopeInfo;
+import org.jboss.metadata.spi.scope.ScopeKey;
/**
* Scoped controller.
@@ -36,13 +38,37 @@
*/
public abstract class ScopedController extends AbstractController
{
+ private ScopeKey scopeKey;
private AbstractController underlyingController;
+ /**
+ * Get scope key.
+ *
+ * @return the scope key
+ */
+ public ScopeKey getScopeKey()
+ {
+ return scopeKey;
+ }
+
+ protected void setScopeKey(ScopeKey scopeKey)
+ {
+ // save a clone scope key - so we don't care about modifications
+ this.scopeKey = scopeKey.clone();
+ this.scopeKey.freeze();
+ }
+
protected void setUnderlyingController(AbstractController underlyingController)
{
this.underlyingController = underlyingController;
}
+ protected void preAliasInstall(ControllerContext aliasContext)
+ {
+ ScopeInfo scopeInfo = aliasContext.getScopeInfo();
+ scopeInfo.setInstallScope(scopeKey);
+ }
+
/**
* Get the context only in this scope.
* No hierarchy lookup.
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-11 10:16:13 UTC (rev 75676)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/AbstractLookupStrategy.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -21,6 +21,8 @@
*/
package org.jboss.dependency.plugins.graph;
+import java.util.Map;
+
import org.jboss.dependency.plugins.AbstractController;
import org.jboss.dependency.spi.Controller;
import org.jboss.dependency.spi.ControllerContext;
@@ -37,9 +39,19 @@
public abstract class AbstractLookupStrategy implements LookupStrategy, SearchInfo
{
private String type;
+ private Map<String, ?> info;
- public String type()
+ protected AbstractLookupStrategy()
{
+ }
+
+ protected AbstractLookupStrategy(Map<String, ?> info)
+ {
+ this.info = info;
+ }
+
+ public String getType()
+ {
if (type == null)
{
String simpleName = getClass().getSimpleName();
@@ -49,6 +61,11 @@
return type;
}
+ public Map<String, ?> getInfo()
+ {
+ return info;
+ }
+
public LookupStrategy getStrategy()
{
return this;
Copied: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ScopeKeySearchInfo.java (from rev 75591, projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/Search.java)
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ScopeKeySearchInfo.java (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/ScopeKeySearchInfo.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -0,0 +1,117 @@
+/*
+* 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.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.dependency.plugins.ScopedController;
+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;
+import org.jboss.metadata.spi.scope.ScopeKey;
+
+/**
+ * ScopeKey search info.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ScopeKeySearchInfo implements SearchInfo
+{
+ public static final String SCOPE_KEY = "ScopeKey";
+ private ScopeKey scopeKey;
+ private Map<String, ?> info;
+
+ public ScopeKeySearchInfo(ScopeKey scopeKey)
+ {
+ if (scopeKey == null)
+ throw new IllegalArgumentException("Null scope key");
+ this.scopeKey = scopeKey;
+ }
+
+ public String getType()
+ {
+ return SCOPE_KEY;
+ }
+
+ public Map<String, ?> getInfo()
+ {
+ if (info == null)
+ info = Collections.singletonMap(SCOPE_KEY, scopeKey);
+
+ return info;
+ }
+
+ public LookupStrategy getStrategy()
+ {
+ return new ScopeKeyLookupStrategy();
+ }
+
+ private class ScopeKeyLookupStrategy extends HierarchyLookupStrategy
+ {
+ protected ControllerContext getContextInternal(AbstractController controller, Object name, ControllerState state)
+ {
+ // go all the way to the top
+ AbstractController parent = controller.getParentController();
+ while (parent != null)
+ {
+ controller = parent;
+ parent = controller.getParentController();
+ }
+
+ AbstractController match = findMatchingScopedController(controller);
+ if (match != null)
+ return getLocalContext(match, name, state);
+
+ return null;
+ }
+
+ /**
+ * Find scope key matching scoped controller.
+ *
+ * @param current the current controller
+ * @return match or null if no match
+ */
+ private AbstractController findMatchingScopedController(AbstractController current)
+ {
+ if (current instanceof ScopedController)
+ {
+ ScopedController scopedController = (ScopedController)current;
+ if (scopeKey.equals(scopedController.getScopeKey()))
+ return current;
+ }
+
+ Set<AbstractController> children = current.getControllers();
+ for (AbstractController child : children)
+ {
+ AbstractController found = findMatchingScopedController(child);
+ if (found != null)
+ return found;
+ }
+
+ return null;
+ }
+ }
+}
\ No newline at end of file
Modified: 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 2008-07-11 10:16:13 UTC (rev 75676)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/graph/Search.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -21,6 +21,8 @@
*/
package org.jboss.dependency.plugins.graph;
+import java.util.Map;
+
import org.jboss.dependency.spi.graph.LookupStrategy;
import org.jboss.dependency.spi.graph.SearchInfo;
@@ -43,32 +45,42 @@
CHILD_ONLY_LEAVES(new ChildrenOnlyLeavesFirstLookupStrategy()),
CHILD_ONLY_WIDTH(new ChildrenOnlyWidthLookupStrategy());
- private SearchInfo info;
+ private SearchInfo delegate;
- Search(SearchInfo info)
+ Search(SearchInfo delegate)
{
- this.info = info;
+ this.delegate = delegate;
}
- public String type()
+ public String getType()
{
- return info.type();
+ return delegate.getType();
}
+ public Map<String, ?> getInfo()
+ {
+ return delegate.getInfo();
+ }
+
public LookupStrategy getStrategy()
{
- return info.getStrategy();
+ return delegate.getStrategy();
}
private static class DefaultSearchInfoWrapper implements SearchInfo
{
private DefaultLookupStrategy strategy = new DefaultLookupStrategy();
- public String type()
+ public String getType()
{
return "<DEFAULT>";
}
+ public Map<String, ?> getInfo()
+ {
+ return null;
+ }
+
public LookupStrategy getStrategy()
{
return strategy;
Modified: 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 2008-07-11 10:16:13 UTC (rev 75676)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/graph/SearchInfo.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -21,6 +21,8 @@
*/
package org.jboss.dependency.spi.graph;
+import java.util.Map;
+
/**
* Search info.
*
@@ -39,9 +41,17 @@
*
* @return
*/
- String type();
+ String getType();
/**
+ * Get the info.
+ * Additional parameters to be used for search.
+ *
+ * @return the additional info
+ */
+ Map<String, ?> getInfo();
+
+ /**
* Get the lookup strategy.
*
* Might be null, but then we expect the GraphController
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchPropertyAnnotationPlugin.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchPropertyAnnotationPlugin.java 2008-07-11 10:16:13 UTC (rev 75676)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/SearchPropertyAnnotationPlugin.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -45,7 +45,7 @@
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);
+ types.put(search.getType().toUpperCase(), search);
}
}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractKernelController.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractKernelController.java 2008-07-11 10:16:13 UTC (rev 75676)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractKernelController.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -22,11 +22,11 @@
package org.jboss.kernel.plugins.dependency;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ScopedKernelController.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ScopedKernelController.java 2008-07-11 10:16:13 UTC (rev 75676)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ScopedKernelController.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -31,7 +31,6 @@
import org.jboss.dependency.plugins.action.ControllerContextAction;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
-import org.jboss.dependency.spi.ScopeInfo;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.KernelFactory;
import org.jboss.kernel.plugins.bootstrap.basic.BasicKernelInitializer;
@@ -58,13 +57,12 @@
public class ScopedKernelController extends AbstractKernelController
{
protected Kernel parentKernel;
- private ScopeKey scopeKey;
public ScopedKernelController(Kernel parentKernel, AbstractController parentController, ScopeKey scopeKey) throws Exception
{
super();
this.parentKernel = parentKernel;
- this.scopeKey = scopeKey;
+ setScopeKey(scopeKey);
if (parentKernel.getController() instanceof AbstractController == false)
throw new IllegalArgumentException("Underlying controller not AbstractController instance!");
setUnderlyingController((AbstractController)parentKernel.getController());
@@ -75,16 +73,6 @@
}
/**
- * Get scope key.
- *
- * @return the scope key
- */
- protected ScopeKey getScopeKey()
- {
- return scopeKey;
- }
-
- /**
* Is parent controller a kernel controller.
*
* @return true if parent controller in kernel controller
@@ -141,12 +129,6 @@
return map;
}
- protected void preAliasInstall(ControllerContext aliasContext)
- {
- ScopeInfo scopeInfo = aliasContext.getScopeInfo();
- scopeInfo.setInstallScope(scopeKey);
- }
-
// override, since kernel's contexts are extended with registry plugin
public ControllerContext getContextLocally(Object name, ControllerState state)
{
Copied: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/ScopeKeySearchTestCase.java (from rev 75591, projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/OrderSearchAnnotationSupportTestCase.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/ScopeKeySearchTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/ScopeKeySearchTestCase.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -0,0 +1,92 @@
+/*
+* 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 junit.framework.Test;
+import org.jboss.dependency.plugins.graph.ScopeKeySearchInfo;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.graph.GraphController;
+import org.jboss.dependency.spi.graph.SearchInfo;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.scope.CommonLevels;
+
+/**
+ * Search scopes by scope key.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ScopeKeySearchTestCase extends AbstractSearchAnnotationSupportTest
+{
+ public ScopeKeySearchTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ScopeKeySearchTestCase.class);
+ }
+
+ public void testScopeKeyControllers() throws Throwable
+ {
+ List<ControllerContext> contexts = new ArrayList<ControllerContext>();
+ try
+ {
+ contexts.add(assertScopeBean("child", "main", "core", 1));
+ contexts.add(assertScopeBean("parent", "main", null, -1));
+ contexts.add(assertScopeBean("local", "main", "core", -1));
+ }
+ finally
+ {
+ ListIterator<ControllerContext> iter = contexts.listIterator(contexts.size());
+ while (iter.hasPrevious())
+ {
+ Object name = iter.previous().getName();
+ getController().uninstall(name);
+ }
+ }
+ }
+
+ protected ControllerContext assertScopeBean(String scope, String app, String deployment, int id) throws Throwable
+ {
+ ControllerContext context = install(scope, app, deployment, id);
+
+ ScopeKey scopeKey = new ScopeKey();
+ if (app != null)
+ scopeKey.addScope(CommonLevels.APPLICATION, app);
+ if (deployment != null)
+ scopeKey.addScope(CommonLevels.DEPLOYMENT, deployment);
+ if (id > 0)
+ scopeKey.addScope(CommonLevels.INSTANCE, "id-" + id);
+
+ SearchInfo searchInfo = new ScopeKeySearchInfo(scopeKey);
+ GraphController gc = (GraphController)getController();
+ ControllerContext lookup = gc.getContext("bean", null, searchInfo);
+ assertSame(context, lookup);
+
+ return context;
+ }
+}
\ No newline at end of file
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/SearchTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/SearchTestSuite.java 2008-07-11 10:16:13 UTC (rev 75676)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/annotations/test/search/SearchTestSuite.java 2008-07-11 10:43:47 UTC (rev 75677)
@@ -43,6 +43,7 @@
suite.addTest(BasicSearchAnnotationSupportTestCase.suite());
suite.addTest(OrderSearchAnnotationSupportTestCase.suite());
+ suite.addTest(ScopeKeySearchTestCase.suite());
return suite;
}
More information about the jboss-cvs-commits
mailing list