1 4 package org.terracotta.dso.editors; 5 6 import org.apache.xmlbeans.XmlObject; 7 8 import com.terracottatech.config.ClassExpression; 9 import com.terracottatech.config.Include; 10 11 public abstract class Rule { 12 public static final int INCLUDE_RULE = 0; 13 public static final int EXCLUDE_RULE = 1; 14 public static final int DEFAULT_TYPE = INCLUDE_RULE; 15 16 protected XmlObject m_xmlObject; 17 18 public static Rule create(XmlObject xmlObject) { 19 validate(xmlObject); 20 21 if(xmlObject instanceof Include) { 22 return new IncludeRule((Include)xmlObject); 23 } 24 else { 25 return new ExcludeRule((ClassExpression)xmlObject); 26 } 27 } 28 29 protected Rule(Include include) { 30 setXmlObject(include); 31 } 32 33 protected Rule(ClassExpression exclude) { 34 setXmlObject(exclude); 35 } 36 37 public int getType() { 38 return m_xmlObject instanceof Include ? INCLUDE_RULE : EXCLUDE_RULE; 39 } 40 41 public boolean isIncludeRule() { 42 return getType() == INCLUDE_RULE; 43 } 44 45 public boolean isExcludeRule() { 46 return !isIncludeRule(); 47 } 48 49 private static void validate(XmlObject xmlObject) { 50 if(xmlObject == null) { 51 throw new AssertionError ("xmlObject is null"); 52 } 53 54 if(!(xmlObject instanceof Include) && !(xmlObject instanceof ClassExpression)) { 55 throw new AssertionError ("xmlObject of wrong type"); 56 } 57 } 58 59 public void setXmlObject(XmlObject xmlObject) { 60 validate(xmlObject); 61 m_xmlObject = xmlObject; 62 } 63 64 protected XmlObject getXmlObject() { 65 return m_xmlObject; 66 } 67 68 public abstract String getExpression(); 69 public abstract void setExpression(String expr); 70 71 public abstract RuleDetail getDetails(); 72 public abstract void setDetails(RuleDetail details); 73 } 74 | Popular Tags |