2362N/A * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 * 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 * 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. 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 0N/A * This class provides a basic implementation of the <tt>Attribute</tt> interface. 0N/A * This implementation does not support the schema methods 0N/A * <tt>getAttributeDefinition()</tt> and <tt>getAttributeSyntaxDefinition()</tt>. 0N/A * They simply throw <tt>OperationNotSupportedException</tt>. 0N/A * Subclasses of <tt>BasicAttribute</tt> should override these methods if they 0N/A * The <tt>BasicAttribute</tt> class by default uses <tt>Object.equals()</tt> to 0N/A * determine equality of attribute values when testing for equality or 0N/A * when searching for values, <em>except</em> when the value is an array. 0N/A * For an array, each element of the array is checked using <tt>Object.equals()</tt>. 0N/A * Subclasses of <tt>BasicAttribute</tt> can make use of schema information 0N/A * when doing similar equality checks by overriding methods 0N/A * in which such use of schema is meaningful. 0N/A * Similarly, the <tt>BasicAttribute</tt> class by default returns the values passed to its 0N/A * Subclasses of <tt>BasicAttribute</tt> can override <tt>get()</tt> and <tt>getAll()</tt> 0N/A * to get the values dynamically from the directory (or implement 0N/A * the <tt>Attribute</tt> interface directly instead of subclassing <tt>BasicAttribute</tt>). 0N/A * Note that updates to <tt>BasicAttribute</tt> (such as adding or removing a value) 0N/A * does not affect the corresponding representation of the attribute 0N/A * in the directory. Updates to the directory can only be effected 0N/A * using operations in the <tt>DirContext</tt> interface. 0N/A * A <tt>BasicAttribute</tt> instance is not synchronized against concurrent 0N/A * multithreaded access. Multiple threads trying to access and modify a 0N/A * <tt>BasicAttribute</tt> should lock the object. 0N/A * @author Rosanna Lee 0N/A * @author Scott Seligman 0N/A * Holds the attribute's id. It is initialized by the public constructor and 0N/A * cannot be null unless methods in BasicAttribute that use attrID 0N/A * have been overridden. 0N/A * Holds the attribute's values. Initialized by public constructors. 0N/A * Cannot be null unless methods in BasicAttribute that use 0N/A * values have been overridden. 0N/A * A flag for recording whether this attribute's values are ordered. 0N/A * Determines whether obj is equal to this attribute. 0N/A * Two attributes are equal if their attribute-ids, syntaxes 0N/A * and values are equal. 0N/A * If the attribute values are unordered, the order that the values were added 0N/A * are irrelevant. If the attribute values are ordered, then the 0N/A * order the values must match. 0N/A * If obj is null or not an Attribute, false is returned. 0N/A * By default <tt>Object.equals()</tt> is used when comparing the attribute 0N/A * id and its values except when a value is an array. For an array, 0N/A * each element of the array is checked using <tt>Object.equals()</tt>. 0N/A * A subclass may override this to make 0N/A * use of schema syntax information and matching rules, 0N/A * which define what it means for two attributes to be equal. 0N/A * How and whether a subclass makes 0N/A * use of the schema information is determined by the subclass. 0N/A * If a subclass overrides <tt>equals()</tt>, it should also override 0N/A * <tt>hashCode()</tt> 0N/A * such that two attributes that are equal have the same hash code. 0N/A * @param obj The possibly null object to check. 0N/A * @return true if obj is equal to this attribute; false otherwise. 0N/A // Check order first 0N/A // Go through both list of values 0N/A for (
int i =
0; i <
len; i++) {
0N/A // order is not relevant; check for existence 0N/A * Calculates the hash code of this attribute. 0N/A * The hash code is computed by adding the hash code of 0N/A * the attribute's id and that of all of its values except for 0N/A * values that are arrays. 0N/A * For an array, the hash code of each element of the array is summed. 0N/A * If a subclass overrides <tt>hashCode()</tt>, it should override 0N/A * as well so that two attributes that are equal have the same hash code. 0N/A * @return an int representing the hash code of this attribute. 0N/A for (
int i =
0; i <
num; i ++) {
0N/A for (
int j =
0 ; j <
len ; j++) {
0N/A * Generates the string representation of this attribute. 0N/A * The string consists of the attribute's id and its values. 0N/A * This string is meant for debugging and not meant to be 0N/A * interpreted programmatically. 0N/A * @return The non-null string representation of this attribute. 0N/A * Constructs a new instance of an unordered attribute with no value. 0N/A * @param id The attribute's id. It cannot be null. 0N/A * Constructs a new instance of an unordered attribute with a single value. 0N/A * @param id The attribute's id. It cannot be null. 0N/A * @param value The attribute's value. If null, a null 0N/A * value is added to the attribute. 0N/A * Constructs a new instance of a possibly ordered attribute with no value. 0N/A * @param id The attribute's id. It cannot be null. 0N/A * @param ordered true means the attribute's values will be ordered; 0N/A * Constructs a new instance of a possibly ordered attribute with a 0N/A * @param id The attribute's id. It cannot be null. 0N/A * @param value The attribute's value. If null, a null 0N/A * value is added to the attribute. 0N/A * @param ordered true means the attribute's values will be ordered; 0N/A * Retrieves an enumeration of this attribute's values. 0N/A * By default, the values returned are those passed to the 0N/A * A subclass may override this to retrieve the values dynamically 0N/A * from the directory. 0N/A * Retrieves one of this attribute's values. 0N/A * By default, the value returned is one of those passed to the 0N/A * A subclass may override this to retrieve the value dynamically 0N/A * from the directory. 0N/A * Determines whether a value is in this attribute. 0N/A * <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt> 0N/A * with this attribute's values except when <tt>attrVal</tt> is an array. 0N/A * For an array, each element of the array is checked using 0N/A * <tt>Object.equals()</tt>. 0N/A * A subclass may use schema information to determine equality. 0N/A // For finding first element that has a null in JDK1.1 Vector. 0N/A // In the Java 2 platform, can just replace this with Vector.indexOf(target); 0N/A for (
int i =
0 ; i <
ct ; i++) {
0N/A for (
int i =
0 ; i <
ct ; i++) {
0N/A return -
1;
// not found 0N/A * Determines whether two attribute values are equal. 0N/A * Use arrayEquals for arrays and <tt>Object.equals()</tt> otherwise. 0N/A return true;
// object references are equal 0N/A return false;
// obj2 was not false 0N/A * Determines whether two arrays are equal by comparing each of their 0N/A * elements using <tt>Object.equals()</tt>. 0N/A for (
int j =
0; j <
len; j++) {
0N/A * Adds a new value to this attribute. 0N/A * By default, <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt> 0N/A * with this attribute's values except when <tt>attrVal</tt> is an array. 0N/A * For an array, each element of the array is checked using 0N/A * <tt>Object.equals()</tt>. 0N/A * A subclass may use schema information to determine equality. 0N/A * Removes a specified value from this attribute. 0N/A * By default, <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt> 0N/A * with this attribute's values except when <tt>attrVal</tt> is an array. 0N/A * For an array, each element of the array is checked using 0N/A * <tt>Object.equals()</tt>. 0N/A * A subclass may use schema information to determine equality. 0N/A // For the Java 2 platform, can just use "return removeElement(attrval);" 0N/A // Need to do the following to handle null case 0N/A// ---- ordering methods 0N/A "Cannot add duplicate to unordered attribute");
0N/A "Cannot add duplicate to unordered attribute");
0N/A// ----------------- Schema methods 0N/A * Retrieves the syntax definition associated with this attribute. 0N/A * This method by default throws OperationNotSupportedException. A subclass 0N/A * should override this method if it supports schema. 0N/A * Retrieves this attribute's schema definition. 0N/A * This method by default throws OperationNotSupportedException. A subclass 0N/A * should override this method if it supports schema. 0N/A// ---- serialization methods 0N/A * Overridden to avoid exposing implementation details 0N/A * @serialData Default field (the attribute ID -- a String), 0N/A * followed by the number of values (an int), and the 0N/A * individual values. 0N/A * Overridden to avoid exposing implementation details. 0N/A * Use serialVersionUID from JNDI 1.1.1 for interoperability.