1 28 29 package com.caucho.relaxng.pattern; 30 31 import com.caucho.relaxng.RelaxException; 32 import com.caucho.relaxng.program.Item; 33 import com.caucho.relaxng.program.NameClassItem; 34 import com.caucho.util.L10N; 35 36 39 abstract public class Pattern { 40 protected static final L10N L = new L10N(Pattern.class); 41 42 private Pattern _parent; 43 private String _elementName; 44 45 private String _location; 46 47 50 public String getTagName() 51 { 52 return getClass().getName(); 53 } 54 55 58 public void setLocation(String location) 59 { 60 _location = location; 61 } 62 63 66 public String getLocation() 67 { 68 if (_location != null) 69 return _location; 70 else if (_parent != null) 71 return _parent.getLocation(); 72 else 73 return null; 74 } 75 76 79 public String getElementName() 80 { 81 return _elementName; 82 } 83 84 87 public void setElementName(String elementName) 88 { 89 _elementName = elementName; 90 } 91 92 95 public void setParent(Pattern parent) 96 throws RelaxException 97 { 98 _parent = parent; 99 } 100 101 104 public Pattern getParent() 105 { 106 return _parent; 107 } 108 109 112 public boolean hasData() 113 { 114 return false; 115 } 116 117 120 public boolean hasElement() 121 { 122 return false; 123 } 124 125 128 public void addNameChild(NameClassPattern child) 129 throws RelaxException 130 { 131 throw new RelaxException(L.l("<{0}> is not an allowed child for <{1}>.", 132 child.getTagName(), getTagName())); 133 } 134 135 138 public void addChild(Pattern child) 139 throws RelaxException 140 { 141 throw new RelaxException(L.l("<{0}> is not an allowed child for <{1}>.", 142 child.getTagName(), getTagName())); 143 } 144 145 148 public void endElement() 149 throws RelaxException 150 { 151 } 152 153 156 public Item createItem(GrammarPattern grammar) 157 throws RelaxException 158 { 159 throw new RelaxException(L.l("item isn't allowed in `{0}'.", 160 getClass().getName())); 161 } 162 163 166 public NameClassItem createNameItem() 167 throws RelaxException 168 { 169 throw new RelaxException(L.l("name-item isn't allowed in `{0}'.", 170 getClass().getName())); 171 } 172 173 abstract public boolean equals(Object o); 174 175 178 public String toProduction() 179 { 180 return "unknown"; 181 } 182 183 186 public RelaxException error(String msg) 187 { 188 String location = getLocation(); 189 190 if (location != null) 191 return new RelaxException(location + ": " + msg); 192 else 193 return new RelaxException(msg); 194 } 195 } 196 | Popular Tags |