Skip to content

Commit

Permalink
Support for ProcessProducer and ProcessObserverMethod event
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3838 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Oct 4, 2009
1 parent 7b76e01 commit 2070e84
Show file tree
Hide file tree
Showing 42 changed files with 390 additions and 180 deletions.
Expand Up @@ -27,7 +27,7 @@
*
* @author Pete Muir
*
* @param <X> the type of the member
* @param <X> the type of the declaring type
*/
public interface AnnotatedMember<X> extends Annotated
{
Expand Down
@@ -1 +1 @@
/* * 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 javax.enterprise.inject.spi;public interface ProcessProducer<X, T>{ public AnnotatedMember<X> getAnnotatedMember(); public Producer<T> getProducer(); public void setProducer(Producer<T> producer); public void addDefinitionError(Throwable t);}
/* * 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 javax.enterprise.inject.spi;public interface ProcessProducer<T, X>{ public AnnotatedMember<T> getAnnotatedMember(); public Producer<X> getProducer(); public void setProducer(Producer<X> producer); public void addDefinitionError(Throwable t);}
Expand Down
@@ -1 +1 @@
/* * 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 javax.enterprise.inject.spi;public interface ProcessProducerField<X, T> extends ProcessBean<T>{ public AnnotatedField<X> getAnnotatedProducerField();}
/* * 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 javax.enterprise.inject.spi;public interface ProcessProducerField<T, X> extends ProcessBean<X>{ public AnnotatedField<T> getAnnotatedProducerField();}
Expand Down
@@ -1 +1 @@
/* * 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 javax.enterprise.inject.spi;public interface ProcessProducerMethod<X, T> extends ProcessBean<T>{ public AnnotatedMethod<X> getAnnotatedProducerMethod(); public AnnotatedParameter<X> getAnnotatedDisposedParameter();}
/* * 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 javax.enterprise.inject.spi;public interface ProcessProducerMethod<T, X> extends ProcessBean<X>{ public AnnotatedMethod<T> getAnnotatedProducerMethod(); public AnnotatedParameter<T> getAnnotatedDisposedParameter();}
Expand Down
27 changes: 19 additions & 8 deletions impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
Expand Up @@ -552,12 +552,17 @@ public void addDecorator(DecoratorImpl<?> bean)
passivationCapableBeans.put(bean.getId(), bean);
decoratorResolver.clear();
}

public <T> Set<ObserverMethod<?, T>> resolveObserverMethods(T event, Annotation... bindings)
{
checkEventObjectType(event);
return resolveObserverMethods(event.getClass(), bindings);
}

@SuppressWarnings("unchecked")
public <T> Set<ObserverMethod<?, T>> resolveObserverMethods(T event, Annotation... bindings)
private <T> Set<ObserverMethod<?, T>> resolveObserverMethods(Type eventType, Annotation... bindings)
{
checkBindingTypes(Arrays.asList(bindings));
Class<?> clazz = event.getClass();

// Manually hack in the default annotations here. We need to redo all the annotation defaulting throughout. PLM
HashSet<Annotation> bindingAnnotations = new HashSet<Annotation>(Arrays.asList(bindings));
Expand All @@ -566,9 +571,8 @@ public <T> Set<ObserverMethod<?, T>> resolveObserverMethods(T event, Annotation.
bindingAnnotations.add(new DefaultLiteral());
}
bindingAnnotations.add(new AnyLiteral());
checkEventType(clazz);
Set<ObserverMethod<?, T>> observers = new HashSet<ObserverMethod<?, T>>();
Set<ObserverMethod<?,?>> eventObservers = observerResolver.resolve(ResolvableFactory.of(new Reflections.HierarchyDiscovery(clazz).getFlattenedTypes(), bindingAnnotations, null));
Set<ObserverMethod<?,?>> eventObservers = observerResolver.resolve(ResolvableFactory.of(new Reflections.HierarchyDiscovery(eventType).getFlattenedTypes(), bindingAnnotations, null));
for (ObserverMethod<?,?> observer : eventObservers)
{
observers.add((ObserverMethod<?, T>) observer);
Expand All @@ -593,11 +597,12 @@ private void checkBindingTypes(Collection<Annotation> bindings)

}

private void checkEventType(Type eventType)
private void checkEventObjectType(Object event)
{
Class<?> eventType = event.getClass();
Type[] types;
Type resolvedType = new Reflections.HierarchyDiscovery(eventType).getResolvedType();
if (resolvedType instanceof Class)
if (resolvedType instanceof Class<?>)
{
types = new Type[0];
}
Expand Down Expand Up @@ -824,9 +829,15 @@ public void addObserver(ObserverMethod<?, ?> observer)
* @see javax.enterprise.inject.spi.BeanManager#fireEvent(java.lang.Object,
* java.lang.annotation.Annotation[])
*/
public void fireEvent(Object event, Annotation... bindings)
public void fireEvent(Object event, Annotation... qualifiers)
{
fireEvent(event.getClass(), event, qualifiers);
}

public void fireEvent(Type eventType, Object event, Annotation... qualifiers)
{
notifyObservers(event, resolveObserverMethods(event, bindings));
checkEventObjectType(event);
notifyObservers(event, resolveObserverMethods(eventType, qualifiers));
}

private <T> void notifyObservers(final T event, final Set<ObserverMethod<?, T>> observers)
Expand Down
6 changes: 3 additions & 3 deletions impl/src/main/java/org/jboss/webbeans/Validator.java
Expand Up @@ -184,7 +184,7 @@ public void validateInjectionPointPassivationCapable(InjectionPoint ij, Bean<?>
{
if (!ij.isTransient() && !Beans.isPassivationCapableBean(resolvedBean))
{
if (resolvedBean.getScope().equals(Dependent.class) && resolvedBean instanceof AbstractProducerBean<?,?>)
if (resolvedBean.getScope().equals(Dependent.class) && resolvedBean instanceof AbstractProducerBean<?, ?,?>)
{
throw new IllegalProductException("The bean " + ij.getBean() + " declares a passivating scope but the producer returned a non-serializable bean for injection: " + resolvedBean);
}
Expand Down Expand Up @@ -308,10 +308,10 @@ private void validateEnabledPolicies(BeanManagerImpl beanManager)

private void validateDisposalMethods(BeanDeployerEnvironment environment)
{
Set<DisposalMethod<?>> beans = environment.getUnresolvedDisposalBeans();
Set<DisposalMethod<?, ?>> beans = environment.getUnresolvedDisposalBeans();
if (!beans.isEmpty())
{
throw new DefinitionException("The following Disposal methods where not declared but not resolved to a producer method" + beans);
throw new DefinitionException("The following Disposal methods were declared but did not resolved to a producer method " + beans);
}
}

Expand Down
Expand Up @@ -56,7 +56,7 @@
* @param <T>
* @param <S>
*/
public abstract class AbstractProducerBean<T, S extends Member> extends AbstractReceiverBean<T, S> implements Producer<T>
public abstract class AbstractProducerBean<X, T, S extends Member> extends AbstractReceiverBean<X, T, S> implements Producer<T>
{
private static final LogProvider log = Logging.getLogProvider(AbstractProducerBean.class);

Expand All @@ -65,13 +65,13 @@ public abstract class AbstractProducerBean<T, S extends Member> extends Abstract
* @param declaringBean The declaring bean
* @param manager The Web Beans manager
*/
public AbstractProducerBean(String idSuffix, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
public AbstractProducerBean(String idSuffix, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
{
super(idSuffix, declaringBean, manager);
}

@Override
protected abstract WBMember<T, ?, S> getAnnotatedItem();
public abstract WBMember<T, X, S> getAnnotatedItem();

@Override
// Overriden to provide the class of the bean that declares the producer method/field
Expand Down
Expand Up @@ -32,15 +32,15 @@
* @author pmuir
*
*/
public abstract class AbstractReceiverBean<T, S extends Member> extends AbstractBean<T, S>
public abstract class AbstractReceiverBean<X, T, S extends Member> extends AbstractBean<T, S>
{

private static final LogProvider log = Logging.getLogProvider(AbstractReceiverBean.class);

private AbstractClassBean<?> declaringBean;
private AbstractClassBean<X> declaringBean;
private boolean policy;

public AbstractReceiverBean(String idSuffix, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
public AbstractReceiverBean(String idSuffix, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
{
super(idSuffix, manager);
this.declaringBean = declaringBean;
Expand Down Expand Up @@ -87,7 +87,7 @@ protected Object getReceiver(CreationalContext<?> creationalContext)
*
* @return The bean representation
*/
public AbstractClassBean<?> getDeclaringBean()
public AbstractClassBean<X> getDeclaringBean()
{
return declaringBean;
}
Expand Down
Expand Up @@ -35,12 +35,12 @@
import org.jboss.webbeans.injection.MethodInjectionPoint;
import org.jboss.webbeans.introspector.WBMethod;

public class DisposalMethod<T> extends AbstractReceiverBean<T, Method>
public class DisposalMethod<X, T> extends AbstractReceiverBean<X, T, Method>
{

protected MethodInjectionPoint<T, ?> disposalMethodInjectionPoint;

protected DisposalMethod(BeanManagerImpl manager, WBMethod<T, ?> disposalMethod, AbstractClassBean<?> declaringBean)
protected DisposalMethod(BeanManagerImpl manager, WBMethod<T, X> disposalMethod, AbstractClassBean<X> declaringBean)
{
super(new StringBuilder().append(DisposalMethod.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(declaringBean.getAnnotatedItem().getName()).append(disposalMethod.getSignature().toString()).toString(), declaringBean, manager);
this.disposalMethodInjectionPoint = MethodInjectionPoint.of(this, disposalMethod);
Expand Down Expand Up @@ -71,9 +71,9 @@ protected void initType()
return disposalMethodInjectionPoint;
}

public static <T> DisposalMethod<T> of(BeanManagerImpl manager, WBMethod<T, ?> disposalMethod, AbstractClassBean<?> declaringBean)
public static <X, T> DisposalMethod<X, T> of(BeanManagerImpl manager, WBMethod<T, X> disposalMethod, AbstractClassBean<X> declaringBean)
{
return new DisposalMethod<T>(manager, disposalMethod, declaringBean);
return new DisposalMethod<X, T>(manager, disposalMethod, declaringBean);
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions impl/src/main/java/org/jboss/webbeans/bean/ProducerField.java
Expand Up @@ -35,10 +35,10 @@
*
* @param <T>
*/
public class ProducerField<T> extends AbstractProducerBean<T, Field>
public class ProducerField<X, T> extends AbstractProducerBean<X, T, Field>
{
// The underlying field
private WBField<T, ?> field;
private WBField<T, X> field;
private final String id;

/**
Expand All @@ -49,9 +49,9 @@ public class ProducerField<T> extends AbstractProducerBean<T, Field>
* @param manager the current manager
* @return A producer field
*/
public static <T> ProducerField<T> of(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
public static <X, T> ProducerField<X, T> of(WBField<T, X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
{
return new ProducerField<T>(field, declaringBean, manager);
return new ProducerField<X, T>(field, declaringBean, manager);
}

/**
Expand All @@ -61,7 +61,7 @@ public static <T> ProducerField<T> of(WBField<T, ?> field, AbstractClassBean<?>
* @param declaringBean The declaring bean
* @param manager The Web Beans manager
*/
protected ProducerField(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
protected ProducerField(WBField<T, X> field, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
{
super(new StringBuilder().append(ProducerField.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(declaringBean.getAnnotatedItem().getName()).append(field.getName()).toString(), declaringBean, manager);
this.field = field;
Expand Down Expand Up @@ -104,7 +104,7 @@ public T produce(CreationalContext<T> ctx)
* @return The annotated item
*/
@Override
protected WBField<T, ?> getAnnotatedItem()
public WBField<T, X> getAnnotatedItem()
{
return field;
}
Expand Down
22 changes: 11 additions & 11 deletions impl/src/main/java/org/jboss/webbeans/bean/ProducerMethod.java
Expand Up @@ -43,14 +43,14 @@
*
* @param <T>
*/
public class ProducerMethod<T> extends AbstractProducerBean<T, Method>
public class ProducerMethod<X, T> extends AbstractProducerBean<X, T, Method>
{
// The underlying method
private MethodInjectionPoint<T, ?> method;
private MethodInjectionPoint<T, X> method;

private DisposalMethod<?> disposalMethodBean;
private DisposalMethod<X, ?> disposalMethodBean;

private ProducerMethod<?> specializedBean;
private ProducerMethod<?, ?> specializedBean;

private final String id;

Expand All @@ -62,14 +62,14 @@ public class ProducerMethod<T> extends AbstractProducerBean<T, Method>
* @param manager the current manager
* @return A producer Web Bean
*/
public static <T> ProducerMethod<T> of(WBMethod<T, ?> method, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
public static <X, T> ProducerMethod<X, T> of(WBMethod<T, X> method, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
{
return new ProducerMethod<T>(method, declaringBean, manager);
return new ProducerMethod<X, T>(method, declaringBean, manager);
}

protected ProducerMethod(WBMethod<T, ?> method, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
protected ProducerMethod(WBMethod<T, X> method, AbstractClassBean<X> declaringBean, BeanManagerImpl manager)
{
super(new StringBuilder().append(ProducerMethod.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(declaringBean.getAnnotatedItem().getName()).append(method.getSignature().toString()).toString(), declaringBean, manager);
super(new StringBuilder().append(ProducerMethod.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(declaringBean.getAnnotatedItem().getName()).append(".").append(method.getSignature().toString()).toString(), declaringBean, manager);
this.method = MethodInjectionPoint.of(this, method);
initType();
initTypes();
Expand Down Expand Up @@ -163,7 +163,7 @@ else if (getDeclaringBean() instanceof SessionBean<?>)
*/
protected void initDisposalMethod(BeanDeployerEnvironment environment)
{
Set<DisposalMethod<?>> disposalBeans = environment.resolveDisposalBeans(getTypes(), getQualifiers(), getDeclaringBean());
Set<DisposalMethod<X, ?>> disposalBeans = environment.<X>resolveDisposalBeans(getTypes(), getQualifiers(), getDeclaringBean());

if (disposalBeans.size() == 1)
{
Expand Down Expand Up @@ -205,7 +205,7 @@ public void dispose(T instance)
* @return The annotated item
*/
@Override
public WBMethod<T, ?> getAnnotatedItem()
public WBMethod<T, X> getAnnotatedItem()
{
return method;
}
Expand All @@ -226,7 +226,7 @@ protected String getDefaultName()
*
* @return The method representation
*/
public DisposalMethod<?> getDisposalMethod()
public DisposalMethod<X, ?> getDisposalMethod()
{
return disposalMethodBean;
}
Expand Down
Expand Up @@ -348,7 +348,7 @@ public boolean isClientCanCallRemoveMethods()
*/
protected void checkObserverMethods()
{
for (WBMethod<?, ?> method : this.annotatedItem.getWBDeclaredMethodsWithAnnotatedParameters(Observes.class))
for (WBMethod<?, ?> method : this.annotatedItem.getDeclaredWBMethodsWithAnnotatedParameters(Observes.class))
{
if (!method.isStatic())
{
Expand Down

0 comments on commit 2070e84

Please sign in to comment.