Skip to content

Commit

Permalink
more tidy up :-)
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2793 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jun 8, 2009
1 parent 10df530 commit c19b400
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 215 deletions.
44 changes: 9 additions & 35 deletions impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -80,7 +80,7 @@
import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.CreationalContextImpl;
import org.jboss.webbeans.el.Namespace;
import org.jboss.webbeans.el.WebBeansELResolver;
import org.jboss.webbeans.el.WebBeansELResolverImpl;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.event.EventObserver;
import org.jboss.webbeans.event.ObserverImpl;
Expand Down Expand Up @@ -194,7 +194,8 @@ public String toString()
*/
private transient final EventManager eventManager;
private transient final Resolver resolver;
private final transient NonContextualInjector nonContextualInjector;
private final transient NonContextualInjector nonContextualInjector;
private final transient ELResolver webbeansELResolver;

/*
* Activity scoped data structures
Expand Down Expand Up @@ -304,6 +305,7 @@ private ManagerImpl(
this.resolver = new Resolver(this);
this.eventManager = new EventManager(this);
this.nonContextualInjector = new NonContextualInjector(this);
this.webbeansELResolver = new WebBeansELResolverImpl(this);
this.childActivities = new CopyOnWriteArraySet<ManagerImpl>();
this.currentInjectionPoint = new ThreadLocal<Stack<InjectionPoint>>()
{
Expand Down Expand Up @@ -740,14 +742,13 @@ public Object getInjectableReference(Bean<?> bean, CreationalContext<?> creation
}


/**
* XXX this is not correct, as the current implementation of getInstance does not
* pay attention to what type the resulting instance needs to implement (non-Javadoc)
* @see javax.enterprise.inject.spi.BeanManager#getReference(javax.enterprise.inject.spi.Bean, java.lang.reflect.Type)
/*
* TODO this is not correct, as the current implementation of getInstance does not
* pay attention to what type the resulting instance needs to implement
*/
public Object getReference(Bean<?> bean, Type beanType)
{
return getInstance(bean,true);
return getInjectableReference(bean, CreationalContextImpl.of(bean));
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -792,33 +793,6 @@ public Object getInjectableReference(InjectionPoint injectionPoint, CreationalCo
}
}

/**
* Gets an instance by name, returning null if none is found and throwing an
* exception if too many beans match
*
* @param name The name to match
* @return An instance of the bean
*
* @see javax.enterprise.inject.spi.BeanManager#getInstanceByName(java.lang.String)
*/
@Deprecated
public Object getInstanceByName(String name)
{
Set<Bean<?>> beans = getBeans(name);
if (beans.size() == 0)
{
return null;
}
else if (beans.size() > 1)
{
throw new AmbiguousResolutionException("Resolved multiple Web Beans with " + name);
}
else
{
return getInstance(beans.iterator().next());
}
}

/**
* Returns an instance by API type and binding types
*
Expand Down Expand Up @@ -1246,7 +1220,7 @@ public int compare(Bean<? extends X> o1, Bean<? extends X> o2)

public ELResolver getELResolver()
{
return new WebBeansELResolver();
return webbeansELResolver;
}

}
49 changes: 49 additions & 0 deletions impl/src/main/java/org/jboss/webbeans/el/ForwardingELResolver.java
@@ -0,0 +1,49 @@
package org.jboss.webbeans.el;

import java.util.Iterator;

import javax.el.ELContext;
import javax.el.ELResolver;

public abstract class ForwardingELResolver extends ELResolver
{

protected abstract ELResolver delegate();

@Override
public Class<?> getCommonPropertyType(ELContext context, Object base)
{
return delegate().getCommonPropertyType(context, base);
}

@Override
public Iterator<?> getFeatureDescriptors(ELContext context, Object base)
{
return delegate().getFeatureDescriptors(context, base);
}

@Override
public Class<?> getType(ELContext context, Object base, Object property)
{
return delegate().getType(context, base, property);
}

@Override
public Object getValue(ELContext context, Object base, Object property)
{
return delegate().getValue(context, base, property);
}

@Override
public boolean isReadOnly(ELContext context, Object base, Object property)
{
return delegate().isReadOnly(context, base, property);
}

@Override
public void setValue(ELContext context, Object base, Object property, Object value)
{
delegate().setValue(context, base, property, value);
}

}
187 changes: 16 additions & 171 deletions impl/src/main/java/org/jboss/webbeans/el/WebBeansELResolver.java
@@ -1,171 +1,16 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.webbeans.el;

import java.beans.FeatureDescriptor;
import java.util.Iterator;

import javax.el.ELContext;
import javax.el.ELResolver;
import javax.inject.ExecutionException;

import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;

/**
* An EL-resolver against the named beans
*
* @author Pete Muir
*/
public class WebBeansELResolver extends ELResolver
{

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)
*/
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base)
{
return null;
}

/**
* @see javax.el.ELResolver#getFeatureDescriptors(ELContext, Object)
*/
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
{
return null;
}

/**
* @see javax.el.ELResolver#getType(ELContext, Object, Object)
*/
@Override
public Class<?> getType(ELContext context, Object base, Object property)
{
return null;
}

/**
* @see javax.el.ELResolver#getValue(ELContext, Object, Object)
*/
@Override
public Object getValue(ELContext context, Object base, Object property)
{
if (property != null)
{
final ManagerImpl manager = CurrentManager.rootManager().getCurrent();
String propertyString = property.toString();
Namespace namespace = null;
if (base == null)
{
if (manager.getRootNamespace().contains(propertyString))
{
context.setPropertyResolved(true);
return manager.getRootNamespace().get(propertyString);
}
}
else if (base instanceof Namespace)
{
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);
}
}
else
{
// let the standard EL resolver chain handle the property
return null;
}
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(manager.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;
}

/**
* @see javax.el.ELResolver#isReadOnly(ELContext, Object, Object)
*/
@Override
public boolean isReadOnly(ELContext context, Object base, Object property)
{
return false;
}

/**
* @see javax.el.ELResolver#setValue(ELContext, Object, Object, Object)
*/
@Override
public void setValue(ELContext context, Object base, Object property, Object value)
{
}

}

package org.jboss.webbeans.el;

import javax.el.ELResolver;

import org.jboss.webbeans.CurrentManager;

public class WebBeansELResolver extends ForwardingELResolver
{

@Override
protected ELResolver delegate()
{
return CurrentManager.rootManager().getCurrent().getELResolver();
}

}

0 comments on commit c19b400

Please sign in to comment.