Ignore:
Timestamp:
01/09/13 00:09:10 (11 years ago)
Author:
psniegowski
Message:

Add f0 parsing and f0->Model transformation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/core/Instance.java

    r77 r78  
    2323    protected Node root;
    2424
    25         protected final Map<String, FramsClass> infoCache = new HashMap<String, FramsClass>();
    2625    public Set<InstanceListener> listeners = new HashSet<InstanceListener>();
    2726
     
    3433    protected void run() {
    3534        super.run();
    36         registerTypicalReflectedClasses();
     35                com.framsticks.model.Package.register(registry);
    3736    }
    3837
    3938    @Override
    40     protected void configure() {
     39    protected void configure() throws Exception {
    4140        super.configure();
    4241    }
    4342
    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        }
    4974
    5075        public void storeValue(Path path, Param param, Object value, final StateFunctor stateFunctor) {
     
    98123        }
    99124
    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         }
    109125
    110126    public final FramsClass getInfoFromCache(Path path) {
     
    115131    public FramsClass getInfoFromCache(String id) {
    116132        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();
    141137
    142138        public AccessInterface createAccess(String name) {
     
    150146                }
    151147
    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);
    157149        }
    158150
     
    188180        AccessInterface access = prepareAccess(node.getParam());
    189181        if (access == null) {
     182                        LOGGER.error("missing access for: " + node.getParam());
    190183            return null;
    191184        }
     
    287280            }
    288281        }
    289         putInfoIntoCache(framsClass);
     282        registry.putInfoIntoCache(framsClass);
    290283        return framsClass;
    291284    }
     
    338331    }
    339332
    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 
    351333    public static Iterator<String> splitPath(String path) {
    352334        List<String> list = new LinkedList<String>();
     
    359341    }
    360342
     343        public Registry getRegistry() {
     344                return registry;
     345        }
    361346}
     347
Note: See TracChangeset for help on using the changeset viewer.