Search in sources :

Example 46 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class LDAPPersister method get.

/**
 * Constructs the DN of the associated entry from the provided object and
 * parent DN and retrieves the contents of that entry as a new instance of
 * that object.
 *
 * @param  o         An object instance to use to construct the DN of the
 *                   entry to retrieve.  It must not be {@code null}, and all
 *                   fields and/or getter methods marked for inclusion in the
 *                   entry RDN must have non-{@code null} values.
 * @param  i         The interface to use to communicate with the directory
 *                   server. It must not be {@code null}.
 * @param  parentDN  The parent DN to use for the entry to retrieve.  If the
 *                   provided object was previously read from a directory
 *                   server and includes a field marked with the
 *                   {@link LDAPDNField} or {@link LDAPEntryField} annotation,
 *                   then that field may be used to retrieve the actual DN of
 *                   the associated entry.  If the actual DN of the target
 *                   entry is not available, then a DN will be constructed
 *                   from the RDN fields and/or getter methods declared in the
 *                   class and this parent DN.  If the provided parent DN is
 *                   {@code null}, then the default parent DN defined in the
 *                   {@link LDAPObject} annotation will be used.
 *
 * @return  The object read from the entry with the provided DN, or
 *          {@code null} if no entry exists with the constructed DN.
 *
 * @throws  LDAPPersistException  If a problem occurs while attempting to
 *                                construct the entry DN, retrieve the
 *                                corresponding entry or decode it as an
 *                                object.
 */
@Nullable()
public T get(@NotNull final T o, @NotNull final LDAPInterface i, @Nullable final String parentDN) throws LDAPPersistException {
    final String dn = handler.constructDN(o, parentDN);
    final Entry entry;
    try {
        entry = i.getEntry(dn, handler.getAttributesToRequest());
        if (entry == null) {
            return null;
        }
    } catch (final LDAPException le) {
        Debug.debugException(le);
        throw new LDAPPersistException(le);
    }
    return decode(entry);
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) LDAPException(com.unboundid.ldap.sdk.LDAPException) Nullable(com.unboundid.util.Nullable)

Example 47 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class JNDIConverter method convertModification.

/**
 * Converts the provided JNDI modification item to an LDAP SDK modification.
 *
 * @param  m  The JNDI modification item to be converted.
 *
 * @return  The LDAP SDK modification that corresponds to the provided JNDI
 *          modification item.
 *
 * @throws  NamingException  If a problem is encountered during the conversion
 *                           process.
 */
@Nullable()
public static Modification convertModification(@Nullable final ModificationItem m) throws NamingException {
    if (m == null) {
        return null;
    }
    final ModificationType modType;
    switch(m.getModificationOp()) {
        case DirContext.ADD_ATTRIBUTE:
            modType = ModificationType.ADD;
            break;
        case DirContext.REMOVE_ATTRIBUTE:
            modType = ModificationType.DELETE;
            break;
        case DirContext.REPLACE_ATTRIBUTE:
            modType = ModificationType.REPLACE;
            break;
        default:
            throw new NamingException("Unsupported modification type " + m);
    }
    final Attribute a = convertAttribute(m.getAttribute());
    return new Modification(modType, a.getName(), a.getRawValues());
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) ModificationType(com.unboundid.ldap.sdk.ModificationType) Attribute(com.unboundid.ldap.sdk.Attribute) BasicAttribute(javax.naming.directory.BasicAttribute) NamingException(javax.naming.NamingException) Nullable(com.unboundid.util.Nullable)

Example 48 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class JNDIConverter method convertAttribute.

/**
 * Converts the provided JNDI attribute to an LDAP SDK attribute.
 *
 * @param  a  The attribute to be converted.
 *
 * @return  The LDAP SDK attribute that corresponds to the provided JNDI
 *          attribute.
 *
 * @throws  NamingException  If a problem is encountered during the conversion
 *                           process.
 */
