IncludeOnLoad.java :  » Net » Terracotta » com » tc » object » config » schema » Java Open Source

Java Open Source » Net » Terracotta 
Terracotta » com » tc » object » config » schema » IncludeOnLoad.java
/*
 * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
 */
package com.tc.object.config.schema;

import com.tc.util.Assert;

/**
 * Represents the on-load xs:choice element
 */
public class IncludeOnLoad {

  private static final int UNDEFINED        = -1;

  public static final int  METHOD           = 0; // String
  public static final int  CALL_CONSTRUCTOR = 1; // Boolean
  public static final int  EXECUTE          = 2; // String

  private int              type;
  private Object           value;

  public IncludeOnLoad() {
    this(UNDEFINED, null);
  }

  public IncludeOnLoad(int type, Object value) {
    this.type = type;
    this.value = value;
  }

  public boolean isCallConstructorOnLoadType() {
    return type == CALL_CONSTRUCTOR;
  }

  public boolean isExecuteScriptOnLoadType() {
    return type == EXECUTE;
  }

  public boolean isCallMethodOnLoadType() {
    return type == METHOD;
  }

  public boolean isCallConstructorOnLoad() {
    if (!isCallConstructorOnLoadType()) { return false; }
    return ((Boolean) value).booleanValue();
  }

  public String getExecuteScript() {
    Assert.eval(isExecuteScriptOnLoadType());
    return (String) value;
  }

  public String getMethod() {
    Assert.eval(isCallMethodOnLoadType());
    return (String) value;
  }

  public void setToCallConstructorOnLoad(boolean b) {
    this.type = CALL_CONSTRUCTOR;
    this.value = new Boolean(b);
  }

  public void setExecuteScriptOnLoad(String script) {
    this.type = EXECUTE;
    this.value = script;
  }

  public void setMethodCallOnLoad(String method) {
    this.type = METHOD;
    this.value = method;
  }

  public int type() {
    return type;
  }

  public Object value() {
    return value;
  }

  public String toString() {
    return "type: " + type + " value=" + value;
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.