* Searchs for the children.
* @throws SearchAbandonException if an error occurs.
*/
private void runSearchChildren() throws SearchAbandonException {
InitialLdapContext ctx = null;
BasicNode parentNode = getNode();
parentNode.setSizeLimitReached(false);
try {
// Send an LDAP search
SearchControls ctls = controller.getBasicSearchControls();
if (useCustomFilter())
{
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
}
else
{
ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
}
ctls.setReturningAttributes(controller.getAttrsForRedSearch());
ctx = controller.findConnectionForDisplayedEntry(parentNode);
String parentDn = controller.findBaseDNForChildEntries(parentNode);
int parentComponents;
try
{
DN dn = DN.decode(parentDn);
parentComponents = dn.getNumComponents();
}
catch (Throwable t)
{
throw new RuntimeException("Error decoding dn: "+parentDn+" . "+t,
t);
}
NamingEnumeration<SearchResult> entries = ctx.search(
new LdapName(parentDn),
controller.getChildSearchFilter(),
ctls);
try
{
while (entries.hasMore())
{
SearchResult r = entries.next();
String name;
if (r.getName().length() == 0)
{
continue;
}
else
{
name = unquoteRelativeName(r.getName())+","+parentDn;
}
boolean add = false;
if (useCustomFilter())
{
// Check that is an immediate child: use a faster method by just
// comparing the number of components.
DN dn = null;
try
{
dn = DN.decode(name);
add = dn.getNumComponents() == parentComponents + 1;
}
catch (Throwable t)
{
throw new RuntimeException("Error decoding dns: "+t, t);
}
if (!add)
{
// Is not a direct child. Check if the parent has been added,
// if it is the case, do not add the parent. If is not the case,
// search for the parent and add it.
RDN[] rdns = new RDN[parentComponents + 1];
int diff = dn.getNumComponents() - rdns.length;
for (int i=0; i < rdns.length; i++)
{
rdns[i] = dn.getRDN(i + diff);
}
final DN parentToAddDN = new DN(rdns);
boolean mustAddParent = true;
for (SearchResult addedEntry : childEntries)
{
try
{
DN addedDN = DN.decode(addedEntry.getName());
if (addedDN.equals(parentToAddDN))
{
mustAddParent = false;
break;
}
}
catch (Throwable t)
{
throw new RuntimeException("Error decoding dn: "+
addedEntry.getName()+" . "+t, t);
}
}
if (mustAddParent)
{
final boolean resultValue[] = {true};
// Check the children added to the tree
try
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
for (int i=0; i<getNode().getChildCount(); i++)
{
BasicNode node = (BasicNode)getNode().getChildAt(i);
try
{
DN dn = DN.decode(node.getDN());
if (dn.equals(parentToAddDN))
{
resultValue[0] = false;
break;
}
}
catch (Throwable t)
{
throw new RuntimeException("Error decoding dn: "+
node.getDN()+" . "+t, t);
}
}
}
});
}