01: package org.kohsuke.rngom.digested;
02:
03: import org.kohsuke.rngom.ast.om.ParsedPattern;
04: import org.kohsuke.rngom.parse.Parseable;
05: import org.xml.sax.Locator;
06:
07: /**
08: * Base class of all the patterns.
09: *
10: * @author Kohsuke Kawaguchi (kk@kohsuke.org)
11: */
12: public abstract class DPattern implements ParsedPattern {
13: Locator location;
14: DAnnotation annotation;
15:
16: /**
17: * Used to chain the child patterns in a doubly-linked list.
18: */
19: DPattern next;
20: DPattern prev;
21:
22: /**
23: * Returns where the pattern is defined in the source code.
24: */
25: public Locator getLocation() {
26: return location;
27: }
28:
29: /**
30: * Returns the annotation associated with it.
31: *
32: * @return
33: * may be empty, but never be null.
34: */
35: public DAnnotation getAnnotation() {
36: if (annotation == null)
37: return DAnnotation.EMPTY;
38: return annotation;
39: }
40:
41: /**
42: * Returns true if this pattern is nullable.
43: *
44: * A nullable pattern is a pattern that can match the empty sequence.
45: */
46: public abstract boolean isNullable();
47:
48: public abstract <V> V accept(DPatternVisitor<V> visitor);
49:
50: /**
51: * Creates a {@link Parseable} object that reparses this pattern.
52: */
53: public Parseable createParseable() {
54: return new PatternParseable(this );
55: }
56:
57: /**
58: * Returns true if this is {@link DElementPattern}.
59: */
60: public final boolean isElement() {
61: return this instanceof DElementPattern;
62: }
63:
64: /**
65: * Returns true if this is {@link DAttributePattern}.
66: */
67: public final boolean isAttribute() {
68: return this instanceof DAttributePattern;
69: }
70: }
|