1 28 29 package com.caucho.relaxng.pattern; 30 31 import com.caucho.relaxng.RelaxException; 32 import com.caucho.relaxng.program.Item; 33 34 37 public class RefPattern extends Pattern { 38 private GrammarPattern _grammar; 39 40 private String _refName; 41 42 45 public RefPattern(GrammarPattern grammar, String refName) 46 { 47 _grammar = grammar; 48 49 _refName = refName; 50 } 51 52 55 public String getTagName() 56 { 57 return "ref"; 58 } 59 60 63 public String getRefName() 64 { 65 return _refName; 66 } 67 68 71 public Item createItem(GrammarPattern grammar) 72 throws RelaxException 73 { 74 Pattern pattern = grammar.getDefinition(_refName); 75 76 if (pattern == null) { 77 throw error(L.l("<ref name=\"{0}\"/> is an unknown reference.", 79 _refName)); 80 } 81 82 for (Pattern ptr = this; 83 ptr != null && ! (ptr instanceof ElementPattern); 84 ptr = ptr.getParent()) { 85 if (ptr == pattern) { 86 throw error(L.l("<define name=\"{0}\"/> calls itself recursively in a <ref/>.", 87 _refName)); 88 } 89 } 90 91 return pattern.createItem(grammar); 92 } 93 94 97 public String toProduction() 98 { 99 Pattern pattern = _grammar.getDefinition(_refName); 100 101 return pattern.toProduction(); 102 } 103 104 107 public boolean equals(Object o) 108 { 109 if (this == o) 110 return true; 111 112 if (! (o instanceof Pattern)) 113 return false; 114 115 return o.equals(_grammar.getDefinition(_refName)); 116 } 117 118 121 public String toString() 122 { 123 return "RefPattern[" + _refName + "]"; 124 } 125 } 126 127 | Popular Tags |