01: /*
02: * ScriptLimits.java
03: *
04: * ===========================================================================
05: */
06: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
07: * Copyright 2007 Laszlo Systems, Inc. All Rights Reserved. *
08: * Use is subject to license terms. *
09: * J_LZ_COPYRIGHT_END *********************************************************/
10: package org.openlaszlo.iv.flash.api;
11:
12: import java.io.PrintStream;
13: import org.openlaszlo.iv.flash.util.*;
14: import org.openlaszlo.iv.flash.parser.*;
15: import org.openlaszlo.iv.flash.api.*;
16: import org.openlaszlo.iv.flash.api.action.*;
17:
18: public class ScriptLimits extends FlashDef {
19:
20: int recursion = 0;
21: int timeout = 0;
22:
23: // Determined empirically
24: public static int DEFAULT_RECURSION = 256;
25: public static int DEFAULT_TIMEOUT = 15;
26:
27: public ScriptLimits(int recursion, int timeout) {
28: this .recursion = (recursion == 0 ? DEFAULT_RECURSION
29: : recursion);
30: this .timeout = (timeout == 0 ? DEFAULT_TIMEOUT : timeout);
31: }
32:
33: public ScriptLimits() {
34: this .recursion = DEFAULT_RECURSION;
35: this .timeout = DEFAULT_TIMEOUT;
36: }
37:
38: public int getTag() {
39: return Tag.SCRIPTLIMITS;
40: }
41:
42: /* This tag set script execution limits (added to the player as of
43: * Flash 8).
44: *
45: * according to FLASM, the tag looks like this
46:
47: writeTagHeader(TAG_SCRIPTLIMITS, 4);
48: flputShort(recursion);
49: flputShort(timeout);
50:
51: */
52:
53: private int tagcode; // tag of this obj
54:
55: public static ScriptLimits parse(Parser p) {
56: ScriptLimits o = new ScriptLimits();
57:
58: o.tagcode = p.getTagCode();
59: o.recursion = p.getUWord();
60: o.timeout = p.getUWord();
61: return o;
62: }
63:
64: public void write(FlashOutput fob) {
65: fob.writeTag(getTag(), 4);
66: fob.writeWord(recursion); // recursion max depth
67: fob.writeWord(timeout); // timeout in seconds
68: }
69:
70: public boolean isConstant() {
71: return true;
72: }
73:
74: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
75: super .copyInto(item, copier);
76:
77: ((ScriptLimits) item).tagcode = tagcode;
78: ((ScriptLimits) item).recursion = recursion;
79: ((ScriptLimits) item).timeout = timeout;
80: return item;
81: }
82:
83: public FlashItem getCopy(ScriptCopier copier) {
84: return copyInto(new ScriptLimits(), copier);
85: }
86:
87: public void printContent(PrintStream out, String indent) {
88: if (getTag() == Tag.SCRIPTLIMITS) {
89: out.println(indent + "ScriptLimits");
90: } else {
91: out.println(indent + "ScriptLimits!");
92: }
93:
94: out.println(indent + " recursion: " + recursion);
95: out.println(indent + " timeout: " + timeout);
96: }
97: }
|