try
{
// Get the base DN, scope, and filter for the search.
DN baseDN = searchOperation.getBaseDN();
SearchScope scope = searchOperation.getScope();
SearchFilter filter = searchOperation.getFilter();
// Make sure the base entry exists if it's supposed to be in this backend.
Entry baseEntry = entryMap.get(baseDN);
if ((baseEntry == null) && handlesEntry(baseDN))
{
DN matchedDN = baseDN.getParentDNInSuffix();
while (matchedDN != null)
{
if (entryMap.containsKey(matchedDN))
{
break;
}
matchedDN = matchedDN.getParentDNInSuffix();
}
Message m = ERR_LDIF_BACKEND_SEARCH_NO_SUCH_BASE.get(
String.valueOf(baseDN));
throw new DirectoryException(
ResultCode.NO_SUCH_OBJECT, m, matchedDN, null);
}
if (baseEntry != null)
{
baseEntry = baseEntry.duplicate(true);
}
// If it's a base-level search, then just get that entry and return it if
// it matches the filter.
if (scope == SearchScope.BASE_OBJECT)
{
if (filter.matchesEntry(baseEntry))
{
searchOperation.returnEntry(baseEntry, new LinkedList<Control>());
}
}
else
{
// Walk through all entries and send the ones that match.
for (Entry e : entryMap.values())
{
e = e.duplicate(true);
if (e.matchesBaseAndScope(baseDN, scope) && filter.matchesEntry(e))
{
searchOperation.returnEntry(e, new LinkedList<Control>());
}
}
}