KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > relaxng > impl > EndAttributesFunction


1 package com.thaiopensource.relaxng.impl;
2
3 class EndAttributesFunction extends AbstractPatternFunction {
4   private final ValidatorPatternBuilder builder;
5
6   EndAttributesFunction(ValidatorPatternBuilder builder) {
7     this.builder = builder;
8   }
9
10   public Object JavaDoc caseOther(Pattern p) {
11     return p;
12   }
13
14   public Object JavaDoc caseGroup(GroupPattern p) {
15     Pattern p1 = p.getOperand1();
16     Pattern p2 = p.getOperand2();
17     Pattern q1 = memoApply(p1);
18     Pattern q2 = memoApply(p2);
19     if (p1 == q1 && p2 == q2)
20       return p;
21     return builder.makeGroup(q1, q2);
22   }
23
24   public Object JavaDoc caseInterleave(InterleavePattern p) {
25     Pattern p1 = p.getOperand1();
26     Pattern p2 = p.getOperand2();
27     Pattern q1 = memoApply(p1);
28     Pattern q2 = memoApply(p2);
29     if (p1 == q1 && p2 == q2)
30       return p;
31     return builder.makeInterleave(q1, q2);
32   }
33
34   public Object JavaDoc caseChoice(ChoicePattern p) {
35     Pattern p1 = p.getOperand1();
36     Pattern p2 = p.getOperand2();
37     Pattern q1 = memoApply(p1);
38     Pattern q2 = memoApply(p2);
39     if (p1 == q1 && p2 == q2)
40       return p;
41     return builder.makeChoice(q1, q2);
42   }
43
44   public Object JavaDoc caseOneOrMore(OneOrMorePattern p) {
45     Pattern p1 = p.getOperand();
46     Pattern q1 = memoApply(p1);
47     if (p1 == q1)
48       return p;
49     return builder.makeOneOrMore(p1);
50   }
51
52   public Object JavaDoc caseAfter(AfterPattern p) {
53     Pattern p1 = p.getOperand1();
54     Pattern q1 = memoApply(p1);
55     if (p1 == q1)
56       return p;
57     return builder.makeAfter(q1, p.getOperand2());
58   }
59
60   public Object JavaDoc caseAttribute(AttributePattern p) {
61     return builder.makeNotAllowed();
62   }
63
64   final Pattern memoApply(Pattern p) {
65     return apply(builder.getPatternMemo(p)).getPattern();
66   }
67
68   PatternMemo apply(PatternMemo memo) {
69     return memo.endAttributes(this);
70   }
71
72   ValidatorPatternBuilder getPatternBuilder() {
73     return builder;
74   }
75 }
76
Popular Tags