From 8ddaf793614ed12c6356d907811498d6b1dce381 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Wed, 18 Feb 2009 13:55:01 +0000 Subject: [PATCH] added debugging output when positioner fails --- .../cooja/java/se/sics/cooja/Positioner.java | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/Positioner.java b/tools/cooja/java/se/sics/cooja/Positioner.java index b608518f0..b295e06cc 100644 --- a/tools/cooja/java/se/sics/cooja/Positioner.java +++ b/tools/cooja/java/se/sics/cooja/Positioner.java @@ -26,17 +26,18 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: Positioner.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $ + * $Id: Positioner.java,v 1.3 2009/02/18 13:55:01 fros4943 Exp $ */ package se.sics.cooja; import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import org.apache.log4j.Logger; /** - * A positioner is used for determining positions of newly created motes. - * + * A positioner is used for determining initial positions of motes. + * * @author Fredrik Osterlind */ public abstract class Positioner { @@ -46,7 +47,7 @@ public abstract class Positioner { * This method creates an instance of the given class with the given interval * information as constructor arguments. Instead of calling the constructors * directly this method may be used. - * + * * @param positionerClass * Positioner class * @param totalNumberOfMotes @@ -68,24 +69,37 @@ public abstract class Positioner { */ public static final Positioner generateInterface( Class positionerClass, int totalNumberOfMotes, - double startX, double endX, double startY, double endY, double startZ, - double endZ) { + double startX, double endX, + double startY, double endY, + double startZ, double endZ) { try { - // Generating positioner - Constructor constr = positionerClass.getConstructor(new Class[] { - int.class, double.class, double.class, double.class, double.class, - double.class, double.class }); - return (Positioner) constr.newInstance(new Object[] { totalNumberOfMotes, - startX, endX, startY, endY, startZ, endZ }); + Constructor constr = + positionerClass.getConstructor(new Class[] { + int.class, + double.class, double.class, + double.class, double.class, + double.class, double.class + }); + return constr.newInstance(new Object[] { + totalNumberOfMotes, + startX, endX, + startY, endY, + startZ, endZ + }); } catch (Exception e) { - logger.fatal("Exception when creating " + positionerClass + ": " + e); + + if (e instanceof InvocationTargetException) { + logger.fatal("Exception when creating " + positionerClass + ": " + e.getCause()); + } else { + logger.fatal("Exception when creating " + positionerClass + ": " + e.getMessage()); + } return null; } } /** * Returns the next mote position. - * + * * @return Position */ public abstract double[] getNextPosition();