Permalink
Browse files

Support any object as a private data key

  • Loading branch information...
dmlloyd committed Apr 8, 2011
1 parent 05b9d8b commit bb0a3a71fd7f86859bb73f6c3a44319a891034f1
Showing with 36 additions and 1 deletion.
  1. +36 −1 src/main/java/org/jboss/invocation/InterceptorContext.java
@@ -50,7 +50,7 @@
private Object timer;
private List<Interceptor> interceptors = EMPTY;
private ListIterator<Interceptor> interceptorIterator = EMPTY_ITR;
private final Map<Class<?>, Object> privateData = new IdentityHashMap<Class<?>, Object>();
private final Map<Object, Object> privateData = new IdentityHashMap<Object, Object>();
private final InvocationContext invocationContext = new Invocation();
/**
@@ -168,6 +168,16 @@ public InvocationContext getInvocationContext() {
return type.cast(privateData.get(type));
}
/**
* Get a private data item. The key will be looked up by object identity, not by value.
*
* @param key the object key
* @return the private data object
*/
public Object getPrivateData(Object key) {
return privateData.get(key);
}
/**
* Insert a private data item.
*
@@ -184,6 +194,31 @@ public InvocationContext getInvocationContext() {
}
}
/**
* Insert a private data item. The key is used by object identity, not by value; in addition, if the key is
* a {@code Class} then the value given must be assignable to that class.
*
* @param key the data key
* @param value the data item value, or {@code null} to remove the mapping
* @return the data item which was previously mapped to this position, or {@code null} if no such item exists
*/
public Object putPrivateData(Object key, Object value) {
if (key instanceof Class) {
final Class<?> type = (Class<?>) key;
if (value == null) {
return type.cast(privateData.remove(type));
} else {
return type.cast(privateData.put(type, type.cast(value)));
}
} else {
if (value == null) {
return privateData.remove(key);
} else {
return privateData.put(key, value);
}
}
}
/**
* Get the current interceptors.
*

0 comments on commit bb0a3a7

Please sign in to comment.