01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.config.schema;
05:
06: import com.tc.util.Assert;
07:
08: /**
09: * Represents the on-load xs:choice element
10: */
11: public class IncludeOnLoad {
12:
13: private static final int UNDEFINED = -1;
14:
15: public static final int METHOD = 0; // String
16: public static final int CALL_CONSTRUCTOR = 1; // Boolean
17: public static final int EXECUTE = 2; // String
18:
19: private int type;
20: private Object value;
21:
22: public IncludeOnLoad() {
23: this (UNDEFINED, null);
24: }
25:
26: public IncludeOnLoad(int type, Object value) {
27: this .type = type;
28: this .value = value;
29: }
30:
31: public boolean isCallConstructorOnLoadType() {
32: return type == CALL_CONSTRUCTOR;
33: }
34:
35: public boolean isExecuteScriptOnLoadType() {
36: return type == EXECUTE;
37: }
38:
39: public boolean isCallMethodOnLoadType() {
40: return type == METHOD;
41: }
42:
43: public boolean isCallConstructorOnLoad() {
44: if (!isCallConstructorOnLoadType()) {
45: return false;
46: }
47: return ((Boolean) value).booleanValue();
48: }
49:
50: public String getExecuteScript() {
51: Assert.eval(isExecuteScriptOnLoadType());
52: return (String) value;
53: }
54:
55: public String getMethod() {
56: Assert.eval(isCallMethodOnLoadType());
57: return (String) value;
58: }
59:
60: public void setToCallConstructorOnLoad(boolean b) {
61: this .type = CALL_CONSTRUCTOR;
62: this .value = new Boolean(b);
63: }
64:
65: public void setExecuteScriptOnLoad(String script) {
66: this .type = EXECUTE;
67: this .value = script;
68: }
69:
70: public void setMethodCallOnLoad(String method) {
71: this .type = METHOD;
72: this .value = method;
73: }
74:
75: public int type() {
76: return type;
77: }
78:
79: public Object value() {
80: return value;
81: }
82:
83: public String toString() {
84: return "type: " + type + " value=" + value;
85: }
86:
87: }
|