Skip to content

Commit

Permalink
Split out namespaces data structure from namespace resolver service
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2943 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jul 1, 2009
1 parent c13680d commit e861fd6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
51 changes: 38 additions & 13 deletions impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
Expand Up @@ -206,15 +206,17 @@ public String toString()
private transient final TypeSafeResolver<EventObserver<?>> observerResolver;
private transient final NameBasedResolver nameBasedResolver;
private transient final ELResolver webbeansELResolver;
private transient Namespace rootNamespace;

/*
* Activity scoped data structures
* ********************************
*/
private transient final List<Bean<?>> beans;
private transient final List<DecoratorBean<?>> decorators;
private transient final Namespace rootNamespace;
private transient final List<String> namespaces;
private transient final List<EventObserver<?>> observers;

private transient final Set<BeanManagerImpl> childActivities;

private final Integer id;
Expand Down Expand Up @@ -244,7 +246,7 @@ public static BeanManagerImpl newRootManager(ServiceRegistry serviceRegistry)
new CopyOnWriteArrayList<Bean<?>>(),
new CopyOnWriteArrayList<DecoratorBean<?>>(),
new CopyOnWriteArrayList<EventObserver<?>>(),
new Namespace(),
new CopyOnWriteArrayList<String>(),
new ConcurrentHashMap<Class<?>, EnterpriseBean<?>>(),
new ConcurrentHashMap<String, RIBean<?>>(),
new ClientProxyProvider(),
Expand All @@ -267,14 +269,15 @@ public static BeanManagerImpl newChildManager(BeanManagerImpl parentManager)

List<EventObserver<?>> registeredObservers = new CopyOnWriteArrayList<EventObserver<?>>();
registeredObservers.addAll(parentManager.getObservers());
Namespace rootNamespace = new Namespace(parentManager.getRootNamespace());
List<String> namespaces = new CopyOnWriteArrayList<String>();
namespaces.addAll(parentManager.getNamespaces());

return new BeanManagerImpl(
parentManager.getServices(),
beans,
parentManager.getDecorators(),
registeredObservers,
rootNamespace,
namespaces,
parentManager.getNewEnterpriseBeanMap(),
parentManager.getRiBeans(),
parentManager.getClientProxyProvider(),
Expand All @@ -292,7 +295,22 @@ public static BeanManagerImpl newChildManager(BeanManagerImpl parentManager)
*
* @param ejbServices the ejbResolver to use
*/
private BeanManagerImpl(ServiceRegistry serviceRegistry, List<Bean<?>> beans, List<DecoratorBean<?>> decorators, List<EventObserver<?>> registeredObservers, Namespace rootNamespace, Map<Class<?>, EnterpriseBean<?>> newEnterpriseBeans, Map<String, RIBean<?>> riBeans, ClientProxyProvider clientProxyProvider, ConcurrentListMultiMap<Class<? extends Annotation>, Context> contexts, Set<CurrentActivity> currentActivities, Map<Contextual<?>, Contextual<?>> specializedBeans, List<Class<? extends Annotation>> enabledDeploymentTypes, List<Class<?>> enabledDecoratorClasses, AtomicInteger ids)
private BeanManagerImpl(
ServiceRegistry serviceRegistry,
List<Bean<?>> beans,
List<DecoratorBean<?>> decorators,
List<EventObserver<?>> registeredObservers,
List<String> namespaces,
Map<Class<?>, EnterpriseBean<?>> newEnterpriseBeans,
Map<String, RIBean<?>> riBeans,
ClientProxyProvider clientProxyProvider,
ConcurrentListMultiMap<Class<? extends Annotation>,
Context> contexts,
Set<CurrentActivity> currentActivities,
Map<Contextual<?>, Contextual<?>> specializedBeans,
List<Class<? extends Annotation>> enabledDeploymentTypes,
List<Class<?>> enabledDecoratorClasses,
AtomicInteger ids)
{
this.services = serviceRegistry;
this.beans = beans;
Expand All @@ -306,7 +324,7 @@ private BeanManagerImpl(ServiceRegistry serviceRegistry, List<Bean<?>> beans, Li
this.observers = registeredObservers;
setEnabledDeploymentTypes(enabledDeploymentTypes);
setEnabledDecoratorClasses(enabledDecoratorClasses);
this.rootNamespace = rootNamespace;
this.namespaces = namespaces;
this.ids = ids;
this.id = ids.incrementAndGet();

Expand Down Expand Up @@ -557,13 +575,7 @@ protected void registerBeanNamespace(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 = getRootNamespace();
for (String s : hierarchy)
{
namespace = namespace.putIfAbsent(s);
}
namespaces.add(bean.getName().substring(0, bean.getName().lastIndexOf('.')));
}
}

Expand Down Expand Up @@ -1040,6 +1052,14 @@ protected ConcurrentListMultiMap<Class<? extends Annotation>, Context> getContex
return contexts;
}

/**
* @return the namespaces
*/
protected List<String> getNamespaces()
{
return namespaces;
}

protected AtomicInteger getIds()
{
return ids;
Expand All @@ -1062,6 +1082,11 @@ public List<EventObserver<?>> getObservers()

public Namespace getRootNamespace()
{
// TODO I don't like this lazy init
if (rootNamespace == null)
{
rootNamespace = new Namespace(getNamespaces());
}
return rootNamespace;
}

Expand Down
28 changes: 11 additions & 17 deletions impl/src/main/java/org/jboss/webbeans/el/Namespace.java
Expand Up @@ -18,7 +18,6 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
* A namespace for bean names
Expand All @@ -33,37 +32,32 @@ public class Namespace
private final Map<String, Namespace> children;

/**
* Create a new namespace hierarchy, creating copies of all children as
* children of this node
* Create a new namespace hierarchy
*
* @param namespace
*/
public Namespace(Namespace namespace)
public Namespace(Iterable<String> namespaces)
{
this(namespace.getName(), namespace.getQualifiedName());
for (Entry<String, Namespace> entry : namespace.getChildren().entrySet())
this(null, null);
for (String namespace : namespaces)
{
children.put(entry.getKey(), new Namespace(entry.getValue()));
String[] hierarchy = namespace.split("\\.");
Namespace n = this;
for (String s : hierarchy)
{
n = n.putIfAbsent(s);
}
}
}

/**
* Create a new, root, namespace
*
*/
public Namespace()
{
this(null, null);
}

protected Namespace(String name, String qualifiedName)
{
this.name = name;
this.qualifiedName = qualifiedName;
this.children = new HashMap<String, Namespace>();
}

public Namespace putIfAbsent(String key)
private Namespace putIfAbsent(String key)
{
Namespace result = children.get(key);
if (result==null)
Expand Down

0 comments on commit e861fd6

Please sign in to comment.