/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2009 Sun Microsystems, Inc.
*/
/**
* This class defines the structures and methods for an LDAP search result entry
* protocol op, which is used to return entries that match the associated search
* criteria.
*/
public class SearchResultEntryProtocolOp
extends ProtocolOp
{
// The set of attributes for this search entry.
// The DN for this search entry.
// The underlying search result entry.
// The LDAP version (determines how attribute options are handled).
private final int ldapVersion;
/**
* Creates a new LDAP search result entry protocol op with the specified DN
* and no attributes.
*
* @param dn The DN for this search result entry.
*/
{
}
/**
* Creates a new LDAP search result entry protocol op with the specified DN
* and set of attributes.
*
* @param dn The DN for this search result entry.
* @param attributes The set of attributes for this search result entry.
*/
{
}
/**
* Creates a new search result entry protocol op from the provided search
* result entry.
*
* @param searchEntry The search result entry object to use to create this
* search result entry protocol op.
*/
{
}
/**
* Creates a new search result entry protocol op from the provided search
* result entry and ldap protocol version.
*
* @param searchEntry The search result entry object to use to create this
* search result entry protocol op.
* @param ldapVersion The version of the LDAP protocol.
*/
int ldapVersion)
{
}
// Generic constructor.
int ldapVersion)
{
this.attributes = attributes;
this.entry = searchEntry;
this.ldapVersion = ldapVersion;
}
/**
* Retrieves the DN for this search result entry.
*
* @return The DN for this search result entry.
*/
{
return dn;
}
/**
* Retrieves the set of attributes for this search result entry. The returned
* list may be altered by the caller.
*
* @return The set of attributes for this search result entry.
*/
{
{
{
if (ldapVersion == 2)
{
// Merge attributes having the same type into a single
// attribute.
boolean needsMerge;
.entrySet())
{
needsMerge = true;
{
if (!a.hasOptions())
{
needsMerge = false;
}
}
if (needsMerge)
{
{
}
}
}
.entrySet())
{
needsMerge = true;
{
if (!a.hasOptions())
{
needsMerge = false;
}
}
if (needsMerge)
{
{
}
}
}
}
else
{
// LDAPv3
.values())
{
{
}
}
{
{
}
}
}
}
attributes = tmp;
// Since the attributes are mutable, null out the entry for consistency.
}
return attributes;
}
/**
* Retrieves the BER type for this protocol op.
*
* @return The BER type for this protocol op.
*/
public byte getType()
{
return OP_TYPE_SEARCH_RESULT_ENTRY;
}
/**
* Retrieves the name for this protocol op type.
*
* @return The name for this protocol op type.
*/
{
return "Search Result Entry";
}
/**
* Writes this protocol op to an ASN.1 output stream.
*
* @param stream The ASN.1 output stream to write to.
* @throws IOException If a problem occurs while writing to the stream.
*/
{
{
.values())
{
{
writeAttribute(stream, a);
}
}
.values())
{
{
writeAttribute(stream, a);
}
}
}
else
{
{
}
}
}
/**
* Appends a string representation of this LDAP protocol op to the provided
* buffer.
*
* @param buffer The buffer to which the string should be appended.
*/
{
{
{
}
}
}
/**
* Appends a multi-line string representation of this LDAP protocol op to the
* provided buffer.
*
* @param buffer The buffer to which the information should be appended.
* @param indent The number of spaces from the margin that the lines should
* be indented.
*/
{
for (int i=0 ; i < indent; i++)
{
}
{
}
}
/**
* Appends an LDIF representation of the entry to the provided buffer.
*
* @param buffer The buffer to which the entry should be appended.
* @param wrapColumn The column at which long lines should be wrapped.
*/
{
// Add the DN to the buffer.
int colsRemaining;
if (needsBase64Encoding(dnString))
{
}
else
{
}
{
}
else
{
int startPos = colsRemaining;
{
}
{
}
}
// Add the attributes to the buffer.
for (LDAPAttribute a : getAttributes())
{
for (ByteString v : a.getValues())
{
if (needsBase64Encoding(v))
{
}
else
{
valueString = v.toString();
}
{
}
else
{
int startPos = colsRemaining;
{
}
if (startPos < valueLength)
{
}
}
}
}
// Make sure to add an extra blank line to ensure that there will be one
// between this entry and the next.
}
/**
* Converts this protocol op to a search result entry.
*
* @return The search result entry created from this protocol op.
*
* @throws LDAPException If a problem occurs while trying to create the
* search result entry.
*/
throws LDAPException
{
{
return entry;
}
for (LDAPAttribute a : getAttributes())
{
if (attrType.isObjectClassType())
{
{
{
}
}
}
else if (attrType.isOperational())
{
{
}
else
{
}
}
else
{
{
}
else
{
// Check to see if any of the existing attributes in the list have the
// same set of options. If so, then add the values to that attribute.
boolean attributeSeen = false;
{
attributeSeen = true;
}
}
if (!attributeSeen)
{
// This is the first occurrence of the attribute and options.
}
}
}
}
return new SearchResultEntry(entry);
}
// Write an attribute without converting to an LDAPAttribute.
throws IOException
{
for (AttributeValue value : a)
{
}
}
}