| File was renamed from opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/com/forgerock/opendj/ldap/LDAPReader.java |
| | |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | |
| | | package com.forgerock.opendj.ldap; |
| | | package com.forgerock.opendj.grizzly; |
| | | |
| | | import static com.forgerock.opendj.ldap.LDAPConstants.*; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_LDAP_MODIFICATION_DECODE_INVALID_MOD_TYPE; |
| | |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.asn1.ASN1; |
| | | import org.forgerock.opendj.asn1.ASN1Reader; |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | |
| | | import com.forgerock.opendj.ldap.LDAPUtils; |
| | | |
| | | /** |
| | | * Static methods for decoding LDAP messages. |
| | | */ |
| | | final class LDAPReader { |
| | | static SearchResultEntry decodeEntry(final ASN1Reader reader, final DecodeOptions options) |
| | | throws IOException { |
| | | Entry entry; |
| | | |
| | | reader.readStartSequence(OP_TYPE_SEARCH_RESULT_ENTRY); |
| | | try { |
| | | final String dnString = reader.readOctetStringAsString(); |
| | | final Schema schema = options.getSchemaResolver().resolveSchema(dnString); |
| | | DN dn; |
| | | try { |
| | | dn = DN.valueOf(dnString, schema); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | throw DecodeException.error(e.getMessageObject()); |
| | | } |
| | | |
| | | entry = options.getEntryFactory().newEntry(dn); |
| | | reader.readStartSequence(); |
| | | try { |
| | | while (reader.hasNextElement()) { |
| | | reader.readStartSequence(); |
| | | try { |
| | | final String ads = reader.readOctetStringAsString(); |
| | | AttributeDescription ad; |
| | | try { |
| | | ad = AttributeDescription.valueOf(ads, schema); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | throw DecodeException.error(e.getMessageObject()); |
| | | } |
| | | |
| | | final Attribute attribute = options.getAttributeFactory().newAttribute(ad); |
| | | |
| | | reader.readStartSet(); |
| | | try { |
| | | while (reader.hasNextElement()) { |
| | | attribute.add(reader.readOctetString()); |
| | | } |
| | | entry.addAttribute(attribute); |
| | | } finally { |
| | | reader.readEndSet(); |
| | | } |
| | | } finally { |
| | | reader.readEndSequence(); |
| | | } |
| | | } |
| | | } finally { |
| | | reader.readEndSequence(); |
| | | } |
| | | } finally { |
| | | reader.readEndSequence(); |
| | | } |
| | | |
| | | return Responses.newSearchResultEntry(entry); |
| | | } |
| | | |
| | | private final DecodeOptions options; |
| | | |