Skip to content

Commit

Permalink
WELDX-120
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jul 26, 2010
1 parent 98bf219 commit 8919dea
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 5 deletions.
@@ -1,7 +1,5 @@
package org.jboss.weld.extensions.bean.generic;

import static org.jboss.weld.extensions.util.Reflections.invokeMethod;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Set;
Expand All @@ -11,20 +9,21 @@
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;

import org.jboss.weld.extensions.bean.InjectableMethod;
import org.jboss.weld.extensions.util.Synthetic;

// TODO Make this passivation capable
class GenericProducerMethod<T, X> extends AbstactGenericBean<T>
{

private final AnnotatedMethod<X> method;
private final InjectableMethod<X> method;
private final Type declaringBeanType;
private final Annotation declaringBeanQualifier;

GenericProducerMethod(Bean<T> originalBean, Annotation genericConfiguration, AnnotatedMethod<X> method, Set<Annotation> qualifiers, Synthetic.Provider syntheticProvider, BeanManager beanManager)
{
super(originalBean, qualifiers, beanManager);
this.method = method;
this.method = new InjectableMethod<X>(method, this, beanManager);
this.declaringBeanType = originalBean.getBeanClass();
this.declaringBeanQualifier = syntheticProvider.get(genericConfiguration);
}
Expand All @@ -36,7 +35,7 @@ public T create(CreationalContext<T> creationalContext)
{
Bean<?> declaringBean = getBeanManager().resolve(getBeanManager().getBeans(declaringBeanType, declaringBeanQualifier));
Object receiver = getBeanManager().getReference(declaringBean, declaringBean.getBeanClass(), creationalContext);
return (T) invokeMethod(method.getJavaMember(), receiver);
return method.invoke(receiver, creationalContext);
}
finally
{
Expand Down
Expand Up @@ -57,4 +57,10 @@ public Message getMessage()
{
return message;
}

@Produces @Wibble
public String getCorge(Wobble wobble)
{
return wobble.getName() + message.value();
}
}
Expand Up @@ -56,6 +56,15 @@ public static Archive<?> deploy()
@Foo(2)
private Message baz2Message;

@Inject
@Foo(1) @Wibble
private String wibble1;

@Inject
@Foo(2) @Wibble
private String wibble2;


@Test
public void testGeneric()
{
Expand All @@ -70,5 +79,10 @@ public void testGeneric()
assertEquals("hello1", baz1Message.value());
assertNotNull(baz2Message);
assertEquals( "hello2", baz2Message.value());

assertNotNull(wibble1);
assertEquals("billhello1", wibble1);
assertNotNull(wibble2);
assertEquals("billhello2", wibble2);
}
}
@@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., 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.weld.extensions.test.bean.generic.field;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

/**
* A qualifier
*
* @author pmuir
*
*/

@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
@Qualifier
public @interface Wibble
{

}
@@ -0,0 +1,33 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., 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.weld.extensions.test.bean.generic.field;

/**
* A normal bean
*
* @author pmuir
*
*/
public class Wobble
{

public String getName()
{
return "bill";
}

}

0 comments on commit 8919dea

Please sign in to comment.