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