com.unboundid.directory.sdk.sync.util
Class ScriptUtils

java.lang.Object
  extended by com.unboundid.directory.sdk.sync.util.ScriptUtils

@ThreadSafety(level=COMPLETELY_THREADSAFE)
public final class ScriptUtils
extends java.lang.Object

This class contains various utility methods for working with the UnboundID LDAP SDK and JDBC objects within script implementations. These are useful for populating LDAP entries with content from JDBC result sets and also for working with DNs, Timestamps, and other objects.


Method Summary
static void addBinaryAttribute(com.unboundid.ldap.sdk.Entry entry, java.lang.String attrName, java.sql.Blob value, int maxBytes)
          Adds an Attribute with the given attribute name and Blob value to the given entry if the underlying byte array is not null or empty.
static void addBooleanAttribute(com.unboundid.ldap.sdk.Entry entry, java.lang.String attrName, java.lang.Boolean value)
          Adds an Attribute with the given attribute name and boolean value to the given entry if the value is not null.
static void addDateAttribute(com.unboundid.ldap.sdk.Entry entry, java.lang.String attrName, java.util.Date date, boolean includeMilliseconds)
          Adds an Attribute with the given attribute name and Date value to the given entry if the value is not null.
static void addNumericAttribute(com.unboundid.ldap.sdk.Entry entry, java.lang.String attrName, java.lang.Number value)
          Adds an Attribute with the given attribute name and numeric value to the given entry if the value is not null.
static void addStringAttribute(com.unboundid.ldap.sdk.Entry entry, java.lang.String attrName, java.lang.String value)
          Adds an Attribute with the given attribute name and string value to the given entry if the value is not null.
static boolean containsAnyValue(com.unboundid.ldap.sdk.Attribute attr, java.lang.String... values)
          Returns true if the given attribute is not null and contains any one or more of the given string values; returns false otherwise.
