Package com.unboundid.ldap.sdk.persist
Class PersistUtils
- java.lang.Object
-
- com.unboundid.ldap.sdk.persist.PersistUtils
-
@ThreadSafety(level=COMPLETELY_THREADSAFE) public final class PersistUtils extends java.lang.Object
This class provides a set of utilities that may be used in the course of persistence processing.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> PersistedObjects<T>
getEntriesAsObjects(DN[] dns, java.lang.Class<T> type, LDAPInterface conn)
Retrieves and decodes the indicated entries as objects of the specified type.static <T> T
getEntryAsObject(DN dn, java.lang.Class<T> type, LDAPInterface conn)
Retrieves the entry with the specified DN and decodes it as an object of the specified type.static boolean
isValidJavaIdentifier(java.lang.String s, java.lang.StringBuilder r)
Indicates whether the provided string could be used as a valid Java identifier.static boolean
isValidLDAPName(java.lang.String s, boolean o, java.lang.StringBuilder r)
Indicates whether the provided string could be used as a valid attribute or object class name.static boolean
isValidLDAPName(java.lang.String s, java.lang.StringBuilder r)
Indicates whether the provided string could be used as a valid attribute or object class name.static java.lang.String
toJavaIdentifier(java.lang.String s)
Transforms the provided string if necessary so that it may be used as a valid Java identifier.
-
-
-
Method Detail
-
isValidLDAPName
public static boolean isValidLDAPName(java.lang.String s, java.lang.StringBuilder r)
Indicates whether the provided string could be used as a valid attribute or object class name. Numeric OIDs will also be considered acceptable.- Parameters:
s
- The string for which to make the determination.r
- A buffer to which the unacceptable reason may be appended. It must not benull
.- Returns:
true
if the provided string is acceptable for use as an LDAP attribute or object class name, orfalse
if not.
-
isValidLDAPName
public static boolean isValidLDAPName(java.lang.String s, boolean o, java.lang.StringBuilder r)
Indicates whether the provided string could be used as a valid attribute or object class name. Numeric OIDs will also be considered acceptable.- Parameters:
s
- The string for which to make the determination.o
- Indicates whether the name should be allowed to contain attribute options (e.g., a semicolon with one or more valid characters after it).r
- A buffer to which the unacceptable reason may be appended. It must not benull
.- Returns:
true
if the provided string is acceptable for use as an LDAP attribute or object class name, orfalse
if not.
-
isValidJavaIdentifier
public static boolean isValidJavaIdentifier(java.lang.String s, java.lang.StringBuilder r)
Indicates whether the provided string could be used as a valid Java identifier. The identifier must begin with an ASCII letter or underscore, and must contain only ASCII letters, ASCII digits, and the underscore character. Even though a dollar sign is technically allowed, it will not be considered valid for the purpose of this method. Similarly, even though Java keywords are not allowed, they will not be rejected by this method.- Parameters:
s
- The string for which to make the determination. It must not benull
.r
- A buffer to which the unacceptable reason may be appended. It must not benull
.- Returns:
true
if the provided string is acceptable for use as a Java identifier, orfalse
if not.
-
toJavaIdentifier
public static java.lang.String toJavaIdentifier(java.lang.String s)
Transforms the provided string if necessary so that it may be used as a valid Java identifier. If the provided string is already a valid Java identifier, then it will be returned as-is. Otherwise, it will be transformed to make it more suitable.- Parameters:
s
- The attribute or object class name to be converted to a Java identifier.- Returns:
- A string that may be used as a valid Java identifier.
-
getEntryAsObject
public static <T> T getEntryAsObject(DN dn, java.lang.Class<T> type, LDAPInterface conn) throws LDAPException
Retrieves the entry with the specified DN and decodes it as an object of the specified type.- Type Parameters:
T
- The type of object as which to decode the entry.- Parameters:
dn
- The DN of the entry to retrieve. It must not benull
.type
- The type of object as which the entry should be decoded. It must not benull
, and the class must be marked with theLDAPObject
annotation type.conn
- The connection that should be used to retrieve the entry. It must not benull
.- Returns:
- The object decoded from the specified entry, or
null
if the entry cannot be retrieved (e.g., because it does not exist or is not readable by the authenticated user). - Throws:
LDAPException
- If a problem occurs while trying to retrieve the entry or decode it as the specified type of object.
-
getEntriesAsObjects
public static <T> PersistedObjects<T> getEntriesAsObjects(DN[] dns, java.lang.Class<T> type, LDAPInterface conn) throws LDAPPersistException
Retrieves and decodes the indicated entries as objects of the specified type.- Type Parameters:
T
- The type of object as which to decode the entries.- Parameters:
dns
- The DNs of the entries to retrieve. It must not benull
.type
- The type of object as which the entries should be decoded. It must not benull
, and the class must be marked with theLDAPObject
annotation type.conn
- The connection that should be used to retrieve the entries. It must not benull
.- Returns:
- A
PersistedObjects
result that may be used to access the objects decoded from the provided set of DNs. - Throws:
LDAPPersistException
- If the requested type cannot be used with the LDAP SDK persistence framework.
-
-