@Nullable()
public static Attribute convertAttribute(@Nullable final javax.naming.directory.Attribute a) throws NamingException {
    if (a == null) {
        return null;
    }
    final String name = a.getID();
    final ASN1OctetString[] values = new ASN1OctetString[a.size()];
    for (int i = 0; i < values.length; i++) {
        final Object value = a.get(i);
        if (value instanceof byte[]) {
            values[i] = new ASN1OctetString((byte[]) value);
        } else {
            values[i] = new ASN1OctetString(String.valueOf(value));
        }
    }
    return new Attribute(name, values);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Attribute(com.unboundid.ldap.sdk.Attribute) BasicAttribute(javax.naming.directory.BasicAttribute) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Nullable(com.unboundid.util.Nullable)

Example 49 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class LDAPSearchResults method nextObject.

/**
 * Retrieves the next object returned from the server, if possible.  When this
 * method returns, then the {@code nextResult} reference will also contain the
 * object that was returned.
 *
 * @return  The next object returned from the server, or {@code null} if there
 *          are no more objects to return.
 */
@Nullable()
private Object nextObject() {
    Object o = nextResult.get();
    if (o != null) {
        return o;
    }
    o = resultQueue.poll();
    if (o != null) {
        nextResult.set(o);
        return o;
    }
    if (searchDone.get() || searchAbandoned.get()) {
        return null;
    }
    try {
        final long stopWaitTime;
        if (maxWaitTime > 0L) {
            stopWaitTime = System.currentTimeMillis() + maxWaitTime;
        } else {
            stopWaitTime = Long.MAX_VALUE;
        }
        while ((!searchAbandoned.get()) && (System.currentTimeMillis() < stopWaitTime)) {
            o = resultQueue.poll(100L, TimeUnit.MILLISECONDS);
            if (o != null) {
                break;
            }
        }
        if (o == null) {
            if (searchAbandoned.get()) {
                o = new SearchResult(-1, ResultCode.USER_CANCELED, null, null, null, 0, 0, null);
                count.incrementAndGet();
            } else {
                o = new SearchResult(-1, ResultCode.TIMEOUT, null, null, null, 0, 0, null);
                count.incrementAndGet();
            }
        }
    } catch (final Exception e) {
        Debug.debugException(e);
        if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
        }
        o = new SearchResult(-1, ResultCode.USER_CANCELED, null, null, null, 0, 0, null);
        count.incrementAndGet();
    }
    nextResult.set(o);
    return o;
}
Also used : SearchResult(com.unboundid.ldap.sdk.SearchResult) NoSuchElementException(java.util.NoSuchElementException) Nullable(com.unboundid.util.Nullable)

Example 50 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class EndTransactionExtendedResult method encodeValue.

/**
 * Encodes the provided information into an appropriate value for this
 * control.
 *
 * @param  failedOpMessageID   The message ID for the operation that failed,
 *                             or {@code null} if there was no failure.
 * @param  opResponseControls  A map containing the response controls for each
 *                             operation, indexed by message ID.  It may be
 *                             {@code null} if there were no response
 *                             controls.
 *
 * @return  An ASN.1 octet string containing the encoded value for this
 *          control, or {@code null} if there should not be a value.
 */
@Nullable()
private static ASN1OctetString encodeValue(@Nullable final Integer failedOpMessageID, @Nullable final Map<Integer, Control[]> opResponseControls) {
    if ((failedOpMessageID == null) && (opResponseControls == null)) {
        return null;
    }
    final ArrayList<ASN1Element> elements = new ArrayList<>(2);
    if (failedOpMessageID != null) {
        elements.add(new ASN1Integer(failedOpMessageID));
    }
    if ((opResponseControls != null) && (!opResponseControls.isEmpty())) {
        final ArrayList<ASN1Element> controlElements = new ArrayList<>(10);
        for (final Map.Entry<Integer, Control[]> e : opResponseControls.entrySet()) {
            final ASN1Element[] ctlElements = { new ASN1Integer(e.getKey()), Control.encodeControls(e.getValue()) };
            controlElements.add(new ASN1Sequence(ctlElements));
        }
        elements.add(new ASN1Sequence(controlElements));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1Integer(com.unboundid.asn1.ASN1Integer) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Integer(com.unboundid.asn1.ASN1Integer) TreeMap(java.util.TreeMap) Map(java.util.Map) Nullable(com.unboundid.util.Nullable)

Aggregations

Nullable (com.unboundid.util.Nullable)149 ArrayList (java.util.ArrayList)47 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)42 Entry (com.unboundid.ldap.sdk.Entry)30 LDAPException (com.unboundid.ldap.sdk.LDAPException)30 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)21 Attribute (com.unboundid.ldap.sdk.Attribute)21 ASN1Element (com.unboundid.asn1.ASN1Element)20 Filter (com.unboundid.ldap.sdk.Filter)20 SearchResult (com.unboundid.ldap.sdk.SearchResult)18 IOException (java.io.IOException)16 ReadOnlyEntry (com.unboundid.ldap.sdk.ReadOnlyEntry)14 File (java.io.File)14 DN (com.unboundid.ldap.sdk.DN)12 ArgumentException (com.unboundid.util.args.ArgumentException)10 RDN (com.unboundid.ldap.sdk.RDN)9 LDIFException (com.unboundid.ldif.LDIFException)8 ChangeLogEntry (com.unboundid.ldap.sdk.ChangeLogEntry)7 Modification (com.unboundid.ldap.sdk.Modification)7 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)7