- Timestamp:
- 06/28/13 11:56:03 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/parsers/MultiParamLoader.java
r86 r87 9 9 10 10 public class MultiParamLoader { 11 12 public interface StatusListener { 13 void onStatusChange(); 14 } 15 11 16 private final static Logger log = Logger.getLogger(MultiParamLoader.class); 12 17 … … 27 32 } 28 33 34 protected final Map<Status, List<StatusListener>> listeners = new HashMap<>(); 35 29 36 /** 30 37 * Specifies the action that should be taken inside loops. … … 36 43 protected AccessInterface lastAccessInterface; 37 44 45 protected static FramsClass emptyFramsClass = FramsClass.build().idAndName("<empty>").finish(); 38 46 /** 39 47 * Empty Param representing unknown classes - used to omit unknown 40 48 * objects in the file. 41 49 */ 42 protected AccessInterface emptyParam = new PropertiesAccess( new FramsClass());50 protected AccessInterface emptyParam = new PropertiesAccess(emptyFramsClass); 43 51 44 52 /** … … 57 65 private Status status = Status.None; 58 66 59 private void setStatus(Status status) {60 log.trace("changing status: " + this.status.toString() + " -> " + status.toString());61 this.status = status;62 }63 67 64 68 /** … … 176 180 lastAccessInterface.load(currentSource); 177 181 178 if (isBreakCondition(Status.AfterObject)) { 179 // break after object creation 182 if (changeStatus(Status.AfterObject)) { 180 183 return LoopAction.Break; 181 184 } 182 183 185 return LoopAction.Continue; 184 186 } else if (status == Status.BeforeUnknown) { … … 187 189 // found unknown object 188 190 emptyParam.load(currentSource); 189 setStatus(Status.AfterObject); 190 191 if (changeStatus(Status.AfterObject)) { 192 return LoopAction.Break; 193 } 191 194 return LoopAction.Continue; 192 195 } … … 236 239 */ 237 240 private LoopAction isCommentLine(String line) { 238 if (line.charAt(0) == '#' && isBreakCondition(Status.OnComment)) { 239 // it's a simple comment - maybe we should break? 241 if (line.charAt(0) == '#') { 240 242 lastComment = line; 241 return LoopAction.Break; 242 } 243 243 if (changeStatus(Status.OnComment)) { 244 // it's a simple comment - maybe we should break? 245 return LoopAction.Break; 246 } 247 } 244 248 return LoopAction.Nothing; 245 249 } … … 255 259 256 260 if (lastAccessInterface != null) { 257 if (isBreakCondition(Status.BeforeObject)) { 258 log.debug("breaking before object"); 261 if (changeStatus(Status.BeforeObject)) { 259 262 return LoopAction.Break; 260 263 } else { … … 263 266 } else { 264 267 lastUnknownObjectName = typeName; 265 if (isBreakCondition(Status.BeforeUnknown)) { 266 log.debug("breaking before unknown"); 268 if (changeStatus(Status.BeforeUnknown)) { 267 269 return LoopAction.Break; 268 270 } else { … … 309 311 } 310 312 311 setStatus(Status.Finished);313 changeStatus(Status.Finished); 312 314 } 313 315 … … 320 322 321 323 currentSource = source; 322 setStatus(Status.Loading);324 changeStatus(Status.Loading); 323 325 324 326 return true; … … 391 393 * Checks whether execution should break on selected condition. 392 394 */ 393 private boolean isBreakCondition(Status condition) { 394 setStatus(condition); 395 return breakConditions.contains(condition); 395 private boolean changeStatus(Status status) { 396 log.trace("changing status: " + this.status.toString() + " -> " + status.toString()); 397 this.status = status; 398 if (listeners.containsKey(status)) { 399 for (StatusListener l : listeners.get(status)) { 400 l.onStatusChange(); 401 } 402 } 403 return breakConditions.contains(status); 396 404 } 397 405 … … 405 413 return result; 406 414 } 415 416 public void addListener(Status status, StatusListener listener) { 417 if (!listeners.containsKey(status)) { 418 listeners.put(status, new LinkedList<StatusListener>()); 419 } 420 listeners.get(status).add(listener); 421 } 407 422 }
Note: See TracChangeset
for help on using the changeset viewer.