[weld-commits] Weld SVN: r6144 - extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Wed Apr 21 22:02:15 EDT 2010
Author: swd847
Date: 2010-04-21 22:02:14 -0400 (Wed, 21 Apr 2010)
New Revision: 6144
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentityWrapper.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentifiableBeanExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentifiableInjectionTarget.java
Log:
updated bean id to work on object identity, so beans that implement equals/hashCode will not break it
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentifiableBeanExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentifiableBeanExtension.java 2010-04-22 00:18:01 UTC (rev 6143)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentifiableBeanExtension.java 2010-04-22 02:02:14 UTC (rev 6144)
@@ -20,7 +20,7 @@
*/
public class IdentifiableBeanExtension implements Extension
{
- Map<Object, AnnotatedType<?>> types = Collections.synchronizedMap(new WeakHashMap<Object, AnnotatedType<?>>(1000));
+ Map<IdentityWrapper, AnnotatedType<?>> types = Collections.synchronizedMap(new WeakHashMap<IdentityWrapper, AnnotatedType<?>>(1000));
public void processInjectionTarget(@Observes ProcessInjectionTarget<?> event)
{
@@ -55,7 +55,7 @@
public AnnotatedType<?> getAnnotatedType(Object instance)
{
- return types.get(instance);
+ return types.get(new IdentityWrapper(instance));
}
}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentifiableInjectionTarget.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentifiableInjectionTarget.java 2010-04-22 00:18:01 UTC (rev 6143)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentifiableInjectionTarget.java 2010-04-22 02:02:14 UTC (rev 6144)
@@ -8,7 +8,8 @@
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
/**
- * wrapper around InjectionTarget that sets a bean id
+ * wrapper around InjectionTarget that maps the instance to it's annotated type
+ *
* @author Stuart Douglas <stuart at baileyroberts.com.au>
*
* @param <T>
@@ -19,9 +20,9 @@
AnnotatedType<?> type;
- Map<Object, AnnotatedType<?>> typeMap;
+ Map<IdentityWrapper, AnnotatedType<?>> typeMap;
- IdentifiableInjectionTarget(InjectionTarget<T> delegate, AnnotatedType<?> type,Map<Object, AnnotatedType<?>> typeMap)
+ IdentifiableInjectionTarget(InjectionTarget<T> delegate, AnnotatedType<?> type, Map<IdentityWrapper, AnnotatedType<?>> typeMap)
{
this.delegate = delegate;
this.type=type;
@@ -31,7 +32,7 @@
public void inject(T instance, CreationalContext<T> ctx)
{
- typeMap.put(instance, type);
+ typeMap.put(new IdentityWrapper(instance), type);
delegate.inject(instance, ctx);
}
@@ -47,7 +48,7 @@
public void dispose(T instance)
{
- typeMap.remove(instance);
+ typeMap.remove(new IdentityWrapper(instance));
delegate.dispose(instance);
}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentityWrapper.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentityWrapper.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/beanid/IdentityWrapper.java 2010-04-22 02:02:14 UTC (rev 6144)
@@ -0,0 +1,40 @@
+package org.jboss.weld.extensions.beanid;
+
+/**
+ * wrapper that overrides equals and hashCode to work on object identity
+ *
+ *
+ * @author Stuart Douglas <stuart at baileyroberts.com.au>
+ *
+ */
+public class IdentityWrapper
+{
+ final Object object;
+
+ public IdentityWrapper(Object object)
+ {
+ this.object = object;
+ }
+
+ public Object getObject()
+ {
+ return object;
+ }
+
+ @Override
+ public boolean equals(Object arg0)
+ {
+ if (arg0 instanceof IdentityWrapper)
+ {
+ IdentityWrapper w = (IdentityWrapper) arg0;
+ return w.getObject() == object;
+ }
+ return object == arg0;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return System.identityHashCode(object);
+ }
+}
More information about the weld-commits
mailing list