1 29 30 package com.caucho.relaxng.pattern; 31 32 import com.caucho.relaxng.RelaxException; 33 import com.caucho.relaxng.program.AttributeItem; 34 import com.caucho.relaxng.program.Item; 35 36 39 public class AttributePattern extends Pattern { 40 41 private NameClassPattern _name; 42 private GroupPattern _children = new GroupPattern(); 43 44 private Item _item; 45 46 49 public AttributePattern() 50 { 51 } 52 53 56 public String getTagName() 57 { 58 return "attribute"; 59 } 60 61 64 public GroupPattern getChildren() 65 { 66 return _children; 67 } 68 69 72 public void addNameChild(NameClassPattern child) 73 throws RelaxException 74 { 75 _name = child; 76 setElementName(_name.toProduction()); 77 } 78 79 82 public NameClassPattern getNameChild() 83 throws RelaxException 84 { 85 return _name; 86 } 87 88 91 public void addChild(Pattern child) 92 throws RelaxException 93 { 94 if (_name == null) 95 throw new RelaxException(L.l("<attribute> must have a <name> definition before any children.")); 96 97 child.setParent(_children); 98 child.setElementName(_children.getElementName()); 99 100 _children.addChild(child); 101 } 102 103 106 public void endElement() 107 throws RelaxException 108 { 109 if (_name == null) 110 throw new RelaxException(L.l("<attribute> must have a <name> definition.")); 111 } 112 113 116 public Item createItem(GrammarPattern grammar) 117 throws RelaxException 118 { 119 if (_item == null) 120 _item = new AttributeItem(_name.createNameItem()); 121 122 return _item; 123 } 124 125 128 public String toProduction() 129 { 130 return "@" + _name.toProduction(); 131 } 132 133 public boolean equals(Object o) 134 { 135 if (this == o) 136 return true; 137 138 if (! (o instanceof AttributePattern)) 139 return false; 140 141 AttributePattern elt = (AttributePattern) o; 142 143 if (! _name.equals(elt._name)) 144 return false; 145 else 146 return _children.equals(elt._children); 147 } 148 149 152 public String toString() 153 { 154 return "AttributePattern[" + _name.toProduction() + "]"; 155 } 156 } 157 158 | Popular Tags |