KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thaiopensource.relaxng.impl;
2
3 import java.util.Hashtable JavaDoc;
4
5 public class FeasibleTransform {
6   private static class FeasiblePatternFunction extends AbstractPatternFunction {
7     private final SchemaPatternBuilder spb;
8     private final Hashtable JavaDoc elementTable = new Hashtable JavaDoc();
9
10     FeasiblePatternFunction(SchemaPatternBuilder spb) {
11       this.spb = spb;
12     }
13
14     public Object JavaDoc caseChoice(ChoicePattern p) {
15       return spb.makeChoice(p.getOperand1().applyForPattern(this), p.getOperand2().applyForPattern(this));
16     }
17
18     public Object JavaDoc caseGroup(GroupPattern p) {
19       return spb.makeGroup(p.getOperand1().applyForPattern(this), p.getOperand2().applyForPattern(this));
20     }
21
22     public Object JavaDoc caseInterleave(InterleavePattern p) {
23       return spb.makeInterleave(p.getOperand1().applyForPattern(this), p.getOperand2().applyForPattern(this));
24     }
25
26     public Object JavaDoc caseOneOrMore(OneOrMorePattern p) {
27       return spb.makeOneOrMore(p.getOperand().applyForPattern(this));
28     }
29
30     public Object JavaDoc caseElement(ElementPattern p) {
31       if (elementTable.get(p) == null) {
32         elementTable.put(p, p);
33         p.setContent(p.getContent().applyForPattern(this));
34       }
35       return spb.makeOptional(p);
36     }
37
38     public Object JavaDoc caseOther(Pattern p) {
39       return spb.makeOptional(p);
40     }
41   }
42
43   public static Pattern transform(SchemaPatternBuilder spb, Pattern p) {
44     return p.applyForPattern(new FeasiblePatternFunction(spb));
45   }
46 }
47
Popular Tags