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 * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 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 * Copyright 2001,2003 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A// Author: James Kempf, Erik Guttman 2N/A * The ServiceLocationAttribute class models SLP attributes. 2N/A * @author James Kempf, Erik Guttman 2N/A // Characters to escape. 2N/A final static char DEL = (
char)
0x7F;
2N/A // Whitespace chars. 2N/A // For character escaping. 2N/A // Bad tag characters. 2N/A // For identifying booleans. 2N/A // Package accessable fields. 2N/A // For V1 compatibility subclass. 2N/A * Construct a service location attribute. 2N/A * @param id The attribute name 2N/A * @param values_in Vector of one or more attribute values. Vector 2N/A * contents must be uniform in type and one of 2N/A * Integer, String, Boolean, or byte[]. If the attribute 2N/A * is a keyword attribute, then values_in should be null. 2N/A * @exception IllegalArgumentException Thrown if the 2N/A * vector contents is not of the right type or 2N/A * an argument is null or syntactically incorrect. 2N/A * Construct a service location attribute from a parenthesized expression. 2N/A * exp = "(" id "=" value-list ")" | keyword 2N/A * value-list = value | value "," value-list 2N/A * @param exp The expression 2N/A * @param dontTypeCheck True if multivalued booleans and vectors 2N/A * of varying types are allowed. 2N/A * @exception ServiceLocationException If there are any syntax errors. 2N/A "null_string_parameter",
2N/A // If start and end paren, then parse out assignment. 2N/A // Parse the comma separated list. 2N/A // Convert to objects. 2N/A for (i =
0; i < n; i++) {
2N/A // Need to determine which type to use. 2N/A "assignment_syntax_err",
2N/A // Check to make sure there's no parens. 2N/A "assignment_syntax_err",
2N/A // Unescape the keyword. 2N/A // If it can be converted into an integer, then convert it. 2N/A // Wasn't an integer. Try boolean. 2N/A // Process the string to remove escapes. 2N/A // If it begins with the opaque prefix, treat it as an 2N/A // Property accessors. 2N/A * @return A vector of attribute values, or null if the attribute is 2N/A * a keyword attribute. If the attribute is single-valued, then 2N/A * the vector contains only one object. 2N/A // Need to process Opaques. 2N/A for (i =
0; i < n; i++) {
2N/A * @return The attribute name. 2N/A * Return an escaped version of the id parameter , suitable for inclusion 2N/A * @param str The string to escape as an id. 2N/A * @return The string with any reserved characters escaped. 2N/A * @exception IllegalArgumentException Thrown if the 2N/A * string contains bad tag characters. 2N/A * Return an escaped version of the value parameter, suitable for inclusion 2N/A * in a query. Opaques are stringified. 2N/A * @param val The value to escape. 2N/A * @return The stringified value. 2N/A * @exception IllegalArgumentException Thrown if the object is not 2N/A * one of byte[], Integer, Boolean, or String. 2N/A // Check type first. 2N/A // Make Opaque out of byte[]. 2N/A // Check type to make sure it's OK. 2N/A // We know the value's type is OK, so just escape it. 2N/A // Escape any characters needing it. 2N/A // Methods for dealing with the type of attribute values. 2N/A // Verify the types of incoming attributes. 2N/A // Make sure the types of objects passed in are acceptable 2N/A // and that all objects in the vector have the same type. 2N/A for (i =
0; i < n; i++) {
2N/A // If it's a boolean and there's more than one, signal error 2N/A // unless multivalued booleans are allowed. 2N/A // If it's a byte array, create a Opaque object. 2N/A // If it's a string and looks like "1" or "true", then 2N/A // append a space onto the end. 2N/A // Methods for externalizing attributes. 2N/A * Externalize the attribute into a string that can be written 2N/A * to a byte stream. Includes escaping any characters that 2N/A * need to be escaped. 2N/A * @return String with attribute's external representation. 2N/A * @exception ServiceLocationException Thrown if the 2N/A * string contains unencodable characters. 2N/A // Escaping and unescaping strings. 2N/A * Escape any escapable characters to a 2 character escape 2N/A * in the attribute string. 2N/A * @param string The String. 2N/A * @param badTag Check for bad tag characters if true. 2N/A * @return The escaped string. 2N/A * @exception ServiceLocationException Thrown if the string 2N/A * contains a character that can't be encoded. 2N/A for (i =
0; i < n; i++) {
2N/A // Check for bad tag characters first. 2N/A // Escape if the character is reserved. 2N/A // Pad with zero if less than 2 characters. 2N/A * Convert any 2 character escapes to the corresponding characters. 2N/A * @param string The string to be processed. 2N/A * @param badTag Check for bad tag characters if true. 2N/A * @return The processed string. 2N/A * @exception ServiceLocationException Thrown if an escape 2N/A * is improperly formatted. 2N/A for (i =
0; i < n; i++) {
2N/A // Check for escaped characters. 2N/A // Get the next two characters. 2N/A "nonterminating_escape",
2N/A // Check whether it's reserved. 2N/A "char_not_reserved_attr",
2N/A // Check whether the character is reserved. 2N/A "reserved_not_escaped",
2N/A // If we need to check for a bad tag character, do so now. 2N/A // Return true if the character c can be escaped. 2N/A // Return true if the character c is reserved. 2N/A * Return a string of integers giving the character's encoding in 2N/A * the character set passed in as encoding. 2N/A * @param c The character to escape. 2N/A * @return The character as a string of integers for the encoding. 2N/A // Assemble the character code. 2N/A * Unescape the character encoded as the string. 2N/A * @param ch The character as a string of hex digits. 2N/A * @return The character. 2N/A * @exception ServiceLocationException If the characters can't be 2N/A * converted into a hex string. 2N/A // Convert to bytes. 2N/A // We allow illegal UTF8 encoding so we can decode byte arrays. 2N/A // Make a string out of it. 2N/A * Merge the values in newAttr into the attribute in the hashtable 2N/A * if a duplicate attribute, signal error if a type mismatch. 2N/A * Both the return vector and hashtable are updated, but the 2N/A * newAttr parameter is left unchanged. 2N/A * @param attr The ServiceLocationAttribute to check. 2N/A * @param attrHash A Hashtable containing the attribute tags as 2N/A * keys and the attributes as values. 2N/A * @param returns A Vector in which to put the attribute when done. 2N/A * @param dontTypeCheck If this flag is true, the value vector 2N/A * may have two booleans, may 2N/A * contain differently typed objects, or the 2N/A * function may merge a keyword and nonkeyword 2N/A * @exception ServiceLocationException Thrown if a type mismatch 2N/A // Look up the attribute 2N/A // Don't try this trick with ServerAttributes! 2N/A // If the attribute isn't in the hashtable, then add to 2N/A // vector and hashtable. 2N/A // If both keywords, nothing further to do. 2N/A // If we are not typechecking and one is keyword while the other 2N/A // is not, then simply merge in the nonkeyword. Otherwise, 2N/A // throw a type check exception. 2N/A "attribute_type_mismatch",
2N/A // Merge the two vectors. We type check against the attrVals 2N/A // vector, if we are type checking. 2N/A for (i =
0; i < n; i++) {
2N/A // Check for type mismatch, throw exception if 2N/A // we are type checking. 2N/A "attribute_type_mismatch",
2N/A // If we are typechecking, and we get two opposite 2N/A // booleans, we need to throw an exception. 2N/A // Add the value if it isn't already there. 2N/A // Set the new attribute's values so they are the same as the old. 2N/A // Object overrides. 2N/A * Return true if the object equals this attribute. 2N/A // check equality of contents, deferring check of all values 2N/A for (i =
0; i < n; i++) {
2N/A * Return a human readable string for the attribute. 2N/A for (i =
0; i < n; i++) {
2N/A // Stringify object. 2N/A // Overrides Object.hashCode().