Ignore:
Timestamp:
06/26/13 13:27:31 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • use java annotations to mark classes and fields to be used when:
    • using java classes with ReflectionAccess? to represent remote objects with FramsClass? description found by "info ..." requests
    • to build up FramsClass? representation of objects not present at remote server
  • allow using primitive types (instead of wraping counterparts) in reflected classes
  • rework FramsClass? creation process (add FramsClassBuilder?)
  • add more tests

CHANGELOG:
Prepare model.World class.

Minor change.

Use primitive types for Genotype and Creature classes.

Use primitive types in model.Neuro* classes.

Use primitive types in model.Joint* classes.

Use primitive types in model.Part* classes.

Fix primitive values.

Extract FramsClassBuilder?.

Add tests of Model classes.

More fixes.

Refactorize out ParamCandidate?.

Several fixes.

Fix all regressions after introducing annotations.

Use annotations throughout the project.

Add exception classes.

Improve creation of FramsClass?.

More changes.

Many changes regarding annotations.

Annotate classes in com.framsticks.model package.

Remove manual FramsClass? constructor.

Construct FramsClass? for Creature. Add test.

Add default values to the ParamAnnotation?.

Add ParamBuilderTest? and ParamAnnotation?.

Add FramsClassAnnotation?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/parsers/MultiParamLoader.java

    r77 r86  
    99
    1010public class MultiParamLoader {
    11         private final static Logger logger = Logger
    12                         .getLogger(MultiParamLoader.class.getName());
     11        private final static Logger log = Logger.getLogger(MultiParamLoader.class);
    1312
    1413        /**
     
    5655         * Status of current execution.
    5756         */
    58         private Status status;
     57        private Status status = Status.None;
     58
     59        private void setStatus(Status status) {
     60                log.trace("changing status: " + this.status.toString() + " -> " + status.toString());
     61                this.status = status;
     62        }
    5963
    6064        /**
     
    6266         */
    6367        private SourceInterface currentSource;
     68
     69        protected String currentLine;
    6470
    6571
     
    8692        private String lastUnknownObjectName;
    8793
     94        /**
     95         * @return the currentLine
     96         */
     97        public String getCurrentLine() {
     98                return currentLine;
     99        }
     100
    88101        public MultiParamLoader() {
    89102
     
    94107         */
    95108        public Status go() throws Exception {
    96                 logger.trace("go");
     109                log.trace("go");
    97110
    98111                while (!isFinished()) {
     
    106119
    107120                        // read data
    108                         String line = currentSource.readLine();
     121                        currentLine = currentSource.readLine();
    109122
    110123                        // end of file
    111                         if (line == null) {
     124                        if (currentLine == null) {
    112125                                if (!returnFromIncluded()) {
    113126                                        finish();
     
    117130                                }
    118131                        }
     132                        log.trace("read line: " + currentLine);
    119133
    120134                        // empty line
    121                         if (line.length() == 0) {
     135                        if (currentLine.length() == 0) {
    122136                                continue;
    123137                        }
    124138
    125139                        // check if some file should be included
    126                         if (isIncludeLine(line) == LoopAction.Continue) {
     140                        if (isIncludeLine(currentLine) == LoopAction.Continue) {
    127141                                continue;
    128142                        }
    129143
    130144                        // check if should break on comment
    131                         if (isCommentLine(line) == LoopAction.Break) {
     145                        if (isCommentLine(currentLine) == LoopAction.Break) {
    132146                                break;
    133147                        }
    134148
    135149                        // get class getName
    136                         if (changeCurrentParamInterface(line) == LoopAction.Break) {
     150                        LoopAction action = changeCurrentParamInterface(currentLine);
     151                        if (action == LoopAction.Break) {
    137152                                break;
    138153                        }
     154                        if (action == LoopAction.Continue) {
     155                                continue;
     156                        }
     157                        log.warn("unknown line: " + currentLine);
    139158                }
    140159
     
    145164         * Checks whether the reader found a known or unknown object and execution
    146165         * should be passed to it.
     166         * @throws Exception
    147167         */
    148168        private LoopAction tryReadObject() throws Exception {
     
    150170                                || (status == Status.BeforeUnknown && lastAccessInterface != null)) {
    151171                        // found object - let it load data
    152             if (lastAccessInterface.getSelected() == null) {
    153                 lastAccessInterface.select(lastAccessInterface.createAccessee());
    154             }
     172                        if (lastAccessInterface.getSelected() == null) {
     173                                lastAccessInterface.select(lastAccessInterface.createAccessee());
     174                        }
     175                        log.trace("loading into " + lastAccessInterface);
    155176                        lastAccessInterface.load(currentSource);
    156177
     
    162183                        return LoopAction.Continue;
    163184                } else if (status == Status.BeforeUnknown) {
    164                         logger.info("Omitting unknown object: " + lastUnknownObjectName);
     185                        log.warn("omitting unknown object: " + lastUnknownObjectName);
    165186
    166187                        // found unknown object
    167188                        emptyParam.load(currentSource);
    168                         status = Status.AfterObject;
     189                        setStatus(Status.AfterObject);
    169190
    170191                        return LoopAction.Continue;
     
    185206                                        int beg = line.indexOf('\"');
    186207                                        if (beg == -1) {
    187                                                 logger.info("Wanted to include some file, but the format is incorrect");
     208                                                log.info("Wanted to include some file, but the format is incorrect");
    188209                                                return LoopAction.Continue;
    189210                                        }
     
    192213                                        int end = includeFileName.indexOf('\"');
    193214                                        if (end == -1) {
    194                                                 logger.info("Wanted to include some file, but the format is incorrect");
     215                                                log.info("Wanted to include some file, but the format is incorrect");
    195216                                                return LoopAction.Continue;
    196217                                        }
     
    235256                        if (lastAccessInterface != null) {
    236257                                if (isBreakCondition(Status.BeforeObject)) {
    237                                         logger.info("Breaking before object");
     258                                        log.debug("breaking before object");
    238259                                        return LoopAction.Break;
     260                                } else {
     261                                        return LoopAction.Continue;
    239262                                }
    240263                        } else {
    241264                                lastUnknownObjectName = typeName;
    242265                                if (isBreakCondition(Status.BeforeUnknown)) {
    243                                         logger.info("Breaking before unknown");
     266                                        log.debug("breaking before unknown");
    244267                                        return LoopAction.Break;
     268                                } else {
     269                                        return LoopAction.Continue;
    245270                                }
    246271                        }
     
    279304
    280305        private void finish() {
     306                log.trace("finishing");
    281307                if (currentSource != null) {
    282308                        currentSource.close();
    283309                }
    284310
    285                 status = Status.Finished;
     311                setStatus(Status.Finished);
    286312        }
    287313
     
    291317
    292318        public boolean setNewSource(SourceInterface source) {
    293                 logger.debug("switching current source to " + source.getFilename() + "...");
     319                log.debug("switching current source to " + source.getFilename() + "...");
    294320
    295321                currentSource = source;
    296                 status = Status.Loading;
     322                setStatus(Status.Loading);
    297323
    298324                return true;
     
    311337                // check if it is already included and break if it is
    312338                if (isAlreadyIncluded(includeFilename)) {
    313                         logger.debug("circular reference ignored (" + includeFilename
     339                        log.debug("circular reference ignored (" + includeFilename
    314340                                        + ")");
    315341                        return;
    316342                }
    317343
    318                 logger.info("including file " + includeFilename + "...");
     344                log.info("including file " + includeFilename + "...");
    319345
    320346                SourceInterface newSource = currentSource.openInclude(includeFilename);
     
    335361                for (String file : fileStack) {
    336362                        if (filename.equals(file)) {
    337                                 logger.warn("file " + filename + " was already included");
     363                                log.warn("file " + filename + " was already included");
    338364                                return true;
    339365                        }
     
    366392         */
    367393        private boolean isBreakCondition(Status condition) {
    368                 status = condition;
     394                setStatus(condition);
    369395                return breakConditions.contains(condition);
    370396        }
    371397
    372398        public Object returnObject() {
     399                assert lastAccessInterface != null;
    373400                Object result = lastAccessInterface.getSelected();
    374401                if (result == null) {
    375402                        return null;
    376403                }
    377         lastAccessInterface.select(null);
     404                lastAccessInterface.select(null);
    378405                return result;
    379406        }
Note: See TracChangeset for help on using the changeset viewer.