Author: pete.muir(a)jboss.org
Date: 2009-04-04 11:54:52 -0400 (Sat, 04 Apr 2009)
New Revision: 2298
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/NamespaceManager.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/RunInDependentContext.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/definition/ELResolverTest.java
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/NamespacedResolver.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/RootManager.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/Namespace.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/WebBeansELResolver.java
ri/trunk/tests/pom.xml
Log:
WBRI-218
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/RootManager.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/RootManager.java 2009-04-04 13:53:33
UTC (rev 2297)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/RootManager.java 2009-04-04 15:54:52
UTC (rev 2298)
@@ -67,6 +67,7 @@
import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.ContextMap;
import org.jboss.webbeans.context.CreationalContextImpl;
+import org.jboss.webbeans.el.NamespaceManager;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.injection.NonContextualInjector;
@@ -135,6 +136,8 @@
private final transient Map<Bean<?>, Bean<?>> specializedBeans;
private final transient NonContextualInjector nonContextualInjector;
+
+ private final transient NamespaceManager namespaceManager;
/**
* Create a new manager
@@ -161,6 +164,7 @@
};
this.specializedBeans = new HashMap<Bean<?>, Bean<?>>();
this.nonContextualInjector = new NonContextualInjector(this);
+ this.namespaceManager = new NamespaceManager();
List<Class<? extends Annotation>> defaultEnabledDeploymentTypes = new
ArrayList<Class<? extends Annotation>>();
defaultEnabledDeploymentTypes.add(0, Standard.class);
defaultEnabledDeploymentTypes.add(1, Production.class);
@@ -206,6 +210,7 @@
}
resolver.clear();
beans.add(bean);
+ namespaceManager.register(bean);
return this;
}
@@ -398,6 +403,7 @@
newEnterpriseBeanMap.put(bean.getType(), (EnterpriseBean<?>) bean);
}
riBeans.put(bean.getId(), bean);
+ namespaceManager.register(bean);
}
resolver.clear();
}
@@ -867,6 +873,11 @@
{
return resolver;
}
+
+ public NamespaceManager getNamespaceManager()
+ {
+ return namespaceManager;
+ }
/**
* Gets a string representation
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/el/Namespace.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/el/Namespace.java 2009-04-04 13:53:33
UTC (rev 2297)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/el/Namespace.java 2009-04-04 15:54:52
UTC (rev 2298)
@@ -11,31 +11,47 @@
*/
public class Namespace
{
+ private final String qualifiedName;
+ private final String name;
+ private final Map<String, Namespace> children = new HashMap<String,
Namespace>();
- private String name;
- private Map<String, Namespace> children = new HashMap<String,
Namespace>();
-
- public Namespace(String name)
+ public Namespace(String name, String qualifiedName)
{
this.name = name;
+ this.qualifiedName = qualifiedName;
}
- public Namespace getChild(String key)
+ public Namespace putIfAbsent(String key)
{
Namespace result = children.get(key);
if (result==null)
{
- result = new Namespace( getQualifiedName(key) + '.' );
- children.put(name, result);
+ result = new Namespace( key, qualifyName(key) );
+ children.put(key, result);
}
return result;
}
+
+ public Namespace get(String key)
+ {
+ return children.get(key);
+ }
+
+ public boolean contains(String key)
+ {
+ return children.containsKey(key);
+ }
- public String getQualifiedName(String key)
+ public String getQualifiedName()
{
- return name==null ? key : name + key;
+ return qualifiedName;
}
+ public String qualifyName(String suffix)
+ {
+ return qualifiedName == null ? suffix : qualifiedName + "." + suffix;
+ }
+
@Override
public int hashCode()
{
@@ -45,15 +61,14 @@
@Override
public boolean equals(Object other)
{
- if ( !(other instanceof Namespace) )
+ if (other instanceof Namespace)
{
- return false;
+ Namespace that = (Namespace) other;
+ return this.getQualifiedName().equals(that.getQualifiedName());
}
else
{
- Namespace ns = (Namespace) other;
- return this.name==ns.name ||
- ( this.name!=null && this.name.equals(ns.name) );
+ return false;
}
}
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/el/NamespaceManager.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/el/NamespaceManager.java
(rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/el/NamespaceManager.java 2009-04-04
15:54:52 UTC (rev 2298)
@@ -0,0 +1,34 @@
+package org.jboss.webbeans.el;
+
+import javax.inject.manager.Bean;
+
+public class NamespaceManager
+{
+
+ private final Namespace root;
+
+ public NamespaceManager()
+ {
+ root = new Namespace(null, null);
+ }
+
+ public void register(Bean<?> bean)
+ {
+ if (bean.getName() != null && bean.getName().indexOf('.') > 0)
+ {
+ String name = bean.getName().substring(0,
bean.getName().lastIndexOf('.'));
+ String[] hierarchy = name.split("\\.");
+ Namespace namespace = root;
+ for (String s : hierarchy)
+ {
+ namespace = namespace.putIfAbsent(s);
+ }
+ }
+ }
+
+ public Namespace getRoot()
+ {
+ return root;
+ }
+
+}
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/NamespaceManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/el/NamespacedResolver.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/el/NamespacedResolver.java 2009-04-04
13:53:33 UTC (rev 2297)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/el/NamespacedResolver.java 2009-04-04
15:54:52 UTC (rev 2298)
@@ -1,110 +0,0 @@
-package org.jboss.webbeans.el;
-
-
-import javax.el.ELContext;
-import javax.inject.ExecutionException;
-
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.context.DependentContext;
-import org.jboss.webbeans.context.DependentInstancesStore;
-import org.jboss.webbeans.context.DependentStorageRequest;
-
-class NamespacedResolver
-{
-
- private final ELContext context;
- private final String property;
- private final Namespace namespace;
- private Object value;
-
- public NamespacedResolver(ELContext context, Namespace namespace, String property)
- {
- this.context = context;
- this.property = property;
- this.namespace = namespace;
- }
-
- public Object getValue()
- {
- return value;
- }
-
- public NamespacedResolver run()
- {
-
- try
- {
- new RunInDependentContext()
- {
-
- @Override
- protected void execute() throws Exception
- {
- value =
CurrentManager.rootManager().getInstanceByName(namespace.getQualifiedName(property));
- if (value != null)
- {
- context.setPropertyResolved(true);
- }
- }
-
- }.run();
- }
- catch (Exception e)
- {
- throw new ExecutionException("Error resolving EL " + property, e);
- }
-
- if (!context.isPropertyResolved())
- {
- // look for a namespace
- value = namespace.getChild(property);
- if (value != null)
- {
- context.setPropertyResolved(true);
- }
- }
- return this;
- }
-
- static abstract class RunInDependentContext
- {
-
- private final DependentStorageRequest dependentStorageRequest;
-
- public RunInDependentContext()
- {
- dependentStorageRequest = DependentStorageRequest.of(new
DependentInstancesStore(), new Object());
- }
-
- private void setup()
- {
- DependentContext.INSTANCE.setActive(true);
- DependentContext.INSTANCE.startCollectingDependents(dependentStorageRequest);
- }
-
- private void cleanup()
- {
- DependentContext.INSTANCE.stopCollectingDependents(dependentStorageRequest);
- // TODO kinky
-
dependentStorageRequest.getDependentInstancesStore().destroyDependentInstances(dependentStorageRequest.getKey());
- DependentContext.INSTANCE.setActive(false);
- }
-
- protected abstract void execute() throws Exception;
-
- public final void run() throws Exception
- {
- try
- {
- setup();
- execute();
- }
- finally
- {
- cleanup();
- }
- }
-
- }
-
-}
\ No newline at end of file
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/el/RunInDependentContext.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/el/RunInDependentContext.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/RunInDependentContext.java 2009-04-04
15:54:52 UTC (rev 2298)
@@ -0,0 +1,49 @@
+/**
+ *
+ */
+package org.jboss.webbeans.el;
+
+import org.jboss.webbeans.context.DependentContext;
+import org.jboss.webbeans.context.DependentInstancesStore;
+import org.jboss.webbeans.context.DependentStorageRequest;
+
+abstract class RunInDependentContext
+{
+
+ private final DependentStorageRequest dependentStorageRequest;
+
+ public RunInDependentContext()
+ {
+ dependentStorageRequest = DependentStorageRequest.of(new DependentInstancesStore(),
new Object());
+ }
+
+ private void setup()
+ {
+ DependentContext.INSTANCE.setActive(true);
+ DependentContext.INSTANCE.startCollectingDependents(dependentStorageRequest);
+ }
+
+ private void cleanup()
+ {
+ DependentContext.INSTANCE.stopCollectingDependents(dependentStorageRequest);
+ // TODO kinky
+
dependentStorageRequest.getDependentInstancesStore().destroyDependentInstances(dependentStorageRequest.getKey());
+ DependentContext.INSTANCE.setActive(false);
+ }
+
+ protected abstract void execute() throws Exception;
+
+ public final void run() throws Exception
+ {
+ try
+ {
+ setup();
+ execute();
+ }
+ finally
+ {
+ cleanup();
+ }
+ }
+
+}
\ No newline at end of file
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/el/RunInDependentContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/el/WebBeansELResolver.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/el/WebBeansELResolver.java 2009-04-04
13:53:33 UTC (rev 2297)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/el/WebBeansELResolver.java 2009-04-04
15:54:52 UTC (rev 2298)
@@ -22,7 +22,10 @@
import javax.el.ELContext;
import javax.el.ELResolver;
+import javax.inject.ExecutionException;
+import org.jboss.webbeans.CurrentManager;
+
/**
* An EL-resolver against the named beans
*
@@ -30,9 +33,24 @@
*/
public class WebBeansELResolver extends ELResolver
{
-
- private static final Namespace ROOT = new Namespace(null);
+ private static final class ValueHolder<T>
+ {
+
+ private T value;
+
+ public T getValue()
+ {
+ return value;
+ }
+
+ public void setValue(T value)
+ {
+ this.value = value;
+ }
+
+ }
+
/**
* @see javax.el.ELResolver#getCommonPropertyType(ELContext, Object)
*/
@@ -68,14 +86,60 @@
{
if (property != null)
{
+ String propertyString = property.toString();
+ Namespace namespace = null;
if (base == null)
{
- return new NamespacedResolver(context, ROOT,
property.toString()).run().getValue();
+ if
(CurrentManager.rootManager().getNamespaceManager().getRoot().contains(propertyString))
+ {
+ context.setPropertyResolved(true);
+ return
CurrentManager.rootManager().getNamespaceManager().getRoot().get(propertyString);
+ }
}
- else if (base instanceof Namespace)
+ else if (base instanceof Namespace)
{
- return new NamespacedResolver(context, (Namespace) base,
property.toString()).run().getValue();
+ namespace = (Namespace) base;
+ // We're definitely the responsible party
+ context.setPropertyResolved(true);
+ if (namespace.contains(propertyString))
+ {
+ // There is a child namespace
+ return namespace.get(propertyString);
+ }
}
+ final String name;
+ if (namespace != null)
+ {
+ // Try looking in the manager for a bean
+ name = namespace.qualifyName(propertyString);
+ }
+ else
+ {
+ name = propertyString;
+ }
+ final ValueHolder<Object> holder = new ValueHolder<Object>();
+ try
+ {
+ new RunInDependentContext()
+ {
+
+ @Override
+ protected void execute() throws Exception
+ {
+ holder.setValue(CurrentManager.rootManager().getInstanceByName(name));
+ }
+
+ }.run();
+ }
+ catch (Exception e)
+ {
+ throw new ExecutionException("Error resolving property " +
propertyString + " against base " + base, e);
+ }
+ if (holder.getValue() != null)
+ {
+ context.setPropertyResolved(true);
+ return holder.getValue();
+ }
}
return null;
}
Modified: ri/trunk/tests/pom.xml
===================================================================
--- ri/trunk/tests/pom.xml 2009-04-04 13:53:33 UTC (rev 2297)
+++ ri/trunk/tests/pom.xml 2009-04-04 15:54:52 UTC (rev 2298)
@@ -42,6 +42,16 @@
</dependency>
<dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-ri</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-api</artifactId>
<optional>true</optional>
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/definition/ELResolverTest.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/definition/ELResolverTest.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/definition/ELResolverTest.java 2009-04-04
15:54:52 UTC (rev 2298)
@@ -0,0 +1,21 @@
+package org.jboss.webbeans.test.unit.definition;
+
+import javax.el.ELContext;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.webbeans.mock.el.EL;
+import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
+import org.testng.annotations.Test;
+
+@Artifact
+public class ELResolverTest extends AbstractWebBeansTest
+{
+
+ @Test
+ public void testNonBeanDoesntResolveToNamespace()
+ {
+ ELContext elContext = EL.createELContext();
+ assert EL.EXPRESSION_FACTORY.createValueExpression(elContext,
"#{foo.bar}", Object.class).getValue(elContext) == null;
+ }
+
+}
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/definition/ELResolverTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain