2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1999 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A *
2N/A */
2N/A
2N/A// AttributeString.java: Model an Attribute value string.
2N/A// Author: James Kempf
2N/A// Created On: Wed Apr 8 10:40:03 1998
2N/A// Last Modified By: James Kempf
2N/A// Last Modified On: Wed Jul 29 15:21:32 1998
2N/A// Update Count: 16
2N/A//
2N/A
2N/Apackage com.sun.slp;
2N/A
2N/Aimport java.util.*;
2N/Aimport java.io.*;
2N/A
2N/A/**
2N/A * The AttributeString class embodies the SLP lower cased, space compressed
2N/A * string matching rules. It precomputes an
2N/A * efficient string for matching, squeezing out whitespace and lower casing.
2N/A * The toString() method returns the original string. Note that it does
2N/A * NOT handle pattern wildcard matching.
2N/A *
2N/A * @author James Kempf
2N/A */
2N/A
2N/Aclass AttributeString extends Object {
2N/A
2N/A String string; // the original string.
2N/A String cstring; // whitespace separated, lower cased parts.
2N/A Locale locale; // the locale in which this string was created.
2N/A
2N/A // Create an attribute string. Use the passed in locale to determine
2N/A // the lower casing rules.
2N/A
2N/A AttributeString(String str, Locale nlocale) {
2N/A
2N/A string = str;
2N/A locale = nlocale;
2N/A
2N/A cstring = parse(str, nlocale);
2N/A
2N/A }
2N/A
2N/A // Parse the string into whitespace separated, lower cased parts.
2N/A
2N/A private String parse(String str, Locale nlocale) {
2N/A
2N/A StringBuffer buf = new StringBuffer();
2N/A
2N/A StringTokenizer tk =
2N/A new StringTokenizer(str, ServiceLocationAttribute.WHITESPACE);
2N/A
2N/A while (tk.hasMoreTokens()) {
2N/A buf.append(tk.nextToken().toLowerCase(nlocale));
2N/A buf.append(ServiceLocationAttribute.SPACE);
2N/A
2N/A }
2N/A
2N/A return buf.toString().trim();
2N/A }
2N/A
2N/A //
2N/A // Comparison operations.
2N/A //
2N/A
2N/A // For compatibility with AttributePattern.
2N/A
2N/A public boolean match(AttributeString str) {
2N/A return equals(str);
2N/A
2N/A }
2N/A
2N/A public boolean lessEqual(AttributeString str) {
2N/A
2N/A return (cstring.compareTo(str.cstring) <= 0);
2N/A
2N/A }
2N/A
2N/A public boolean greaterEqual(AttributeString str) {
2N/A return (cstring.compareTo(str.cstring) >= 0);
2N/A
2N/A }
2N/A
2N/A //
2N/A // Object overrides.
2N/A //
2N/A
2N/A /**
2N/A * Return true if obj pattern matches with this string.
2N/A */
2N/A
2N/A public boolean equals(Object obj) {
2N/A
2N/A if (obj == this) {
2N/A return true;
2N/A
2N/A }
2N/A
2N/A if (!(obj instanceof AttributeString)) {
2N/A return false;
2N/A
2N/A }
2N/A
2N/A return cstring.equals(((AttributeString)obj).cstring);
2N/A }
2N/A
2N/A /**
2N/A * Return the original string.
2N/A */
2N/A
2N/A public String toString() {
2N/A return string;
2N/A
2N/A }
2N/A
2N/A /**
2N/A * Hash on the computed string.
2N/A */
2N/A
2N/A public int hashCode() {
2N/A return cstring.toString().hashCode();
2N/A
2N/A }
2N/A
2N/A}