All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickntap.smart.SmartAction Maven / Gradle / Ivy

There is a newer version: 1.189
Show newest version
package com.clickntap.smart;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;
import org.springframework.util.StringUtils;

public class SmartAction {

  public String target;

  private List loads;
  private List binds;
  private List inits;
  private List execs;
  private List rules;
  private List elses;

  public SmartAction(Element actionElement) {
    target = actionElement.attributeValue("target");
    List initElements = actionElement.elements("init");
    inits = new ArrayList(initElements.size());
    for (Element initElement : initElements)
      inits.add(initElement.getTextTrim());
    List bindElements = actionElement.elements("bind");
    binds = new ArrayList(bindElements.size());
    for (Element bindElement : bindElements)
      binds.add(new BindingElement(bindElement));
    List loadElements = actionElement.elements("load");
    loads = new ArrayList(loadElements.size());
    for (Element loadElement : loadElements)
      loads.add(new BindingElement(loadElement));
    List execElements = actionElement.elements("exec");
    execs = new ArrayList(execElements.size());
    for (Element execElement : execElements)
      execs.add(execElement.getTextTrim());
    List ruleElements = actionElement.elements("rule");
    rules = new ArrayList(ruleElements.size());
    for (Element ruleElement : ruleElements)
      rules.add(ruleElement.getTextTrim());
    List elseElements = actionElement.elements("else");
    elses = new ArrayList(elseElements.size());
    for (Element elseElement : elseElements)
      elses.add(elseElement.getTextTrim());
  }

  public String getTarget() {
    return target;
  }

  public List getInits() {
    return inits;
  }

  public List getExecs() {
    return execs;
  }

  public List getRules() {
    return rules;
  }

  public List getBinds() {
    return binds;
  }

  public List getLoads() {
    return loads;
  }

  public List getElses() {
    return elses;
  }

  public class BindingElement {
    private String objectClass;
    private String objectName;
    private String[] allowedFields;
    private String[] disallowedFields;
    private String scope;
    private String channel;
    private String validationGroup;
    private String script;

    public BindingElement(Element element) {
      this.objectClass = element.attributeValue("class");
      this.objectName = element.attributeValue("name");
      this.allowedFields = StringUtils.commaDelimitedListToStringArray(element.attributeValue("allowedFields"));
      this.disallowedFields = StringUtils.commaDelimitedListToStringArray(element.attributeValue("disallowedFields"));
      this.scope = element.attributeValue("scope");
      this.channel = element.attributeValue("channel");
      this.validationGroup = element.attributeValue("validation-group");
      this.script = element.getTextTrim();
    }

    public String getScript() {
      return script;
    }

    public String getValidationGroup() {
      return validationGroup;
    }

    public String getObjectClass() {
      return objectClass;
    }

    public String getObjectName() {
      return objectName;
    }

    public String[] getAllowedFields() {
      return allowedFields;
    }

    public String[] getDisallowedFields() {
      return disallowedFields;
    }

    public String getChannel(String context) {
      return channel + context;
    }

    public String getScope() {
      return scope;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy