diff options
Diffstat (limited to 'NET/worlds/scape/SuperRoot.java')
| -rw-r--r-- | NET/worlds/scape/SuperRoot.java | 742 |
1 files changed, 742 insertions, 0 deletions
diff --git a/NET/worlds/scape/SuperRoot.java b/NET/worlds/scape/SuperRoot.java new file mode 100644 index 0000000..9a3b9e7 --- /dev/null +++ b/NET/worlds/scape/SuperRoot.java @@ -0,0 +1,742 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import NET.worlds.console.Console; +/* */ import NET.worlds.network.URL; +/* */ import java.io.ByteArrayInputStream; +/* */ import java.io.ByteArrayOutputStream; +/* */ import java.io.DataInputStream; +/* */ import java.io.DataOutputStream; +/* */ import java.io.FileNotFoundException; +/* */ import java.io.IOException; +/* */ import java.io.PrintStream; +/* */ import java.text.MessageFormat; +/* */ import java.util.Enumeration; +/* */ import java.util.Hashtable; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class SuperRoot +/* */ implements Properties, Persister +/* */ { +/* */ private String name; +/* */ +/* */ public final String getShortClassName() +/* */ { +/* 128 */ String s = getClass().getName(); +/* */ int index; +/* 130 */ if ((index = s.lastIndexOf('.')) != -1) +/* 131 */ s = s.substring(index + 1); +/* 132 */ return s; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public String getName() +/* */ { +/* 150 */ if (this.name == null) { +/* 151 */ int digits = 0; +/* 152 */ String classname = getShortClassName(); +/* */ +/* 154 */ Enumeration<Object> en = getRoot().getDeepOwned(); +/* */ +/* 156 */ while (en.hasMoreElements()) { +/* 157 */ SuperRoot x = (SuperRoot)en.nextElement(); +/* 158 */ if ((x.name != null) && (x.name.startsWith(classname))) { +/* */ try +/* */ { +/* 161 */ int tmp = Integer.valueOf( +/* 162 */ x.name.substring(classname.length())) +/* 163 */ .intValue(); +/* 164 */ if (tmp > digits) { +/* 165 */ digits = tmp; +/* */ } +/* */ } +/* */ catch (NumberFormatException localNumberFormatException) {} +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* 174 */ digits++; +/* */ +/* */ +/* */ +/* 178 */ this.name = (classname + digits); +/* */ } +/* */ +/* 181 */ return this.name; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public String getNameMaybeNull() +/* */ { +/* 189 */ return this.name; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setName(String v) +/* */ { +/* 200 */ if ((v == null) && +/* 201 */ (this.owner != null)) { +/* 202 */ Object[] arguments = { new String(this.owner.getName()) }; +/* 203 */ Console.println(MessageFormat.format( +/* 204 */ Console.message("Warning-null-name"), arguments)); +/* */ } +/* */ +/* 207 */ this.name = v; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static SuperRoot nameSearch(Enumeration<?> enumeration, String name) +/* */ { +/* 216 */ while (enumeration.hasMoreElements()) { +/* 217 */ SuperRoot n = (SuperRoot)enumeration.nextElement(); +/* 218 */ if (name.equals(n.name)) { +/* 219 */ return n; +/* */ } +/* */ } +/* 222 */ return null; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 236 */ protected static String helpURL = "home:internal/"; +/* */ private SuperRoot owner; +/* */ +/* 239 */ public URL getHelpURL() { String helpString = helpURL + getClass().getName() + +/* 240 */ Console.message(".html"); +/* 241 */ URL helpPage = URL.make(helpString); +/* */ +/* 243 */ if (Console.wasHttpNoSuchFile(helpString)) +/* 244 */ helpPage = URL.make(helpURL + getClass().getName() + ".html"); +/* 245 */ return helpPage; +/* */ } +/* */ +/* */ +/* */ +/* */ public URL getHelpURL(Property p) +/* */ { +/* 252 */ String namesub = p.getName().replace(' ', '_'); +/* 253 */ String helpString = helpURL + getClass().getName() + "#" + namesub + +/* 254 */ Console.message(".html"); +/* 255 */ URL helpPage = URL.make(helpString); +/* 256 */ if (Console.wasHttpNoSuchFile(helpString)) +/* 257 */ helpPage = URL.make(helpURL + getClass().getName() + "#" + namesub + +/* 258 */ ".html"); +/* 259 */ return helpPage; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public String toString() +/* */ { +/* 267 */ if (isActive()) { +/* 268 */ return getName(); +/* */ } +/* 270 */ return getName() + "(inactive)"; +/* */ } +/* */ +/* */ +/* */ public Object properties(int index, int offset, int mode, Object value) +/* */ throws NoSuchPropertyException +/* */ { +/* 277 */ Object ret = null; +/* 278 */ switch (index - offset) { +/* */ case 0: +/* 280 */ if (mode == 0) { +/* 281 */ ret = StringPropertyEditor.make(new Property(this, index, +/* 282 */ "Name")); +/* 283 */ } else if (mode == 1) { +/* 284 */ ret = getName(); +/* 285 */ } else if (mode == 4) { +/* 286 */ setName(null); +/* 287 */ } else if (mode == 2) { +/* 288 */ String s = (String)value; +/* 289 */ if ((s.equals(this.name)) || (this.owner == null) || +/* 290 */ (nameSearch(getRoot().getDeepOwned(), s) == null)) { +/* 291 */ setName((String)value); +/* */ } else { +/* 293 */ Object[] arguments = { new String(s), +/* 294 */ new String(getRoot().getName()) }; +/* 295 */ Console.println(MessageFormat.format( +/* 296 */ Console.message("Name-in-use"), arguments)); +/* */ } +/* */ } +/* 299 */ break; +/* */ +/* */ case 1: +/* 302 */ if (mode == 0) +/* */ { +/* */ +/* 305 */ ret = URLPropertyEditor.make(new Property(this, index, +/* 306 */ "Source URL").allowSetNull(), "*wob", false); +/* 307 */ } else if (mode == 1) { +/* 308 */ ret = this.sourceURL; +/* 309 */ } else if (mode == 2) +/* 310 */ setSourceURL((URL)value); +/* 311 */ break; +/* */ +/* */ default: +/* 314 */ throw new NoSuchPropertyException(); +/* */ } +/* 316 */ return ret; +/* */ } +/* */ +/* */ public Object propertyParent() { +/* 320 */ return this.owner; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public SuperRoot getOwner() +/* */ { +/* 328 */ return this.owner; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void discard() +/* */ { +/* 342 */ detach(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected void add(SuperRoot x) +/* */ { +/* 353 */ if ((x.owner != null) && (x.owner != this)) { +/* 354 */ System.out.println("double-setting owner of " + x + " from " + +/* 355 */ x.owner + " to " + this); +/* 356 */ throw new Error("double-setting owner of " + x); +/* */ } +/* 358 */ x.noteAddingTo(this); +/* 359 */ x.owner = this; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void detach() +/* */ { +/* 368 */ if (this.owner != null) +/* */ { +/* 370 */ this.owner.noteUnadding(this); +/* */ +/* 372 */ this.owner = null; +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected void noteAddingTo(SuperRoot s) {} +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected void noteUnadding(SuperRoot s) {} +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Enumeration<Object> getOwned() +/* */ { +/* 395 */ return new ShallowEnumeration(this); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Enumeration<Object> getDeepOwned() +/* */ { +/* 404 */ return new DeepEnumeration(this); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void getChildren(DeepEnumeration<?> d) {} +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public World getWorld() +/* */ { +/* 420 */ SuperRoot owner = getOwner(); +/* */ +/* 422 */ if (owner == null) { +/* 423 */ return null; +/* */ } +/* 425 */ return owner.getWorld(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Room getRoom() +/* */ { +/* 436 */ SuperRoot owner = getOwner(); +/* */ +/* 438 */ if (owner == null) { +/* 439 */ return null; +/* */ } +/* 441 */ return owner.getRoom(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public SuperRoot getRoot() +/* */ { +/* 449 */ SuperRoot owner = getOwner(); +/* */ +/* 451 */ if (owner == null) { +/* 452 */ return this; +/* */ } +/* 454 */ return owner.getRoot(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public boolean isActive() +/* */ { +/* 464 */ return getWorld() != null; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public URL getSourceURL() +/* */ { +/* 476 */ return this.sourceURL; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public void setSourceURL(URL s) +/* */ { +/* 484 */ this.sourceURL = s; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public URL getContainingSourceURL() +/* */ { +/* 492 */ if (this.sourceURL != null) { +/* 493 */ return this.sourceURL; +/* */ } +/* 495 */ if (this.owner != null) { +/* 496 */ return this.owner.getContainingSourceURL(); +/* */ } +/* 498 */ return null; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void markEdited() +/* */ { +/* 511 */ if (this.owner != null) { +/* 512 */ this.owner.markEdited(); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ public static SuperRoot readFile(String urlLocal, URL url) +/* */ { +/* */ Exception ex; +/* */ +/* */ try +/* */ { +/* 524 */ Restorer r = new Restorer(urlLocal, url); +/* 525 */ SuperRoot o = (SuperRoot)r.restore(); +/* 526 */ r.done(); +/* 527 */ o.setSourceURL(url); +/* 528 */ return o; +/* */ } catch (FileNotFoundException e) { +/* 530 */ ex = e; +/* */ } catch (ClassCastException e) { Exception ex; +/* 532 */ ex = e; +/* */ } catch (IOException e) { Exception ex; +/* 534 */ ex = e; +/* */ } catch (TooNewException e) { Exception ex; +/* 536 */ ex = e; +/* */ } catch (BadFormatException e) { Exception ex; +/* 538 */ ex = e; +/* */ } +/* */ +/* */ +/* */ +/* 543 */ return null; +/* */ } +/* */ +/* */ public static SuperRoot readFile(URL url) { +/* 547 */ return readFile(url.unalias(), url); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected URL sourceURL; +/* */ +/* */ +/* */ +/* */ +/* */ public void loadInit() {} +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void saveFile(URL url) +/* */ throws IOException +/* */ { +/* 568 */ if ((this instanceof NonPersister)) { +/* 569 */ throw new IOException("Can't save NonPersister"); +/* */ } +/* 571 */ Saver s = new Saver(url); +/* 572 */ s.save(this); +/* 573 */ s.done(); +/* 574 */ setSourceURL(url); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Object clone() +/* */ { +/* 584 */ byte[] b = getByteCopy(); +/* */ +/* 586 */ return getCopyFromBytes(b); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public byte[] getByteCopy() +/* */ { +/* 595 */ if ((this instanceof NonPersister)) { +/* 596 */ return null; +/* */ } +/* 598 */ ByteArrayOutputStream buffer = new ByteArrayOutputStream(); +/* */ try { +/* 600 */ Saver saver = new Saver(new DataOutputStream(buffer)); +/* 601 */ saver.save(this); +/* 602 */ saver.done(); +/* 603 */ return buffer.toByteArray(); +/* */ } catch (Exception e) { +/* 605 */ e.printStackTrace(System.out); +/* 606 */ throw new Error("Can't save"); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public static SuperRoot getCopyFromBytes(byte[] b) +/* */ { +/* 615 */ if (b == null) { +/* 616 */ return null; +/* */ } +/* */ try { +/* 619 */ Restorer r = new Restorer(new DataInputStream( +/* 620 */ new ByteArrayInputStream(b))); +/* 621 */ SuperRoot obj = (SuperRoot)r.restore(); +/* 622 */ r.done(); +/* 623 */ return obj; +/* */ } catch (Exception e) { +/* 625 */ e.printStackTrace(System.out); +/* 626 */ throw new Error("Can't restore"); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* 632 */ private static Object classCookie = new Object(); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void saveState(Saver s) +/* */ throws IOException +/* */ { +/* 643 */ s.saveVersion(2, classCookie); +/* 644 */ s.saveString(this.name); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void restoreState(Restorer r) +/* */ throws IOException, TooNewException +/* */ { +/* 658 */ restoreStateSuperRoot(r); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected final void restoreStateSuperRoot(Restorer r) +/* */ throws IOException, TooNewException +/* */ { +/* 668 */ switch (r.restoreVersion(classCookie)) { +/* */ case 1: +/* 670 */ r.setOldFlag(); +/* 671 */ String n; if ((n = r.restoreString()) != null) +/* 672 */ setName(n); +/* 673 */ r.restoreMaybeNull(); +/* 674 */ break; +/* */ case 0: +/* 676 */ r.setOldFlag(); +/* */ case 2: String n; +/* 678 */ if ((n = r.restoreString()) != null) +/* 679 */ setName(n); +/* 680 */ break; +/* */ +/* */ default: +/* 683 */ throw new TooNewException(); +/* */ } +/* */ +/* */ +/* */ String n; +/* */ } +/* */ +/* */ +/* */ public void postRestore(int version) {} +/* */ +/* */ +/* 694 */ static Hashtable<Class<? extends Object>, Integer> finalizedClasses = new Hashtable(); +/* */ +/* */ public static void finalizeCounter(Object o) { +/* 697 */ Class<? extends Object> c = o.getClass(); +/* 698 */ Integer icnt = (Integer)finalizedClasses.get(c); +/* 699 */ int cnt = 0; +/* 700 */ if (icnt != null) { +/* 701 */ cnt = icnt.intValue(); +/* */ } +/* 703 */ cnt++; if (cnt == 1000) { +/* 704 */ System.out.println("Finalized 1000 times: " + c); +/* 705 */ cnt = 0; +/* */ } +/* */ +/* 708 */ finalizedClasses.put(o.getClass(), new Integer(cnt)); +/* */ } +/* */ +/* */ +/* */ protected void finalize() {} +/* */ +/* */ +/* 715 */ static Hashtable<Class<? extends Object>, Integer> classCounter = new Hashtable(); +/* */ +/* */ public static void countClass(Object o, int inc) { +/* 718 */ Class<? extends Object> c = o.getClass(); +/* 719 */ Integer icnt = (Integer)classCounter.get(c); +/* 720 */ int cnt = 0; +/* 721 */ if (icnt != null) { +/* 722 */ cnt = icnt.intValue(); +/* */ } +/* 724 */ cnt += inc; +/* */ +/* 726 */ classCounter.put(c, new Integer(cnt)); +/* */ } +/* */ +/* */ public static void printClassCounts() { +/* 730 */ for (Enumeration<Class<? extends Object>> e = classCounter.keys(); e.hasMoreElements();) { +/* 731 */ Class<?> c = (Class)e.nextElement(); +/* 732 */ System.out.println("Class " + c.getName() + " has " + +/* 733 */ classCounter.get(c)); +/* */ } +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\SuperRoot.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |