1 package com.thaiopensource.relaxng.impl; 2 3 import java.util.Hashtable ; 4 5 public class FeasibleTransform { 6 private static class FeasiblePatternFunction extends AbstractPatternFunction { 7 private final SchemaPatternBuilder spb; 8 private final Hashtable elementTable = new Hashtable (); 9 10 FeasiblePatternFunction(SchemaPatternBuilder spb) { 11 this.spb = spb; 12 } 13 14 public Object caseChoice(ChoicePattern p) { 15 return spb.makeChoice(p.getOperand1().applyForPattern(this), p.getOperand2().applyForPattern(this)); 16 } 17 18 public Object caseGroup(GroupPattern p) { 19 return spb.makeGroup(p.getOperand1().applyForPattern(this), p.getOperand2().applyForPattern(this)); 20 } 21 22 public Object caseInterleave(InterleavePattern p) { 23 return spb.makeInterleave(p.getOperand1().applyForPattern(this), p.getOperand2().applyForPattern(this)); 24 } 25 26 public Object caseOneOrMore(OneOrMorePattern p) { 27 return spb.makeOneOrMore(p.getOperand().applyForPattern(this)); 28 } 29 30 public Object 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 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 |