Author: ruschein
Date: 2011-07-06 15:10:28 -0700 (Wed, 06 Jul 2011)
New Revision: 26075
Modified:
core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTunableInterceptor.java
core3/work-api/trunk/src/test/java/org/cytoscape/work/AbstractTunableInterceptorTest.java
Log:
fixes #293
Modified:
core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTunableInterceptor.java
===================================================================
---
core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTunableInterceptor.java
2011-07-06 21:41:07 UTC (rev 26074)
+++
core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTunableInterceptor.java
2011-07-06 22:10:28 UTC (rev 26075)
@@ -78,6 +78,8 @@
* @param <TH> <code>TunableHandler</code>s created in the factory
*/
public abstract class AbstractTunableInterceptor<TH extends TunableHandler>
implements TunableInterceptor<TH> {
+ private boolean throwException;
+
/**
* Factory for Handlers
*/
@@ -103,11 +105,17 @@
* or <code>PropHandlerFactory</code> to get the <code>Handlers</code>
for Properties.
*/
public AbstractTunableInterceptor(TunableHandlerFactory<TH>
tunableHandlerFactory) {
+ this.throwException = false;
this.factory = tunableHandlerFactory;
handlerMap = new HashMap<Object, LinkedHashMap<String, TH>>();
guiProviderMap = new HashMap<Object, Method>();
}
+ /** Used for testing only! */
+ void setThrowExceptions(final boolean throwException) {
+ this.throwException = throwException;
+ }
+
/**
* To detect fields and methods annotated with <code>Tunable</code>,
create a <code>Handler</code> for
* each from the factory, and store it in <code>handlerMap</code>.
@@ -135,10 +143,19 @@
if (handler != null)
handlerList.put(field.getName(), handler);
else
- System.out.println("No
handler for type: " + field.getType().getName());
+ throw new Exception("No
handler for type: "
+ +
field.getType().getName());
} catch (final Throwable ex) {
- System.out.println("tunable
field intercept failed: " + field.toString());
- ex.printStackTrace();
+ final StringBuilder msg = new
StringBuilder("tunable field intercept failed for "
+
+ field.toString() + "\r\n");
+ msg.append(ex.getMessage());
+ msg.append("\r\n");
+ for (final StackTraceElement
ste : ex.getStackTrace()) {
+
msg.append(ste.toString());
+ msg.append("\r\n");
+ }
+
+
logOrThrowException(msg.toString());
}
}
}
@@ -170,10 +187,12 @@
"Can't find a
setter compatible with the "
+
method.getName() + "() getter!");
- // Get a handler with for get
and set methods:
- final TH handler =
factory.getHandler(method, setter, obj, tunableMap.get(rootName));
+ // Get a handler for get and
set methods:
+ final TH handler =
+
factory.getHandler(method, setter, obj,
+
tunableMap.get(rootName));
if (handler == null)
- throw new
IllegalArgumentException(
+ logOrThrowException(
"Failed to
create a handler for " + setter.getName() + "()!");
else
handlerList.put("getset" + rootName, handler);
@@ -266,4 +285,11 @@
return false;
}
+
+ private final void logOrThrowException(final String msg) {
+ if (throwException)
+ throw new IllegalArgumentException(msg);
+ else
+ logger.warn(msg);
+ }
}
Modified:
core3/work-api/trunk/src/test/java/org/cytoscape/work/AbstractTunableInterceptorTest.java
===================================================================
---
core3/work-api/trunk/src/test/java/org/cytoscape/work/AbstractTunableInterceptorTest.java
2011-07-06 21:41:07 UTC (rev 26074)
+++
core3/work-api/trunk/src/test/java/org/cytoscape/work/AbstractTunableInterceptorTest.java
2011-07-06 22:10:28 UTC (rev 26075)
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2010, 2011, The Cytoscape Consortium (www.cytoscape.org)
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
@@ -53,7 +53,6 @@
hasAnnotatedField = new HasAnnotatedField();
hasAnnotatedSetterAndGetterMethods = new
HasAnnotatedSetterAndGetterMethods();
providesGUI = new ProvidesGUIExample();
-
}
@Test
@@ -91,6 +90,11 @@
}
@Test(expected=IllegalArgumentException.class)
+ public final void testInvalidAnnotatedType() {
+ interceptor.loadTunables(new HasInvalidAnotatedType());
+ }
+
+ @Test(expected=IllegalArgumentException.class)
public final void testInvalidProvidesGUIReturnType() {
interceptor.loadTunables(new HasInvalidProvidesGUIMethod());
}
@@ -121,6 +125,7 @@
}
}
+
class FakeTunableHandler extends AbstractTunableHandler {
public FakeTunableHandler(Field f, Object o, Tunable t) {
super(f,o,t);
@@ -131,8 +136,11 @@
public void handle() {}
}
+
class SimpleHandlerFactory implements
TunableHandlerFactory<AbstractTunableHandler> {
public AbstractTunableHandler getHandler(final Field field, final
Object instance, final Tunable tunable) {
+ if (field.getType() == Exception.class)
+ return null;
return new FakeTunableHandler(field, instance, tunable);
}
@@ -145,6 +153,7 @@
class ConcreteTunableInterceptor extends AbstractTunableInterceptor {
ConcreteTunableInterceptor(final
TunableHandlerFactory<AbstractTunableHandler> handlerFactory) {
super(handlerFactory);
+ setThrowExceptions(true);
}
public boolean validateAndWriteBackTunables(Object... objs) {
@@ -182,6 +191,13 @@
public void setStuff() { }
}
+
+class HasInvalidAnotatedType {
+ @Tunable
+ public Exception e;
+}
+
+
class SetterAnnotatedInsteadOfGetter {
public int getStuff() { return -1; }
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.