本文整理汇总了Java中javax.naming.directory.Attributes.getAll方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes.getAll方法的具体用法?Java Attributes.getAll怎么用?Java Attributes.getAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.directory.Attributes
的用法示例。
在下文中一共展示了Attributes.getAll方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRangeRestrictedAttribute
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Gets the values of a repeating attribute that may have range restriction options. If an attribute is range
* restricted, it will appear in the attribute set with a ";range=i-j" option, where i and j indicate the start and
* end index, and j is '*' if it is at the end.
*
* @param attributes
* the attributes
* @param attributeName
* the attribute name
* @return the range restricted attribute
* @throws NamingException
* the naming exception
*/
private Attribute getRangeRestrictedAttribute(Attributes attributes, String attributeName) throws NamingException
{
Attribute unrestricted = attributes.get(attributeName);
if (unrestricted != null)
{
return unrestricted;
}
NamingEnumeration<? extends Attribute> i = attributes.getAll();
String searchString = attributeName.toLowerCase() + ';';
while (i.hasMore())
{
Attribute attribute = i.next();
if (attribute.getID().toLowerCase().startsWith(searchString))
{
return attribute;
}
}
return null;
}
示例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 <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
}
示例3: 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
}
示例4: toEntry
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Convert a BasicAttributes or a AttributesImpl to an Entry
*
* @param attributes the BasicAttributes or AttributesImpl instance to convert
* @param dn The Dn which is needed by the Entry
* @return An instance of a Entry object
*
* @throws LdapException If we get an invalid attribute
*/
public static Entry toEntry( Attributes attributes, Dn dn ) throws LdapException
{
if ( attributes instanceof BasicAttributes )
{
try
{
Entry entry = new DefaultEntry( dn );
for ( NamingEnumeration<? extends javax.naming.directory.Attribute> attrs = attributes.getAll(); attrs
.hasMoreElements(); )
{
javax.naming.directory.Attribute attr = attrs.nextElement();
Attribute entryAttribute = toApiAttribute( attr );
if ( entryAttribute != null )
{
entry.put( entryAttribute );
}
}
return entry;
}
catch ( LdapException ne )
{
throw new LdapInvalidAttributeTypeException( ne.getMessage(), ne );
}
}
else
{
return null;
}
}
示例5: reverseDNS
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* This method uses JNDI to look up an address in DNS and return its name
*
* @param addr
*
* @return the host name associated with the address or null if lookup isn't possible or there is
* no host name for this address
*/
public static String reverseDNS(InetAddress addr) {
byte[] addrBytes = addr.getAddress();
// reverse the address suitable for reverse lookup
String lookup = "";
for (int index = addrBytes.length - 1; index >= 0; index--) {
lookup = lookup + (addrBytes[index] & 0xff) + '.';
}
lookup += "in-addr.arpa";
// System.out.println("Looking up: " + lookup);
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
DirContext ctx = new InitialDirContext(env);
Attributes attrs = ctx.getAttributes(lookup, new String[] {"PTR"});
for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements();) {
Attribute attr = (Attribute) ae.next();
for (Enumeration vals = attr.getAll(); vals.hasMoreElements();) {
Object elem = vals.nextElement();
if ("PTR".equals(attr.getID()) && elem != null) {
return elem.toString();
}
}
}
ctx.close();
} catch (Exception e) {
// ignored
}
return null;
}
示例6: reverseDNS
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* This method uses JNDI to look up an address in DNS and return its name
*
* @return the host name associated with the address or null if lookup isn't possible or there is
* no host name for this address
*/
private static String reverseDNS(InetAddress addr) {
byte[] addrBytes = addr.getAddress();
// reverse the address suitable for reverse lookup
StringBuilder sb = new StringBuilder();
for (int index = addrBytes.length - 1; index >= 0; index--) {
// lookup = lookup + (addrBytes[index] & 0xff) + '.';
sb.append((addrBytes[index] & 0xff)).append('.');
}
sb.append("in-addr.arpa");
String lookup = sb.toString();
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
DirContext ctx = new InitialDirContext(env);
Attributes attrs = ctx.getAttributes(lookup, new String[] {"PTR"});
for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements();) {
Attribute attr = (Attribute) ae.next();
for (Enumeration vals = attr.getAll(); vals.hasMoreElements();) {
Object elem = vals.nextElement();
if ("PTR".equals(attr.getID()) && elem != null) {
return elem.toString();
}
}
}
ctx.close();
} catch (Exception e) {
// ignored
}
return null;
}
示例7: getSomeAttributes
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* @param dn
* @param attributeNames
* @return
* @throws NamingException
*/
public NamingEnumeration getSomeAttributes(String dn, String[] attributeNames) throws NamingException
{
Attributes attrs = m_ctx.getAttributes(dn, attributeNames);
NamingEnumeration enumSome = attrs.getAll();
while (enumSome.hasMore())
{
Attribute a = (Attribute)enumSome.next();
Log.logDebug(a.getID()+" = "+a.get());
}
return enumSome;
}
示例8: toCaseInsensitive
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* Check if the attributes is a BasicAttributes, and if so, switch
* the case sensitivity to false to avoid tricky problems in the server.
* (Ldap attributeTypes are *always* case insensitive)
*
* @param attributes The Attributes to check
* @return The modified Attributes
*/
public static Attributes toCaseInsensitive( Attributes attributes )
{
if ( attributes == null )
{
return attributes;
}
if ( attributes instanceof BasicAttributes )
{
if ( attributes.isCaseIgnored() )
{
// Just do nothing if the Attributes is already case insensitive
return attributes;
}
else
{
// Ok, bad news : we have to create a new BasicAttributes
// which will be case insensitive
Attributes newAttrs = new BasicAttributes( true );
NamingEnumeration<?> attrs = attributes.getAll();
if ( attrs != null )
{
// Iterate through the attributes now
while ( attrs.hasMoreElements() )
{
newAttrs.put( ( javax.naming.directory.Attribute ) attrs.nextElement() );
}
}
return newAttrs;
}
}
else
{
// we can safely return the attributes if it's not a BasicAttributes
return attributes;
}
}
示例9: 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;
}
示例10: getAllAttributes
import javax.naming.directory.Attributes; //导入方法依赖的package包/类
/**
* @param dn
* @return
* @throws NamingException
*/
public NamingEnumeration getAllAttributes(String dn) throws NamingException
{
Attributes attrs = m_ctx.getAttributes(dn);
return attrs.getAll();
}