Skip to content

Commit

Permalink
add SingletonContext, remove a couple of uneeded checks, add atinject…
Browse files Browse the repository at this point in the history
… tck runner module

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3818 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Sep 30, 2009
1 parent e8348dd commit 1d17d64
Show file tree
Hide file tree
Showing 29 changed files with 439 additions and 205 deletions.
24 changes: 4 additions & 20 deletions impl/src/main/java/org/jboss/webbeans/Validator.java
Expand Up @@ -18,10 +18,10 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -43,16 +43,15 @@
import org.jboss.webbeans.bean.AbstractProducerBean;
import org.jboss.webbeans.bean.DecoratorImpl;
import org.jboss.webbeans.bean.DisposalMethod;
import org.jboss.webbeans.bean.NewSessionBean;
import org.jboss.webbeans.bean.NewManagedBean;
import org.jboss.webbeans.bean.NewSessionBean;
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.bootstrap.api.Service;
import org.jboss.webbeans.introspector.WBAnnotated;
import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
import org.jboss.webbeans.resolution.ResolvableWBClass;
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.Names;
import org.jboss.webbeans.util.Proxies;
import org.jboss.webbeans.util.Reflections;

Expand Down Expand Up @@ -153,33 +152,18 @@ public void validateInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManage
{
throw new DefinitionException("Cannot declare an injection point with a type variable " + ij);
}
if (ij.getType() instanceof ParameterizedType)
{
ParameterizedType parameterizedType = (ParameterizedType) ij.getType();
for (Type type : parameterizedType.getActualTypeArguments())
{
// if (type instanceof TypeVariable<?>)
// {
// throw new DefinitionException("Injection point cannot have a type variable type parameter " + ij);
// }
// if (type instanceof WildcardType)
// {
// throw new DefinitionException("Injection point cannot have a wildcard type parameter " + ij);
// }
}
}
checkFacadeInjectionPoint(ij, Instance.class);
checkFacadeInjectionPoint(ij, Event.class);
Annotation[] bindings = ij.getQualifiers().toArray(new Annotation[0]);
WBAnnotated<?, ?> annotatedItem = ResolvableWBClass.of(ij.getType(), bindings, beanManager);
Set<?> resolvedBeans = beanManager.getBeanResolver().resolve(beanManager.getInjectableBeans(ij));
if (resolvedBeans.isEmpty())
{
throw new DeploymentException("The injection point " + ij + " with binding types " + Names.annotationsToString(ij.getQualifiers()) + " in " + ij.getBean() + " has unsatisfied dependencies with binding types ");
throw new DeploymentException("Injection point has unstatisfied dependencies. Injection point: " + ij.toString() + "; Qualifiers: " + Arrays.toString(bindings));
}
if (resolvedBeans.size() > 1)
{
throw new DeploymentException("The injection point " + ij + " with binding types " + Names.annotationsToString(ij.getQualifiers()) + " in " + ij.getBean() + " has ambiguous dependencies " + resolvedBeans);
throw new DeploymentException("Injection point has ambiguous dependencies. Injection point: " + ij.toString() + "; Qualifiers: " + Arrays.toString(bindings) +"; Possible dependencies: " + resolvedBeans);
}
Bean<?> resolvedBean = (Bean<?>) resolvedBeans.iterator().next();
if (beanManager.getServices().get(MetaAnnotationStore.class).getScopeModel(resolvedBean.getScope()).isNormal() && !Proxies.isTypeProxyable(ij.getType()))
Expand Down
6 changes: 6 additions & 0 deletions impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
Expand Up @@ -31,6 +31,7 @@
import javax.inject.Qualifier;

import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.Container;
import org.jboss.webbeans.DefinitionException;
import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.injection.WBInjectionPoint;
Expand Down Expand Up @@ -468,6 +469,11 @@ public boolean isDependent()
return Dependent.class.equals(getScope());
}

public boolean isNormalScoped()
{
return Container.instance().deploymentServices().get(MetaAnnotationStore.class).getScopeModel(getScope()).isNormal();
}

