Changeset 78 for java/main/src/main/java/com/framsticks/core/Instance.java
- Timestamp:
- 01/09/13 00:09:10 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/core/Instance.java
r77 r78 23 23 protected Node root; 24 24 25 protected final Map<String, FramsClass> infoCache = new HashMap<String, FramsClass>();26 25 public Set<InstanceListener> listeners = new HashSet<InstanceListener>(); 27 26 … … 34 33 protected void run() { 35 34 super.run(); 36 registerTypicalReflectedClasses();35 com.framsticks.model.Package.register(registry); 37 36 } 38 37 39 38 @Override 40 protected void configure() {39 protected void configure() throws Exception { 41 40 super.configure(); 42 41 } 43 42 44 protected abstract void fetchInfo(Path path, Future<FramsClass> future); 45 public abstract void resolve(Path path, Future<Path> future); 46 public abstract void fetchValue(Path path, Param param, StateFunctor stateFunctor); 47 public abstract void fetchValues(Path path, StateFunctor stateFunctor); 48 protected abstract void tryRegisterOnChangeEvents(Path path); 43 protected void fetchInfo(Path path, Future<FramsClass> future) { 44 future.result(null, new UnsupportedOperationException()); 45 } 46 47 public void resolve(Path path, Future<Path> future) { 48 assert isActive(); 49 assert path.isOwner(this); 50 if (path.getTop().getObject() != null) { 51 future.result(path, null); 52 return; 53 } 54 AccessInterface access = bindAccess(path.getUnder()); 55 Object object = access.get(path.getTop().getParam(), Object.class); 56 if (object == null) { 57 future.result(path, null); 58 return; 59 } 60 future.result(path.appendResolution(object), null); 61 } 62 63 public void fetchValue(Path path, Param param, StateFunctor stateFunctor) { 64 stateFunctor.call(null); 65 } 66 67 public void fetchValues(Path path, StateFunctor stateFunctor) { 68 stateFunctor.call(null); 69 } 70 71 protected void tryRegisterOnChangeEvents(Path path) { 72 73 } 49 74 50 75 public void storeValue(Path path, Param param, Object value, final StateFunctor stateFunctor) { … … 98 123 } 99 124 100 public void putInfoIntoCache(FramsClass framsClass) {101 assert isActive();102 if (infoCache.containsKey(framsClass.getId())) {103 LOGGER.info("already cached " + framsClass);104 return;105 }106 LOGGER.debug("caching info for " + framsClass);107 infoCache.put(framsClass.getId(), framsClass);108 }109 125 110 126 public final FramsClass getInfoFromCache(Path path) { … … 115 131 public FramsClass getInfoFromCache(String id) { 116 132 assert isActive(); 117 if (id == null) { 118 return null; 119 } 120 if (infoCache.containsKey(id)) { 121 return infoCache.get(id); 122 } 123 return null; 124 } 125 126 protected final Map<String, Class> reflectedClasses = new HashMap<String, Class>(); 127 128 public final void registerReflectedClass(String name, String className) { 129 assert isActive(); 130 try { 131 registerReflectedClass(name, Class.forName(className)); 132 } catch (ClassNotFoundException e) { 133 LOGGER.fatal("class not found during registration: " + e); 134 } 135 } 136 137 public void registerReflectedClass(String name, Class reflectedClass) { 138 assert isActive(); 139 reflectedClasses.put(name, reflectedClass); 140 } 133 return registry.getInfoFromCache(id); 134 } 135 136 protected Registry registry = new Registry(); 141 137 142 138 public AccessInterface createAccess(String name) { … … 150 146 } 151 147 152 if (reflectedClasses.containsKey(name)) { 153 return new ReflectionAccess(reflectedClasses.get(name), framsClass); 154 } 155 156 return new PropertiesAccess(framsClass); 148 return registry.createAccess(name, framsClass); 157 149 } 158 150 … … 188 180 AccessInterface access = prepareAccess(node.getParam()); 189 181 if (access == null) { 182 LOGGER.error("missing access for: " + node.getParam()); 190 183 return null; 191 184 } … … 287 280 } 288 281 } 289 putInfoIntoCache(framsClass);282 registry.putInfoIntoCache(framsClass); 290 283 return framsClass; 291 284 } … … 338 331 } 339 332 340 public void registerTypicalReflectedClasses() {341 registerReflectedClass("MechPart", "com.framsticks.model.MechPart");342 registerReflectedClass("Joint", "com.framsticks.model.Joint");343 registerReflectedClass("MechJoint", "com.framsticks.model.MechJoint");344 registerReflectedClass("Neuro", "com.framsticks.model.Neuro");345 registerReflectedClass("NeuroDef", "com.framsticks.model.NeuroDef");346 registerReflectedClass("Part", "com.framsticks.model.Part");347 registerReflectedClass("Creature", "com.framsticks.model.Creature");348 registerReflectedClass("Genotype", "com.framsticks.model.Genotype");349 }350 351 333 public static Iterator<String> splitPath(String path) { 352 334 List<String> list = new LinkedList<String>(); … … 359 341 } 360 342 343 public Registry getRegistry() { 344 return registry; 345 } 361 346 } 347
Note: See TracChangeset
for help on using the changeset viewer.