jdk/src/share/classes/javax/naming/directory/BasicAttribute.java
author psandoz
Mon, 16 Jun 2014 17:45:26 +0100
changeset 24969 afa6934dd8e8
parent 10324 e28265130e4f
permissions -rw-r--r--
8041679: Replace uses of StringBuffer with StringBuilder within core library classes Reviewed-by: psandoz, alanb, xuelei, dfuchs, jfranck, prr, serb, chegar Contributed-by: otaviopolianasantana@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.naming.directory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.NoSuchElementException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.Array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.naming.NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.naming.NamingEnumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.naming.OperationNotSupportedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  * This class provides a basic implementation of the <tt>Attribute</tt> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  * This implementation does not support the schema methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  * <tt>getAttributeDefinition()</tt> and <tt>getAttributeSyntaxDefinition()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  * They simply throw <tt>OperationNotSupportedException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  * Subclasses of <tt>BasicAttribute</tt> should override these methods if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  * support them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  * The <tt>BasicAttribute</tt> class by default uses <tt>Object.equals()</tt> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  * determine equality of attribute values when testing for equality or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  * when searching for values, <em>except</em> when the value is an array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  * For an array, each element of the array is checked using <tt>Object.equals()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  * Subclasses of <tt>BasicAttribute</tt> can make use of schema information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  * when doing similar equality checks by overriding methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  * in which such use of schema is meaningful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  * Similarly, the <tt>BasicAttribute</tt> class by default returns the values passed to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  * constructor and/or manipulated using the add/remove methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  * Subclasses of <tt>BasicAttribute</tt> can override <tt>get()</tt> and <tt>getAll()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  * to get the values dynamically from the directory (or implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  * the <tt>Attribute</tt> interface directly instead of subclassing <tt>BasicAttribute</tt>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  * Note that updates to <tt>BasicAttribute</tt> (such as adding or removing a value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  * does not affect the corresponding representation of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  * in the directory.  Updates to the directory can only be effected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  * using operations in the <tt>DirContext</tt> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  * A <tt>BasicAttribute</tt> instance is not synchronized against concurrent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  * multithreaded access. Multiple threads trying to access and modify a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  * <tt>BasicAttribute</tt> should lock the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public class BasicAttribute implements Attribute {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Holds the attribute's id. It is initialized by the public constructor and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * cannot be null unless methods in BasicAttribute that use attrID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * have been overridden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected String attrID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Holds the attribute's values. Initialized by public constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Cannot be null unless methods in BasicAttribute that use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * values have been overridden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected transient Vector<Object> values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * A flag for recording whether this attribute's values are ordered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected boolean ordered = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    94
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        BasicAttribute attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            attr = (BasicAttribute)super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            attr = new BasicAttribute(attrID, ordered);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   102
        attr.values = (Vector<Object>)values.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
      * Determines whether obj is equal to this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      * Two attributes are equal if their attribute-ids, syntaxes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      * and values are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
      * If the attribute values are unordered, the order that the values were added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      * are irrelevant. If the attribute values are ordered, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      * order the values must match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      * If obj is null or not an Attribute, false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      * By default <tt>Object.equals()</tt> is used when comparing the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
      * id and its values except when a value is an array. For an array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      * each element of the array is checked using <tt>Object.equals()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      * A subclass may override this to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      * use of schema syntax information and matching rules,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      * which define what it means for two attributes to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      * How and whether a subclass makes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
      * use of the schema information is determined by the subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      * If a subclass overrides <tt>equals()</tt>, it should also override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
      * <tt>hashCode()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      * such that two attributes that are equal have the same hash code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
      * @param obj      The possibly null object to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      * @return true if obj is equal to this attribute; false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
      * @see #hashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      * @see #contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if ((obj != null) && (obj instanceof Attribute)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            Attribute target = (Attribute)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            // Check order first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            if (isOrdered() != target.isOrdered()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            if (attrID.equals(target.getID()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                (len=size()) == target.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    if (isOrdered()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                        // Go through both list of values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                            if (!valueEquals(get(i), target.get(i))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                        // order is not relevant; check for existence
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   153
                        Enumeration<?> theirs = target.getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                        while (theirs.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                            if (find(theirs.nextElement()) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      * Calculates the hash code of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      * The hash code is computed by adding the hash code of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
      * the attribute's id and that of all of its values except for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      * values that are arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      * For an array, the hash code of each element of the array is summed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      * If a subclass overrides <tt>hashCode()</tt>, it should override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      * <tt>equals()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      * as well so that two attributes that are equal have the same hash code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
      * @return an int representing the hash code of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
      * @see #equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        int hash = attrID.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        int num = values.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        Object val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        for (int i = 0; i < num; i ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            val = values.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (val != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                if (val.getClass().isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    Object it;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    int len = Array.getLength(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    for (int j = 0 ; j < len ; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        it = Array.get(val, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                        if (it != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                            hash += it.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    hash += val.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
      * Generates the string representation of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
      * The string consists of the attribute's id and its values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
      * This string is meant for debugging and not meant to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
      * interpreted programmatically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
      * @return The non-null string representation of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public String toString() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 10324
diff changeset
   214
        StringBuilder answer = new StringBuilder(attrID + ": ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if (values.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            answer.append("No values");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            boolean start = true;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   219
            for (Enumeration<Object> e = values.elements(); e.hasMoreElements(); ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                if (!start)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    answer.append(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                answer.append(e.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                start = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return answer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
      * Constructs a new instance of an unordered attribute with no value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
      * @param id The attribute's id. It cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public BasicAttribute(String id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        this(id, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
      * Constructs a new instance of an unordered attribute with a single value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
      * @param id The attribute's id. It cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
      * @param value The attribute's value. If null, a null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
      *        value is added to the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public BasicAttribute(String id, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        this(id, value, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      * Constructs a new instance of a possibly ordered attribute with no value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      * @param id The attribute's id. It cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      * @param ordered true means the attribute's values will be ordered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public BasicAttribute(String id, boolean ordered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        attrID = id;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   258
        values = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        this.ordered = ordered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      * Constructs a new instance of a possibly ordered attribute with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
      * single value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
      * @param id The attribute's id. It cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      * @param value The attribute's value. If null, a null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
      *        value is added to the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      * @param ordered true means the attribute's values will be ordered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public BasicAttribute(String id, Object value, boolean ordered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        this(id, ordered);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        values.addElement(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
      * Retrieves an enumeration of this attribute's values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
      * By default, the values returned are those passed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
      * constructor and/or manipulated using the add/replace/remove methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
      * A subclass may override this to retrieve the values dynamically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
      * from the directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public NamingEnumeration<?> getAll() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      return new ValuesEnumImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      * Retrieves one of this attribute's values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      * By default, the value returned is one of those passed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      * constructor and/or manipulated using the add/replace/remove methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      * A subclass may override this to retrieve the value dynamically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
      * from the directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public Object get() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (values.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        NoSuchElementException("Attribute " + getID() + " has no value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            return values.elementAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
      return values.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public String getID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return attrID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
      * Determines whether a value is in this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
      * By default,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      * <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      * with this attribute's values except when <tt>attrVal</tt> is an array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
      * For an array, each element of the array is checked using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      * <tt>Object.equals()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      * A subclass may use schema information to determine equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public boolean contains(Object attrVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return (find(attrVal) >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    // For finding first element that has a null in JDK1.1 Vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    // In the Java 2 platform, can just replace this with Vector.indexOf(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    private int find(Object target) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   331
        Class<?> cl;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (target == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            int ct = values.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            for (int i = 0 ; i < ct ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                if (values.elementAt(i) == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        } else if ((cl=target.getClass()).isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            int ct = values.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            Object it;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            for (int i = 0 ; i < ct ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                it = values.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                if (it != null && cl == it.getClass()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    && arrayEquals(target, it))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            return values.indexOf(target, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return -1;  // not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Determines whether two attribute values are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Use arrayEquals for arrays and <tt>Object.equals()</tt> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    private static boolean valueEquals(Object obj1, Object obj2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (obj1 == obj2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            return true; // object references are equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (obj1 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            return false; // obj2 was not false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (obj1.getClass().isArray() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            obj2.getClass().isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            return arrayEquals(obj1, obj2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return (obj1.equals(obj2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * Determines whether two arrays are equal by comparing each of their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * elements using <tt>Object.equals()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    private static boolean arrayEquals(Object a1, Object a2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if ((len = Array.getLength(a1)) != Array.getLength(a2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        for (int j = 0; j < len; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            Object i1 = Array.get(a1, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            Object i2 = Array.get(a2, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            if (i1 == null || i2 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                if (i1 != i2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            } else if (!i1.equals(i2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
      * Adds a new value to this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
      * By default, <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
      * with this attribute's values except when <tt>attrVal</tt> is an array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
      * For an array, each element of the array is checked using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
      * <tt>Object.equals()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
      * A subclass may use schema information to determine equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public boolean add(Object attrVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (isOrdered() || (find(attrVal) < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            values.addElement(attrVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
      * Removes a specified value from this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
      * By default, <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
      * with this attribute's values except when <tt>attrVal</tt> is an array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
      * For an array, each element of the array is checked using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
      * <tt>Object.equals()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
      * A subclass may use schema information to determine equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public boolean remove(Object attrval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        // For the Java 2 platform, can just use "return removeElement(attrval);"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        // Need to do the following to handle null case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        int i = find(attrval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if (i >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            values.removeElementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        values.setSize(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
//  ---- ordering methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public boolean isOrdered() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return ordered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    public Object get(int ix) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        return values.elementAt(ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public Object remove(int ix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        Object answer = values.elementAt(ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        values.removeElementAt(ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public void add(int ix, Object attrVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (!isOrdered() && contains(attrVal)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                "Cannot add duplicate to unordered attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        values.insertElementAt(attrVal, ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public Object set(int ix, Object attrVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (!isOrdered() && contains(attrVal)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            throw new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                "Cannot add duplicate to unordered attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        Object answer = values.elementAt(ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        values.setElementAt(attrVal, ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return answer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
// ----------------- Schema methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
      * Retrieves the syntax definition associated with this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
      * This method by default throws OperationNotSupportedException. A subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
      * should override this method if it supports schema.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public DirContext getAttributeSyntaxDefinition() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            throw new OperationNotSupportedException("attribute syntax");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
      * Retrieves this attribute's schema definition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
      * This method by default throws OperationNotSupportedException. A subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
      * should override this method if it supports schema.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public DirContext getAttributeDefinition() throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        throw new OperationNotSupportedException("attribute definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
//  ---- serialization methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * Overridden to avoid exposing implementation details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @serialData Default field (the attribute ID -- a String),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * followed by the number of values (an int), and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * individual values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        s.defaultWriteObject(); // write out the attrID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        s.writeInt(values.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        for (int i = 0; i < values.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            s.writeObject(values.elementAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Overridden to avoid exposing implementation details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            throws java.io.IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        s.defaultReadObject();  // read in the attrID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        int n = s.readInt();    // number of values
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   518
        values = new Vector<>(n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        while (--n >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            values.addElement(s.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    class ValuesEnumImpl implements NamingEnumeration<Object> {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   526
        Enumeration<Object> list;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   528
        ValuesEnumImpl() {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   529
            list = values.elements();
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   530
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   532
        public boolean hasMoreElements() {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   533
            return list.hasMoreElements();
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   534
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   536
        public Object nextElement() {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   537
            return(list.nextElement());
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   538
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   540
        public Object next() throws NamingException {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   541
            return list.nextElement();
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   542
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   544
        public boolean hasMore() throws NamingException {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   545
            return list.hasMoreElements();
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   546
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   548
        public void close() throws NamingException {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   549
            list = null;
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   550
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Use serialVersionUID from JNDI 1.1.1 for interoperability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    private static final long serialVersionUID = 6743528196119291326L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
}