001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.relaxng.program;
030:
031: import com.caucho.xml.QName;
032:
033: import java.util.HashSet;
034:
035: /**
036: * Matches names.
037: */
038: public class NsNameItem extends NameClassItem {
039: private String _ns;
040:
041: private NameClassItem _except;
042:
043: public NsNameItem(String ns) {
044: _ns = ns;
045: }
046:
047: public void setExcept(NameClassItem except) {
048: _except = except;
049: }
050:
051: /**
052: * Adds to the first set, the set of element names possible.
053: */
054: public void firstSet(HashSet<QName> set) {
055: set.add(new QName("*", _ns));
056: }
057:
058: /**
059: * Returns true if the name matches.
060: */
061: public boolean matches(QName name) {
062: if (!_ns.equals(name.getNamespaceURI()))
063: return false;
064: else if (_except != null && _except.matches(name))
065: return false;
066: else
067: return true;
068: }
069:
070: /**
071: * Returns the pretty printed syntax.
072: */
073: public String toSyntaxDescription(String prefix) {
074: if (_except != null) {
075: if (prefix.equals(""))
076: return "<{" + _ns + "}:* -"
077: + _except.toSyntaxDescription(" ") + ">";
078: else
079: return prefix + "(" + "{" + _ns + "}:* -"
080: + _except.toSyntaxDescription(" ") + ")";
081: } else if (prefix.equals(""))
082: return "<{" + _ns + "}:*>";
083: else
084: return prefix + "{" + _ns + "}:*";
085: }
086:
087: public int hashCode() {
088: return _ns.hashCode();
089: }
090:
091: public boolean equals(Object o) {
092: if (this == o)
093: return true;
094:
095: if (!(o instanceof NsNameItem))
096: return false;
097:
098: NsNameItem name = (NsNameItem) o;
099:
100: if (!_ns.equals(name._ns))
101: return false;
102:
103: if (_except == null)
104: return name._except == null;
105: else
106: return _except.equals(name._except);
107: }
108: }
|