made project class loader public + throw exception is mote class could not be loaded

This commit is contained in:
fros4943 2009-11-25 20:47:18 +00:00
parent ac424ca88a
commit 93672649d2
2 changed files with 9 additions and 10 deletions

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: GUI.java,v 1.154 2009/11/25 10:29:21 fros4943 Exp $
* $Id: GUI.java,v 1.155 2009/11/25 20:47:18 fros4943 Exp $
*/
package se.sics.cooja;
@ -302,7 +302,7 @@ public class GUI extends Observable {
private Vector<File> currentProjectDirs = new Vector<File>();
private ClassLoader projectDirClassLoader;
public ClassLoader projectDirClassLoader;
private Vector<Class<? extends MoteType>> moteTypeClasses = new Vector<Class<? extends MoteType>>();
@ -2846,12 +2846,9 @@ public class GUI extends Observable {
/**
* Help method that tries to load and initialize a class with given name.
*
* @param <N>
* Class extending given class type
* @param classType
* Class type
* @param className
* Class name
* @param <N> Class extending given class type
* @param classType Class type
* @param className Class name
* @return Class extending given class type or null if not found
*/
public <N extends Object> Class<? extends N> tryLoadClass(

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: Simulation.java,v 1.54 2009/11/13 08:37:36 fros4943 Exp $
* $Id: Simulation.java,v 1.55 2009/11/25 20:47:19 fros4943 Exp $
*/
package se.sics.cooja;
@ -610,7 +610,9 @@ public class Simulation extends Observable implements Runnable {
if (element.getName().equals("mote")) {
Class<? extends Mote> moteClass = myGUI.tryLoadClass(this, Mote.class,
element.getText().trim());
if (moteClass == null) {
throw new Exception("Could not load mote class: " + element.getText().trim());
}
Mote mote = moteClass.getConstructor((Class[]) null).newInstance((Object[]) null);
if (mote.setConfigXML(this, element.getChildren(), visAvailable)) {
addMote(mote);