From 5c1dcd25c3a749b3cbc255a841898431398a2823 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 9 Jan 2007 10:18:08 +0000 Subject: [PATCH] new help method for generating radio mediums during config load. --- .../cooja/java/se/sics/cooja/RadioMedium.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/RadioMedium.java b/tools/cooja/java/se/sics/cooja/RadioMedium.java index 6af056dcf..b2a3e422e 100644 --- a/tools/cooja/java/se/sics/cooja/RadioMedium.java +++ b/tools/cooja/java/se/sics/cooja/RadioMedium.java @@ -26,13 +26,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: RadioMedium.java,v 1.1 2006/08/21 12:12:55 fros4943 Exp $ + * $Id: RadioMedium.java,v 1.2 2007/01/09 10:18:08 fros4943 Exp $ */ package se.sics.cooja; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.Collection; +import java.util.Observable; import java.util.Observer; - +import org.apache.log4j.Logger; import org.jdom.Element; import se.sics.cooja.interfaces.Position; @@ -50,6 +53,7 @@ import se.sics.cooja.interfaces.Radio; * @author Fredrik Osterlind */ public abstract class RadioMedium { + private static Logger logger = Logger.getLogger(RadioMedium.class); /** * Registers a mote to this medium. @@ -118,6 +122,11 @@ public abstract class RadioMedium { */ public abstract void addRadioMediumObserver(Observer observer); + /** + * @return Radio medium observable + */ + public abstract Observable getRadioMediumObservable(); + /** * Deletes an radio medium observer. * @@ -171,6 +180,24 @@ public abstract class RadioMedium { * Config XML elements * @return True if config was set successfully, false otherwise */ - public abstract boolean setConfigXML(Collection configXML); + public abstract boolean setConfigXML(Collection configXML, boolean visAvailable); + + /** + * This method creates an instance of the given class with the given + * simulation constructor argument. Instead of calling the constructors + * directly this method may be used. + * + * @return Radio medium instance + */ + public static final RadioMedium generateInterface( + Class radioMediumClass, Simulation simulation) + throws NoSuchMethodException, InvocationTargetException, + IllegalAccessException, InstantiationException { + + // Generating radio medium + Constructor constr = radioMediumClass + .getConstructor(new Class[] { Simulation.class }); + return (RadioMedium) constr.newInstance(new Object[] { simulation }); + } }