Skip to content

Commit

Permalink
WELD-354
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jan 6, 2010
1 parent 7f22310 commit b187cf0
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 3 deletions.
Expand Up @@ -95,7 +95,9 @@ else if (type instanceof ParameterizedType)
}

/**
* Gets the property name from a getter method
* Gets the property name from a getter method.
*
* We extend JavaBean conventions, allowing the getter method to have parameters
*
* @param method The getter method
* @return The name of the property. Returns null if method wasn't JavaBean
Expand All @@ -104,11 +106,11 @@ else if (type instanceof ParameterizedType)
public static String getPropertyName(Method method)
{
String methodName = method.getName();
if (methodName.matches("^(get).*") && method.getParameterTypes().length == 0)
if (methodName.matches("^(get).*"))
{
return Introspector.decapitalize(methodName.substring(3));
}
else if (methodName.matches("^(is).*") && method.getParameterTypes().length == 0)
else if (methodName.matches("^(is).*"))
{
return Introspector.decapitalize(methodName.substring(2));
}
Expand Down
@@ -0,0 +1,18 @@
package org.jboss.weld.tests.producer.method;

public class JmsTemplate
{

private final int receiveTimeout;

public JmsTemplate(int receiveTimeout)
{
this.receiveTimeout = receiveTimeout;
}

public int getReceiveTimeout()
{
return receiveTimeout;
}

}
@@ -0,0 +1,31 @@
package org.jboss.weld.tests.producer.method;

import javax.enterprise.inject.Produces;
import javax.inject.Named;

public class JmsTemplateConfigurationProducer
{

public static final int LONG_RECEIVE_TIMEOUT = 3 * 3600;
public static final int SHORT_RECEIVE_TIMEOUT = 100;

@Produces @Long
private int longReceiveTimeout = LONG_RECEIVE_TIMEOUT;

@Produces @Short
private int shortReceiveTimeout = SHORT_RECEIVE_TIMEOUT;

@Produces
@Named
public JmsTemplate getErrorQueueTemplate(@Long int receiveTimeout)
{
return new JmsTemplate(receiveTimeout);
}

@Produces
@Named
public JmsTemplate getLogQueueTemplate(@Short int receiveTimeout)
{
return new JmsTemplate(receiveTimeout);
}
}
25 changes: 25 additions & 0 deletions tests/src/test/java/org/jboss/weld/tests/producer/method/Long.java
@@ -0,0 +1,25 @@
package org.jboss.weld.tests.producer.method;

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.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

/**
* @author Dan Allen
*/
@Target( { TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
@Qualifier
@Inherited
public @interface Long {
}
@@ -1,5 +1,10 @@
package org.jboss.weld.tests.producer.method;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import javax.enterprise.inject.spi.Bean;

import org.jboss.testharness.impl.packaging.Artifact;
Expand All @@ -9,6 +14,7 @@
@Artifact
public class NamedProducerTest extends AbstractWeldTest
{

@Test
public void testNamedProducer()
{
Expand All @@ -19,5 +25,18 @@ public void testNamedProducer()
String[] itoen = (String[]) getCurrentManager().getReference(itoenBean, Object.class, getCurrentManager().createCreationalContext(itoenBean));
assert itoen.length == 2;
}

@Test
public void testDefaultNamedProducerMethod()
{
Set<Bean<?>> beans = getCurrentManager().getBeans(JmsTemplate.class);
assert beans.size() == 2;
List<String> beanNames = new ArrayList<String>(Arrays.asList("errorQueueTemplate", "logQueueTemplate"));
for (Bean<?> b : beans)
{
beanNames.remove(b.getName());
}
assert beanNames.isEmpty();
}

}
@@ -0,0 +1,25 @@
package org.jboss.weld.tests.producer.method;

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.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

/**
* @author Dan Allen
*/
@Target( { TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
@Qualifier
@Inherited
public @interface Short {
}

0 comments on commit b187cf0

Please sign in to comment.