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;
05:
06: import org.apache.xmlbeans.XmlObject;
07:
08: import com.terracottatech.config.ClassExpression;
09: 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: } else {
24: return new ExcludeRule((ClassExpression) xmlObject);
25: }
26: }
27:
28: protected Rule(Include include) {
29: setXmlObject(include);
30: }
31:
32: protected Rule(ClassExpression exclude) {
33: setXmlObject(exclude);
34: }
35:
36: public int getType() {
37: return m_xmlObject instanceof Include ? INCLUDE_RULE
38: : 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)
55: && !(xmlObject instanceof ClassExpression)) {
56: throw new AssertionError("xmlObject of wrong type");
57: }
58: }
59:
60: public void setXmlObject(XmlObject xmlObject) {
61: validate(xmlObject);
62: m_xmlObject = xmlObject;
63: }
64:
65: protected XmlObject getXmlObject() {
66: return m_xmlObject;
67: }
68:
69: public abstract String getExpression();
70:
71: public abstract void setExpression(String expr);
72:
73: public abstract RuleDetail getDetails();
74:
75: public abstract void setDetails(RuleDetail details);
76: }
|