added debugging output when positioner fails

This commit is contained in:
fros4943 2009-02-18 13:55:01 +00:00
parent 9e9b712e5d
commit 8ddaf79361

View file

@ -26,16 +26,17 @@
* 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
*/
@ -68,17 +69,30 @@ public abstract class Positioner {
*/
public static final Positioner generateInterface(
Class<? extends Positioner> 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<? extends Positioner> 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;
}
}