1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 1999 by Sun Microsystems, Inc. 23 * All rights reserved. 24 * 25 */ 26 27 // AttributeString.java: Model an Attribute value string. 28 // Author: James Kempf 29 // Created On: Wed Apr 8 10:40:03 1998 30 // Last Modified By: James Kempf 31 // Last Modified On: Wed Jul 29 15:21:32 1998 32 // Update Count: 16 33 // 34 35 package com.sun.slp; 36 37 import java.util.*; 38 import java.io.*; 39 40 /** 41 * The AttributeString class embodies the SLP lower cased, space compressed 42 * string matching rules. It precomputes an 43 * efficient string for matching, squeezing out whitespace and lower casing. 44 * The toString() method returns the original string. Note that it does 45 * NOT handle pattern wildcard matching. 46 * 47 * @author James Kempf 48 */ 49 50 class AttributeString extends Object { 51 52 String string; // the original string. 53 String cstring; // whitespace separated, lower cased parts. 54 Locale locale; // the locale in which this string was created. 55 56 // Create an attribute string. Use the passed in locale to determine 57 // the lower casing rules. 58 AttributeString(String str, Locale nlocale)59 AttributeString(String str, Locale nlocale) { 60 61 string = str; 62 locale = nlocale; 63 64 cstring = parse(str, nlocale); 65 66 } 67 68 // Parse the string into whitespace separated, lower cased parts. 69 parse(String str, Locale nlocale)70 private String parse(String str, Locale nlocale) { 71 72 StringBuffer buf = new StringBuffer(); 73 74 StringTokenizer tk = 75 new StringTokenizer(str, ServiceLocationAttribute.WHITESPACE); 76 77 while (tk.hasMoreTokens()) { 78 buf.append(tk.nextToken().toLowerCase(nlocale)); 79 buf.append(ServiceLocationAttribute.SPACE); 80 81 } 82 83 return buf.toString().trim(); 84 } 85 86 // 87 // Comparison operations. 88 // 89 90 // For compatibility with AttributePattern. 91 match(AttributeString str)92 public boolean match(AttributeString str) { 93 return equals(str); 94 95 } 96 lessEqual(AttributeString str)97 public boolean lessEqual(AttributeString str) { 98 99 return (cstring.compareTo(str.cstring) <= 0); 100 101 } 102 greaterEqual(AttributeString str)103 public boolean greaterEqual(AttributeString str) { 104 return (cstring.compareTo(str.cstring) >= 0); 105 106 } 107 108 // 109 // Object overrides. 110 // 111 112 /** 113 * Return true if obj pattern matches with this string. 114 */ 115 equals(Object obj)116 public boolean equals(Object obj) { 117 118 if (obj == this) { 119 return true; 120 121 } 122 123 if (!(obj instanceof AttributeString)) { 124 return false; 125 126 } 127 128 return cstring.equals(((AttributeString)obj).cstring); 129 } 130 131 /** 132 * Return the original string. 133 */ 134 toString()135 public String toString() { 136 return string; 137 138 } 139 140 /** 141 * Hash on the computed string. 142 */ 143 hashCode()144 public int hashCode() { 145 return cstring.toString().hashCode(); 146 147 } 148 149 } 150