本文整理汇总了Java中javax.naming.directory.Attributes.size方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes.size方法的具体用法?Java Attributes.size怎么用?Java Attributes.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.directory.Attributes
的用法示例。
在下文中一共展示了Attributes.size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Rdn
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Constructs an Rdn from the given attribute set. See
* {@link javax.naming.directory.Attributes Attributes}.
* <p>
* The string attribute values are not interpreted as
* <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a>
* formatted RDN strings. That is, the values are used
* literally (not parsed) and assumed to be unescaped.
*
* @param attrSet The non-null and non-empty attributes containing
* type/value mappings.
* @throws InvalidNameException If contents of <tt>attrSet</tt> cannot
* be used to construct a valid RDN.
*/
public Rdn(Attributes attrSet) throws InvalidNameException {
if (attrSet.size() == 0) {
throw new InvalidNameException("Attributes cannot be empty");
}
entries = new ArrayList<>(attrSet.size());
NamingEnumeration<? extends Attribute> attrs = attrSet.getAll();
try {
for (int nEntries = 0; attrs.hasMore(); nEntries++) {
RdnEntry entry = new RdnEntry();
Attribute attr = attrs.next();
entry.type = attr.getID();
entry.value = attr.get();
entries.add(nEntries, entry);
}
} catch (NamingException e) {
InvalidNameException e2 = new InvalidNameException(
e.getMessage());
e2.initCause(e);
throw e2;
}
sort(); // arrange entries for comparison
}
示例2: Rdn
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Constructs an Rdn from the given attribute set. See
* {@link javax.naming.directory.Attributes Attributes}.
* <p>
* The string attribute values are not interpreted as
* <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a>
* formatted RDN strings. That is, the values are used
* literally (not parsed) and assumed to be unescaped.
*
* @param attrSet The non-null and non-empty attributes containing
* type/value mappings.
* @throws InvalidNameException If contents of {@code attrSet} cannot
* be used to construct a valid RDN.
*/
public Rdn(Attributes attrSet) throws InvalidNameException {
if (attrSet.size() == 0) {
throw new InvalidNameException("Attributes cannot be empty");
}
entries = new ArrayList<>(attrSet.size());
NamingEnumeration<? extends Attribute> attrs = attrSet.getAll();
try {
for (int nEntries = 0; attrs.hasMore(); nEntries++) {
RdnEntry entry = new RdnEntry();
Attribute attr = attrs.next();
entry.type = attr.getID();
entry.value = attr.get();
entries.add(nEntries, entry);
}
} catch (NamingException e) {
InvalidNameException e2 = new InvalidNameException(
e.getMessage());
e2.initCause(e);
throw e2;
}
sort(); // arrange entries for comparison
}
示例3: decodeAttributes
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Converts a JNDI Attributes into our LdapEntry object.
*
* @param dn The dn associated with the search.
* @param attrNames an array of attribute names to be returned.
* If null, all available attributes are returned.
* @param attrraw Then JNDI Attributes object resulting from the search.
*/
private LdapEntry decodeAttributes(
String dn,
String[] attrNames,
Attributes attrraw)
throws LdapException
{
LdapEntry entry = new LdapEntry( dn);
if (bugs >= 1) prtln("\nReturned dn: " + dn);
if (attrraw.size() == 0) {
if (bugs >= 1) prtln("No attributes returned");
if (attrNames != null) {
// No attrs returned, but attr names were specified, so
// we must return an empty array with just the attr names.
entry.allocAttrs( attrNames.length);
for (int iattr = 0; iattr < attrNames.length; iattr++) {
entry.allocAttrsRow( iattr, 1); // all rows just 1 long
entry.setAttr( iattr, 0, attrNames[iattr]);
}
}
}
else {
NamingEnumeration attrenum = attrraw.getAll();
ArrayExc attrvec = fixEnum( attrenum);
if (attrvec.exc != null)
throw new LdapException("attrvec hidden exception", attrvec.exc);
// If attrNames specified, use that format
if (attrNames != null) {
entry.allocAttrs( attrNames.length);
// Fill in each requested attr name
for (int iattr = 0; iattr < attrNames.length; iattr++) {
// Search result set for matching name
BasicAttribute foundattr = null;
for (int ires = 0; ires < attrvec.vals.length; ires++) {
BasicAttribute testattr = (BasicAttribute)
attrvec.vals[ ires];
if (testattr.getID().equals( attrNames[ iattr])) {
foundattr = testattr;
break;
}
}
if (foundattr == null) {
entry.allocAttrsRow( iattr, 1); // just the attr name
entry.setAttr( iattr, 0, attrNames[ iattr]);
}
else entry.setAttrsRow( iattr, decodeValues( foundattr));
}
}
// Else no attrNames: return ALL attributes.
else {
entry.allocAttrs( attrvec.vals.length);
// Sort the attributes by attribute ID (attribute name)
Arrays.sort( attrvec.vals, new Comparator() {
public int compare( Object obja, Object objb) {
BasicAttribute attra = (BasicAttribute) obja;
BasicAttribute attrb = (BasicAttribute) objb;
return attra.getID().compareTo( attrb.getID());
}
public boolean equals( Object obj) { return false; }
});
for (int iattr = 0; iattr < attrvec.vals.length; iattr++) {
entry.setAttrsRow( iattr, decodeValues(
(BasicAttribute) attrvec.vals[ iattr]));
}
}
}
return entry;
}