(External ex, Map<String, Box> specialBoxes)
| 394 | private void fromExternal(External ex, Map<String, Box> specialBoxes) { |
| 395 | |
| 396 | File dataFile = filenameFor(ex.dataFile); |
| 397 | |
| 398 | String currentPrefix = dataFile.getParent(); |
| 399 | |
| 400 | Map<String, List<Object>> options = null; |
| 401 | if (pluginList != null) try { |
| 402 | options = pluginList.read(dataFile.getAbsolutePath(), false); |
| 403 | pluginList.interpretClassPathAndOptions(options); |
| 404 | } catch (Throwable e) { |
| 405 | Log.log("io.error", () -> "trouble loading external " + dataFile + ". Corrupt file?"); |
| 406 | System.err.println(" io error : trouble loading external " + dataFile + ". corrupt?"); |
| 407 | e.printStackTrace(); |
| 408 | } |
| 409 | |
| 410 | try { |
| 411 | Class c = this.getClass() |
| 412 | .getClassLoader() |
| 413 | .loadClass(ex.boxClass); |
| 414 | try { |
| 415 | Constructor<Box> cc = c.getDeclaredConstructor(); |
| 416 | cc.setAccessible(true); |
| 417 | ex.box = cc.newInstance(); |
| 418 | ex.box.properties.put(desiredBoxClass, ex.boxClass); |
| 419 | } catch (NoSuchMethodException e) { |
| 420 | Constructor<Box> cc = c.getDeclaredConstructor(Box.class); |
| 421 | cc.setAccessible(true); |
| 422 | ex.box = cc.newInstance(specialBoxes.get(">>root<<")); |
| 423 | } |
| 424 | } catch (Throwable e) { |
| 425 | Log.log("io.error", () -> " while looking for class <" + ex.boxClass + "> needed for <" + ex.id + " / " + ex.textFiles + "> an exception was thrown"); |
| 426 | Log.log("io.error", () -> e); |
| 427 | Log.log("io.error", () -> " will proceed with just a vanilla Box class, but custom behavior will be lost "); |
| 428 | ex.box = new Box(); |
| 429 | |
| 430 | ex.box.properties.put(desiredBoxClass, ex.boxClass); |
| 431 | } |
| 432 | |
| 433 | for (Map.Entry<String, String> e : ex.textFiles.entrySet()) { |
| 434 | File filename = filenameFor(currentPrefix, e.getValue()); |
| 435 | String text = readFromFile(filename); |
| 436 | ex.box.properties.put(new Dict.Prop<String>(e.getKey()), text); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | String read = readFromFile(dataFile); |
| 441 | if (read != null) { |
| 442 | try { |
| 443 | Map<?, ?> m = (Map) serializeFromString(read); |
| 444 | for (Map.Entry<?, ?> entry : m.entrySet()) { |
| 445 | Dict.Prop p = new Dict.Prop((String) entry.getKey()); |
| 446 | p.toCanon().getAttributes().put(persistent, true); |
| 447 | ex.box.properties.put(p, entry.getValue()); |
| 448 | } |
| 449 | } catch (Exception e) { |
| 450 | Log.log("io.error", () -> "trouble loading external " + dataFile + ". Corrupt file?"); |
| 451 | e.printStackTrace(); |
| 452 | } |
| 453 | } |
no test coverage detected