Skip to content

Commit

Permalink
WBRI-212
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2260 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Mar 30, 2009
1 parent dfcfa14 commit 485ca52
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 57 deletions.
24 changes: 0 additions & 24 deletions impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
Expand Up @@ -532,29 +532,5 @@ public boolean isSpecializing()
return getAnnotatedItem().isAnnotationPresent(Specializes.class);
}

@Override
// TODO Fix this!!!
public boolean equals(Object other)
{
if (other instanceof AbstractBean)
{
AbstractBean<?, ?> that = (AbstractBean<?, ?>) other;
boolean equal = this.getTypes().equals(that.getTypes()) && this.getBindings().equals(that.getBindings());
return equal;
}
else
{
return false;
}
}

@Override
public int hashCode()
{
int result = 17;
result = 31 * result + getTypes().hashCode();
result = 31 * result + getBindings().hashCode();
return result;
}

}
17 changes: 6 additions & 11 deletions impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
Expand Up @@ -66,6 +66,8 @@ public abstract class AbstractClassBean<T> extends AbstractBean<T, Class<T>>
// The initializer methods
private Set<MethodInjectionPoint<?>> initializerMethods;
private Set<String> dependencies;

private final String id;

/**
* Constructor
Expand All @@ -77,6 +79,7 @@ protected AbstractClassBean(AnnotatedClass<T> type, ManagerImpl manager)
{
super(manager);
this.annotatedItem = type;
this.id = createId(getClass().getSimpleName() + "-" + type.getName());
}

/**
Expand Down Expand Up @@ -344,19 +347,11 @@ protected Class<? extends Annotation> getDefaultDeploymentType()
{
return Production.class;
}

@Override
public boolean equals(Object other)
public String getId()
{
if (other instanceof AbstractClassBean)
{
AbstractClassBean<?> that = (AbstractClassBean<?>) other;
return super.equals(other) && that.getType().equals(this.getType());
}
else
{
return false;
}
return id;
}

}
Expand Up @@ -381,18 +381,4 @@ public String toString()
return buffer.toString();
}

@Override
public boolean equals(Object other)
{
if (other instanceof AbstractProducerBean)
{
AbstractProducerBean<?, ?> that = (AbstractProducerBean<?, ?>) other;
return super.equals(other) && this.getAnnotatedItem().getDeclaringClass().equals(that.getAnnotatedItem().getDeclaringClass());
}
else
{
return false;
}
}

}
Expand Up @@ -37,6 +37,7 @@ public class ProducerFieldBean<T> extends AbstractProducerBean<T, Field>
{
// The underlying field
private AnnotatedField<T> field;
private final String id;

/**
* Creates a producer field Web Bean
Expand Down Expand Up @@ -65,6 +66,7 @@ protected ProducerFieldBean(AnnotatedField<T> field, AbstractClassBean<?> declar
initType();
initTypes();
initBindings();
this.id = createId("ProducerField-" + declaringBean.getType().getName() + "-"+ field.getName());
}

@Override
Expand Down Expand Up @@ -140,5 +142,11 @@ public boolean isSpecializing()
{
return false;
}

@Override
public String getId()
{
return id;
}

}
Expand Up @@ -51,6 +51,8 @@ public class ProducerMethodBean<T> extends AbstractProducerBean<T, Method>
private AnnotatedMethod<?> disposalMethod;

private ProducerMethodBean<?> specializedBean;

private final String id;

/**
* Creates a producer method Web Bean
Expand All @@ -75,6 +77,7 @@ protected ProducerMethodBean(AnnotatedMethod<T> method, AbstractClassBean<?> dec
initType();
initTypes();
initBindings();
this.id = createId("ProducerField-" + declaringBean.getType().getName() + "-"+ method.getSignature().toString());
}

protected T produceInstance(CreationalContext<T> creationalContext)
Expand Down Expand Up @@ -254,4 +257,10 @@ protected void specialize(BeanDeployerEnvironment environment)
this.specializedBean = environment.getProducerMethod(superClassMethod);
}

@Override
public String getId()
{
return id;
}

}
34 changes: 28 additions & 6 deletions impl/src/main/java/org/jboss/webbeans/bean/RIBean.java
Expand Up @@ -17,6 +17,8 @@
package org.jboss.webbeans.bean;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;

import javax.context.Dependent;
Expand All @@ -34,18 +36,21 @@
public abstract class RIBean<T> extends Bean<T>
{

private static final AtomicInteger idGenerator = new AtomicInteger();
private static final ConcurrentMap<String, AtomicInteger> ids = new ConcurrentHashMap<String, AtomicInteger>();

private final ManagerImpl manager;

private final String id;

protected RIBean(ManagerImpl manager)
{
super(manager);
this.manager = manager;
// TODO better ID strategy (human readable)
this.id = getClass().getName() + "-" + idGenerator.getAndIncrement();
}

protected static String createId(String prefix)
{
AtomicInteger i = ids.putIfAbsent(prefix, new AtomicInteger());
return prefix + "-" + i;
}

@Override
Expand Down Expand Up @@ -73,9 +78,26 @@ public boolean isDependent()

public abstract RIBean<?> getSpecializedBean();

public String getId()
public abstract String getId();

@Override
public boolean equals(Object obj)
{
if (obj instanceof RIBean)
{
RIBean<?> that = (RIBean<?>) obj;
return this.getId().equals(that.getId());
}
else
{
return false;
}
}

@Override
public int hashCode()
{
return id;
return getId().hashCode();
}

}
Expand Up @@ -18,9 +18,15 @@
public abstract class AbstractStandardBean<T> extends RIBean<T>
{

private static final Annotation[] DEFAULT_BINDING_ARRAY = { new CurrentLiteral() };
private static final Set<Annotation> DEFAULT_BINDING = new HashSet<Annotation>(Arrays.asList(DEFAULT_BINDING_ARRAY));

private final String id;

protected AbstractStandardBean(ManagerImpl manager)
{
super(manager);
this.id = getClass().getSimpleName();
}

@Override
Expand All @@ -29,8 +35,7 @@ public void initialize(BeanDeployerEnvironment environment)
// No-op
}

private static final Annotation[] DEFAULT_BINDING_ARRAY = { new CurrentLiteral() };
private static final Set<Annotation> DEFAULT_BINDING = new HashSet<Annotation>(Arrays.asList(DEFAULT_BINDING_ARRAY));


@Override
public Set<Annotation> getBindings()
Expand Down Expand Up @@ -98,4 +103,10 @@ public boolean isProxyable()
return false;
}

@Override
public String getId()
{
return id;
}

}
Expand Up @@ -55,4 +55,10 @@ public String[] getParameterTypes()
return parameterTypes;
}

@Override
public String toString()
{
return getMethodName() + Arrays.asList(getParameterTypes()).toString().replace('[', '(').replace(']', ')');
}

}
@@ -0,0 +1,21 @@
package org.jboss.webbeans.test.unit.implementation.producer.method;

import javax.annotation.Named;
import javax.inject.Produces;

public class NamedProducer
{
@Named("itoen")
@Produces
public String[] createName()
{
return new String[] { "oh", "otya" };
}

@Named("iemon")
@Produces
public String[] createName2()
{
return new String[] { "fukujyuen", "iemon", "otya" };
}
}
@@ -0,0 +1,19 @@
package org.jboss.webbeans.test.unit.implementation.producer.method;

import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
import org.testng.annotations.Test;

@Artifact
public class NamedProducerTest extends AbstractWebBeansTest
{
@Test
public void testNamedProducer()
{
String[] iemon = (String[]) manager.getInstanceByName("iemon");
assert iemon.length == 3;
String[] itoen = (String[]) manager.getInstanceByName("itoen");
assert itoen.length == 2;
}

}

0 comments on commit 485ca52

Please sign in to comment.