git://wamblee.org
/
utils
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
cff330d
)
(no commit message)
author
erik
<erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 30 Jul 2010 18:44:22 +0000
(18:44 +0000)
committer
erik
<erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 30 Jul 2010 18:44:22 +0000
(18:44 +0000)
test/enterprise/src/main/java/org/wamblee/test/jndi/LookupProxyFactory.java
[moved from
test/enterprise/src/main/java/org/wamblee/test/jndi/JndiProxyFactory.java
with 72% similarity]
patch
|
blob
|
history
test/enterprise/src/main/java/org/wamblee/test/jndi/package-info.java
patch
|
blob
|
history
diff --git
a/test/enterprise/src/main/java/org/wamblee/test/jndi/JndiProxyFactory.java
b/test/enterprise/src/main/java/org/wamblee/test/jndi/LookupProxyFactory.java
similarity index 72%
rename from
test/enterprise/src/main/java/org/wamblee/test/jndi/JndiProxyFactory.java
rename to
test/enterprise/src/main/java/org/wamblee/test/jndi/LookupProxyFactory.java
index d326fa029219bf1ad4ab55d011cffb0ae84144bb..0c53d0cfd449687003dcc02bf0f5fe3b009ca4fd 100644
(file)
--- a/
test/enterprise/src/main/java/org/wamblee/test/jndi/JndiProxyFactory.java
+++ b/
test/enterprise/src/main/java/org/wamblee/test/jndi/LookupProxyFactory.java
@@
-25,28
+25,40
@@
import javax.naming.NamingException;
/**
* Proxy factory that can provide contextual references to objects retrieved
/**
* Proxy factory that can provide contextual references to objects retrieved
- * from JNDI.
- *
- * NOTE: This class is probably better suited as a production class, not a test support class.
- * It needs to find a new home in a Java EE production utilities library.
+ * through a lookup mechanism.
*
* @param T
* Interface to proxy.
* @author Erik Brakkee
*
*/
*
* @param T
* Interface to proxy.
* @author Erik Brakkee
*
*/
-public class JndiProxyFactory<T> {
+public class LookupProxyFactory<T> {
+
+ /**
+ * Interface to lookup the object to delegate to.
+ *
+ * @author Erik Brakkee
+ */
+ public static interface Lookup {
+ /**
+ * Looks up the object.
+ * @return Object (non-null)
+ * @throws Any exception in case the object cannot be found.
+ */
+ Object lookup() throws Exception;
+ }
+
/**
* Exception thrown in case an object cannot be retrieved from JNDI.
*
* @author Erik Brakkee
*/
/**
* Exception thrown in case an object cannot be retrieved from JNDI.
*
* @author Erik Brakkee
*/
- public static class
JndiWiring
Exception extends RuntimeException {
- public
JndiWiring
Exception(String aMsg, Throwable aCause) {
+ public static class
Lookup
Exception extends RuntimeException {
+ public
Lookup
Exception(String aMsg, Throwable aCause) {
super(aMsg, aCause);
}
super(aMsg, aCause);
}
- public
JndiWiring
Exception(String aMsg) {
+ public
Lookup
Exception(String aMsg) {
super(aMsg);
}
}
super(aMsg);
}
}
@@
-57,7
+69,7
@@
public class JndiProxyFactory<T> {
*
* @author Erik Brakkee
*/
*
* @author Erik Brakkee
*/
- private class
Jndi
InvocationHandler implements InvocationHandler {
+ private class
Lookup
InvocationHandler implements InvocationHandler {
@Override
/**
@Override
/**
@@
-67,19
+79,16
@@
public class JndiProxyFactory<T> {
throws Throwable {
Object svcObj = null;
try {
throws Throwable {
Object svcObj = null;
try {
- InitialContext ctx = new InitialContext();
- svcObj = ctx.lookup(jndi);
- } catch (NamingException e) {
- throw new JndiWiringException(
- "Error looking up object in JNDI at '" + jndi + "'", e);
+ svcObj = lookup.lookup();
+ } catch (Exception e) {
+ throw new LookupException(
+ "Error looking up object", e);
}
if (svcObj == null) {
}
if (svcObj == null) {
- throw new JndiWiringException("Object at '" + jndi +
- "' is null");
+ throw new LookupException("Object at is null");
}
if (!clazz.isInstance(svcObj)) {
}
if (!clazz.isInstance(svcObj)) {
- throw new JndiWiringException("Object in JNDI tree at '" +
- jndi + "' not of type " + clazz.getName() +
+ throw new LookupException("Object '" + svcObj + "' is not of type " + clazz.getName() +
" but of type " + svcObj.getClass().getName());
}
T svc = (T) svcObj;
" but of type " + svcObj.getClass().getName());
}
T svc = (T) svcObj;
@@
-91,7
+100,7
@@
public class JndiProxyFactory<T> {
}
}
}
}
- private
String jndi
;
+ private
Lookup lookup
;
private Class clazz;
/**
private Class clazz;
/**
@@
-102,13
+111,13
@@
public class JndiProxyFactory<T> {
* @param aJndi JNDI name of the object to lookup.
*
*/
* @param aJndi JNDI name of the object to lookup.
*
*/
- public
JndiProxyFactory(Class<T> aClass, String aJndi
) {
+ public
LookupProxyFactory(Class<T> aClass, Lookup aLookup
) {
if (!aClass.isInterface()) {
throw new IllegalArgumentException("Class " + aClass.getName() +
" is not an interface");
}
clazz = aClass;
if (!aClass.isInterface()) {
throw new IllegalArgumentException("Class " + aClass.getName() +
" is not an interface");
}
clazz = aClass;
-
jndi = aJndi
;
+
lookup = aLookup
;
}
/**
}
/**
@@
-116,12
+125,12
@@
public class JndiProxyFactory<T> {
* {@link #set(Object)}
*
* When at runtime the proxy cannot find lookup the object in JNDI, it
* {@link #set(Object)}
*
* When at runtime the proxy cannot find lookup the object in JNDI, it
- * throws {@link
JndiWiring
Exception}.
+ * throws {@link
Lookup
Exception}.
*
* @return Proxy.
*/
public T getProxy() {
*
* @return Proxy.
*/
public T getProxy() {
- InvocationHandler handler = new
Jndi
InvocationHandler();
+ InvocationHandler handler = new
Lookup
InvocationHandler();
Class proxyClass = Proxy.getProxyClass(clazz.getClassLoader(),
new Class[] { clazz });
T proxy;
Class proxyClass = Proxy.getProxyClass(clazz.getClassLoader(),
new Class[] { clazz });
T proxy;
diff --git
a/test/enterprise/src/main/java/org/wamblee/test/jndi/package-info.java
b/test/enterprise/src/main/java/org/wamblee/test/jndi/package-info.java
index 8777cdbb941fb257ae7b6cb3d73422c331a3b5a3..7fd7ddbc8bf2e4337855627701aba08fc779982f 100644
(file)
--- a/
test/enterprise/src/main/java/org/wamblee/test/jndi/package-info.java
+++ b/
test/enterprise/src/main/java/org/wamblee/test/jndi/package-info.java
@@
-17,7
+17,5
@@
* This package provides utilities for JNDI testing.
*
* Using {@link StubInitialContextFactory}, JNDI can be mocked in junit tests.
* This package provides utilities for JNDI testing.
*
* Using {@link StubInitialContextFactory}, JNDI can be mocked in junit tests.
- * {@link JndiProxyFactory} provides a proxy that transparently delegates to an object in the
- * JNDI tree.
*/
package org.wamblee.test.jndi;
\ No newline at end of file
*/
package org.wamblee.test.jndi;
\ No newline at end of file