3 Commits

Author SHA1 Message Date
bc5ccd6356 Fixed a comment 2025-03-29 20:59:30 +01:00
8279033d74 Fixed name of StockAsset and inserted Sockasset to example 2020-10-23 10:02:30 +02:00
2e1a53789f Added some comments 2020-10-23 09:45:44 +02:00
4 changed files with 24 additions and 11 deletions

View File

@ -46,7 +46,7 @@ public class Main {
); );
// We have to bootstrap with a god world because // We have to bootstrap with a god world because
// there whould be no way to to initialize the world // there whould be no way to initialize the world
GodWorld godworld = new GodWorld(is); GodWorld godworld = new GodWorld(is);
System.out.println("finished"); System.out.println("finished");

View File

@ -2,9 +2,9 @@
"version": 0.2, "version": 0.2,
"assets": [ "assets": [
{ {
"type": "opensesim.sesim.assets.FurtureAsset", "type": "opensesim.sesim.assets.StockAsset",
"symbol": "MSFT", "symbol": "MSFT",
"name": "Hello" "name": "Microsoft"
} }
] ]
} }

View File

@ -34,9 +34,9 @@ import org.json.JSONObject;
* *
* @author 7u83 <7u83@mail.ru> * @author 7u83 <7u83@mail.ru>
*/ */
public class StockAssett extends AbstractAsset{ public class StockAsset extends AbstractAsset{
public StockAssett(GodWorld world, JSONObject cfg) { public StockAsset(GodWorld world, JSONObject cfg) {
super(world, cfg); super(world, cfg);
} }

View File

@ -110,6 +110,13 @@ public class GodWorld implements GetJson, World {
init(cfg,false); init(cfg,false);
} }
private void init(JSONObject cfg, boolean mt) {
// this.scheduler = new Scheduler();
// this.scheduler.start();
putJson(cfg);
}
public Scheduler getScheduler() { public Scheduler getScheduler() {
return scheduler; return scheduler;
} }
@ -122,11 +129,6 @@ public class GodWorld implements GetJson, World {
this(new JSONObject("{}")); this(new JSONObject("{}"));
} }
private void init(JSONObject cfg, boolean mt) {
this.scheduler = new Scheduler();
this.scheduler.start();
putJson(cfg);
}
private void putJson(JSONObject cfg) { private void putJson(JSONObject cfg) {
// Read assets // Read assets
@ -186,11 +188,19 @@ public class GodWorld implements GetJson, World {
return cfg; return cfg;
} }
/**
* Create an asset from a JSON object
*
* @param cfg the JSON object to create the asset from
* @return the created asset
* @throws SeSimException
*/
public AbstractAsset createAsset(JSONObject cfg) throws SeSimException { public AbstractAsset createAsset(JSONObject cfg) throws SeSimException {
AbstractAsset a; AbstractAsset a;
String class_name; String class_name;
Class<AbstractAsset> cls; Class<AbstractAsset> cls;
// get asset name
try { try {
class_name = cfg.getString(JKEYS.ASSET_TYPE); class_name = cfg.getString(JKEYS.ASSET_TYPE);
} catch (JSONException jex) { } catch (JSONException jex) {
@ -198,10 +208,13 @@ public class GodWorld implements GetJson, World {
return null; return null;
} }
// create class from name
try { try {
cls = (Class<AbstractAsset>) Class.forName(class_name); cls = (Class<AbstractAsset>) Class.forName(class_name);
a = cls.getConstructor(GodWorld.class, JSONObject.class).newInstance(this, cfg); a = cls.getConstructor(GodWorld.class, JSONObject.class).newInstance(this, cfg);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { } catch (ClassNotFoundException | NoSuchMethodException | SecurityException
| InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException ex) {
Logger.getLogger(GodWorld.class.getName()).log(Level.SEVERE, class_name, ex); Logger.getLogger(GodWorld.class.getName()).log(Level.SEVERE, class_name, ex);
return null; return null;
} }