Path: blob/master/src/java.naming/share/classes/javax/naming/directory/Attribute.java
41159 views
/*1* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming.directory;2627import java.util.Vector;28import java.util.Enumeration;29import java.util.NoSuchElementException;3031import javax.naming.NamingException;32import javax.naming.NamingEnumeration;33import javax.naming.OperationNotSupportedException;3435/**36* This interface represents an attribute associated with a named object.37*<p>38* In a directory, named objects can have associated with them39* attributes. The {@code Attribute} interface represents an attribute associated40* with a named object. An attribute contains 0 or more, possibly null, values.41* The attribute values can be ordered or unordered (see {@code isOrdered()}).42* If the values are unordered, no duplicates are allowed.43* If the values are ordered, duplicates are allowed.44*<p>45* The content and representation of an attribute and its values is defined by46* the attribute's <em>schema</em>. The schema contains information47* about the attribute's syntax and other properties about the attribute.48* See {@code getAttributeDefinition()} and49* {@code getAttributeSyntaxDefinition()}50* for details regarding how to get schema information about an attribute51* if the underlying directory service supports schemas.52*<p>53* Equality of two attributes is determined by the implementation class.54* A simple implementation can use {@code Object.equals()} to determine equality55* of attribute values, while a more sophisticated implementation might56* make use of schema information to determine equality.57* Similarly, one implementation might provide a static storage58* structure which simply returns the values passed to its59* constructor, while another implementation might define {@code get()} and60* {@code getAll()}.61* to get the values dynamically from the directory.62*<p>63* Note that updates to {@code Attribute} (such as adding or removing a64* value) do not affect the corresponding representation of the attribute65* in the directory. Updates to the directory can only be effected66* using operations in the {@code DirContext} interface.67*68* @author Rosanna Lee69* @author Scott Seligman70*71* @see BasicAttribute72* @since 1.373*/74public interface Attribute extends Cloneable, java.io.Serializable {75/**76* Retrieves an enumeration of the attribute's values.77* The behaviour of this enumeration is unspecified78* if the attribute's values are added, changed,79* or removed while the enumeration is in progress.80* If the attribute values are ordered, the enumeration's items81* will be ordered.82*83* @return A non-null enumeration of the attribute's values.84* Each element of the enumeration is a possibly null Object. The object's85* class is the class of the attribute value. The element is null86* if the attribute's value is null.87* If the attribute has zero values, an empty enumeration88* is returned.89* @exception NamingException90* If a naming exception was encountered while retrieving91* the values.92* @see #isOrdered93*/94NamingEnumeration<?> getAll() throws NamingException;9596/**97* Retrieves one of this attribute's values.98* If the attribute has more than one value and is unordered, any one of99* the values is returned.100* If the attribute has more than one value and is ordered, the101* first value is returned.102*103* @return A possibly null object representing one of104* the attribute's value. It is null if the attribute's value105* is null.106* @exception NamingException107* If a naming exception was encountered while retrieving108* the value.109* @exception java.util.NoSuchElementException110* If this attribute has no values.111*/112Object get() throws NamingException;113114/**115* Retrieves the number of values in this attribute.116*117* @return The nonnegative number of values in this attribute.118*/119int size();120121/**122* Retrieves the id of this attribute.123*124* @return The id of this attribute. It cannot be null.125*/126String getID();127128/**129* Determines whether a value is in the attribute.130* Equality is determined by the implementation, which may use131* {@code Object.equals()} or schema information to determine equality.132*133* @param attrVal The possibly null value to check. If null, check134* whether the attribute has an attribute value whose value is null.135* @return true if attrVal is one of this attribute's values; false otherwise.136* @see java.lang.Object#equals137* @see BasicAttribute#equals138*/139boolean contains(Object attrVal);140/**141* Adds a new value to the attribute.142* If the attribute values are unordered and143* {@code attrVal} is already in the attribute, this method does nothing.144* If the attribute values are ordered, {@code attrVal} is added to the end of145* the list of attribute values.146*<p>147* Equality is determined by the implementation, which may use148* {@code Object.equals()} or schema information to determine equality.149*150* @param attrVal The new possibly null value to add. If null, null151* is added as an attribute value.152* @return true if a value was added; false otherwise.153*/154boolean add(Object attrVal);155156/**157* Removes a specified value from the attribute.158* If {@code attrval} is not in the attribute, this method does nothing.159* If the attribute values are ordered, the first occurrence of160* {@code attrVal} is removed and attribute values at indices greater161* than the removed162* value are shifted up towards the head of the list (and their indices163* decremented by one).164*<p>165* Equality is determined by the implementation, which may use166* {@code Object.equals()} or schema information to determine equality.167*168* @param attrval The possibly null value to remove from this attribute.169* If null, remove the attribute value that is null.170* @return true if the value was removed; false otherwise.171*/172boolean remove(Object attrval);173174/**175* Removes all values from this attribute.176*/177void clear();178179/**180* Retrieves the syntax definition associated with the attribute.181* An attribute's syntax definition specifies the format182* of the attribute's value(s). Note that this is different from183* the attribute value's representation as a Java object. Syntax184* definition refers to the directory's notion of <em>syntax</em>.185*<p>186* For example, even though a value might be187* a Java String object, its directory syntax might be "Printable String"188* or "Telephone Number". Or a value might be a byte array, and its189* directory syntax is "JPEG" or "Certificate".190* For example, if this attribute's syntax is "JPEG",191* this method would return the syntax definition for "JPEG".192* <p>193* The information that you can retrieve from a syntax definition194* is directory-dependent.195*<p>196* If an implementation does not support schemas, it should throw197* OperationNotSupportedException. If an implementation does support198* schemas, it should define this method to return the appropriate199* information.200* @return The attribute's syntax definition. Null if the implementation201* supports schemas but this particular attribute does not have202* any schema information.203* @exception OperationNotSupportedException If getting the schema204* is not supported.205* @exception NamingException If a naming exception occurs while getting206* the schema.207*/208209DirContext getAttributeSyntaxDefinition() throws NamingException;210211/**212* Retrieves the attribute's schema definition.213* An attribute's schema definition contains information214* such as whether the attribute is multivalued or single-valued,215* the matching rules to use when comparing the attribute's values.216*217* The information that you can retrieve from an attribute definition218* is directory-dependent.219*220*<p>221* If an implementation does not support schemas, it should throw222* OperationNotSupportedException. If an implementation does support223* schemas, it should define this method to return the appropriate224* information.225* @return This attribute's schema definition. Null if the implementation226* supports schemas but this particular attribute does not have227* any schema information.228* @exception OperationNotSupportedException If getting the schema229* is not supported.230* @exception NamingException If a naming exception occurs while getting231* the schema.232*/233DirContext getAttributeDefinition() throws NamingException;234235/**236* Makes a copy of the attribute.237* The copy contains the same attribute values as the original attribute:238* the attribute values are not themselves cloned.239* Changes to the copy will not affect the original and vice versa.240*241* @return A non-null copy of the attribute.242*/243Object clone();244245//----------- Methods to support ordered multivalued attributes246247/**248* Determines whether this attribute's values are ordered.249* If an attribute's values are ordered, duplicate values are allowed.250* If an attribute's values are unordered, they are presented251* in any order and there are no duplicate values.252* @return true if this attribute's values are ordered; false otherwise.253* @see #get(int)254* @see #remove(int)255* @see #add(int, java.lang.Object)256* @see #set(int, java.lang.Object)257*/258boolean isOrdered();259260/**261* Retrieves the attribute value from the ordered list of attribute values.262* This method returns the value at the {@code ix} index of the list of263* attribute values.264* If the attribute values are unordered,265* this method returns the value that happens to be at that index.266* @param ix The index of the value in the ordered list of attribute values.267* {@code 0 <= ix < size()}.268* @return The possibly null attribute value at index {@code ix};269* null if the attribute value is null.270* @exception NamingException If a naming exception was encountered while271* retrieving the value.272* @exception IndexOutOfBoundsException If {@code ix} is outside the specified range.273*/274Object get(int ix) throws NamingException;275276/**277* Removes an attribute value from the ordered list of attribute values.278* This method removes the value at the {@code ix} index of the list of279* attribute values.280* If the attribute values are unordered,281* this method removes the value that happens to be at that index.282* Values located at indices greater than {@code ix} are shifted up towards283* the front of the list (and their indices decremented by one).284*285* @param ix The index of the value to remove.286* {@code 0 <= ix < size()}.287* @return The possibly null attribute value at index {@code ix} that was removed;288* null if the attribute value is null.289* @exception IndexOutOfBoundsException If {@code ix} is outside the specified range.290*/291Object remove(int ix);292293/**294* Adds an attribute value to the ordered list of attribute values.295* This method adds {@code attrVal} to the list of attribute values at296* index {@code ix}.297* Values located at indices at or greater than {@code ix} are298* shifted down towards the end of the list (and their indices incremented299* by one).300* If the attribute values are unordered and already have {@code attrVal},301* {@code IllegalStateException} is thrown.302*303* @param ix The index in the ordered list of attribute values to add the new value.304* {@code 0 <= ix <= size()}.305* @param attrVal The possibly null attribute value to add; if null, null is306* the value added.307* @exception IndexOutOfBoundsException If {@code ix} is outside the specified range.308* @exception IllegalStateException If the attribute values are unordered and309* {@code attrVal} is one of those values.310*/311void add(int ix, Object attrVal);312313314/**315* Sets an attribute value in the ordered list of attribute values.316* This method sets the value at the {@code ix} index of the list of317* attribute values to be {@code attrVal}. The old value is removed.318* If the attribute values are unordered,319* this method sets the value that happens to be at that index320* to {@code attrVal}, unless {@code attrVal} is already one of the values.321* In that case, {@code IllegalStateException} is thrown.322*323* @param ix The index of the value in the ordered list of attribute values.324* {@code 0 <= ix < size()}.325* @param attrVal The possibly null attribute value to use.326* If null, 'null' replaces the old value.327* @return The possibly null attribute value at index ix that was replaced.328* Null if the attribute value was null.329* @exception IndexOutOfBoundsException If {@code ix} is outside the specified range.330* @exception IllegalStateException If {@code attrVal} already exists and the331* attribute values are unordered.332*/333Object set(int ix, Object attrVal);334335/**336* Use serialVersionUID from JNDI 1.1.1 for interoperability.337*338* @deprecated A {@code serialVersionUID} field in an interface is339* ineffectual. Do not use; no replacement.340*/341@Deprecated342@SuppressWarnings("serial")343static final long serialVersionUID = 8707690322213556804L;344}345346347