public boolean isAlternative()
{
return policy;
Expand Down
Expand Up @@ -250,7 +250,7 @@ protected void checkType()
protected void checkBeanImplementation()
{
super.checkBeanImplementation();
if (!isDependent())
if (isNormalScoped())
{
for (WBField<?, ?> field : getAnnotatedItem().getWBFields())
{
Expand Down
Expand Up @@ -25,6 +25,7 @@
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.TypeLiteral;
import javax.inject.Provider;

import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.literal.AnyLiteral;
Expand All @@ -34,11 +35,13 @@
public class InstanceBean extends AbstractFacadeBean<Instance<?>>
{

private static final Class<Instance<?>> TYPE = new TypeLiteral<Instance<?>>() {}.getRawType();
private static final Set<Type> DEFAULT_TYPES = Arrays2.<Type>asSet(TYPE, Object.class);
private static final Class<Instance<?>> INSTANCE_TYPE = new TypeLiteral<Instance<?>>() {}.getRawType();
private static final Class<Provider<?>> PROVIDER_TYPE = new TypeLiteral<Provider<?>>() {}.getRawType();
private static final Set<Type> DEFAULT_TYPES = Arrays2.<Type>asSet(INSTANCE_TYPE, PROVIDER_TYPE, Object.class);
private static final Any ANY = new AnyLiteral();
private static final Set<Annotation> DEFAULT_BINDINGS = new HashSet<Annotation>(Arrays.asList(ANY));
public static final ResolvableTransformer TRANSFORMER = new FacadeBeanResolvableTransformer(TYPE);
public static final ResolvableTransformer INSTANCE_TRANSFORMER = new FacadeBeanResolvableTransformer(INSTANCE_TYPE);
public static final ResolvableTransformer PROVIDER_TRANSFORMER = new FacadeBeanResolvableTransformer(PROVIDER_TYPE);

public InstanceBean(BeanManagerImpl manager)
{
Expand All @@ -48,7 +51,7 @@ public InstanceBean(BeanManagerImpl manager)
@Override
public Class<Instance<?>> getType()
{
return TYPE;
return INSTANCE_TYPE;
}

@Override
Expand Down
Expand Up @@ -42,12 +42,14 @@
import org.jboss.webbeans.bootstrap.api.helpers.SimpleServiceRegistry;
import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.webbeans.bootstrap.spi.Deployment;
import org.jboss.webbeans.context.AbstractApplicationContext;
import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.ContextLifecycle;
import org.jboss.webbeans.context.ConversationContext;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.context.RequestContext;
import org.jboss.webbeans.context.SessionContext;
import org.jboss.webbeans.context.SingletonContext;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.ejb.EJBApiAbstraction;
import org.jboss.webbeans.jsf.JsfApiAbstraction;
Expand Down Expand Up @@ -380,17 +382,19 @@ protected void initializeContexts()
deploymentManager.addContext(lifecycle.getConversationContext());
deploymentManager.addContext(lifecycle.getSessionContext());
deploymentManager.addContext(lifecycle.getApplicationContext());
deploymentManager.addContext(lifecycle.getSingletonContext());
}

protected void createContexts()
{
ApplicationContext applicationContext = new ApplicationContext();
AbstractApplicationContext applicationContext = new ApplicationContext();
AbstractApplicationContext singletonContext = new SingletonContext();
SessionContext sessionContext = new SessionContext();
ConversationContext conversationContext = new ConversationContext();
RequestContext requestContext = new RequestContext();
DependentContext dependentContext = new DependentContext();

deployment.getServices().add(ContextLifecycle.class, new ContextLifecycle(applicationContext, sessionContext, conversationContext, requestContext, dependentContext));
deployment.getServices().add(ContextLifecycle.class, new ContextLifecycle(applicationContext, singletonContext, sessionContext, conversationContext, requestContext, dependentContext));
}

public void shutdown()
Expand Down
@@ -0,0 +1,111 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
*
* Use is subject to license terms.
*
* 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.context;

import java.lang.annotation.Annotation;
import java.util.concurrent.atomic.AtomicBoolean;

import org.jboss.webbeans.context.api.BeanStore;

/**
* The Application context
*
* @author Nicklas Karlsson
*
* @see org.jboss.webbeans.context.AbstractApplicationContext
*/
public abstract class AbstractApplicationContext extends AbstractMapContext
{

// The beans
private BeanStore beanStore;
// Is the context active?
private final AtomicBoolean active;

/**
* Constructor
*/
public AbstractApplicationContext(Class<? extends Annotation> scope)
{
super(scope);
this.active = new AtomicBoolean(false);
}

/**
* Gets the bean store
*
* @return The bean store
*/
@Override
public BeanStore getBeanStore()
{
return this.beanStore;
}

/**
* Sets the bean store
*
* @param applicationBeanStore The bean store
*/
public void setBeanStore(BeanStore applicationBeanStore)
{
this.beanStore = applicationBeanStore;
}

/**
* Indicates if the context is active
*
* @return True if active, false otherwise
*/
@Override
public boolean isActive()
{
return active.get();
}

/**
* Sets the active state of the context
*
* @param active The new state
*/
@Override
public void setActive(boolean active)
{
this.active.set(active);
}

@Override
public String toString()
{
String active = isActive() ? "Active " : "Inactive ";
String beanStoreInfo = getBeanStore() == null ? "" : getBeanStore().toString();
return active + "application context " + beanStoreInfo;
}

@Override
protected boolean isCreationLockRequired()
{
return true;
}

}

0 comments on commit 1d17d64

Please sign in to comment.