/* */ package NET.worlds.scape; /* */ /* */ import NET.worlds.console.Console; /* */ import NET.worlds.network.URL; /* */ import java.io.ByteArrayOutputStream; /* */ import java.io.DataInputStream; /* */ import java.io.DataOutputStream; /* */ import java.io.IOException; /* */ import java.io.PrintStream; /* */ import java.text.MessageFormat; /* */ import java.util.Enumeration; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class DynamicForwardAttribute /* */ extends Attribute /* */ implements NonPersister, WobLoaded /* */ { /* 43 */ WObject wob = null; /* */ /* */ DynamicForwardAttribute(int attrID) /* */ { /* 47 */ super(attrID); /* */ } /* */ /* 50 */ static int DYNAMIC_CODE = 21990; /* */ /* */ WobLoader wobLoader; /* */ DataInputStream wobLoaderProps; /* */ /* */ private URL getDynamicHeader(DataInputStream ds) /* */ { /* */ try /* */ { /* 59 */ if (ds.readUnsignedShort() != DYNAMIC_CODE) { /* 60 */ return null; /* */ } /* 62 */ return new URL(this, ds.readUTF()); /* */ } /* */ catch (IOException e) {} /* 65 */ return null; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void setFromNetData(DataInputStream ds, int len) /* */ throws IOException /* */ { /* 84 */ URL wobName = getDynamicHeader(ds); /* 85 */ if ((wobName == null) || (this.wob == null) || /* 86 */ (!wobName.equals(this.wob.getSourceURL()))) /* */ { /* */ /* 89 */ if (this.wob != null) /* */ { /* */ /* */ /* 93 */ WObject w = this.wob; /* 94 */ this.wob = null; /* 95 */ w.detach(); /* */ } /* */ /* */ /* 99 */ if (wobName == null) /* */ { /* 101 */ ((Sharer)getOwner()).removeAttribute(this); /* 102 */ return; /* */ } /* */ /* */ /* */ /* 107 */ if ((this.wobLoader == null) || (!this.wobLoader.getWobName().equals(wobName))) { /* 108 */ this.wobLoader = new WobLoader(wobName, this); /* */ } /* */ /* 111 */ this.wobLoaderProps = ds; /* */ } /* */ else /* */ { /* 115 */ setProps(ds); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ public void wobLoaded(WobLoader loader, SuperRoot w) /* */ { /* 124 */ if (loader != this.wobLoader) { /* 125 */ return; /* */ } /* 127 */ Object[] arguments = { new String( /* 128 */ loader.getWobName().toString()) }; /* */ /* 130 */ if (w == null) /* */ { /* */ /* */ /* 134 */ Console.println(MessageFormat.format( /* 135 */ Console.message("Couldnt-load"), arguments)); /* 136 */ this.wobLoaderProps = null; /* 137 */ return; } /* 138 */ if (!(w instanceof WObject)) { /* 139 */ Console.println(MessageFormat.format( /* 140 */ Console.message("not-WObject"), arguments)); /* 141 */ this.wobLoaderProps = null; /* 142 */ return; /* */ } /* */ /* 145 */ this.wob = ((WObject)w); /* */ /* */ /* 148 */ this.wob.getSharer().createDynamicForwardedFromNet(this); /* */ /* */ /* 151 */ ((WObject)getOwner().getOwner()).add(this.wob); /* */ /* */ /* 154 */ setProps(this.wobLoaderProps); /* 155 */ this.wobLoaderProps = null; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ void connect(WObject w) /* */ { /* 164 */ assert (this.wob == null); /* 165 */ this.wob = w; /* */ /* 167 */ noteChange(); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ void unconnect() /* */ { /* 177 */ if (this.wob != null) /* */ { /* 179 */ this.wob = null; /* 180 */ noteChange(); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void setProps(DataInputStream ds) /* */ { /* */ for (;;) /* */ { /* */ try /* */ { /* */ int id; /* */ /* */ /* */ /* */ /* 200 */ if ((id = ds.read()) == -1) { /* 201 */ return; /* */ } /* 203 */ int len = ds.readByte(); /* 204 */ byte[] b = new byte[len]; /* 205 */ ds.readFully(b, 0, len); } catch (IOException e) { break; } /* */ int len; /* */ byte[] b; /* */ int id; /* 209 */ this.wob.getSharer().setFromNetData(id, b); /* */ } /* */ /* 212 */ Object[] arguments = { new String(getAttrID()) }; /* 213 */ Console.println(MessageFormat.format( /* 214 */ Console.message("Early-EOF"), arguments)); /* */ } /* */ /* */ /* */ /* */ /* */ /* 221 */ private ByteArrayOutputStream _bs = new ByteArrayOutputStream(); /* */ /* */ /* */ /* */ /* */ public void generateNetData(DataOutputStream s) /* */ throws IOException /* */ { /* 229 */ if ((this.wob == null) || (this.wob.getSourceURL() == null)) { /* 230 */ return; /* */ } /* 232 */ s.writeShort(DYNAMIC_CODE); /* */ /* 234 */ s.writeUTF(this.wob.getSourceURL().getRelativeTo(this)); /* */ /* */ /* 237 */ Enumeration e = this.wob.getSharer().getAttributes(); /* 238 */ while (e.hasMoreElements()) /* */ { /* */ /* 241 */ Attribute a = (Attribute)e.nextElement(); /* 242 */ s.writeByte(a.getAttrID()); /* */ /* 244 */ this._bs.reset(); /* */ try { /* 246 */ a.generateNetData(new DataOutputStream(this._bs)); /* */ } /* */ catch (IOException ex) /* */ { /* 250 */ System.err.println(ex); /* 251 */ throw new Error("Fatal in generateNetData"); /* */ } /* */ /* 254 */ s.writeByte(this._bs.size()); /* 255 */ this._bs.writeTo(s); /* */ } /* */ } /* */ /* */ /* */ protected void noteAddingTo(SuperRoot owner) /* */ { /* 262 */ WObject w = (WObject)owner.getOwner(); /* 263 */ if ((w.getSharer().getMode() & 0x1) != 0) { /* 264 */ throw new ClassCastException( /* 265 */ "Must forward to unforwarded object"); /* */ } /* */ } /* */ /* */ public void detach() { /* 270 */ if ((this.wob == null) && (!this._waitingForFeedback)) /* */ { /* 272 */ this.wobLoader = null; /* 273 */ super.detach(); /* */ } /* */ else /* */ { /* 277 */ Console.println(Console.message("Shutting-down")); /* 278 */ if (this.wob != null) { /* 279 */ this.wob.detach(); /* */ } /* */ } /* */ } /* */ /* */ public void setAttrID(int newID) { /* 285 */ Console.println(Console.message("Cant-change-ID")); /* */ } /* */ /* */ public String toString() /* */ { /* 290 */ if (this.wob == null) { /* 291 */ return super.toString(); /* */ } /* 293 */ return /* 294 */ super.toString() + "[forwarding wob " + this.wob.getName() + "]"; /* */ } /* */ /* */ public void restoreState(Restorer r) /* */ throws IOException, TooNewException /* */ { /* 300 */ if (!$assertionsDisabled) throw new AssertionError(); /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\DynamicForwardAttribute.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */