1 28 29 package com.caucho.relaxng.pattern; 30 31 import com.caucho.relaxng.RelaxException; 32 import com.caucho.util.L10N; 33 34 import java.util.HashMap ; 35 import java.util.Iterator ; 36 37 40 public class GrammarPattern extends Pattern { 41 protected static final L10N L = new L10N(GrammarPattern.class); 42 43 private Pattern _start; 44 private int _id; 45 46 private HashMap <String ,Pattern> _definitions = new HashMap <String ,Pattern>(); 47 48 51 public GrammarPattern() 52 { 53 } 54 55 58 public String getTagName() 59 { 60 return "grammar"; 61 } 62 63 66 public Pattern getStart() 67 { 68 return _start; 69 } 70 71 74 public void setStart(Pattern start) 75 throws RelaxException 76 { 77 if (_start != null) 78 throw new RelaxException(L.l("Duplicate <start> in <grammar>. The <grammar> element can only have one <start>.")); 79 80 _start = start; 81 } 82 83 86 public String generateId() 87 { 88 return "__caucho_" + _id++; 89 } 90 91 94 public void setDefinition(String name, Pattern pattern) 95 { 96 _definitions.put(name, pattern); 97 } 98 99 102 public Pattern getDefinition(String name) 103 { 104 return _definitions.get(name); 105 } 106 107 110 public void mergeInclude(GrammarPattern grammar) 111 { 112 Iterator <String > names = grammar._definitions.keySet().iterator(); 113 114 while (names.hasNext()) { 115 String name = names.next(); 116 117 Pattern includePattern = grammar._definitions.get(name); 118 119 _definitions.put(name, includePattern); 120 } 121 } 122 123 126 public boolean equals(Object o) 127 { 128 return this == o; 129 } 130 131 134 public String toString() 135 { 136 return "GrammarPattern[" + _start + "]"; 137 } 138 } 139 140 | Popular Tags |