KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thaiopensource.relaxng.impl;
2
3 import com.thaiopensource.xml.util.Name;
4
5 class StartTagOpenDerivFunction extends AbstractPatternFunction {
6   private final Name name;
7   private final ValidatorPatternBuilder builder;
8
9   StartTagOpenDerivFunction(Name name, ValidatorPatternBuilder builder) {
10     this.name = name;
11     this.builder = builder;
12   }
13
14   public Object JavaDoc caseChoice(ChoicePattern p) {
15     return builder.makeChoice(memoApply(p.getOperand1()),
16                   memoApply(p.getOperand2()));
17   }
18
19   public Object JavaDoc caseGroup(GroupPattern p) {
20     final Pattern p1 = p.getOperand1();
21     final Pattern p2 = p.getOperand2();
22     Pattern tem = memoApply(p1).applyForPattern(
23                       new ApplyAfterFunction(builder) {
24                       Pattern apply(Pattern x) {
25                         return builder.makeGroup(x, p2);
26                       }
27                     });
28     return p1.isNullable() ? builder.makeChoice(tem, memoApply(p2)) : tem;
29   }
30
31   public Object JavaDoc caseInterleave(InterleavePattern p) {
32     final Pattern p1 = p.getOperand1();
33     final Pattern p2 = p.getOperand2();
34     return builder.makeChoice(
35                   memoApply(p1).applyForPattern(new ApplyAfterFunction(builder) {
36                   Pattern apply(Pattern x) {
37                     return builder.makeInterleave(x, p2);
38                   }
39                 }),
40                   memoApply(p2).applyForPattern(new ApplyAfterFunction(builder) {
41                   Pattern apply(Pattern x) {
42                     return builder.makeInterleave(p1, x);
43                   }
44                 }));
45   }
46
47   public Object JavaDoc caseAfter(AfterPattern p) {
48     final Pattern p1 = p.getOperand1();
49     final Pattern p2 = p.getOperand2();
50     return memoApply(p1).applyForPattern(
51                    new ApplyAfterFunction(builder) {
52                    Pattern apply(Pattern x) {
53                      return builder.makeAfter(x, p2);
54                    }
55                  });
56   }
57
58   public Object JavaDoc caseOneOrMore(final OneOrMorePattern p) {
59     final Pattern p1 = p.getOperand();
60     return memoApply(p1).applyForPattern(
61                    new ApplyAfterFunction(builder) {
62                    Pattern apply(Pattern x) {
63                      return builder.makeGroup(x,
64                                   builder.makeOptional(p));
65                    }
66                  });
67   }
68
69
70   public Object JavaDoc caseElement(ElementPattern p) {
71     if (!p.getNameClass().contains(name))
72       return builder.makeNotAllowed();
73     return builder.makeAfter(p.getContent(), builder.makeEmpty());
74   }
75
76   public Object JavaDoc caseOther(Pattern p) {
77     return builder.makeNotAllowed();
78   }
79
80   final Pattern memoApply(Pattern p) {
81     return apply(builder.getPatternMemo(p)).getPattern();
82   }
83
84   PatternMemo apply(PatternMemo memo) {
85     return memo.startTagOpenDeriv(this);
86   }
87
88   Name getName() {
89     return name;
90   }
91
92   ValidatorPatternBuilder getPatternBuilder() {
93     return builder;
94   }
95 }
96
Popular Tags