- Timestamp:
- 06/26/13 13:27:31 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/parsers/MultiParamLoader.java
r77 r86 9 9 10 10 public class MultiParamLoader { 11 private final static Logger logger = Logger 12 .getLogger(MultiParamLoader.class.getName()); 11 private final static Logger log = Logger.getLogger(MultiParamLoader.class); 13 12 14 13 /** … … 56 55 * Status of current execution. 57 56 */ 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 } 59 63 60 64 /** … … 62 66 */ 63 67 private SourceInterface currentSource; 68 69 protected String currentLine; 64 70 65 71 … … 86 92 private String lastUnknownObjectName; 87 93 94 /** 95 * @return the currentLine 96 */ 97 public String getCurrentLine() { 98 return currentLine; 99 } 100 88 101 public MultiParamLoader() { 89 102 … … 94 107 */ 95 108 public Status go() throws Exception { 96 log ger.trace("go");109 log.trace("go"); 97 110 98 111 while (!isFinished()) { … … 106 119 107 120 // read data 108 String line = currentSource.readLine();121 currentLine = currentSource.readLine(); 109 122 110 123 // end of file 111 if ( line == null) {124 if (currentLine == null) { 112 125 if (!returnFromIncluded()) { 113 126 finish(); … … 117 130 } 118 131 } 132 log.trace("read line: " + currentLine); 119 133 120 134 // empty line 121 if ( line.length() == 0) {135 if (currentLine.length() == 0) { 122 136 continue; 123 137 } 124 138 125 139 // check if some file should be included 126 if (isIncludeLine( line) == LoopAction.Continue) {140 if (isIncludeLine(currentLine) == LoopAction.Continue) { 127 141 continue; 128 142 } 129 143 130 144 // check if should break on comment 131 if (isCommentLine( line) == LoopAction.Break) {145 if (isCommentLine(currentLine) == LoopAction.Break) { 132 146 break; 133 147 } 134 148 135 149 // get class getName 136 if (changeCurrentParamInterface(line) == LoopAction.Break) { 150 LoopAction action = changeCurrentParamInterface(currentLine); 151 if (action == LoopAction.Break) { 137 152 break; 138 153 } 154 if (action == LoopAction.Continue) { 155 continue; 156 } 157 log.warn("unknown line: " + currentLine); 139 158 } 140 159 … … 145 164 * Checks whether the reader found a known or unknown object and execution 146 165 * should be passed to it. 166 * @throws Exception 147 167 */ 148 168 private LoopAction tryReadObject() throws Exception { … … 150 170 || (status == Status.BeforeUnknown && lastAccessInterface != null)) { 151 171 // 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); 155 176 lastAccessInterface.load(currentSource); 156 177 … … 162 183 return LoopAction.Continue; 163 184 } else if (status == Status.BeforeUnknown) { 164 log ger.info("Omitting unknown object: " + lastUnknownObjectName);185 log.warn("omitting unknown object: " + lastUnknownObjectName); 165 186 166 187 // found unknown object 167 188 emptyParam.load(currentSource); 168 s tatus = Status.AfterObject;189 setStatus(Status.AfterObject); 169 190 170 191 return LoopAction.Continue; … … 185 206 int beg = line.indexOf('\"'); 186 207 if (beg == -1) { 187 log ger.info("Wanted to include some file, but the format is incorrect");208 log.info("Wanted to include some file, but the format is incorrect"); 188 209 return LoopAction.Continue; 189 210 } … … 192 213 int end = includeFileName.indexOf('\"'); 193 214 if (end == -1) { 194 log ger.info("Wanted to include some file, but the format is incorrect");215 log.info("Wanted to include some file, but the format is incorrect"); 195 216 return LoopAction.Continue; 196 217 } … … 235 256 if (lastAccessInterface != null) { 236 257 if (isBreakCondition(Status.BeforeObject)) { 237 log ger.info("Breaking before object");258 log.debug("breaking before object"); 238 259 return LoopAction.Break; 260 } else { 261 return LoopAction.Continue; 239 262 } 240 263 } else { 241 264 lastUnknownObjectName = typeName; 242 265 if (isBreakCondition(Status.BeforeUnknown)) { 243 log ger.info("Breaking before unknown");266 log.debug("breaking before unknown"); 244 267 return LoopAction.Break; 268 } else { 269 return LoopAction.Continue; 245 270 } 246 271 } … … 279 304 280 305 private void finish() { 306 log.trace("finishing"); 281 307 if (currentSource != null) { 282 308 currentSource.close(); 283 309 } 284 310 285 s tatus = Status.Finished;311 setStatus(Status.Finished); 286 312 } 287 313 … … 291 317 292 318 public boolean setNewSource(SourceInterface source) { 293 log ger.debug("switching current source to " + source.getFilename() + "...");319 log.debug("switching current source to " + source.getFilename() + "..."); 294 320 295 321 currentSource = source; 296 s tatus = Status.Loading;322 setStatus(Status.Loading); 297 323 298 324 return true; … … 311 337 // check if it is already included and break if it is 312 338 if (isAlreadyIncluded(includeFilename)) { 313 log ger.debug("circular reference ignored (" + includeFilename339 log.debug("circular reference ignored (" + includeFilename 314 340 + ")"); 315 341 return; 316 342 } 317 343 318 log ger.info("including file " + includeFilename + "...");344 log.info("including file " + includeFilename + "..."); 319 345 320 346 SourceInterface newSource = currentSource.openInclude(includeFilename); … … 335 361 for (String file : fileStack) { 336 362 if (filename.equals(file)) { 337 log ger.warn("file " + filename + " was already included");363 log.warn("file " + filename + " was already included"); 338 364 return true; 339 365 } … … 366 392 */ 367 393 private boolean isBreakCondition(Status condition) { 368 s tatus = condition;394 setStatus(condition); 369 395 return breakConditions.contains(condition); 370 396 } 371 397 372 398 public Object returnObject() { 399 assert lastAccessInterface != null; 373 400 Object result = lastAccessInterface.getSelected(); 374 401 if (result == null) { 375 402 return null; 376 403 } 377 404 lastAccessInterface.select(null); 378 405 return result; 379 406 }
Note: See TracChangeset
for help on using the changeset viewer.