1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43:
44:
49: public final class NameTest
50: extends Test
51: {
52:
53: final QName qName;
54: final boolean anyLocalName;
55: final boolean any;
56:
57: public NameTest(QName qName, boolean anyLocalName, boolean any)
58: {
59: this.anyLocalName = anyLocalName;
60: this.any = any;
61: this.qName = qName;
62: }
63:
64: public boolean matchesAny()
65: {
66: return any;
67: }
68:
69: public boolean matchesAnyLocalName()
70: {
71: return anyLocalName;
72: }
73:
74: public boolean matches(Node node, int pos, int len)
75: {
76: switch (node.getNodeType())
77: {
78: case Node.ATTRIBUTE_NODE:
79:
80: String uri = node.getNamespaceURI();
81: if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) ||
82: XMLConstants.XMLNS_ATTRIBUTE.equals(node.getPrefix()) ||
83: XMLConstants.XMLNS_ATTRIBUTE.equals(node.getNodeName()))
84: {
85: return false;
86: }
87:
88: case Node.ELEMENT_NODE:
89: break;
90: default:
91: return false;
92: }
93: if (any)
94: return true;
95: String uri = qName.getNamespaceURI();
96: String nodeUri = node.getNamespaceURI();
97: if (!equal(uri, nodeUri))
98: return false;
99: if (anyLocalName)
100: return true;
101: String localName = qName.getLocalPart();
102: String nodeLocalName = getLocalName(node);
103: return (localName.equals(nodeLocalName));
104: }
105:
106: static String getLocalName(Node node)
107: {
108: String localName = node.getLocalName();
109: if (localName == null)
110: {
111: localName = node.getNodeName();
112: int ci = localName.indexOf(':');
113: if (ci != -1)
114: localName = localName.substring(ci + 1);
115: }
116: return localName;
117: }
118:
119: static boolean equal(String s1, String s2)
120: {
121: return (((s1 == null || s1.length() == 0) &&
122: (s2 == null || s2.length() == 0)) ||
123: s1 != null && s1.equals(s2));
124: }
125:
126: public Test clone(Object context)
127: {
128: return new NameTest(qName, anyLocalName, any);
129: }
130:
131: public boolean references(QName var)
132: {
133: return false;
134: }
135:
136: public String toString ()
137: {
138: if (any)
139: return "*";
140: return qName.toString();
141: }
142:
143: }