public class BasicAttribute extends Object implements Attribute
此实现不支持模式方法getAttributeDefinition()和getAttributeSyntaxDefinition()。他们只是把OperationNotSupportedException。子BasicAttribute应该重写这些方法,如果他们支持他们。
默认情况下,BasicAttribute类使用Object.equals()确定属性值相等时测试相等或在寻找价值,但价值是一个数组。对于一个数组,数组的每个元素是检查使用Object.equals()。子BasicAttribute可以利用架构信息时做类似的等式进行重写方法在其中使用模式是有意义的。同样,默认情况下,BasicAttribute类返回值传递给其构造函数和/或操纵使用添加/删除方法。子类可以重写BasicAttribute get()和getAll()动态地从目录中获取的值(或实施Attribute接口直接代替子BasicAttribute)。
注意更新BasicAttribute(如添加或删除一个值)不影响该目录中的属性对应的表示。目录的更新只能在DirContext接口使用操作的影响。
一个BasicAttribute实例不同步的并发多线程访问。多个线程试图访问和修改BasicAttribute应该锁定对象。
Modifier and Type | Field and Description |
---|---|
protected String |
attrID
保存属性的标识。
|
protected boolean |
ordered
记录此属性的值是否有序的标志。
|
protected Vector<Object> |
values
保存属性的值。
|
Constructor and Description |
---|
BasicAttribute(String id)
构建一个没有价值的无序属性的一个新实例。
|
BasicAttribute(String id, boolean ordered)
构造一个可能有没有值的有序属性的新实例。
|
BasicAttribute(String id, Object value)
构建一个单一的价值无序属性的一个新实例。
|
BasicAttribute(String id, Object value, boolean ordered)
构造一个可能具有单个值的可能有序属性的新实例。
|
Modifier and Type | Method and Description |
---|---|
void |
add(int ix, Object attrVal)
将属性值添加到属性值的有序列表中。
|
boolean |
add(Object attrVal)
向此属性添加一个新值。
|
void |
clear()
从这个属性中移除所有的值。
|
Object |
clone()
创建并返回此对象的副本。
|
boolean |
contains(Object attrVal)
确定一个值是否在这个属性中。
|
boolean |
equals(Object obj)
确定目标等于该属性。
|
Object |
get()
检索此属性的值的一个。
|
Object |
get(int ix)
从属性值的有序列表中检索属性值。
|
NamingEnumeration<?> |
getAll()
检索此属性的值的枚举。
|
DirContext |
getAttributeDefinition()
检索此属性的架构定义。
|
DirContext |
getAttributeSyntaxDefinition()
检索与此属性关联的语法定义。
|
String |
getID()
检索此属性的标识。
|
int |
hashCode()
计算此属性的哈希代码。
|
boolean |
isOrdered()
确定此属性的值是否有序。
|
Object |
remove(int ix)
从属性值的有序列表中移除属性值。
|
boolean |
remove(Object attrval)
从这个属性中移除指定的值。
|
Object |
set(int ix, Object attrVal)
在属性值的有序列表中设置一个属性值。
|
int |
size()
检索此属性中的值的数目。
|
String |
toString()
生成此属性的字符串表示形式。
|
protected String attrID
protected transient Vector<Object> values
protected boolean ordered
public BasicAttribute(String id)
id
-属性的ID,它不能为空。
public BasicAttribute(String id, Object value)
id
-属性的ID,它不能为空。
value
-属性的值。如果为空,则将一个空值添加到属性中。
public BasicAttribute(String id, boolean ordered)
id
-属性的ID,它不能为空。
ordered
-真的意味着属性的值将被命令;否则为false。
public Object clone()
Object
x
,表达:
将是真实的,并表示:x.clone() != x
将x.clone().getClass() == x.getClass()
true
,但这些都不是绝对的要求。虽然这是通常的情况下,
将x.clone().equals(x)
true
,这不是一个绝对的要求。
按照惯例,返回的对象应该通过调用super.clone
得到。如果一个类和它的所有父类(除Object
)遵守本公约的情况下,这将是x.clone().getClass() == x.getClass()
。
根据惯例,这个方法返回的对象应该是独立于这个对象(正在被克隆)。为了实现这种独立性,需要修改的super.clone
返回对象的一个或多个字段然后返回。通常,这意味着复制任何可变对象,包括内部的“深层结构”被克隆对象的更换与该份对这些对象的引用的参考文献。如果一个类只包含原始字段或对不可变对象的引用,那么它是通常的情况下,通过super.clone
返回的对象中的任何字段需要修改。
类的方法Object
clone
执行特定的复制操作。首先,如果此对象的类不实现接口Cloneable
,然后CloneNotSupportedException
抛出。请注意,所有的数组都被实现的接口Cloneable
,数组类型的clone
T[]
方法的返回类型是T[]
其中T是任何参考或原始类型。否则,此方法创建此对象的类的新实例并初始化与正是这个对象的相应字段内容的各个领域,如分配;字段的内容不克隆自己。因此,该方法执行此对象的“浅副本”,而不是“深复制”操作。
这类Object
本身不实现接口Cloneable
,所以叫clone
方法对一个对象的类是Object
将导致在运行时抛出异常。
public boolean equals(Object obj)
默认情况下Object.equals()是用于比较的属性ID和它的价值除了当一个值的数组。对于一个数组,数组的每个元素都是使用Object.equals()检查。一个子类可以重写此来使用架构语法信息和匹配规则,它定义了两个属性是相等的两个属性的方法。如何以及子类是否利用架构信息由子类决定的。如果子类重写equals(),它也应该重写hashCode()这样两个属性,同样具有相同的哈希代码。
equals
方法重写,继承类
Object
obj
-检查可能的空对象。
hashCode()
,
contains(java.lang.Object)
public int hashCode()
哈希代码计算通过添加属性的身份证的哈希代码和它的所有值,除了数组的值。对于一个数组,可以求出数组中每个元素的哈希代码。如果子类重写hashCode(),它应该覆盖equals()这样两个属性,同样具有相同的哈希代码。
hashCode
方法重写,继承类
Object
equals(java.lang.Object)
public String toString()
public NamingEnumeration<?> getAll() throws NamingException
默认情况下,返回的值是那些传递给构造函数和/或操作使用的添加/替换/删除方法。子类可以重写此,从目录中动态检索值。
getAll
接口
Attribute
NamingException
-如果在检索值,遇到的是一个命名的例外。
Attribute.isOrdered()
public Object get() throws NamingException
默认情况下,返回的值是传递给构造函数和/或操作使用添加/替换/删除方法的那些人之一。子类可以重写此以从目录中动态检索值。
get
接口
Attribute
NamingException
-如果在检索值,遇到的是一个命名的例外。
public int size()
Attribute
public boolean contains(Object attrVal)
默认情况下,Object.equals()时使用此属性的值进行比较attrVal除了attrVal是数组。对于一个数组,数组的每个元素都是使用Object.equals()检查。子类可以使用模式信息来确定等式。
contains
接口
Attribute
attrVal
-可能的空值检查。如果为空,则检查该属性是否具有一个属性值,该属性值为空。
Object.equals(java.lang.Object)
,
equals(java.lang.Object)
public boolean add(Object attrVal)
默认情况下,Object.equals()时使用此属性的值进行比较attrVal除了attrVal是数组。对于一个数组,数组的每个元素是检查使用Object.equals()。子类可以使用模式信息来确定平等。
public boolean remove(Object attrval)
默认情况下,Object.equals()时使用此属性的值进行比较attrVal除了attrVal是数组。对于一个数组,数组的每个元素都是使用Object.equals()检查。子类可以使用模式信息来确定等式。
public boolean isOrdered()
Attribute
isOrdered
接口
Attribute
Attribute.get(int)
,
Attribute.remove(int)
,
Attribute.add(int, java.lang.Object)
,
Attribute.set(int, java.lang.Object)
public Object get(int ix) throws NamingException
Attribute
get
接口
Attribute
ix
-属性值的有序列表的值的索引。
0 <= ix < size()
。
NamingException
-如果在检索值,遇到的是一个命名的例外。
public Object remove(int ix)
Attribute
public void add(int ix, Object attrVal)
Attribute
public Object set(int ix, Object attrVal)
Attribute
public DirContext getAttributeSyntaxDefinition() throws NamingException
这种方法在默认情况下将operationnotsupportedexception。子类应重写此方法,如果它支持模式。
getAttributeSyntaxDefinition
接口
Attribute
OperationNotSupportedException
如果得到的模式是不支持的。
NamingException
如果发生异常而获得命名模式。
public DirContext getAttributeDefinition() throws NamingException
这种方法在默认情况下将operationnotsupportedexception。子类应重写此方法,如果它支持模式。
getAttributeDefinition
接口
Attribute
OperationNotSupportedException
如果得到的模式是不支持的。
NamingException
如果发生异常而获得命名模式。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.