0N/A/*
2362N/A * Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.naming;
0N/A
0N/Aimport java.util.Vector;
0N/Aimport java.util.Enumeration;
0N/Aimport java.util.Properties;
0N/Aimport java.util.NoSuchElementException;
0N/A
0N/A/**
0N/A * The implementation class for CompoundName and CompositeName.
0N/A * This class is package private.
0N/A *
0N/A * @author Rosanna Lee
0N/A * @author Scott Seligman
0N/A * @author Aravindan Ranganathan
0N/A * @since 1.3
0N/A */
0N/A
0N/Aclass NameImpl {
0N/A private static final byte LEFT_TO_RIGHT = 1;
0N/A private static final byte RIGHT_TO_LEFT = 2;
0N/A private static final byte FLAT = 0;
0N/A
0N/A private Vector components;
0N/A
0N/A private byte syntaxDirection = LEFT_TO_RIGHT;
0N/A private String syntaxSeparator = "/";
0N/A private String syntaxSeparator2 = null;
0N/A private boolean syntaxCaseInsensitive = false;
0N/A private boolean syntaxTrimBlanks = false;
0N/A private String syntaxEscape = "\\";
0N/A private String syntaxBeginQuote1 = "\"";
0N/A private String syntaxEndQuote1 = "\"";
0N/A private String syntaxBeginQuote2 = "'";
0N/A private String syntaxEndQuote2 = "'";
0N/A private String syntaxAvaSeparator = null;
0N/A private String syntaxTypevalSeparator = null;
0N/A
0N/A // escapingStyle gives the method used at creation time for
0N/A // quoting or escaping characters in the name. It is set to the
0N/A // first style of quote or escape encountered if and when the name
0N/A // is parsed.
0N/A private static final int STYLE_NONE = 0;
0N/A private static final int STYLE_QUOTE1 = 1;
0N/A private static final int STYLE_QUOTE2 = 2;
0N/A private static final int STYLE_ESCAPE = 3;
0N/A private int escapingStyle = STYLE_NONE;
0N/A
0N/A // Returns true if "match" is not null, and n contains "match" at
0N/A // position i.
0N/A private final boolean isA(String n, int i, String match) {
0N/A return (match != null && n.startsWith(match, i));
0N/A }
0N/A
0N/A private final boolean isMeta(String n, int i) {
0N/A return (isA(n, i, syntaxEscape) ||
0N/A isA(n, i, syntaxBeginQuote1) ||
0N/A isA(n, i, syntaxBeginQuote2) ||
0N/A isSeparator(n, i));
0N/A }
0N/A
0N/A private final boolean isSeparator(String n, int i) {
0N/A return (isA(n, i, syntaxSeparator) ||
0N/A isA(n, i, syntaxSeparator2));
0N/A }
0N/A
0N/A private final int skipSeparator(String name, int i) {
0N/A if (isA(name, i, syntaxSeparator)) {
0N/A i += syntaxSeparator.length();
0N/A } else if (isA(name, i, syntaxSeparator2)) {
0N/A i += syntaxSeparator2.length();
0N/A }
0N/A return (i);
0N/A }
0N/A
0N/A private final int extractComp(String name, int i, int len, Vector comps)
0N/A throws InvalidNameException {
0N/A String beginQuote;
0N/A String endQuote;
0N/A boolean start = true;
0N/A boolean one = false;
0N/A StringBuffer answer = new StringBuffer(len);
0N/A
0N/A while (i < len) {
0N/A // handle quoted strings
0N/A if (start && ((one = isA(name, i, syntaxBeginQuote1)) ||
0N/A isA(name, i, syntaxBeginQuote2))) {
0N/A
0N/A // record choice of quote chars being used
0N/A beginQuote = one ? syntaxBeginQuote1 : syntaxBeginQuote2;
0N/A endQuote = one ? syntaxEndQuote1 : syntaxEndQuote2;
0N/A if (escapingStyle == STYLE_NONE) {
0N/A escapingStyle = one ? STYLE_QUOTE1 : STYLE_QUOTE2;
0N/A }
0N/A
0N/A // consume string until matching quote
0N/A for (i += beginQuote.length();
0N/A ((i < len) && !name.startsWith(endQuote, i));
0N/A i++) {
0N/A // skip escape character if it is escaping ending quote
0N/A // otherwise leave as is.
0N/A if (isA(name, i, syntaxEscape) &&
0N/A isA(name, i + syntaxEscape.length(), endQuote)) {
0N/A i += syntaxEscape.length();
0N/A }
0N/A answer.append(name.charAt(i)); // copy char
0N/A }
0N/A
0N/A // no ending quote found
0N/A if (i >= len)
0N/A throw
0N/A new InvalidNameException(name + ": no close quote");
0N/A// new Exception("no close quote");
0N/A
0N/A i += endQuote.length();
0N/A
0N/A // verify that end-quote occurs at separator or end of string
0N/A if (i == len || isSeparator(name, i)) {
0N/A break;
0N/A }
0N/A// throw (new Exception(
0N/A throw (new InvalidNameException(name +
0N/A ": close quote appears before end of component"));
0N/A
0N/A } else if (isSeparator(name, i)) {
0N/A break;
0N/A
0N/A } else if (isA(name, i, syntaxEscape)) {
0N/A if (isMeta(name, i + syntaxEscape.length())) {
0N/A // if escape precedes meta, consume escape and let
0N/A // meta through
0N/A i += syntaxEscape.length();
0N/A if (escapingStyle == STYLE_NONE) {
0N/A escapingStyle = STYLE_ESCAPE;
0N/A }
0N/A } else if (i + syntaxEscape.length() >= len) {
0N/A throw (new InvalidNameException(name +
0N/A ": unescaped " + syntaxEscape + " at end of component"));
0N/A }
0N/A } else if (isA(name, i, syntaxTypevalSeparator) &&
0N/A ((one = isA(name, i+syntaxTypevalSeparator.length(), syntaxBeginQuote1)) ||
0N/A isA(name, i+syntaxTypevalSeparator.length(), syntaxBeginQuote2))) {
0N/A // Handle quote occurring after typeval separator
0N/A beginQuote = one ? syntaxBeginQuote1 : syntaxBeginQuote2;
0N/A endQuote = one ? syntaxEndQuote1 : syntaxEndQuote2;
0N/A
0N/A i += syntaxTypevalSeparator.length();
0N/A answer.append(syntaxTypevalSeparator+beginQuote); // add back
0N/A
0N/A // consume string until matching quote
0N/A for (i += beginQuote.length();
0N/A ((i < len) && !name.startsWith(endQuote, i));
0N/A i++) {
0N/A // skip escape character if it is escaping ending quote
0N/A // otherwise leave as is.
0N/A if (isA(name, i, syntaxEscape) &&
0N/A isA(name, i + syntaxEscape.length(), endQuote)) {
0N/A i += syntaxEscape.length();
0N/A }
0N/A answer.append(name.charAt(i)); // copy char
0N/A }
0N/A
0N/A // no ending quote found
0N/A if (i >= len)
0N/A throw
0N/A new InvalidNameException(name + ": typeval no close quote");
0N/A
0N/A i += endQuote.length();
0N/A answer.append(endQuote); // add back
0N/A
0N/A // verify that end-quote occurs at separator or end of string
0N/A if (i == len || isSeparator(name, i)) {
0N/A break;
0N/A }
0N/A throw (new InvalidNameException(name.substring(i) +
0N/A ": typeval close quote appears before end of component"));
0N/A }
0N/A
0N/A answer.append(name.charAt(i++));
0N/A start = false;
0N/A }
0N/A
0N/A if (syntaxDirection == RIGHT_TO_LEFT)
0N/A comps.insertElementAt(answer.toString(), 0);
0N/A else
0N/A comps.addElement(answer.toString());
0N/A return i;
0N/A }
0N/A
0N/A private static boolean getBoolean(Properties p, String name) {
0N/A return toBoolean(p.getProperty(name));
0N/A }
0N/A
0N/A private static boolean toBoolean(String name) {
0N/A return ((name != null) && name.toLowerCase().equals("true"));
0N/A }
0N/A
0N/A private final void recordNamingConvention(Properties p) {
0N/A String syntaxDirectionStr =
0N/A p.getProperty("jndi.syntax.direction", "flat");
0N/A if (syntaxDirectionStr.equals("left_to_right")) {
0N/A syntaxDirection = LEFT_TO_RIGHT;
0N/A } else if (syntaxDirectionStr.equals("right_to_left")) {
0N/A syntaxDirection = RIGHT_TO_LEFT;
0N/A } else if (syntaxDirectionStr.equals("flat")) {
0N/A syntaxDirection = FLAT;
0N/A } else {
0N/A throw new IllegalArgumentException(syntaxDirectionStr +
0N/A "is not a valid value for the jndi.syntax.direction property");
0N/A }
0N/A
0N/A if (syntaxDirection != FLAT) {
0N/A syntaxSeparator = p.getProperty("jndi.syntax.separator");
0N/A syntaxSeparator2 = p.getProperty("jndi.syntax.separator2");
0N/A if (syntaxSeparator == null) {
0N/A throw new IllegalArgumentException(
0N/A "jndi.syntax.separator property required for non-flat syntax");
0N/A }
0N/A } else {
0N/A syntaxSeparator = null;
0N/A }
0N/A syntaxEscape = p.getProperty("jndi.syntax.escape");
0N/A
0N/A syntaxCaseInsensitive = getBoolean(p, "jndi.syntax.ignorecase");
0N/A syntaxTrimBlanks = getBoolean(p, "jndi.syntax.trimblanks");
0N/A
0N/A syntaxBeginQuote1 = p.getProperty("jndi.syntax.beginquote");
0N/A syntaxEndQuote1 = p.getProperty("jndi.syntax.endquote");
0N/A if (syntaxEndQuote1 == null && syntaxBeginQuote1 != null)
0N/A syntaxEndQuote1 = syntaxBeginQuote1;
0N/A else if (syntaxBeginQuote1 == null && syntaxEndQuote1 != null)
0N/A syntaxBeginQuote1 = syntaxEndQuote1;
0N/A syntaxBeginQuote2 = p.getProperty("jndi.syntax.beginquote2");
0N/A syntaxEndQuote2 = p.getProperty("jndi.syntax.endquote2");
0N/A if (syntaxEndQuote2 == null && syntaxBeginQuote2 != null)
0N/A syntaxEndQuote2 = syntaxBeginQuote2;
0N/A else if (syntaxBeginQuote2 == null && syntaxEndQuote2 != null)
0N/A syntaxBeginQuote2 = syntaxEndQuote2;
0N/A
0N/A syntaxAvaSeparator = p.getProperty("jndi.syntax.separator.ava");
0N/A syntaxTypevalSeparator =
0N/A p.getProperty("jndi.syntax.separator.typeval");
0N/A }
0N/A
0N/A NameImpl(Properties syntax) {
0N/A if (syntax != null) {
0N/A recordNamingConvention(syntax);
0N/A }
0N/A components = new Vector();
0N/A }
0N/A
0N/A NameImpl(Properties syntax, String n) throws InvalidNameException {
0N/A this(syntax);
0N/A
0N/A boolean rToL = (syntaxDirection == RIGHT_TO_LEFT);
0N/A boolean compsAllEmpty = true;
0N/A int len = n.length();
0N/A
0N/A for (int i = 0; i < len; ) {
0N/A i = extractComp(n, i, len, components);
0N/A
0N/A String comp = rToL
0N/A ? (String)components.firstElement()
0N/A : (String)components.lastElement();
0N/A if (comp.length() >= 1) {
0N/A compsAllEmpty = false;
0N/A }
0N/A
0N/A if (i < len) {
0N/A i = skipSeparator(n, i);
0N/A if ((i == len) && !compsAllEmpty) {
0N/A // Trailing separator found. Add an empty component.
0N/A if (rToL) {
0N/A components.insertElementAt("", 0);
0N/A } else {
0N/A components.addElement("");
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A NameImpl(Properties syntax, Enumeration comps) {
0N/A this(syntax);
0N/A
0N/A // %% comps could shrink in the middle.
0N/A while (comps.hasMoreElements())
0N/A components.addElement(comps.nextElement());
0N/A }
0N/A/*
0N/A // Determines whether this component needs any escaping.
0N/A private final boolean escapingNeeded(String comp) {
0N/A int len = comp.length();
0N/A for (int i = 0; i < len; i++) {
0N/A if (i == 0) {
0N/A if (isA(comp, 0, syntaxBeginQuote1) ||
0N/A isA(comp, 0, syntaxBeginQuote2)) {
0N/A return (true);
0N/A }
0N/A }
0N/A if (isSeparator(comp, i)) {
0N/A return (true);
0N/A }
0N/A if (isA(comp, i, syntaxEscape)) {
0N/A i += syntaxEscape.length();
0N/A if (i >= len || isMeta(comp, i)) {
0N/A return (true);
0N/A }
0N/A }
0N/A }
0N/A return (false);
0N/A }
0N/A*/
0N/A private final String stringifyComp(String comp) {
0N/A int len = comp.length();
0N/A boolean escapeSeparator = false, escapeSeparator2 = false;
0N/A String beginQuote = null, endQuote = null;
0N/A StringBuffer strbuf = new StringBuffer(len);
0N/A
0N/A // determine whether there are any separators; if so escape
0N/A // or quote them
0N/A if (syntaxSeparator != null &&
0N/A comp.indexOf(syntaxSeparator) >= 0) {
0N/A if (syntaxBeginQuote1 != null) {
0N/A beginQuote = syntaxBeginQuote1;
0N/A endQuote = syntaxEndQuote1;
0N/A } else if (syntaxBeginQuote2 != null) {
0N/A beginQuote = syntaxBeginQuote2;
0N/A endQuote = syntaxEndQuote2;
0N/A } else if (syntaxEscape != null)
0N/A escapeSeparator = true;
0N/A }
0N/A if (syntaxSeparator2 != null &&
0N/A comp.indexOf(syntaxSeparator2) >= 0) {
0N/A if (syntaxBeginQuote1 != null) {
0N/A if (beginQuote == null) {
0N/A beginQuote = syntaxBeginQuote1;
0N/A endQuote = syntaxEndQuote1;
0N/A }
0N/A } else if (syntaxBeginQuote2 != null) {
0N/A if (beginQuote == null) {
0N/A beginQuote = syntaxBeginQuote2;
0N/A endQuote = syntaxEndQuote2;
0N/A }
0N/A } else if (syntaxEscape != null)
0N/A escapeSeparator2 = true;
0N/A }
0N/A
0N/A // if quoting component,
0N/A if (beginQuote != null) {
0N/A
0N/A // start string off with opening quote
0N/A strbuf = strbuf.append(beginQuote);
0N/A
0N/A // component is being quoted, so we only need to worry about
0N/A // escaping end quotes that occur in component
0N/A for (int i = 0; i < len; ) {
0N/A if (comp.startsWith(endQuote, i)) {
0N/A // end-quotes must be escaped when inside a quoted string
0N/A strbuf.append(syntaxEscape).append(endQuote);
0N/A i += endQuote.length();
0N/A } else {
0N/A // no special treatment required
0N/A strbuf.append(comp.charAt(i++));
0N/A }
0N/A }
0N/A
0N/A // end with closing quote
0N/A strbuf.append(endQuote);
0N/A
0N/A } else {
0N/A
0N/A // When component is not quoted, add escape for:
0N/A // 1. leading quote
0N/A // 2. an escape preceding any meta char
0N/A // 3. an escape at the end of a component
0N/A // 4. separator
0N/A
0N/A // go through characters in component and escape where necessary
0N/A boolean start = true;
0N/A for (int i = 0; i < len; ) {
0N/A // leading quote must be escaped
0N/A if (start && isA(comp, i, syntaxBeginQuote1)) {
0N/A strbuf.append(syntaxEscape).append(syntaxBeginQuote1);
0N/A i += syntaxBeginQuote1.length();
0N/A } else if (start && isA(comp, i, syntaxBeginQuote2)) {
0N/A strbuf.append(syntaxEscape).append(syntaxBeginQuote2);
0N/A i += syntaxBeginQuote2.length();
0N/A } else
0N/A
0N/A // Escape an escape preceding meta characters, or at end.
0N/A // Other escapes pass through.
0N/A if (isA(comp, i, syntaxEscape)) {
0N/A if (i + syntaxEscape.length() >= len) {
0N/A // escape an ending escape
0N/A strbuf.append(syntaxEscape);
0N/A } else if (isMeta(comp, i + syntaxEscape.length())) {
0N/A // escape meta strings
0N/A strbuf.append(syntaxEscape);
0N/A }
0N/A strbuf.append(syntaxEscape);
0N/A i += syntaxEscape.length();
0N/A } else
0N/A
0N/A // escape unescaped separator
0N/A if (escapeSeparator && comp.startsWith(syntaxSeparator, i)) {
0N/A // escape separator
0N/A strbuf.append(syntaxEscape).append(syntaxSeparator);
0N/A i += syntaxSeparator.length();
0N/A } else if (escapeSeparator2 &&
0N/A comp.startsWith(syntaxSeparator2, i)) {
0N/A // escape separator2
0N/A strbuf.append(syntaxEscape).append(syntaxSeparator2);
0N/A i += syntaxSeparator2.length();
0N/A } else {
0N/A // no special treatment required
0N/A strbuf.append(comp.charAt(i++));
0N/A }
0N/A start = false;
0N/A }
0N/A }
0N/A return (strbuf.toString());
0N/A }
0N/A
0N/A public String toString() {
0N/A StringBuffer answer = new StringBuffer();
0N/A String comp;
0N/A boolean compsAllEmpty = true;
0N/A int size = components.size();
0N/A
0N/A for (int i = 0; i < size; i++) {
0N/A if (syntaxDirection == RIGHT_TO_LEFT) {
0N/A comp =
0N/A stringifyComp((String) components.elementAt(size - 1 - i));
0N/A } else {
0N/A comp = stringifyComp((String) components.elementAt(i));
0N/A }
0N/A if ((i != 0) && (syntaxSeparator != null))
0N/A answer.append(syntaxSeparator);
0N/A if (comp.length() >= 1)
0N/A compsAllEmpty = false;
0N/A answer = answer.append(comp);
0N/A }
0N/A if (compsAllEmpty && (size >= 1) && (syntaxSeparator != null))
0N/A answer = answer.append(syntaxSeparator);
0N/A return (answer.toString());
0N/A }
0N/A
0N/A public boolean equals(Object obj) {
0N/A if ((obj != null) && (obj instanceof NameImpl)) {
0N/A NameImpl target = (NameImpl)obj;
0N/A if (target.size() == this.size()) {
0N/A Enumeration mycomps = getAll();
0N/A Enumeration comps = target.getAll();
0N/A while (mycomps.hasMoreElements()) {
0N/A // %% comps could shrink in the middle.
0N/A String my = (String)mycomps.nextElement();
0N/A String his = (String)comps.nextElement();
0N/A if (syntaxTrimBlanks) {
0N/A my = my.trim();
0N/A his = his.trim();
0N/A }
0N/A if (syntaxCaseInsensitive) {
0N/A if (!(my.equalsIgnoreCase(his)))
0N/A return false;
0N/A } else {
0N/A if (!(my.equals(his)))
0N/A return false;
0N/A }
0N/A }
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Compares obj to this NameImpl to determine ordering.
0N/A * Takes into account syntactic properties such as
0N/A * elimination of blanks, case-ignore, etc, if relevant.
0N/A *
0N/A * Note: using syntax of this NameImpl and ignoring
0N/A * that of comparison target.
0N/A */
0N/A public int compareTo(NameImpl obj) {
0N/A if (this == obj) {
0N/A return 0;
0N/A }
0N/A
0N/A int len1 = size();
0N/A int len2 = obj.size();
0N/A int n = Math.min(len1, len2);
0N/A
0N/A int index1 = 0, index2 = 0;
0N/A
0N/A while (n-- != 0) {
0N/A String comp1 = get(index1++);
0N/A String comp2 = obj.get(index2++);
0N/A
0N/A // normalize according to syntax
0N/A if (syntaxTrimBlanks) {
0N/A comp1 = comp1.trim();
0N/A comp2 = comp2.trim();
0N/A }
0N/A if (syntaxCaseInsensitive) {
0N/A comp1 = comp1.toLowerCase();
0N/A comp2 = comp2.toLowerCase();
0N/A }
0N/A int local = comp1.compareTo(comp2);
0N/A if (local != 0) {
0N/A return local;
0N/A }
0N/A }
0N/A
0N/A return len1 - len2;
0N/A }
0N/A
0N/A public int size() {
0N/A return (components.size());
0N/A }
0N/A
0N/A public Enumeration getAll() {
0N/A return components.elements();
0N/A }
0N/A
0N/A public String get(int posn) {
0N/A return ((String) components.elementAt(posn));
0N/A }
0N/A
0N/A public Enumeration getPrefix(int posn) {
0N/A if (posn < 0 || posn > size()) {
0N/A throw new ArrayIndexOutOfBoundsException(posn);
0N/A }
0N/A return new NameImplEnumerator(components, 0, posn);
0N/A }
0N/A
0N/A public Enumeration getSuffix(int posn) {
0N/A int cnt = size();
0N/A if (posn < 0 || posn > cnt) {
0N/A throw new ArrayIndexOutOfBoundsException(posn);
0N/A }
0N/A return new NameImplEnumerator(components, posn, cnt);
0N/A }
0N/A
0N/A public boolean isEmpty() {
0N/A return (components.isEmpty());
0N/A }
0N/A
0N/A public boolean startsWith(int posn, Enumeration prefix) {
0N/A if (posn < 0 || posn > size()) {
0N/A return false;
0N/A }
0N/A try {
0N/A Enumeration mycomps = getPrefix(posn);
0N/A while (mycomps.hasMoreElements()) {
0N/A String my = (String)mycomps.nextElement();
0N/A String his = (String)prefix.nextElement();
0N/A if (syntaxTrimBlanks) {
0N/A my = my.trim();
0N/A his = his.trim();
0N/A }
0N/A if (syntaxCaseInsensitive) {
0N/A if (!(my.equalsIgnoreCase(his)))
0N/A return false;
0N/A } else {
0N/A if (!(my.equals(his)))
0N/A return false;
0N/A }
0N/A }
0N/A } catch (NoSuchElementException e) {
0N/A return false;
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A public boolean endsWith(int posn, Enumeration suffix) {
0N/A // posn is number of elements in suffix
0N/A // startIndex is the starting position in this name
0N/A // at which to start the comparison. It is calculated by
0N/A // subtracting 'posn' from size()
0N/A int startIndex = size() - posn;
0N/A if (startIndex < 0 || startIndex > size()) {
0N/A return false;
0N/A }
0N/A try {
0N/A Enumeration mycomps = getSuffix(startIndex);
0N/A while (mycomps.hasMoreElements()) {
0N/A String my = (String)mycomps.nextElement();
0N/A String his = (String)suffix.nextElement();
0N/A if (syntaxTrimBlanks) {
0N/A my = my.trim();
0N/A his = his.trim();
0N/A }
0N/A if (syntaxCaseInsensitive) {
0N/A if (!(my.equalsIgnoreCase(his)))
0N/A return false;
0N/A } else {
0N/A if (!(my.equals(his)))
0N/A return false;
0N/A }
0N/A }
0N/A } catch (NoSuchElementException e) {
0N/A return false;
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A public boolean addAll(Enumeration comps) throws InvalidNameException {
0N/A boolean added = false;
0N/A while (comps.hasMoreElements()) {
0N/A try {
0N/A Object comp = comps.nextElement();
0N/A if (size() > 0 && syntaxDirection == FLAT) {
0N/A throw new InvalidNameException(
0N/A "A flat name can only have a single component");
0N/A }
0N/A components.addElement(comp);
0N/A added = true;
0N/A } catch (NoSuchElementException e) {
0N/A break; // "comps" has shrunk.
0N/A }
0N/A }
0N/A return added;
0N/A }
0N/A
0N/A public boolean addAll(int posn, Enumeration comps)
0N/A throws InvalidNameException {
0N/A boolean added = false;
0N/A for (int i = posn; comps.hasMoreElements(); i++) {
0N/A try {
0N/A Object comp = comps.nextElement();
0N/A if (size() > 0 && syntaxDirection == FLAT) {
0N/A throw new InvalidNameException(
0N/A "A flat name can only have a single component");
0N/A }
0N/A components.insertElementAt(comp, i);
0N/A added = true;
0N/A } catch (NoSuchElementException e) {
0N/A break; // "comps" has shrunk.
0N/A }
0N/A }
0N/A return added;
0N/A }
0N/A
0N/A public void add(String comp) throws InvalidNameException {
0N/A if (size() > 0 && syntaxDirection == FLAT) {
0N/A throw new InvalidNameException(
0N/A "A flat name can only have a single component");
0N/A }
0N/A components.addElement(comp);
0N/A }
0N/A
0N/A public void add(int posn, String comp) throws InvalidNameException {
0N/A if (size() > 0 && syntaxDirection == FLAT) {
0N/A throw new InvalidNameException(
0N/A "A flat name can only zero or one component");
0N/A }
0N/A components.insertElementAt(comp, posn);
0N/A }
0N/A
0N/A public Object remove(int posn) {
0N/A Object r = components.elementAt(posn);
0N/A components.removeElementAt(posn);
0N/A return r;
0N/A }
0N/A
0N/A public int hashCode() {
0N/A int hash = 0;
0N/A for (Enumeration e = getAll(); e.hasMoreElements();) {
0N/A String comp = (String)e.nextElement();
0N/A if (syntaxTrimBlanks) {
0N/A comp = comp.trim();
0N/A }
0N/A if (syntaxCaseInsensitive) {
0N/A comp = comp.toLowerCase();
0N/A }
0N/A
0N/A hash += comp.hashCode();
0N/A }
0N/A return hash;
0N/A }
0N/A}
0N/A
0N/Afinal
0N/Aclass NameImplEnumerator implements Enumeration {
0N/A Vector vector;
0N/A int count;
0N/A int limit;
0N/A
0N/A NameImplEnumerator(Vector v, int start, int lim) {
0N/A vector = v;
0N/A count = start;
0N/A limit = lim;
0N/A }
0N/A
0N/A public boolean hasMoreElements() {
0N/A return count < limit;
0N/A }
0N/A
0N/A public Object nextElement() {
0N/A if (count < limit) {
0N/A return vector.elementAt(count++);
0N/A }
0N/A throw new NoSuchElementException("NameImplEnumerator");
0N/A }
0N/A}