feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
340
jdkSrc/jdk8/javax/naming/directory/Attribute.java
Normal file
340
jdkSrc/jdk8/javax/naming/directory/Attribute.java
Normal file
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.OperationNotSupportedException;
|
||||
|
||||
/**
|
||||
* This interface represents an attribute associated with a named object.
|
||||
*<p>
|
||||
* In a directory, named objects can have associated with them
|
||||
* attributes. The <tt>Attribute</tt> interface represents an attribute associated
|
||||
* with a named object. An attribute contains 0 or more, possibly null, values.
|
||||
* The attribute values can be ordered or unordered (see <tt>isOrdered()</tt>).
|
||||
* If the values are unordered, no duplicates are allowed.
|
||||
* If the values are ordered, duplicates are allowed.
|
||||
*<p>
|
||||
* The content and representation of an attribute and its values is defined by
|
||||
* the attribute's <em>schema</em>. The schema contains information
|
||||
* about the attribute's syntax and other properties about the attribute.
|
||||
* See <tt>getAttributeDefinition()</tt> and
|
||||
* <tt>getAttributeSyntaxDefinition()</tt>
|
||||
* for details regarding how to get schema information about an attribute
|
||||
* if the underlying directory service supports schemas.
|
||||
*<p>
|
||||
* Equality of two attributes is determined by the implementation class.
|
||||
* A simple implementation can use <tt>Object.equals()</tt> to determine equality
|
||||
* of attribute values, while a more sophisticated implementation might
|
||||
* make use of schema information to determine equality.
|
||||
* Similarly, one implementation might provide a static storage
|
||||
* structure which simply returns the values passed to its
|
||||
* constructor, while another implementation might define <tt>get()</tt> and
|
||||
* <tt>getAll()</tt>.
|
||||
* to get the values dynamically from the directory.
|
||||
*<p>
|
||||
* Note that updates to <tt>Attribute</tt> (such as adding or removing a
|
||||
* value) do not affect the corresponding representation of the attribute
|
||||
* in the directory. Updates to the directory can only be effected
|
||||
* using operations in the <tt>DirContext</tt> interface.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
*
|
||||
* @see BasicAttribute
|
||||
* @since 1.3
|
||||
*/
|
||||
public interface Attribute extends Cloneable, java.io.Serializable {
|
||||
/**
|
||||
* Retrieves an enumeration of the attribute's values.
|
||||
* The behaviour of this enumeration is unspecified
|
||||
* if the attribute's values are added, changed,
|
||||
* or removed while the enumeration is in progress.
|
||||
* If the attribute values are ordered, the enumeration's items
|
||||
* will be ordered.
|
||||
*
|
||||
* @return A non-null enumeration of the attribute's values.
|
||||
* Each element of the enumeration is a possibly null Object. The object's
|
||||
* class is the class of the attribute value. The element is null
|
||||
* if the attribute's value is null.
|
||||
* If the attribute has zero values, an empty enumeration
|
||||
* is returned.
|
||||
* @exception NamingException
|
||||
* If a naming exception was encountered while retrieving
|
||||
* the values.
|
||||
* @see #isOrdered
|
||||
*/
|
||||
NamingEnumeration<?> getAll() throws NamingException;
|
||||
|
||||
/**
|
||||
* Retrieves one of this attribute's values.
|
||||
* If the attribute has more than one value and is unordered, any one of
|
||||
* the values is returned.
|
||||
* If the attribute has more than one value and is ordered, the
|
||||
* first value is returned.
|
||||
*
|
||||
* @return A possibly null object representing one of
|
||||
* the attribute's value. It is null if the attribute's value
|
||||
* is null.
|
||||
* @exception NamingException
|
||||
* If a naming exception was encountered while retrieving
|
||||
* the value.
|
||||
* @exception java.util.NoSuchElementException
|
||||
* If this attribute has no values.
|
||||
*/
|
||||
Object get() throws NamingException;
|
||||
|
||||
/**
|
||||
* Retrieves the number of values in this attribute.
|
||||
*
|
||||
* @return The nonnegative number of values in this attribute.
|
||||
*/
|
||||
int size();
|
||||
|
||||
/**
|
||||
* Retrieves the id of this attribute.
|
||||
*
|
||||
* @return The id of this attribute. It cannot be null.
|
||||
*/
|
||||
String getID();
|
||||
|
||||
/**
|
||||
* Determines whether a value is in the attribute.
|
||||
* Equality is determined by the implementation, which may use
|
||||
* <tt>Object.equals()</tt> or schema information to determine equality.
|
||||
*
|
||||
* @param attrVal The possibly null value to check. If null, check
|
||||
* whether the attribute has an attribute value whose value is null.
|
||||
* @return true if attrVal is one of this attribute's values; false otherwise.
|
||||
* @see java.lang.Object#equals
|
||||
* @see BasicAttribute#equals
|
||||
*/
|
||||
boolean contains(Object attrVal);
|
||||
/**
|
||||
* Adds a new value to the attribute.
|
||||
* If the attribute values are unordered and
|
||||
* <tt>attrVal</tt> is already in the attribute, this method does nothing.
|
||||
* If the attribute values are ordered, <tt>attrVal</tt> is added to the end of
|
||||
* the list of attribute values.
|
||||
*<p>
|
||||
* Equality is determined by the implementation, which may use
|
||||
* <tt>Object.equals()</tt> or schema information to determine equality.
|
||||
*
|
||||
* @param attrVal The new possibly null value to add. If null, null
|
||||
* is added as an attribute value.
|
||||
* @return true if a value was added; false otherwise.
|
||||
*/
|
||||
boolean add(Object attrVal);
|
||||
|
||||
/**
|
||||
* Removes a specified value from the attribute.
|
||||
* If <tt>attrval</tt> is not in the attribute, this method does nothing.
|
||||
* If the attribute values are ordered, the first occurrence of
|
||||
* <tt>attrVal</tt> is removed and attribute values at indices greater
|
||||
* than the removed
|
||||
* value are shifted up towards the head of the list (and their indices
|
||||
* decremented by one).
|
||||
*<p>
|
||||
* Equality is determined by the implementation, which may use
|
||||
* <tt>Object.equals()</tt> or schema information to determine equality.
|
||||
*
|
||||
* @param attrval The possibly null value to remove from this attribute.
|
||||
* If null, remove the attribute value that is null.
|
||||
* @return true if the value was removed; false otherwise.
|
||||
*/
|
||||
boolean remove(Object attrval);
|
||||
|
||||
/**
|
||||
* Removes all values from this attribute.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Retrieves the syntax definition associated with the attribute.
|
||||
* An attribute's syntax definition specifies the format
|
||||
* of the attribute's value(s). Note that this is different from
|
||||
* the attribute value's representation as a Java object. Syntax
|
||||
* definition refers to the directory's notion of <em>syntax</em>.
|
||||
*<p>
|
||||
* For example, even though a value might be
|
||||
* a Java String object, its directory syntax might be "Printable String"
|
||||
* or "Telephone Number". Or a value might be a byte array, and its
|
||||
* directory syntax is "JPEG" or "Certificate".
|
||||
* For example, if this attribute's syntax is "JPEG",
|
||||
* this method would return the syntax definition for "JPEG".
|
||||
* <p>
|
||||
* The information that you can retrieve from a syntax definition
|
||||
* is directory-dependent.
|
||||
*<p>
|
||||
* If an implementation does not support schemas, it should throw
|
||||
* OperationNotSupportedException. If an implementation does support
|
||||
* schemas, it should define this method to return the appropriate
|
||||
* information.
|
||||
* @return The attribute's syntax definition. Null if the implementation
|
||||
* supports schemas but this particular attribute does not have
|
||||
* any schema information.
|
||||
* @exception OperationNotSupportedException If getting the schema
|
||||
* is not supported.
|
||||
* @exception NamingException If a naming exception occurs while getting
|
||||
* the schema.
|
||||
*/
|
||||
|
||||
DirContext getAttributeSyntaxDefinition() throws NamingException;
|
||||
|
||||
/**
|
||||
* Retrieves the attribute's schema definition.
|
||||
* An attribute's schema definition contains information
|
||||
* such as whether the attribute is multivalued or single-valued,
|
||||
* the matching rules to use when comparing the attribute's values.
|
||||
*
|
||||
* The information that you can retrieve from an attribute definition
|
||||
* is directory-dependent.
|
||||
*
|
||||
*<p>
|
||||
* If an implementation does not support schemas, it should throw
|
||||
* OperationNotSupportedException. If an implementation does support
|
||||
* schemas, it should define this method to return the appropriate
|
||||
* information.
|
||||
* @return This attribute's schema definition. Null if the implementation
|
||||
* supports schemas but this particular attribute does not have
|
||||
* any schema information.
|
||||
* @exception OperationNotSupportedException If getting the schema
|
||||
* is not supported.
|
||||
* @exception NamingException If a naming exception occurs while getting
|
||||
* the schema.
|
||||
*/
|
||||
DirContext getAttributeDefinition() throws NamingException;
|
||||
|
||||
/**
|
||||
* Makes a copy of the attribute.
|
||||
* The copy contains the same attribute values as the original attribute:
|
||||
* the attribute values are not themselves cloned.
|
||||
* Changes to the copy will not affect the original and vice versa.
|
||||
*
|
||||
* @return A non-null copy of the attribute.
|
||||
*/
|
||||
Object clone();
|
||||
|
||||
//----------- Methods to support ordered multivalued attributes
|
||||
|
||||
/**
|
||||
* Determines whether this attribute's values are ordered.
|
||||
* If an attribute's values are ordered, duplicate values are allowed.
|
||||
* If an attribute's values are unordered, they are presented
|
||||
* in any order and there are no duplicate values.
|
||||
* @return true if this attribute's values are ordered; false otherwise.
|
||||
* @see #get(int)
|
||||
* @see #remove(int)
|
||||
* @see #add(int, java.lang.Object)
|
||||
* @see #set(int, java.lang.Object)
|
||||
*/
|
||||
boolean isOrdered();
|
||||
|
||||
/**
|
||||
* Retrieves the attribute value from the ordered list of attribute values.
|
||||
* This method returns the value at the <tt>ix</tt> index of the list of
|
||||
* attribute values.
|
||||
* If the attribute values are unordered,
|
||||
* this method returns the value that happens to be at that index.
|
||||
* @param ix The index of the value in the ordered list of attribute values.
|
||||
* {@code 0 <= ix < size()}.
|
||||
* @return The possibly null attribute value at index <tt>ix</tt>;
|
||||
* null if the attribute value is null.
|
||||
* @exception NamingException If a naming exception was encountered while
|
||||
* retrieving the value.
|
||||
* @exception IndexOutOfBoundsException If <tt>ix</tt> is outside the specified range.
|
||||
*/
|
||||
Object get(int ix) throws NamingException;
|
||||
|
||||
/**
|
||||
* Removes an attribute value from the ordered list of attribute values.
|
||||
* This method removes the value at the <tt>ix</tt> index of the list of
|
||||
* attribute values.
|
||||
* If the attribute values are unordered,
|
||||
* this method removes the value that happens to be at that index.
|
||||
* Values located at indices greater than <tt>ix</tt> are shifted up towards
|
||||
* the front of the list (and their indices decremented by one).
|
||||
*
|
||||
* @param ix The index of the value to remove.
|
||||
* {@code 0 <= ix < size()}.
|
||||
* @return The possibly null attribute value at index <tt>ix</tt> that was removed;
|
||||
* null if the attribute value is null.
|
||||
* @exception IndexOutOfBoundsException If <tt>ix</tt> is outside the specified range.
|
||||
*/
|
||||
Object remove(int ix);
|
||||
|
||||
/**
|
||||
* Adds an attribute value to the ordered list of attribute values.
|
||||
* This method adds <tt>attrVal</tt> to the list of attribute values at
|
||||
* index <tt>ix</tt>.
|
||||
* Values located at indices at or greater than <tt>ix</tt> are
|
||||
* shifted down towards the end of the list (and their indices incremented
|
||||
* by one).
|
||||
* If the attribute values are unordered and already have <tt>attrVal</tt>,
|
||||
* <tt>IllegalStateException</tt> is thrown.
|
||||
*
|
||||
* @param ix The index in the ordered list of attribute values to add the new value.
|
||||
* {@code 0 <= ix <= size()}.
|
||||
* @param attrVal The possibly null attribute value to add; if null, null is
|
||||
* the value added.
|
||||
* @exception IndexOutOfBoundsException If <tt>ix</tt> is outside the specified range.
|
||||
* @exception IllegalStateException If the attribute values are unordered and
|
||||
* <tt>attrVal</tt> is one of those values.
|
||||
*/
|
||||
void add(int ix, Object attrVal);
|
||||
|
||||
|
||||
/**
|
||||
* Sets an attribute value in the ordered list of attribute values.
|
||||
* This method sets the value at the <tt>ix</tt> index of the list of
|
||||
* attribute values to be <tt>attrVal</tt>. The old value is removed.
|
||||
* If the attribute values are unordered,
|
||||
* this method sets the value that happens to be at that index
|
||||
* to <tt>attrVal</tt>, unless <tt>attrVal</tt> is already one of the values.
|
||||
* In that case, <tt>IllegalStateException</tt> is thrown.
|
||||
*
|
||||
* @param ix The index of the value in the ordered list of attribute values.
|
||||
* {@code 0 <= ix < size()}.
|
||||
* @param attrVal The possibly null attribute value to use.
|
||||
* If null, 'null' replaces the old value.
|
||||
* @return The possibly null attribute value at index ix that was replaced.
|
||||
* Null if the attribute value was null.
|
||||
* @exception IndexOutOfBoundsException If <tt>ix</tt> is outside the specified range.
|
||||
* @exception IllegalStateException If <tt>attrVal</tt> already exists and the
|
||||
* attribute values are unordered.
|
||||
*/
|
||||
Object set(int ix, Object attrVal);
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability.
|
||||
*/
|
||||
static final long serialVersionUID = 8707690322213556804L;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when an operation attempts
|
||||
* to add an attribute that already exists.
|
||||
* <p>
|
||||
* Synchronization and serialization issues that apply to NamingException
|
||||
* apply directly here.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
*
|
||||
* @see DirContext#modifyAttributes
|
||||
* @since 1.3
|
||||
*/
|
||||
public class AttributeInUseException extends NamingException {
|
||||
/**
|
||||
* Constructs a new instance of AttributeInUseException with
|
||||
* an explanation. All other fields are set to null.
|
||||
*
|
||||
* @param explanation Possibly null additional detail about this exception.
|
||||
* @see java.lang.Throwable#getMessage
|
||||
*/
|
||||
public AttributeInUseException(String explanation) {
|
||||
super(explanation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of AttributeInUseException.
|
||||
* All fields are initialized to null.
|
||||
*/
|
||||
public AttributeInUseException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = 4437710305529322564L;
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when an attempt is
|
||||
* made to add, or remove, or modify an attribute, its identifier,
|
||||
* or its values that conflicts with the attribute's (schema) definition
|
||||
* or the attribute's state.
|
||||
* It is thrown in response to DirContext.modifyAttributes().
|
||||
* It contains a list of modifications that have not been performed, in the
|
||||
* order that they were supplied to modifyAttributes().
|
||||
* If the list is null, none of the modifications were performed successfully.
|
||||
*<p>
|
||||
* An AttributeModificationException instance is not synchronized
|
||||
* against concurrent multithreaded access. Multiple threads trying
|
||||
* to access and modify a single AttributeModification instance
|
||||
* should lock the object.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
*
|
||||
* @see DirContext#modifyAttributes
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
/*
|
||||
*<p>
|
||||
* The serialized form of an AttributeModificationException object
|
||||
* consists of the serialized fields of its NamingException
|
||||
* superclass, followed by an array of ModificationItem objects.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
public class AttributeModificationException extends NamingException {
|
||||
/**
|
||||
* Contains the possibly null list of unexecuted modifications.
|
||||
* @serial
|
||||
*/
|
||||
private ModificationItem[] unexecs = null;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of AttributeModificationException using
|
||||
* an explanation. All other fields are set to null.
|
||||
*
|
||||
* @param explanation Possibly null additional detail about this exception.
|
||||
* If null, this exception has no detail message.
|
||||
|
||||
* @see java.lang.Throwable#getMessage
|
||||
*/
|
||||
public AttributeModificationException(String explanation) {
|
||||
super(explanation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of AttributeModificationException.
|
||||
* All fields are set to null.
|
||||
*/
|
||||
public AttributeModificationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the unexecuted modification list to be e.
|
||||
* Items in the list must appear in the same order in which they were
|
||||
* originally supplied in DirContext.modifyAttributes().
|
||||
* The first item in the list is the first one that was not executed.
|
||||
* If this list is null, none of the operations originally submitted
|
||||
* to modifyAttributes() were executed.
|
||||
|
||||
* @param e The possibly null list of unexecuted modifications.
|
||||
* @see #getUnexecutedModifications
|
||||
*/
|
||||
public void setUnexecutedModifications(ModificationItem[] e) {
|
||||
unexecs = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the unexecuted modification list.
|
||||
* Items in the list appear in the same order in which they were
|
||||
* originally supplied in DirContext.modifyAttributes().
|
||||
* The first item in the list is the first one that was not executed.
|
||||
* If this list is null, none of the operations originally submitted
|
||||
* to modifyAttributes() were executed.
|
||||
|
||||
* @return The possibly null unexecuted modification list.
|
||||
* @see #setUnexecutedModifications
|
||||
*/
|
||||
public ModificationItem[] getUnexecutedModifications() {
|
||||
return unexecs;
|
||||
}
|
||||
|
||||
/**
|
||||
* The string representation of this exception consists of
|
||||
* information about where the error occurred, and
|
||||
* the first unexecuted modification.
|
||||
* This string is meant for debugging and not mean to be interpreted
|
||||
* programmatically.
|
||||
* @return The non-null string representation of this exception.
|
||||
*/
|
||||
public String toString() {
|
||||
String orig = super.toString();
|
||||
if (unexecs != null) {
|
||||
orig += ("First unexecuted modification: " +
|
||||
unexecs[0].toString());
|
||||
}
|
||||
return orig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = 8060676069678710186L;
|
||||
}
|
||||
183
jdkSrc/jdk8/javax/naming/directory/Attributes.java
Normal file
183
jdkSrc/jdk8/javax/naming/directory/Attributes.java
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.NamingEnumeration;
|
||||
|
||||
/**
|
||||
* This interface represents a collection of attributes.
|
||||
*<p>
|
||||
* In a directory, named objects can have associated with them
|
||||
* attributes. The Attributes interface represents a collection of attributes.
|
||||
* For example, you can request from the directory the attributes
|
||||
* associated with an object. Those attributes are returned in
|
||||
* an object that implements the Attributes interface.
|
||||
*<p>
|
||||
* Attributes in an object that implements the Attributes interface are
|
||||
* unordered. The object can have zero or more attributes.
|
||||
* Attributes is either case-sensitive or case-insensitive (case-ignore).
|
||||
* This property is determined at the time the Attributes object is
|
||||
* created. (see BasicAttributes constructor for example).
|
||||
* In a case-insensitive Attributes, the case of its attribute identifiers
|
||||
* is ignored when searching for an attribute, or adding attributes.
|
||||
* In a case-sensitive Attributes, the case is significant.
|
||||
*<p>
|
||||
* Note that updates to Attributes (such as adding or removing an attribute)
|
||||
* do not affect the corresponding representation in the directory.
|
||||
* Updates to the directory can only be effected
|
||||
* using operations in the DirContext interface.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
*
|
||||
* @see DirContext#getAttributes
|
||||
* @see DirContext#modifyAttributes
|
||||
* @see DirContext#bind
|
||||
* @see DirContext#rebind
|
||||
* @see DirContext#createSubcontext
|
||||
* @see DirContext#search
|
||||
* @see BasicAttributes
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
public interface Attributes extends Cloneable, java.io.Serializable {
|
||||
/**
|
||||
* Determines whether the attribute set ignores the case of
|
||||
* attribute identifiers when retrieving or adding attributes.
|
||||
* @return true if case is ignored; false otherwise.
|
||||
*/
|
||||
boolean isCaseIgnored();
|
||||
|
||||
/**
|
||||
* Retrieves the number of attributes in the attribute set.
|
||||
*
|
||||
* @return The nonnegative number of attributes in this attribute set.
|
||||
*/
|
||||
int size();
|
||||
|
||||
/**
|
||||
* Retrieves the attribute with the given attribute id from the
|
||||
* attribute set.
|
||||
*
|
||||
* @param attrID The non-null id of the attribute to retrieve.
|
||||
* If this attribute set ignores the character
|
||||
* case of its attribute ids, the case of attrID
|
||||
* is ignored.
|
||||
* @return The attribute identified by attrID; null if not found.
|
||||
* @see #put
|
||||
* @see #remove
|
||||
*/
|
||||
Attribute get(String attrID);
|
||||
|
||||
/**
|
||||
* Retrieves an enumeration of the attributes in the attribute set.
|
||||
* The effects of updates to this attribute set on this enumeration
|
||||
* are undefined.
|
||||
*
|
||||
* @return A non-null enumeration of the attributes in this attribute set.
|
||||
* Each element of the enumeration is of class <tt>Attribute</tt>.
|
||||
* If attribute set has zero attributes, an empty enumeration
|
||||
* is returned.
|
||||
*/
|
||||
NamingEnumeration<? extends Attribute> getAll();
|
||||
|
||||
/**
|
||||
* Retrieves an enumeration of the ids of the attributes in the
|
||||
* attribute set.
|
||||
* The effects of updates to this attribute set on this enumeration
|
||||
* are undefined.
|
||||
*
|
||||
* @return A non-null enumeration of the attributes' ids in
|
||||
* this attribute set. Each element of the enumeration is
|
||||
* of class String.
|
||||
* If attribute set has zero attributes, an empty enumeration
|
||||
* is returned.
|
||||
*/
|
||||
NamingEnumeration<String> getIDs();
|
||||
|
||||
/**
|
||||
* Adds a new attribute to the attribute set.
|
||||
*
|
||||
* @param attrID non-null The id of the attribute to add.
|
||||
* If the attribute set ignores the character
|
||||
* case of its attribute ids, the case of attrID
|
||||
* is ignored.
|
||||
* @param val The possibly null value of the attribute to add.
|
||||
* If null, the attribute does not have any values.
|
||||
* @return The Attribute with attrID that was previous in this attribute set;
|
||||
* null if no such attribute existed.
|
||||
* @see #remove
|
||||
*/
|
||||
Attribute put(String attrID, Object val);
|
||||
|
||||
/**
|
||||
* Adds a new attribute to the attribute set.
|
||||
*
|
||||
* @param attr The non-null attribute to add.
|
||||
* If the attribute set ignores the character
|
||||
* case of its attribute ids, the case of
|
||||
* attr's identifier is ignored.
|
||||
* @return The Attribute with the same ID as attr that was previous
|
||||
* in this attribute set;
|
||||
* null if no such attribute existed.
|
||||
* @see #remove
|
||||
*/
|
||||
Attribute put(Attribute attr);
|
||||
|
||||
/**
|
||||
* Removes the attribute with the attribute id 'attrID' from
|
||||
* the attribute set. If the attribute does not exist, ignore.
|
||||
*
|
||||
* @param attrID The non-null id of the attribute to remove.
|
||||
* If the attribute set ignores the character
|
||||
* case of its attribute ids, the case of
|
||||
* attrID is ignored.
|
||||
* @return The Attribute with the same ID as attrID that was previous
|
||||
* in the attribute set;
|
||||
* null if no such attribute existed.
|
||||
*/
|
||||
Attribute remove(String attrID);
|
||||
|
||||
/**
|
||||
* Makes a copy of the attribute set.
|
||||
* The new set contains the same attributes as the original set:
|
||||
* the attributes are not themselves cloned.
|
||||
* Changes to the copy will not affect the original and vice versa.
|
||||
*
|
||||
* @return A non-null copy of this attribute set.
|
||||
*/
|
||||
Object clone();
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
// static final long serialVersionUID = -7247874645443605347L;
|
||||
}
|
||||
557
jdkSrc/jdk8/javax/naming/directory/BasicAttribute.java
Normal file
557
jdkSrc/jdk8/javax/naming/directory/BasicAttribute.java
Normal file
@@ -0,0 +1,557 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.OperationNotSupportedException;
|
||||
|
||||
/**
|
||||
* This class provides a basic implementation of the <tt>Attribute</tt> interface.
|
||||
*<p>
|
||||
* This implementation does not support the schema methods
|
||||
* <tt>getAttributeDefinition()</tt> and <tt>getAttributeSyntaxDefinition()</tt>.
|
||||
* They simply throw <tt>OperationNotSupportedException</tt>.
|
||||
* Subclasses of <tt>BasicAttribute</tt> should override these methods if they
|
||||
* support them.
|
||||
*<p>
|
||||
* The <tt>BasicAttribute</tt> class by default uses <tt>Object.equals()</tt> to
|
||||
* determine equality of attribute values when testing for equality or
|
||||
* when searching for values, <em>except</em> when the value is an array.
|
||||
* For an array, each element of the array is checked using <tt>Object.equals()</tt>.
|
||||
* Subclasses of <tt>BasicAttribute</tt> can make use of schema information
|
||||
* when doing similar equality checks by overriding methods
|
||||
* in which such use of schema is meaningful.
|
||||
* Similarly, the <tt>BasicAttribute</tt> class by default returns the values passed to its
|
||||
* constructor and/or manipulated using the add/remove methods.
|
||||
* Subclasses of <tt>BasicAttribute</tt> can override <tt>get()</tt> and <tt>getAll()</tt>
|
||||
* to get the values dynamically from the directory (or implement
|
||||
* the <tt>Attribute</tt> interface directly instead of subclassing <tt>BasicAttribute</tt>).
|
||||
*<p>
|
||||
* Note that updates to <tt>BasicAttribute</tt> (such as adding or removing a value)
|
||||
* does not affect the corresponding representation of the attribute
|
||||
* in the directory. Updates to the directory can only be effected
|
||||
* using operations in the <tt>DirContext</tt> interface.
|
||||
*<p>
|
||||
* A <tt>BasicAttribute</tt> instance is not synchronized against concurrent
|
||||
* multithreaded access. Multiple threads trying to access and modify a
|
||||
* <tt>BasicAttribute</tt> should lock the object.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
* @since 1.3
|
||||
*/
|
||||
public class BasicAttribute implements Attribute {
|
||||
/**
|
||||
* Holds the attribute's id. It is initialized by the public constructor and
|
||||
* cannot be null unless methods in BasicAttribute that use attrID
|
||||
* have been overridden.
|
||||
* @serial
|
||||
*/
|
||||
protected String attrID;
|
||||
|
||||
/**
|
||||
* Holds the attribute's values. Initialized by public constructors.
|
||||
* Cannot be null unless methods in BasicAttribute that use
|
||||
* values have been overridden.
|
||||
*/
|
||||
protected transient Vector<Object> values;
|
||||
|
||||
/**
|
||||
* A flag for recording whether this attribute's values are ordered.
|
||||
* @serial
|
||||
*/
|
||||
protected boolean ordered = false;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object clone() {
|
||||
BasicAttribute attr;
|
||||
try {
|
||||
attr = (BasicAttribute)super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
attr = new BasicAttribute(attrID, ordered);
|
||||
}
|
||||
attr.values = (Vector<Object>)values.clone();
|
||||
return attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether obj is equal to this attribute.
|
||||
* Two attributes are equal if their attribute-ids, syntaxes
|
||||
* and values are equal.
|
||||
* If the attribute values are unordered, the order that the values were added
|
||||
* are irrelevant. If the attribute values are ordered, then the
|
||||
* order the values must match.
|
||||
* If obj is null or not an Attribute, false is returned.
|
||||
*<p>
|
||||
* By default <tt>Object.equals()</tt> is used when comparing the attribute
|
||||
* id and its values except when a value is an array. For an array,
|
||||
* each element of the array is checked using <tt>Object.equals()</tt>.
|
||||
* A subclass may override this to make
|
||||
* use of schema syntax information and matching rules,
|
||||
* which define what it means for two attributes to be equal.
|
||||
* How and whether a subclass makes
|
||||
* use of the schema information is determined by the subclass.
|
||||
* If a subclass overrides <tt>equals()</tt>, it should also override
|
||||
* <tt>hashCode()</tt>
|
||||
* such that two attributes that are equal have the same hash code.
|
||||
*
|
||||
* @param obj The possibly null object to check.
|
||||
* @return true if obj is equal to this attribute; false otherwise.
|
||||
* @see #hashCode
|
||||
* @see #contains
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if ((obj != null) && (obj instanceof Attribute)) {
|
||||
Attribute target = (Attribute)obj;
|
||||
|
||||
// Check order first
|
||||
if (isOrdered() != target.isOrdered()) {
|
||||
return false;
|
||||
}
|
||||
int len;
|
||||
if (attrID.equals(target.getID()) &&
|
||||
(len=size()) == target.size()) {
|
||||
try {
|
||||
if (isOrdered()) {
|
||||
// Go through both list of values
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (!valueEquals(get(i), target.get(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// order is not relevant; check for existence
|
||||
Enumeration<?> theirs = target.getAll();
|
||||
while (theirs.hasMoreElements()) {
|
||||
if (find(theirs.nextElement()) < 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (NamingException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the hash code of this attribute.
|
||||
*<p>
|
||||
* The hash code is computed by adding the hash code of
|
||||
* the attribute's id and that of all of its values except for
|
||||
* values that are arrays.
|
||||
* For an array, the hash code of each element of the array is summed.
|
||||
* If a subclass overrides <tt>hashCode()</tt>, it should override
|
||||
* <tt>equals()</tt>
|
||||
* as well so that two attributes that are equal have the same hash code.
|
||||
*
|
||||
* @return an int representing the hash code of this attribute.
|
||||
* @see #equals
|
||||
*/
|
||||
public int hashCode() {
|
||||
int hash = attrID.hashCode();
|
||||
int num = values.size();
|
||||
Object val;
|
||||
for (int i = 0; i < num; i ++) {
|
||||
val = values.elementAt(i);
|
||||
if (val != null) {
|
||||
if (val.getClass().isArray()) {
|
||||
Object it;
|
||||
int len = Array.getLength(val);
|
||||
for (int j = 0 ; j < len ; j++) {
|
||||
it = Array.get(val, j);
|
||||
if (it != null) {
|
||||
hash += it.hashCode();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
hash += val.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the string representation of this attribute.
|
||||
* The string consists of the attribute's id and its values.
|
||||
* This string is meant for debugging and not meant to be
|
||||
* interpreted programmatically.
|
||||
* @return The non-null string representation of this attribute.
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer answer = new StringBuffer(attrID + ": ");
|
||||
if (values.size() == 0) {
|
||||
answer.append("No values");
|
||||
} else {
|
||||
boolean start = true;
|
||||
for (Enumeration<Object> e = values.elements(); e.hasMoreElements(); ) {
|
||||
if (!start)
|
||||
answer.append(", ");
|
||||
answer.append(e.nextElement());
|
||||
start = false;
|
||||
}
|
||||
}
|
||||
return answer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of an unordered attribute with no value.
|
||||
*
|
||||
* @param id The attribute's id. It cannot be null.
|
||||
*/
|
||||
public BasicAttribute(String id) {
|
||||
this(id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of an unordered attribute with a single value.
|
||||
*
|
||||
* @param id The attribute's id. It cannot be null.
|
||||
* @param value The attribute's value. If null, a null
|
||||
* value is added to the attribute.
|
||||
*/
|
||||
public BasicAttribute(String id, Object value) {
|
||||
this(id, value, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of a possibly ordered attribute with no value.
|
||||
*
|
||||
* @param id The attribute's id. It cannot be null.
|
||||
* @param ordered true means the attribute's values will be ordered;
|
||||
* false otherwise.
|
||||
*/
|
||||
public BasicAttribute(String id, boolean ordered) {
|
||||
attrID = id;
|
||||
values = new Vector<>();
|
||||
this.ordered = ordered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of a possibly ordered attribute with a
|
||||
* single value.
|
||||
*
|
||||
* @param id The attribute's id. It cannot be null.
|
||||
* @param value The attribute's value. If null, a null
|
||||
* value is added to the attribute.
|
||||
* @param ordered true means the attribute's values will be ordered;
|
||||
* false otherwise.
|
||||
*/
|
||||
public BasicAttribute(String id, Object value, boolean ordered) {
|
||||
this(id, ordered);
|
||||
values.addElement(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an enumeration of this attribute's values.
|
||||
*<p>
|
||||
* By default, the values returned are those passed to the
|
||||
* constructor and/or manipulated using the add/replace/remove methods.
|
||||
* A subclass may override this to retrieve the values dynamically
|
||||
* from the directory.
|
||||
*/
|
||||
public NamingEnumeration<?> getAll() throws NamingException {
|
||||
return new ValuesEnumImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves one of this attribute's values.
|
||||
*<p>
|
||||
* By default, the value returned is one of those passed to the
|
||||
* constructor and/or manipulated using the add/replace/remove methods.
|
||||
* A subclass may override this to retrieve the value dynamically
|
||||
* from the directory.
|
||||
*/
|
||||
public Object get() throws NamingException {
|
||||
if (values.size() == 0) {
|
||||
throw new
|
||||
NoSuchElementException("Attribute " + getID() + " has no value");
|
||||
} else {
|
||||
return values.elementAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return values.size();
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return attrID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a value is in this attribute.
|
||||
*<p>
|
||||
* By default,
|
||||
* <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt>
|
||||
* with this attribute's values except when <tt>attrVal</tt> is an array.
|
||||
* For an array, each element of the array is checked using
|
||||
* <tt>Object.equals()</tt>.
|
||||
* A subclass may use schema information to determine equality.
|
||||
*/
|
||||
public boolean contains(Object attrVal) {
|
||||
return (find(attrVal) >= 0);
|
||||
}
|
||||
|
||||
// For finding first element that has a null in JDK1.1 Vector.
|
||||
// In the Java 2 platform, can just replace this with Vector.indexOf(target);
|
||||
private int find(Object target) {
|
||||
Class<?> cl;
|
||||
if (target == null) {
|
||||
int ct = values.size();
|
||||
for (int i = 0 ; i < ct ; i++) {
|
||||
if (values.elementAt(i) == null)
|
||||
return i;
|
||||
}
|
||||
} else if ((cl=target.getClass()).isArray()) {
|
||||
int ct = values.size();
|
||||
Object it;
|
||||
for (int i = 0 ; i < ct ; i++) {
|
||||
it = values.elementAt(i);
|
||||
if (it != null && cl == it.getClass()
|
||||
&& arrayEquals(target, it))
|
||||
return i;
|
||||
}
|
||||
} else {
|
||||
return values.indexOf(target, 0);
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether two attribute values are equal.
|
||||
* Use arrayEquals for arrays and <tt>Object.equals()</tt> otherwise.
|
||||
*/
|
||||
private static boolean valueEquals(Object obj1, Object obj2) {
|
||||
if (obj1 == obj2) {
|
||||
return true; // object references are equal
|
||||
}
|
||||
if (obj1 == null) {
|
||||
return false; // obj2 was not false
|
||||
}
|
||||
if (obj1.getClass().isArray() &&
|
||||
obj2.getClass().isArray()) {
|
||||
return arrayEquals(obj1, obj2);
|
||||
}
|
||||
return (obj1.equals(obj2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether two arrays are equal by comparing each of their
|
||||
* elements using <tt>Object.equals()</tt>.
|
||||
*/
|
||||
private static boolean arrayEquals(Object a1, Object a2) {
|
||||
int len;
|
||||
if ((len = Array.getLength(a1)) != Array.getLength(a2))
|
||||
return false;
|
||||
|
||||
for (int j = 0; j < len; j++) {
|
||||
Object i1 = Array.get(a1, j);
|
||||
Object i2 = Array.get(a2, j);
|
||||
if (i1 == null || i2 == null) {
|
||||
if (i1 != i2)
|
||||
return false;
|
||||
} else if (!i1.equals(i2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new value to this attribute.
|
||||
*<p>
|
||||
* By default, <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt>
|
||||
* with this attribute's values except when <tt>attrVal</tt> is an array.
|
||||
* For an array, each element of the array is checked using
|
||||
* <tt>Object.equals()</tt>.
|
||||
* A subclass may use schema information to determine equality.
|
||||
*/
|
||||
public boolean add(Object attrVal) {
|
||||
if (isOrdered() || (find(attrVal) < 0)) {
|
||||
values.addElement(attrVal);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a specified value from this attribute.
|
||||
*<p>
|
||||
* By default, <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt>
|
||||
* with this attribute's values except when <tt>attrVal</tt> is an array.
|
||||
* For an array, each element of the array is checked using
|
||||
* <tt>Object.equals()</tt>.
|
||||
* A subclass may use schema information to determine equality.
|
||||
*/
|
||||
public boolean remove(Object attrval) {
|
||||
// For the Java 2 platform, can just use "return removeElement(attrval);"
|
||||
// Need to do the following to handle null case
|
||||
|
||||
int i = find(attrval);
|
||||
if (i >= 0) {
|
||||
values.removeElementAt(i);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
values.setSize(0);
|
||||
}
|
||||
|
||||
// ---- ordering methods
|
||||
|
||||
public boolean isOrdered() {
|
||||
return ordered;
|
||||
}
|
||||
|
||||
public Object get(int ix) throws NamingException {
|
||||
return values.elementAt(ix);
|
||||
}
|
||||
|
||||
public Object remove(int ix) {
|
||||
Object answer = values.elementAt(ix);
|
||||
values.removeElementAt(ix);
|
||||
return answer;
|
||||
}
|
||||
|
||||
public void add(int ix, Object attrVal) {
|
||||
if (!isOrdered() && contains(attrVal)) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot add duplicate to unordered attribute");
|
||||
}
|
||||
values.insertElementAt(attrVal, ix);
|
||||
}
|
||||
|
||||
public Object set(int ix, Object attrVal) {
|
||||
if (!isOrdered() && contains(attrVal)) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot add duplicate to unordered attribute");
|
||||
}
|
||||
|
||||
Object answer = values.elementAt(ix);
|
||||
values.setElementAt(attrVal, ix);
|
||||
return answer;
|
||||
}
|
||||
|
||||
// ----------------- Schema methods
|
||||
|
||||
/**
|
||||
* Retrieves the syntax definition associated with this attribute.
|
||||
*<p>
|
||||
* This method by default throws OperationNotSupportedException. A subclass
|
||||
* should override this method if it supports schema.
|
||||
*/
|
||||
public DirContext getAttributeSyntaxDefinition() throws NamingException {
|
||||
throw new OperationNotSupportedException("attribute syntax");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves this attribute's schema definition.
|
||||
*<p>
|
||||
* This method by default throws OperationNotSupportedException. A subclass
|
||||
* should override this method if it supports schema.
|
||||
*/
|
||||
public DirContext getAttributeDefinition() throws NamingException {
|
||||
throw new OperationNotSupportedException("attribute definition");
|
||||
}
|
||||
|
||||
|
||||
// ---- serialization methods
|
||||
|
||||
/**
|
||||
* Overridden to avoid exposing implementation details
|
||||
* @serialData Default field (the attribute ID -- a String),
|
||||
* followed by the number of values (an int), and the
|
||||
* individual values.
|
||||
*/
|
||||
private void writeObject(java.io.ObjectOutputStream s)
|
||||
throws java.io.IOException {
|
||||
s.defaultWriteObject(); // write out the attrID
|
||||
s.writeInt(values.size());
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
s.writeObject(values.elementAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden to avoid exposing implementation details.
|
||||
*/
|
||||
private void readObject(java.io.ObjectInputStream s)
|
||||
throws java.io.IOException, ClassNotFoundException {
|
||||
s.defaultReadObject(); // read in the attrID
|
||||
int n = s.readInt(); // number of values
|
||||
values = new Vector<>(Math.min(1024, n));
|
||||
while (--n >= 0) {
|
||||
values.addElement(s.readObject());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ValuesEnumImpl implements NamingEnumeration<Object> {
|
||||
Enumeration<Object> list;
|
||||
|
||||
ValuesEnumImpl() {
|
||||
list = values.elements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return list.hasMoreElements();
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
return(list.nextElement());
|
||||
}
|
||||
|
||||
public Object next() throws NamingException {
|
||||
return list.nextElement();
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException {
|
||||
return list.hasMoreElements();
|
||||
}
|
||||
|
||||
public void close() throws NamingException {
|
||||
list = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 6743528196119291326L;
|
||||
}
|
||||
378
jdkSrc/jdk8/javax/naming/directory/BasicAttributes.java
Normal file
378
jdkSrc/jdk8/javax/naming/directory/BasicAttributes.java
Normal file
@@ -0,0 +1,378 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.NamingEnumeration;
|
||||
|
||||
/**
|
||||
* This class provides a basic implementation
|
||||
* of the Attributes interface.
|
||||
*<p>
|
||||
* BasicAttributes is either case-sensitive or case-insensitive (case-ignore).
|
||||
* This property is determined at the time the BasicAttributes constructor
|
||||
* is called.
|
||||
* In a case-insensitive BasicAttributes, the case of its attribute identifiers
|
||||
* is ignored when searching for an attribute, or adding attributes.
|
||||
* In a case-sensitive BasicAttributes, the case is significant.
|
||||
*<p>
|
||||
* When the BasicAttributes class needs to create an Attribute, it
|
||||
* uses BasicAttribute. There is no other dependency on BasicAttribute.
|
||||
*<p>
|
||||
* Note that updates to BasicAttributes (such as adding or removing an attribute)
|
||||
* does not affect the corresponding representation in the directory.
|
||||
* Updates to the directory can only be effected
|
||||
* using operations in the DirContext interface.
|
||||
*<p>
|
||||
* A BasicAttributes instance is not synchronized against concurrent
|
||||
* multithreaded access. Multiple threads trying to access and modify
|
||||
* a single BasicAttributes instance should lock the object.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
*
|
||||
* @see DirContext#getAttributes
|
||||
* @see DirContext#modifyAttributes
|
||||
* @see DirContext#bind
|
||||
* @see DirContext#rebind
|
||||
* @see DirContext#createSubcontext
|
||||
* @see DirContext#search
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
public class BasicAttributes implements Attributes {
|
||||
/**
|
||||
* Indicates whether case of attribute ids is ignored.
|
||||
* @serial
|
||||
*/
|
||||
private boolean ignoreCase = false;
|
||||
|
||||
// The 'key' in attrs is stored in the 'right case'.
|
||||
// If ignoreCase is true, key is aways lowercase.
|
||||
// If ignoreCase is false, key is stored as supplied by put().
|
||||
// %%% Not declared "private" due to bug 4064984.
|
||||
transient Hashtable<String,Attribute> attrs = new Hashtable<>(11);
|
||||
|
||||
/**
|
||||
* Constructs a new instance of Attributes.
|
||||
* The character case of attribute identifiers
|
||||
* is significant when subsequently retrieving or adding attributes.
|
||||
*/
|
||||
public BasicAttributes() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of Attributes.
|
||||
* If <code>ignoreCase</code> is true, the character case of attribute
|
||||
* identifiers is ignored; otherwise the case is significant.
|
||||
* @param ignoreCase true means this attribute set will ignore
|
||||
* the case of its attribute identifiers
|
||||
* when retrieving or adding attributes;
|
||||
* false means case is respected.
|
||||
*/
|
||||
public BasicAttributes(boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of Attributes with one attribute.
|
||||
* The attribute specified by attrID and val are added to the newly
|
||||
* created attribute.
|
||||
* The character case of attribute identifiers
|
||||
* is significant when subsequently retrieving or adding attributes.
|
||||
* @param attrID non-null The id of the attribute to add.
|
||||
* @param val The value of the attribute to add. If null, a null
|
||||
* value is added to the attribute.
|
||||
*/
|
||||
public BasicAttributes(String attrID, Object val) {
|
||||
this();
|
||||
this.put(new BasicAttribute(attrID, val));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of Attributes with one attribute.
|
||||
* The attribute specified by attrID and val are added to the newly
|
||||
* created attribute.
|
||||
* If <code>ignoreCase</code> is true, the character case of attribute
|
||||
* identifiers is ignored; otherwise the case is significant.
|
||||
* @param attrID non-null The id of the attribute to add.
|
||||
* If this attribute set ignores the character
|
||||
* case of its attribute ids, the case of attrID
|
||||
* is ignored.
|
||||
* @param val The value of the attribute to add. If null, a null
|
||||
* value is added to the attribute.
|
||||
* @param ignoreCase true means this attribute set will ignore
|
||||
* the case of its attribute identifiers
|
||||
* when retrieving or adding attributes;
|
||||
* false means case is respected.
|
||||
*/
|
||||
public BasicAttributes(String attrID, Object val, boolean ignoreCase) {
|
||||
this(ignoreCase);
|
||||
this.put(new BasicAttribute(attrID, val));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object clone() {
|
||||
BasicAttributes attrset;
|
||||
try {
|
||||
attrset = (BasicAttributes)super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
attrset = new BasicAttributes(ignoreCase);
|
||||
}
|
||||
attrset.attrs = (Hashtable<String,Attribute>)attrs.clone();
|
||||
return attrset;
|
||||
}
|
||||
|
||||
public boolean isCaseIgnored() {
|
||||
return ignoreCase;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return attrs.size();
|
||||
}
|
||||
|
||||
public Attribute get(String attrID) {
|
||||
Attribute attr = attrs.get(
|
||||
ignoreCase ? attrID.toLowerCase(Locale.ENGLISH) : attrID);
|
||||
return (attr);
|
||||
}
|
||||
|
||||
public NamingEnumeration<Attribute> getAll() {
|
||||
return new AttrEnumImpl();
|
||||
}
|
||||
|
||||
public NamingEnumeration<String> getIDs() {
|
||||
return new IDEnumImpl();
|
||||
}
|
||||
|
||||
public Attribute put(String attrID, Object val) {
|
||||
return this.put(new BasicAttribute(attrID, val));
|
||||
}
|
||||
|
||||
public Attribute put(Attribute attr) {
|
||||
String id = attr.getID();
|
||||
if (ignoreCase) {
|
||||
id = id.toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
return attrs.put(id, attr);
|
||||
}
|
||||
|
||||
public Attribute remove(String attrID) {
|
||||
String id = (ignoreCase ? attrID.toLowerCase(Locale.ENGLISH) : attrID);
|
||||
return attrs.remove(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the string representation of this attribute set.
|
||||
* The string consists of each attribute identifier and the contents
|
||||
* of each attribute. The contents of this string is useful
|
||||
* for debugging and is not meant to be interpreted programmatically.
|
||||
*
|
||||
* @return A non-null string listing the contents of this attribute set.
|
||||
*/
|
||||
public String toString() {
|
||||
if (attrs.size() == 0) {
|
||||
return("No attributes");
|
||||
} else {
|
||||
return attrs.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether this <tt>BasicAttributes</tt> is equal to another
|
||||
* <tt>Attributes</tt>
|
||||
* Two <tt>Attributes</tt> are equal if they are both instances of
|
||||
* <tt>Attributes</tt>,
|
||||
* treat the case of attribute IDs the same way, and contain the
|
||||
* same attributes. Each <tt>Attribute</tt> in this <tt>BasicAttributes</tt>
|
||||
* is checked for equality using <tt>Object.equals()</tt>, which may have
|
||||
* be overridden by implementations of <tt>Attribute</tt>).
|
||||
* If a subclass overrides <tt>equals()</tt>,
|
||||
* it should override <tt>hashCode()</tt>
|
||||
* as well so that two <tt>Attributes</tt> instances that are equal
|
||||
* have the same hash code.
|
||||
* @param obj the possibly null object to compare against.
|
||||
*
|
||||
* @return true If obj is equal to this BasicAttributes.
|
||||
* @see #hashCode
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if ((obj != null) && (obj instanceof Attributes)) {
|
||||
Attributes target = (Attributes)obj;
|
||||
|
||||
// Check case first
|
||||
if (ignoreCase != target.isCaseIgnored()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (size() == target.size()) {
|
||||
Attribute their, mine;
|
||||
try {
|
||||
NamingEnumeration<?> theirs = target.getAll();
|
||||
while (theirs.hasMore()) {
|
||||
their = (Attribute)theirs.next();
|
||||
mine = get(their.getID());
|
||||
if (!their.equals(mine)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (NamingException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the hash code of this BasicAttributes.
|
||||
*<p>
|
||||
* The hash code is computed by adding the hash code of
|
||||
* the attributes of this object. If this BasicAttributes
|
||||
* ignores case of its attribute IDs, one is added to the hash code.
|
||||
* If a subclass overrides <tt>hashCode()</tt>,
|
||||
* it should override <tt>equals()</tt>
|
||||
* as well so that two <tt>Attributes</tt> instances that are equal
|
||||
* have the same hash code.
|
||||
*
|
||||
* @return an int representing the hash code of this BasicAttributes instance.
|
||||
* @see #equals
|
||||
*/
|
||||
public int hashCode() {
|
||||
int hash = (ignoreCase ? 1 : 0);
|
||||
try {
|
||||
NamingEnumeration<?> all = getAll();
|
||||
while (all.hasMore()) {
|
||||
hash += all.next().hashCode();
|
||||
}
|
||||
} catch (NamingException e) {}
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden to avoid exposing implementation details.
|
||||
* @serialData Default field (ignoreCase flag -- a boolean), followed by
|
||||
* the number of attributes in the set
|
||||
* (an int), and then the individual Attribute objects.
|
||||
*/
|
||||
private void writeObject(java.io.ObjectOutputStream s)
|
||||
throws java.io.IOException {
|
||||
s.defaultWriteObject(); // write out the ignoreCase flag
|
||||
s.writeInt(attrs.size());
|
||||
Enumeration<Attribute> attrEnum = attrs.elements();
|
||||
while (attrEnum.hasMoreElements()) {
|
||||
s.writeObject(attrEnum.nextElement());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden to avoid exposing implementation details.
|
||||
*/
|
||||
private void readObject(java.io.ObjectInputStream s)
|
||||
throws java.io.IOException, ClassNotFoundException {
|
||||
s.defaultReadObject(); // read in the ignoreCase flag
|
||||
int n = s.readInt(); // number of attributes
|
||||
attrs = (n >= 1)
|
||||
? new Hashtable<>(1 + (int) (Math.min(768, n) / .75f))
|
||||
: new Hashtable<>(2); // can't have initial size of 0 (grrr...)
|
||||
while (--n >= 0) {
|
||||
put((Attribute)s.readObject());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class AttrEnumImpl implements NamingEnumeration<Attribute> {
|
||||
|
||||
Enumeration<Attribute> elements;
|
||||
|
||||
public AttrEnumImpl() {
|
||||
this.elements = attrs.elements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return elements.hasMoreElements();
|
||||
}
|
||||
|
||||
public Attribute nextElement() {
|
||||
return elements.nextElement();
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException {
|
||||
return hasMoreElements();
|
||||
}
|
||||
|
||||
public Attribute next() throws NamingException {
|
||||
return nextElement();
|
||||
}
|
||||
|
||||
public void close() throws NamingException {
|
||||
elements = null;
|
||||
}
|
||||
}
|
||||
|
||||
class IDEnumImpl implements NamingEnumeration<String> {
|
||||
|
||||
Enumeration<Attribute> elements;
|
||||
|
||||
public IDEnumImpl() {
|
||||
// Walking through the elements, rather than the keys, gives
|
||||
// us attribute IDs that have not been converted to lowercase.
|
||||
this.elements = attrs.elements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return elements.hasMoreElements();
|
||||
}
|
||||
|
||||
public String nextElement() {
|
||||
Attribute attr = elements.nextElement();
|
||||
return attr.getID();
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException {
|
||||
return hasMoreElements();
|
||||
}
|
||||
|
||||
public String next() throws NamingException {
|
||||
return nextElement();
|
||||
}
|
||||
|
||||
public void close() throws NamingException {
|
||||
elements = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 4980164073184639448L;
|
||||
}
|
||||
1039
jdkSrc/jdk8/javax/naming/directory/DirContext.java
Normal file
1039
jdkSrc/jdk8/javax/naming/directory/DirContext.java
Normal file
File diff suppressed because it is too large
Load Diff
300
jdkSrc/jdk8/javax/naming/directory/InitialDirContext.java
Normal file
300
jdkSrc/jdk8/javax/naming/directory/InitialDirContext.java
Normal file
@@ -0,0 +1,300 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import javax.naming.spi.NamingManager;
|
||||
import javax.naming.*;
|
||||
|
||||
/**
|
||||
* This class is the starting context for performing
|
||||
* directory operations. The documentation in the class description
|
||||
* of InitialContext (including those for synchronization) apply here.
|
||||
*
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
*
|
||||
* @see javax.naming.InitialContext
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
public class InitialDirContext extends InitialContext implements DirContext {
|
||||
|
||||
/**
|
||||
* Constructs an initial DirContext with the option of not
|
||||
* initializing it. This may be used by a constructor in
|
||||
* a subclass when the value of the environment parameter
|
||||
* is not yet known at the time the <tt>InitialDirContext</tt>
|
||||
* constructor is called. The subclass's constructor will
|
||||
* call this constructor, compute the value of the environment,
|
||||
* and then call <tt>init()</tt> before returning.
|
||||
*
|
||||
* @param lazy
|
||||
* true means do not initialize the initial DirContext; false
|
||||
* is equivalent to calling <tt>new InitialDirContext()</tt>
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*
|
||||
* @see InitialContext#init(Hashtable)
|
||||
* @since 1.3
|
||||
*/
|
||||
protected InitialDirContext(boolean lazy) throws NamingException {
|
||||
super(lazy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an initial DirContext.
|
||||
* No environment properties are supplied.
|
||||
* Equivalent to <tt>new InitialDirContext(null)</tt>.
|
||||
*
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*
|
||||
* @see #InitialDirContext(Hashtable)
|
||||
*/
|
||||
public InitialDirContext() throws NamingException {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an initial DirContext using the supplied environment.
|
||||
* Environment properties are discussed in the
|
||||
* <tt>javax.naming.InitialContext</tt> class description.
|
||||
*
|
||||
* <p> This constructor will not modify <tt>environment</tt>
|
||||
* or save a reference to it, but may save a clone.
|
||||
* Caller should not modify mutable keys and values in
|
||||
* <tt>environment</tt> after it has been passed to the constructor.
|
||||
*
|
||||
* @param environment
|
||||
* environment used to create the initial DirContext.
|
||||
* Null indicates an empty environment.
|
||||
*
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
public InitialDirContext(Hashtable<?,?> environment)
|
||||
throws NamingException
|
||||
{
|
||||
super(environment);
|
||||
}
|
||||
|
||||
private DirContext getURLOrDefaultInitDirCtx(String name)
|
||||
throws NamingException {
|
||||
Context answer = getURLOrDefaultInitCtx(name);
|
||||
if (!(answer instanceof DirContext)) {
|
||||
if (answer == null) {
|
||||
throw new NoInitialContextException();
|
||||
} else {
|
||||
throw new NotContextException(
|
||||
"Not an instance of DirContext");
|
||||
}
|
||||
}
|
||||
return (DirContext)answer;
|
||||
}
|
||||
|
||||
private DirContext getURLOrDefaultInitDirCtx(Name name)
|
||||
throws NamingException {
|
||||
Context answer = getURLOrDefaultInitCtx(name);
|
||||
if (!(answer instanceof DirContext)) {
|
||||
if (answer == null) {
|
||||
throw new NoInitialContextException();
|
||||
} else {
|
||||
throw new NotContextException(
|
||||
"Not an instance of DirContext");
|
||||
}
|
||||
}
|
||||
return (DirContext)answer;
|
||||
}
|
||||
|
||||
// DirContext methods
|
||||
// Most Javadoc is deferred to the DirContext interface.
|
||||
|
||||
public Attributes getAttributes(String name)
|
||||
throws NamingException {
|
||||
return getAttributes(name, null);
|
||||
}
|
||||
|
||||
public Attributes getAttributes(String name, String[] attrIds)
|
||||
throws NamingException {
|
||||
return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds);
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name)
|
||||
throws NamingException {
|
||||
return getAttributes(name, null);
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name, String[] attrIds)
|
||||
throws NamingException {
|
||||
return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds);
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs)
|
||||
throws NamingException {
|
||||
getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs);
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs)
|
||||
throws NamingException {
|
||||
getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs);
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, ModificationItem[] mods)
|
||||
throws NamingException {
|
||||
getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods);
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods)
|
||||
throws NamingException {
|
||||
getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods);
|
||||
}
|
||||
|
||||
public void bind(String name, Object obj, Attributes attrs)
|
||||
throws NamingException {
|
||||
getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs);
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj, Attributes attrs)
|
||||
throws NamingException {
|
||||
getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs);
|
||||
}
|
||||
|
||||
public void rebind(String name, Object obj, Attributes attrs)
|
||||
throws NamingException {
|
||||
getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs);
|
||||
}
|
||||
|
||||
public void rebind(Name name, Object obj, Attributes attrs)
|
||||
throws NamingException {
|
||||
getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs);
|
||||
}
|
||||
|
||||
public DirContext createSubcontext(String name, Attributes attrs)
|
||||
throws NamingException {
|
||||
return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs);
|
||||
}
|
||||
|
||||
public DirContext createSubcontext(Name name, Attributes attrs)
|
||||
throws NamingException {
|
||||
return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs);
|
||||
}
|
||||
|
||||
public DirContext getSchema(String name) throws NamingException {
|
||||
return getURLOrDefaultInitDirCtx(name).getSchema(name);
|
||||
}
|
||||
|
||||
public DirContext getSchema(Name name) throws NamingException {
|
||||
return getURLOrDefaultInitDirCtx(name).getSchema(name);
|
||||
}
|
||||
|
||||
public DirContext getSchemaClassDefinition(String name)
|
||||
throws NamingException {
|
||||
return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name);
|
||||
}
|
||||
|
||||
public DirContext getSchemaClassDefinition(Name name)
|
||||
throws NamingException {
|
||||
return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name);
|
||||
}
|
||||
|
||||
// -------------------- search operations
|
||||
|
||||
public NamingEnumeration<SearchResult>
|
||||
search(String name, Attributes matchingAttributes)
|
||||
throws NamingException
|
||||
{
|
||||
return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes);
|
||||
}
|
||||
|
||||
public NamingEnumeration<SearchResult>
|
||||
search(Name name, Attributes matchingAttributes)
|
||||
throws NamingException
|
||||
{
|
||||
return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes);
|
||||
}
|
||||
|
||||
public NamingEnumeration<SearchResult>
|
||||
search(String name,
|
||||
Attributes matchingAttributes,
|
||||
String[] attributesToReturn)
|
||||
throws NamingException
|
||||
{
|
||||
return getURLOrDefaultInitDirCtx(name).search(name,
|
||||
matchingAttributes,
|
||||
attributesToReturn);
|
||||
}
|
||||
|
||||
public NamingEnumeration<SearchResult>
|
||||
search(Name name,
|
||||
Attributes matchingAttributes,
|
||||
String[] attributesToReturn)
|
||||
throws NamingException
|
||||
{
|
||||
return getURLOrDefaultInitDirCtx(name).search(name,
|
||||
matchingAttributes,
|
||||
attributesToReturn);
|
||||
}
|
||||
|
||||
public NamingEnumeration<SearchResult>
|
||||
search(String name,
|
||||
String filter,
|
||||
SearchControls cons)
|
||||
throws NamingException
|
||||
{
|
||||
return getURLOrDefaultInitDirCtx(name).search(name, filter, cons);
|
||||
}
|
||||
|
||||
public NamingEnumeration<SearchResult>
|
||||
search(Name name,
|
||||
String filter,
|
||||
SearchControls cons)
|
||||
throws NamingException
|
||||
{
|
||||
return getURLOrDefaultInitDirCtx(name).search(name, filter, cons);
|
||||
}
|
||||
|
||||
public NamingEnumeration<SearchResult>
|
||||
search(String name,
|
||||
String filterExpr,
|
||||
Object[] filterArgs,
|
||||
SearchControls cons)
|
||||
throws NamingException
|
||||
{
|
||||
return getURLOrDefaultInitDirCtx(name).search(name, filterExpr,
|
||||
filterArgs, cons);
|
||||
}
|
||||
|
||||
public NamingEnumeration<SearchResult>
|
||||
search(Name name,
|
||||
String filterExpr,
|
||||
Object[] filterArgs,
|
||||
SearchControls cons)
|
||||
throws NamingException
|
||||
{
|
||||
return getURLOrDefaultInitDirCtx(name).search(name, filterExpr,
|
||||
filterArgs, cons);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when an attempt is
|
||||
* made to add to create an attribute with an invalid attribute identifier.
|
||||
* The validity of an attribute identifier is directory-specific.
|
||||
* <p>
|
||||
* Synchronization and serialization issues that apply to NamingException
|
||||
* apply directly here.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
public class InvalidAttributeIdentifierException extends NamingException {
|
||||
/**
|
||||
* Constructs a new instance of InvalidAttributeIdentifierException using the
|
||||
* explanation supplied. All other fields set to null.
|
||||
* @param explanation Possibly null string containing additional detail about this exception.
|
||||
* @see java.lang.Throwable#getMessage
|
||||
*/
|
||||
public InvalidAttributeIdentifierException(String explanation) {
|
||||
super(explanation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of InvalidAttributeIdentifierException.
|
||||
* All fields are set to null.
|
||||
*/
|
||||
public InvalidAttributeIdentifierException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = -9036920266322999923L;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* This class is thrown when an attempt is
|
||||
* made to add to an attribute a value that conflicts with the attribute's
|
||||
* schema definition. This could happen, for example, if attempting
|
||||
* to add an attribute with no value when the attribute is required
|
||||
* to have at least one value, or if attempting to add more than
|
||||
* one value to a single valued-attribute, or if attempting to
|
||||
* add a value that conflicts with the syntax of the attribute.
|
||||
* <p>
|
||||
* Synchronization and serialization issues that apply to NamingException
|
||||
* apply directly here.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
public class InvalidAttributeValueException extends NamingException {
|
||||
/**
|
||||
* Constructs a new instance of InvalidAttributeValueException using
|
||||
* an explanation. All other fields are set to null.
|
||||
* @param explanation Additional detail about this exception. Can be null.
|
||||
* @see java.lang.Throwable#getMessage
|
||||
*/
|
||||
public InvalidAttributeValueException(String explanation) {
|
||||
super(explanation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of InvalidAttributeValueException.
|
||||
* All fields are set to null.
|
||||
*/
|
||||
public InvalidAttributeValueException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = 8720050295499275011L;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when an attempt is
|
||||
* made to add or modify an attribute set that has been specified
|
||||
* incompletely or incorrectly. This could happen, for example,
|
||||
* when attempting to add or modify a binding, or to create a new
|
||||
* subcontext without specifying all the mandatory attributes
|
||||
* required for creation of the object. Another situation in
|
||||
* which this exception is thrown is by specification of incompatible
|
||||
* attributes within the same attribute set, or attributes in conflict
|
||||
* with that specified by the object's schema.
|
||||
* <p>
|
||||
* Synchronization and serialization issues that apply to NamingException
|
||||
* apply directly here.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
public class InvalidAttributesException extends NamingException {
|
||||
/**
|
||||
* Constructs a new instance of InvalidAttributesException using an
|
||||
* explanation. All other fields are set to null.
|
||||
* @param explanation Additional detail about this exception. Can be null.
|
||||
* @see java.lang.Throwable#getMessage
|
||||
*/
|
||||
public InvalidAttributesException(String explanation) {
|
||||
super(explanation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of InvalidAttributesException.
|
||||
* All fields are set to null.
|
||||
*/
|
||||
public InvalidAttributesException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = 2607612850539889765L;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when the specification of
|
||||
* the SearchControls for a search operation is invalid. For example, if the scope is
|
||||
* set to a value other than OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE,
|
||||
* this exception is thrown.
|
||||
* <p>
|
||||
* Synchronization and serialization issues that apply to NamingException
|
||||
* apply directly here.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
* @since 1.3
|
||||
*/
|
||||
public class InvalidSearchControlsException extends NamingException {
|
||||
/**
|
||||
* Constructs a new instance of InvalidSearchControlsException.
|
||||
* All fields are set to null.
|
||||
*/
|
||||
public InvalidSearchControlsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of InvalidSearchControlsException
|
||||
* with an explanation. All other fields set to null.
|
||||
* @param msg Detail about this exception. Can be null.
|
||||
* @see java.lang.Throwable#getMessage
|
||||
*/
|
||||
public InvalidSearchControlsException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = -5124108943352665777L;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when the specification of
|
||||
* a search filter is invalid. The expression of the filter may
|
||||
* be invalid, or there may be a problem with one of the parameters
|
||||
* passed to the filter.
|
||||
* <p>
|
||||
* Synchronization and serialization issues that apply to NamingException
|
||||
* apply directly here.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
* @since 1.3
|
||||
*/
|
||||
public class InvalidSearchFilterException extends NamingException {
|
||||
/**
|
||||
* Constructs a new instance of InvalidSearchFilterException.
|
||||
* All fields are set to null.
|
||||
*/
|
||||
public InvalidSearchFilterException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of InvalidSearchFilterException
|
||||
* with an explanation. All other fields are set to null.
|
||||
* @param msg Detail about this exception. Can be null.
|
||||
* @see java.lang.Throwable#getMessage
|
||||
*/
|
||||
public InvalidSearchFilterException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = 2902700940682875441L;
|
||||
}
|
||||
133
jdkSrc/jdk8/javax/naming/directory/ModificationItem.java
Normal file
133
jdkSrc/jdk8/javax/naming/directory/ModificationItem.java
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
/**
|
||||
* This class represents a modification item.
|
||||
* It consists of a modification code and an attribute on which to operate.
|
||||
*<p>
|
||||
* A ModificationItem instance is not synchronized against concurrent
|
||||
* multithreaded access. Multiple threads trying to access and modify
|
||||
* a single ModificationItem instance should lock the object.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
/*
|
||||
*<p>
|
||||
* The serialized form of a ModificationItem object consists of the
|
||||
* modification op (and int) and the corresponding Attribute.
|
||||
*/
|
||||
|
||||
public class ModificationItem implements java.io.Serializable {
|
||||
/**
|
||||
* Contains an integer identify the modification
|
||||
* to be performed.
|
||||
* @serial
|
||||
*/
|
||||
private int mod_op;
|
||||
/**
|
||||
* Contains the attribute identifying
|
||||
* the attribute and/or its value to be applied for the modification.
|
||||
* @serial
|
||||
*/
|
||||
private Attribute attr;
|
||||
|
||||
/**
|
||||
* Creates a new instance of ModificationItem.
|
||||
* @param mod_op Modification to apply. It must be one of:
|
||||
* DirContext.ADD_ATTRIBUTE
|
||||
* DirContext.REPLACE_ATTRIBUTE
|
||||
* DirContext.REMOVE_ATTRIBUTE
|
||||
* @param attr The non-null attribute to use for modification.
|
||||
* @exception IllegalArgumentException If attr is null, or if mod_op is
|
||||
* not one of the ones specified above.
|
||||
*/
|
||||
public ModificationItem(int mod_op, Attribute attr) {
|
||||
switch (mod_op) {
|
||||
case DirContext.ADD_ATTRIBUTE:
|
||||
case DirContext.REPLACE_ATTRIBUTE:
|
||||
case DirContext.REMOVE_ATTRIBUTE:
|
||||
if (attr == null)
|
||||
throw new IllegalArgumentException("Must specify non-null attribute for modification");
|
||||
|
||||
this.mod_op = mod_op;
|
||||
this.attr = attr;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid modification code " + mod_op);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the modification code of this modification item.
|
||||
* @return The modification code. It is one of:
|
||||
* DirContext.ADD_ATTRIBUTE
|
||||
* DirContext.REPLACE_ATTRIBUTE
|
||||
* DirContext.REMOVE_ATTRIBUTE
|
||||
*/
|
||||
public int getModificationOp() {
|
||||
return mod_op;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the attribute associated with this modification item.
|
||||
* @return The non-null attribute to use for the modification.
|
||||
*/
|
||||
public Attribute getAttribute() {
|
||||
return attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the string representation of this modification item,
|
||||
* which consists of the modification operation and its related attribute.
|
||||
* The string representation is meant for debugging and not to be
|
||||
* interpreted programmatically.
|
||||
*
|
||||
* @return The non-null string representation of this modification item.
|
||||
*/
|
||||
public String toString() {
|
||||
switch (mod_op) {
|
||||
case DirContext.ADD_ATTRIBUTE:
|
||||
return ("Add attribute: " + attr.toString());
|
||||
|
||||
case DirContext.REPLACE_ATTRIBUTE:
|
||||
return ("Replace attribute: " + attr.toString());
|
||||
|
||||
case DirContext.REMOVE_ATTRIBUTE:
|
||||
return ("Remove attribute: " + attr.toString());
|
||||
}
|
||||
return ""; // should never happen
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = 7573258562534746850L;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when attempting to access
|
||||
* an attribute that does not exist.
|
||||
* <p>
|
||||
* Synchronization and serialization issues that apply to NamingException
|
||||
* apply directly here.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
public class NoSuchAttributeException extends NamingException {
|
||||
/**
|
||||
* Constructs a new instance of NoSuchAttributeException using
|
||||
* an explanation. All other fields are set to null.
|
||||
* @param explanation Additional detail about this exception. Can be null.
|
||||
* @see java.lang.Throwable#getMessage
|
||||
*/
|
||||
public NoSuchAttributeException(String explanation) {
|
||||
super(explanation);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new instance of NoSuchAttributeException.
|
||||
* All fields are initialized to null.
|
||||
*/
|
||||
public NoSuchAttributeException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = 4836415647935888137L;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* This exception is thrown when a method
|
||||
* in some ways violates the schema. An example of schema violation
|
||||
* is modifying attributes of an object that violates the object's
|
||||
* schema definition. Another example is renaming or moving an object
|
||||
* to a part of the namespace that violates the namespace's
|
||||
* schema definition.
|
||||
* <p>
|
||||
* Synchronization and serialization issues that apply to NamingException
|
||||
* apply directly here.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
*
|
||||
* @see javax.naming.Context#bind
|
||||
* @see DirContext#bind
|
||||
* @see javax.naming.Context#rebind
|
||||
* @see DirContext#rebind
|
||||
* @see DirContext#createSubcontext
|
||||
* @see javax.naming.Context#createSubcontext
|
||||
* @see DirContext#modifyAttributes
|
||||
* @since 1.3
|
||||
*/
|
||||
public class SchemaViolationException extends NamingException {
|
||||
/**
|
||||
* Constructs a new instance of SchemaViolationException.
|
||||
* All fields are set to null.
|
||||
*/
|
||||
public SchemaViolationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of SchemaViolationException
|
||||
* using the explanation supplied. All other fields are set to null.
|
||||
* @param explanation Detail about this exception. Can be null.
|
||||
* @see java.lang.Throwable#getMessage
|
||||
*/
|
||||
public SchemaViolationException(String explanation) {
|
||||
super(explanation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = -3041762429525049663L;
|
||||
}
|
||||
336
jdkSrc/jdk8/javax/naming/directory/SearchControls.java
Normal file
336
jdkSrc/jdk8/javax/naming/directory/SearchControls.java
Normal file
@@ -0,0 +1,336 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
/**
|
||||
* This class encapsulates
|
||||
* factors that determine scope of search and what gets returned
|
||||
* as a result of the search.
|
||||
*<p>
|
||||
* A SearchControls instance is not synchronized against concurrent
|
||||
* multithreaded access. Multiple threads trying to access and modify
|
||||
* a single SearchControls instance should lock the object.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
public class SearchControls implements java.io.Serializable {
|
||||
/**
|
||||
* Search the named object.
|
||||
*<p>
|
||||
* The NamingEnumeration that results from search()
|
||||
* using OBJECT_SCOPE will contain one or zero element.
|
||||
* The enumeration contains one element if the named object satisfies
|
||||
* the search filter specified in search().
|
||||
* The element will have as its name the empty string because the names
|
||||
* of elements in the NamingEnumeration are relative to the
|
||||
* target context--in this case, the target context is the named object.
|
||||
* It contains zero element if the named object does not satisfy
|
||||
* the search filter specified in search().
|
||||
* <p>
|
||||
* The value of this constant is <tt>0</tt>.
|
||||
*/
|
||||
public final static int OBJECT_SCOPE = 0;
|
||||
|
||||
/**
|
||||
* Search one level of the named context.
|
||||
*<p>
|
||||
* The NamingEnumeration that results from search()
|
||||
* using ONELEVEL_SCOPE contains elements with
|
||||
* objects in the named context that satisfy
|
||||
* the search filter specified in search().
|
||||
* The names of elements in the NamingEnumeration are atomic names
|
||||
* relative to the named context.
|
||||
* <p>
|
||||
* The value of this constant is <tt>1</tt>.
|
||||
*/
|
||||
public final static int ONELEVEL_SCOPE = 1;
|
||||
/**
|
||||
* Search the entire subtree rooted at the named object.
|
||||
*<p>
|
||||
* If the named object is not a DirContext, search only the object.
|
||||
* If the named object is a DirContext, search the subtree
|
||||
* rooted at the named object, including the named object itself.
|
||||
*<p>
|
||||
* The search will not cross naming system boundaries.
|
||||
*<p>
|
||||
* The NamingEnumeration that results from search()
|
||||
* using SUBTREE_SCOPE contains elements of objects
|
||||
* from the subtree (including the named context)
|
||||
* that satisfy the search filter specified in search().
|
||||
* The names of elements in the NamingEnumeration are either
|
||||
* relative to the named context or is a URL string.
|
||||
* If the named context satisfies the search filter, it is
|
||||
* included in the enumeration with the empty string as
|
||||
* its name.
|
||||
* <p>
|
||||
* The value of this constant is <tt>2</tt>.
|
||||
*/
|
||||
public final static int SUBTREE_SCOPE = 2;
|
||||
|
||||
/**
|
||||
* Contains the scope with which to apply the search. One of
|
||||
* <tt>ONELEVEL_SCOPE</tt>, <tt>OBJECT_SCOPE</tt>, or
|
||||
* <tt>SUBTREE_SCOPE</tt>.
|
||||
* @serial
|
||||
*/
|
||||
private int searchScope;
|
||||
|
||||
/**
|
||||
* Contains the milliseconds to wait before returning
|
||||
* from search.
|
||||
* @serial
|
||||
*/
|
||||
private int timeLimit;
|
||||
|
||||
/**
|
||||
* Indicates whether JNDI links are dereferenced during
|
||||
* search.
|
||||
* @serial
|
||||
*/
|
||||
private boolean derefLink;
|
||||
|
||||
/**
|
||||
* Indicates whether object is returned in <tt>SearchResult</tt>.
|
||||
* @serial
|
||||
*/
|
||||
private boolean returnObj;
|
||||
|
||||
/**
|
||||
* Contains the maximum number of SearchResults to return.
|
||||
* @serial
|
||||
*/
|
||||
private long countLimit;
|
||||
|
||||
/**
|
||||
* Contains the list of attributes to be returned in
|
||||
* <tt>SearchResult</tt> for each matching entry of search. <tt>null</tt>
|
||||
* indicates that all attributes are to be returned.
|
||||
* @serial
|
||||
*/
|
||||
private String[] attributesToReturn;
|
||||
|
||||
/**
|
||||
* Constructs a search constraints using defaults.
|
||||
*<p>
|
||||
* The defaults are:
|
||||
* <ul>
|
||||
* <li>search one level
|
||||
* <li>no maximum return limit for search results
|
||||
* <li>no time limit for search
|
||||
* <li>return all attributes associated with objects that satisfy
|
||||
* the search filter.
|
||||
* <li>do not return named object (return only name and class)
|
||||
* <li>do not dereference links during search
|
||||
*</ul>
|
||||
*/
|
||||
public SearchControls() {
|
||||
searchScope = ONELEVEL_SCOPE;
|
||||
timeLimit = 0; // no limit
|
||||
countLimit = 0; // no limit
|
||||
derefLink = false;
|
||||
returnObj = false;
|
||||
attributesToReturn = null; // return all
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a search constraints using arguments.
|
||||
* @param scope The search scope. One of:
|
||||
* OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE.
|
||||
* @param timelim The number of milliseconds to wait before returning.
|
||||
* If 0, wait indefinitely.
|
||||
* @param deref If true, dereference links during search.
|
||||
* @param countlim The maximum number of entries to return. If 0, return
|
||||
* all entries that satisfy filter.
|
||||
* @param retobj If true, return the object bound to the name of the
|
||||
* entry; if false, do not return object.
|
||||
* @param attrs The identifiers of the attributes to return along with
|
||||
* the entry. If null, return all attributes. If empty
|
||||
* return no attributes.
|
||||
*/
|
||||
public SearchControls(int scope,
|
||||
long countlim,
|
||||
int timelim,
|
||||
String[] attrs,
|
||||
boolean retobj,
|
||||
boolean deref) {
|
||||
searchScope = scope;
|
||||
timeLimit = timelim; // no limit
|
||||
derefLink = deref;
|
||||
returnObj = retobj;
|
||||
countLimit = countlim; // no limit
|
||||
attributesToReturn = attrs; // return all
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the search scope of these SearchControls.
|
||||
*<p>
|
||||
* One of OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE.
|
||||
*
|
||||
* @return The search scope of this SearchControls.
|
||||
* @see #setSearchScope
|
||||
*/
|
||||
public int getSearchScope() {
|
||||
return searchScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the time limit of these SearchControls in milliseconds.
|
||||
*<p>
|
||||
* If the value is 0, this means to wait indefinitely.
|
||||
* @return The time limit of these SearchControls in milliseconds.
|
||||
* @see #setTimeLimit
|
||||
*/
|
||||
public int getTimeLimit() {
|
||||
return timeLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether links will be dereferenced during the search.
|
||||
*
|
||||
* @return true if links will be dereferenced; false otherwise.
|
||||
* @see #setDerefLinkFlag
|
||||
*/
|
||||
public boolean getDerefLinkFlag() {
|
||||
return derefLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether objects will be returned as part of the result.
|
||||
*
|
||||
* @return true if objects will be returned; false otherwise.
|
||||
* @see #setReturningObjFlag
|
||||
*/
|
||||
public boolean getReturningObjFlag() {
|
||||
return returnObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the maximum number of entries that will be returned
|
||||
* as a result of the search.
|
||||
*<p>
|
||||
* 0 indicates that all entries will be returned.
|
||||
* @return The maximum number of entries that will be returned.
|
||||
* @see #setCountLimit
|
||||
*/
|
||||
public long getCountLimit() {
|
||||
return countLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the attributes that will be returned as part of the search.
|
||||
*<p>
|
||||
* A value of null indicates that all attributes will be returned.
|
||||
* An empty array indicates that no attributes are to be returned.
|
||||
*
|
||||
* @return An array of attribute ids identifying the attributes that
|
||||
* will be returned. Can be null.
|
||||
* @see #setReturningAttributes
|
||||
*/
|
||||
public String[] getReturningAttributes() {
|
||||
return attributesToReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the search scope to one of:
|
||||
* OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE.
|
||||
* @param scope The search scope of this SearchControls.
|
||||
* @see #getSearchScope
|
||||
*/
|
||||
public void setSearchScope(int scope) {
|
||||
searchScope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time limit of these SearchControls in milliseconds.
|
||||
*<p>
|
||||
* If the value is 0, this means to wait indefinitely.
|
||||
* @param ms The time limit of these SearchControls in milliseconds.
|
||||
* @see #getTimeLimit
|
||||
*/
|
||||
public void setTimeLimit(int ms) {
|
||||
timeLimit = ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables/disables link dereferencing during the search.
|
||||
*
|
||||
* @param on if true links will be dereferenced; if false, not followed.
|
||||
* @see #getDerefLinkFlag
|
||||
*/
|
||||
public void setDerefLinkFlag(boolean on) {
|
||||
derefLink = on;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables/disables returning objects returned as part of the result.
|
||||
*<p>
|
||||
* If disabled, only the name and class of the object is returned.
|
||||
* If enabled, the object will be returned.
|
||||
*
|
||||
* @param on if true, objects will be returned; if false,
|
||||
* objects will not be returned.
|
||||
* @see #getReturningObjFlag
|
||||
*/
|
||||
public void setReturningObjFlag(boolean on) {
|
||||
returnObj = on;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of entries to be returned
|
||||
* as a result of the search.
|
||||
*<p>
|
||||
* 0 indicates no limit: all entries will be returned.
|
||||
*
|
||||
* @param limit The maximum number of entries that will be returned.
|
||||
* @see #getCountLimit
|
||||
*/
|
||||
public void setCountLimit(long limit) {
|
||||
countLimit = limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the attributes that will be returned as part of the search.
|
||||
*<p>
|
||||
* null indicates that all attributes will be returned.
|
||||
* An empty array indicates no attributes are returned.
|
||||
*
|
||||
* @param attrs An array of attribute ids identifying the attributes that
|
||||
* will be returned. Can be null.
|
||||
* @see #getReturningAttributes
|
||||
*/
|
||||
public void setReturningAttributes(String[] attrs) {
|
||||
attributesToReturn = attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = -2480540967773454797L;
|
||||
}
|
||||
189
jdkSrc/jdk8/javax/naming/directory/SearchResult.java
Normal file
189
jdkSrc/jdk8/javax/naming/directory/SearchResult.java
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.naming.directory;
|
||||
|
||||
import javax.naming.Binding;
|
||||
|
||||
/**
|
||||
* This class represents an item in the NamingEnumeration returned as a
|
||||
* result of the DirContext.search() methods.
|
||||
*<p>
|
||||
* A SearchResult instance is not synchronized against concurrent
|
||||
* multithreaded access. Multiple threads trying to access and modify
|
||||
* a single SearchResult instance should lock the object.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
*
|
||||
* @see DirContext#search
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
public class SearchResult extends Binding {
|
||||
/**
|
||||
* Contains the attributes returned with the object.
|
||||
* @serial
|
||||
*/
|
||||
private Attributes attrs;
|
||||
|
||||
/**
|
||||
* Constructs a search result using the result's name, its bound object, and
|
||||
* its attributes.
|
||||
*<p>
|
||||
* <tt>getClassName()</tt> will return the class name of <tt>obj</tt>
|
||||
* (or null if <tt>obj</tt> is null) unless the class name has been
|
||||
* explicitly set using <tt>setClassName()</tt>.
|
||||
*
|
||||
* @param name The non-null name of the search item. It is relative
|
||||
* to the <em>target context</em> of the search (which is
|
||||
* named by the first parameter of the <code>search()</code> method)
|
||||
*
|
||||
* @param obj The object bound to name. Can be null.
|
||||
* @param attrs The attributes that were requested to be returned with
|
||||
* this search item. Cannot be null.
|
||||
* @see javax.naming.NameClassPair#setClassName
|
||||
* @see javax.naming.NameClassPair#getClassName
|
||||
*/
|
||||
public SearchResult(String name, Object obj, Attributes attrs) {
|
||||
super(name, obj);
|
||||
this.attrs = attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a search result using the result's name, its bound object, and
|
||||
* its attributes, and whether the name is relative.
|
||||
*<p>
|
||||
* <tt>getClassName()</tt> will return the class name of <tt>obj</tt>
|
||||
* (or null if <tt>obj</tt> is null) unless the class name has been
|
||||
* explicitly set using <tt>setClassName()</tt>
|
||||
*
|
||||
* @param name The non-null name of the search item.
|
||||
* @param obj The object bound to name. Can be null.
|
||||
* @param attrs The attributes that were requested to be returned with
|
||||
* this search item. Cannot be null.
|
||||
* @param isRelative true if <code>name</code> is relative
|
||||
* to the target context of the search (which is named by
|
||||
* the first parameter of the <code>search()</code> method);
|
||||
* false if <code>name</code> is a URL string.
|
||||
* @see javax.naming.NameClassPair#setClassName
|
||||
* @see javax.naming.NameClassPair#getClassName
|
||||
*/
|
||||
public SearchResult(String name, Object obj, Attributes attrs,
|
||||
boolean isRelative) {
|
||||
super(name, obj, isRelative);
|
||||
this.attrs = attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a search result using the result's name, its class name,
|
||||
* its bound object, and its attributes.
|
||||
*
|
||||
* @param name The non-null name of the search item. It is relative
|
||||
* to the <em>target context</em> of the search (which is
|
||||
* named by the first parameter of the <code>search()</code> method)
|
||||
*
|
||||
* @param className The possibly null class name of the object
|
||||
* bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is
|
||||
* returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also null,
|
||||
* <tt>getClassName()</tt> will return null.
|
||||
* @param obj The object bound to name. Can be null.
|
||||
* @param attrs The attributes that were requested to be returned with
|
||||
* this search item. Cannot be null.
|
||||
* @see javax.naming.NameClassPair#setClassName
|
||||
* @see javax.naming.NameClassPair#getClassName
|
||||
*/
|
||||
public SearchResult(String name, String className,
|
||||
Object obj, Attributes attrs) {
|
||||
super(name, className, obj);
|
||||
this.attrs = attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a search result using the result's name, its class name,
|
||||
* its bound object, its attributes, and whether the name is relative.
|
||||
*
|
||||
* @param name The non-null name of the search item.
|
||||
* @param className The possibly null class name of the object
|
||||
* bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is
|
||||
* returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also null,
|
||||
* <tt>getClassName()</tt> will return null.
|
||||
* @param obj The object bound to name. Can be null.
|
||||
* @param attrs The attributes that were requested to be returned with
|
||||
* this search item. Cannot be null.
|
||||
* @param isRelative true if <code>name</code> is relative
|
||||
* to the target context of the search (which is named by
|
||||
* the first parameter of the <code>search()</code> method);
|
||||
* false if <code>name</code> is a URL string.
|
||||
* @see javax.naming.NameClassPair#setClassName
|
||||
* @see javax.naming.NameClassPair#getClassName
|
||||
*/
|
||||
public SearchResult(String name, String className, Object obj,
|
||||
Attributes attrs, boolean isRelative) {
|
||||
super(name, className, obj, isRelative);
|
||||
this.attrs = attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the attributes in this search result.
|
||||
*
|
||||
* @return The non-null attributes in this search result. Can be empty.
|
||||
* @see #setAttributes
|
||||
*/
|
||||
public Attributes getAttributes() {
|
||||
return attrs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the attributes of this search result to <code>attrs</code>.
|
||||
* @param attrs The non-null attributes to use. Can be empty.
|
||||
* @see #getAttributes
|
||||
*/
|
||||
public void setAttributes(Attributes attrs) {
|
||||
this.attrs = attrs;
|
||||
// ??? check for null?
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates the string representation of this SearchResult.
|
||||
* The string representation consists of the string representation
|
||||
* of the binding and the string representation of
|
||||
* this search result's attributes, separated by ':'.
|
||||
* The contents of this string is useful
|
||||
* for debugging and is not meant to be interpreted programmatically.
|
||||
*
|
||||
* @return The string representation of this SearchResult. Cannot be null.
|
||||
*/
|
||||
public String toString() {
|
||||
return super.toString() + ":" + getAttributes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use serialVersionUID from JNDI 1.1.1 for interoperability
|
||||
*/
|
||||
private static final long serialVersionUID = -9158063327699723172L;
|
||||
}
|
||||
Reference in New Issue
Block a user