static java.util.Map<java.lang.String,java.lang.String> dnToMap(com.unboundid.ldap.sdk.DN identifiableInfo)
          Takes an identifier DN (such as the output from idStringToDN(String,String) and creates a hash map of the components (RDN attributes) to their respective values.
static java.sql.Timestamp getTimestampFromString(java.lang.String value)
          Returns a SQL Timestamp based on the string value that is passed in.
static com.unboundid.ldap.sdk.DN idStringToDN(java.lang.String identifiableInfo, java.lang.String delimiter)
          Takes an identifier string (for example from the database changelog table) and creates a DN from the components.
static boolean isNullOrEmpty(java.lang.String value)
          String helper method to check if a value is a null object or empty string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addStringAttribute

public static void addStringAttribute(com.unboundid.ldap.sdk.Entry entry,
                                      java.lang.String attrName,
                                      java.lang.String value)
Adds an Attribute with the given attribute name and string value to the given entry if the value is not null.

Parameters:
entry - an LDAP entry instance. May be null.
attrName - the name of the attribute to add to the entry. May not be null.
value - the value for the attribute to add to the entry. May be null.

addNumericAttribute

public static void addNumericAttribute(com.unboundid.ldap.sdk.Entry entry,
                                       java.lang.String attrName,
                                       java.lang.Number value)
Adds an Attribute with the given attribute name and numeric value to the given entry if the value is not null.

Parameters:
entry - an LDAP entry instance. May be null.
attrName - the name of the attribute to add to the entry. May not be null.
value - the value for the attribute to add to the entry. May be null.

addBooleanAttribute

public static void addBooleanAttribute(com.unboundid.ldap.sdk.Entry entry,
                                       java.lang.String attrName,
                                       java.lang.Boolean value)
Adds an Attribute with the given attribute name and boolean value to the given entry if the value is not null. If the boolean is true, the attribute value will be the string "true", otherwise it will be the string "false".

Parameters:
entry - an LDAP entry instance. May be null.
attrName - the name of the attribute to add to the entry. May not be null.
value - the value for the attribute to add to the entry. May be null.

addDateAttribute

public static void addDateAttribute(com.unboundid.ldap.sdk.Entry entry,
                                    java.lang.String attrName,
                                    java.util.Date date,
                                    boolean includeMilliseconds)
Adds an Attribute with the given attribute name and Date value to the given entry if the value is not null. The date is formatted using the generalized time syntax with a four-digit year and an optional milliseconds component (i.e. yyyyMMddHHmmss[.SSS]'Z').

Parameters:
entry - entry an LDAP entry instance. May be null.
attrName - the name of the attribute to add to the entry. May not be null.
date - the Date value for the attribute to add to the entry. May be null.
includeMilliseconds - whether to include the milliseconds component in the attribute value

addBinaryAttribute

public static void addBinaryAttribute(com.unboundid.ldap.sdk.Entry entry,
                                      java.lang.String attrName,
                                      java.sql.Blob value,
                                      int maxBytes)
Adds an Attribute with the given attribute name and Blob value to the given entry if the underlying byte array is not null or empty. This method calls free() on the Blob object after the attribute has been added to the entry.

Parameters:
entry - an LDAP entry instance. May be null.
attrName - the name of the attribute to add to the entry. May not be null.
value - the value for the attribute to add to the entry. May be null.
maxBytes - the maximum number of bytes to extract from the Blob and add to the entry.

containsAnyValue

public static boolean containsAnyValue(com.unboundid.ldap.sdk.Attribute attr,
                                       java.lang.String... values)
Returns true if the given attribute is not null and contains any one or more of the given string values; returns false otherwise. This method is case-insensitive.

Parameters:
attr - the Attribute whose values to check
values - the value(s) you are looking for
Returns:
true if any of the values were found in the attribute, false if not

isNullOrEmpty

public static boolean isNullOrEmpty(java.lang.String value)
String helper method to check if a value is a null object or empty string.

Parameters:
value - the String object to check
Returns:
true if the value is null or empty string, false otherwise

getTimestampFromString

public static java.sql.Timestamp getTimestampFromString(java.lang.String value)
Returns a SQL Timestamp based on the string value that is passed in. The string is parsed using generalized time syntax first with and then without milliseconds (i.e. yyyyMMddHHmmss[.SSS]'Z'). If the string cannot be parsed, null is returned.

Parameters:
value - a string that represents a timestamp in generalized time format
Returns:
a SQL Timestamp value set to the time that was passed in, or null if the value cannot be parsed

idStringToDN

public static com.unboundid.ldap.sdk.DN idStringToDN(java.lang.String identifiableInfo,
                                                     java.lang.String delimiter)
Takes an identifier string (for example from the database changelog table) and creates a DN from the components. If there are multiple primary keys in the identifier, they must be delimited by a unique string with which the identifier can be split. For example, you could specify a delimiter of "%%" to handle the following identifier: account_id=123%%group_id=5.

The resulting DN will contain a RDN per component, and the relative order of RDNs will be consistent with the order of the components in the original identifier string. The components here are usually primary keys for the entry in the database.

Parameters:
identifiableInfo - the identifier string for a given database entry. This cannot be null.
delimiter - The delimiter used to split separate components of the identifiable info. If this is null, the default of "%%" will be used.
Returns:
a DN representing the given identifier.

dnToMap

public static java.util.Map<java.lang.String,java.lang.String> dnToMap(com.unboundid.ldap.sdk.DN identifiableInfo)
Takes an identifier DN (such as the output from idStringToDN(String,String) and creates a hash map of the components (RDN attributes) to their respective values. Each RDN will have a separate entry in the resulting map.

This method is meant to handle database entry identifier DNs, and as such does not handle DNs with multi-valued RDNs (i.e. pk1=John+pk2=Doe,groupID=123).

Parameters:
identifiableInfo - the identifier DN for a particular database entry. This cannot be null.
Returns:
a map of each RDN name to its value (from the given DN)