- Timestamp:
- 01/09/13 00:09:10 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java
r77 r78 38 38 this.framsClass = framsClass; 39 39 } 40 41 42 43 44 40 /** 45 41 * Simple String key, value class. 46 42 */ 47 p rivatestatic class Entry {48 49 String key;50 String value;51 52 Entry(String key, String value) {43 public static class Entry { 44 45 public final String key; 46 public final String value; 47 48 public Entry(String key, String value) { 53 49 this.key = key; 54 50 this.value = value; … … 331 327 332 328 Entry entry; 333 334 329 while ((entry = readEntry(source)) != null) { 335 330 Param param = getParam(entry.key); … … 351 346 } 352 347 353 @Override 354 public List<Exception> load2(String line) throws Exception { 355 this.clearValues(); 356 357 // list of not terminable exceptions that occured 358 List<Exception> exceptions = new ArrayList<Exception>(); 359 360 int indexOfColon = line.indexOf(':'); 361 if (indexOfColon < 0) 362 indexOfColon = line.length(); 363 String classId = line.substring(0, indexOfColon).trim(); 364 if (!getId().equals(classId)) 365 throw new Exception( 366 "Inappropriate getId of param interface (class), specified \"" 367 + classId + "\" while should be \"" + getId() 368 + "\""); 369 String parameters; 370 if (indexOfColon == line.length()) 371 parameters = ""; 372 else 373 parameters = line.substring(indexOfColon + 1); 374 375 // tokenize 376 boolean doubleQuotes = false; 377 char previousChar = ','; 378 List<Entry> result = new ArrayList<Entry>(); 379 StringBuilder stringBuilder = new StringBuilder(); 380 String key = ""; 381 if (parameters.trim().length() > 0) { 382 for (char currentChar : parameters.toCharArray()) { 383 if (!doubleQuotes && currentChar == '=' && "".equals(key)) { 384 key = stringBuilder.toString(); 385 stringBuilder = new StringBuilder(); 386 } else if (!doubleQuotes && currentChar == ',') { 387 if (previousChar == ',') { 388 result.add(new Entry(key.trim(), null)); 389 } else { 390 result.add(new Entry(key.trim(), stringBuilder 391 .toString().trim())); 392 } 393 stringBuilder = new StringBuilder(); 394 key = ""; 395 } else if (currentChar == '"') { 396 if (previousChar == '\\') { 397 stringBuilder.deleteCharAt(stringBuilder.length() - 1); 398 stringBuilder.append(currentChar); 399 } else 400 doubleQuotes = !doubleQuotes; 401 } else { 402 stringBuilder.append(currentChar); 403 } 404 405 previousChar = currentChar; 406 } 407 408 String last = stringBuilder.toString().trim(); 409 // if (last.length() > 0 || previousChar == '\"' 410 // || previousChar == ':') 411 result.add(new Entry(key.trim(), last)); 412 413 if (doubleQuotes) 414 throw new Exception( 415 "Double quotes expected while end of line met"); 416 } 417 418 // if successfully parsed set all necessary values 419 420 //TODO: name omitting 421 Param currentParam = null; 422 boolean illegallyOmittedName = false; 423 for (Entry pair : result) { 424 try { 425 426 if (pair.key != null && !"".equals(pair.key)) { 427 Param param = getParam(pair.key); 428 if (param == null) { 429 illegallyOmittedName = true; 430 throw new Exception("No parameter with such id: " 431 + pair.key); 432 } else { 433 currentParam = param; 434 illegallyOmittedName = false; 435 } 436 } else if (illegallyOmittedName 437 || (currentParam.getFlags() & Flags.CANOMITNAME) == 0) { 438 throw new Exception( 439 "Parameter with offset: " 440 + currentParam 441 + " is not set, " 442 + "because it's definition or definition of one of the previous params " 443 + "does not contain flag, which allow to skip the getName (flag 1024)"); 444 } 445 446 if (pair.value != null) { 447 int setFlag = this.set(currentParam, pair.value); 448 if ((setFlag & Flags.PSET_HITMIN) != 0) { 449 exceptions.add(createBoundaryHitException(currentParam, pair.value, Flags.PSET_HITMIN)); 450 } 451 452 if ((setFlag & Flags.PSET_HITMAX) != 0) { 453 exceptions.add(createBoundaryHitException(currentParam, pair.value, Flags.PSET_HITMAX)); 454 } 455 456 if ((setFlag & Flags.PSET_RONLY) != 0) { 457 throw (new Exception( 458 "Tried to set a read-only attribute \"" 459 + currentParam.getId() 460 + "\" in class \"" + getId() + "\"")); 461 } 462 } 463 464 } catch (Exception e) { 465 exceptions.add(e); 466 //} finally { 467 // currentProperty++; 468 } 469 } 470 return exceptions; 471 } 472 473 private Exception createBoundaryHitException(Param param, String value, int flag) { 474 boolean minimum = (flag & Flags.PSET_HITMIN) != 0; 475 String boundary = (minimum ? param.getMin(Object.class) : param.getMax(Object.class)).toString(); 476 String name = (minimum ? "minimum" : "maximum"); 477 return new Exception("Tried to set attribute \"" 478 + param.getId() 479 + "\" in class \"" 480 + getId() 481 + "\" to value which exceeds " + name + " (" 482 + value 483 + "), truncated to: " 484 + boundary); 485 } 486 348 349 487 350 protected abstract <T> void internalSet(Param param, T value); 488 351
Note: See TracChangeset
for help on using the changeset viewer.