001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.ukit.jaxp;
028:
029: /**
030: * A name with value pair.
031: *
032: * This class keeps name with value pair with additional information and
033: * supports pair chaining.
034: */
035:
036: /* package */class Pair {
037: /** The pair name. */
038: public String name;
039:
040: /** The pair value. */
041: public String value;
042:
043: /** The characters of name. */
044: public char[] chars;
045:
046: /** The pair identifier. */
047: public char id;
048:
049: /** The list of associated pairs. */
050: public Pair list;
051:
052: /** The next pair in a chain. */
053: public Pair next;
054:
055: /**
056: * Creates a qualified name string from qualified name.
057: *
058: * @return The qualified name string.
059: */
060: public String qname() {
061: return new String(chars, 1, chars.length - 1);
062: }
063:
064: /**
065: * Creates a local name string from qualified name.
066: *
067: * @return The local name string.
068: */
069: public String local() {
070: if (chars[0] != 0) {
071: return new String(chars, chars[0] + 1, chars.length
072: - chars[0] - 1);
073: }
074: return new String(chars, 1, chars.length - 1);
075: }
076:
077: /**
078: * Creates a prefix string from qualified name.
079: *
080: * @return The prefix string.
081: */
082: public String pref() {
083: if (chars[0] != 0) {
084: return new String(chars, 1, chars[0] - 1);
085: }
086: return "";
087: }
088:
089: /**
090: * Compares two qualified name prefixes.
091: *
092: * @param qname A qualified name.
093: * @return true if prefixes are equal.
094: */
095: public boolean eqpref(char[] qname) {
096: if (chars[0] == qname[0]) {
097: char len = chars[0];
098: for (char i = 1; i < len; i += 1) {
099: if (chars[i] != qname[i])
100: return false;
101: }
102: return true;
103: }
104: return false;
105: }
106:
107: /**
108: * Compares two qualified names.
109: *
110: * @param qname A qualified name.
111: * @return true if qualified names are equal.
112: */
113: public boolean eqname(char[] qname) {
114: char len = (char) chars.length;
115: if (len == qname.length) {
116: for (char i = 0; i < len; i += 1) {
117: if (chars[i] != qname[i])
118: return false;
119: }
120: return true;
121: }
122: return false;
123: }
124: }
|