diff --git a/nbproject/project.properties b/nbproject/project.properties index 25adfda..beb8a81 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sat, 25 Jul 2020 01:09:41 +0200 +#Sat, 25 Jul 2020 03:07:19 +0200 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/opensesim/cli/Main.java b/src/opensesim/cli/Main.java index b8646ed..c295d4a 100644 --- a/src/opensesim/cli/Main.java +++ b/src/opensesim/cli/Main.java @@ -25,12 +25,30 @@ */ package opensesim.cli; +import java.io.IOException; +import java.io.InputStream; +import java.util.Scanner; +import opensesim.world.GodWorld; +import opensesim.world.World; + /** * * @author tube */ public class Main { - public static void main(String[] args){ - + + public static void main(String[] args) throws IOException { + System.out.println("OpenSeSim Cli"); + + InputStream is; + is = Main.class.getResourceAsStream( + "/opensesim/resources/files/example.json" + ); + + // We have to bootstrap with a god world because + // there whould be no way to to initialize the world + GodWorld godworld = new GodWorld(is); + + System.out.println("finished"); } } diff --git a/src/opensesim/resources/files/example.json b/src/opensesim/resources/files/example.json new file mode 100644 index 0000000..96477de --- /dev/null +++ b/src/opensesim/resources/files/example.json @@ -0,0 +1,10 @@ +{ + "version": 0.2, + "assets": [ + { + "type": "opensesim.sesim.Assets.FurtureAsset", + "symbol": "MSFT", + "name": "Hello" + } + ] +} diff --git a/src/opensesim/world/GodWorld.java b/src/opensesim/world/GodWorld.java index 8c59c0f..d15d7b2 100644 --- a/src/opensesim/world/GodWorld.java +++ b/src/opensesim/world/GodWorld.java @@ -25,6 +25,8 @@ */ package opensesim.world; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Collection; @@ -32,6 +34,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Random; +import java.util.Scanner; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -74,8 +77,12 @@ public class GodWorld implements GetJson, World { public static final String ASSET_SYMBOL = "symbol"; public static final String ASSET_TYPE = "type"; + + public static final String VERSION = "version"; } + + public static double VERSION = 0.2; /* HashSet assetsById = new HashSet<>(); HashMap assetsBySymbol = new HashMap<>(); @@ -91,7 +98,16 @@ public class GodWorld implements GetJson, World { */ public GodWorld(JSONObject cfg) { init(cfg, false); - + } + + public GodWorld(InputStream is) throws IOException{ + String s = new Scanner(is, "UTF-8").useDelimiter("\\A").next(); + JSONObject cfg = new JSONObject(s); + Double version = cfg.getDouble(GodWorld.JKEYS.VERSION); + if (version != GodWorld.VERSION) { + throw new IOException("File has wrong version."); + } + init(cfg,false); } public Scheduler getScheduler() { @@ -186,7 +202,7 @@ public class GodWorld implements GetJson, World { cls = (Class) Class.forName(class_name); a = cls.getConstructor(GodWorld.class, JSONObject.class).newInstance(this, cfg); } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - Logger.getLogger(GodWorld.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(GodWorld.class.getName()).log(Level.SEVERE, class_name, ex); return null; }