directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Danilo Luiz Rheinheimer <dan...@floripa.com.br>
Subject Re: I think I've misunderstood Partitions...
Date Wed, 27 Apr 2005 02:41:04 GMT
Chris Betts wrote:

> Aha!
>
> So I extend ContextPartition and implement 'getSuffix()' to return, 
> say, 'chris', and then set 'server.db.partitions=chris' and 
> 'server.db.partitions.suffix.chris=o=chris', and I'm away?
>
Chris, I am not a Apache Directory guru. I am starting to learn about it 
like you.
So this is my first try :

package org.sigea.demo.ldap;

import java.util.Map;

import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;

import org.apache.ldap.common.filter.ExprNode;
import org.apache.ldap.common.message.LockableAttributesImpl;
import org.apache.ldap.common.util.SingletonEnumeration;
import org.apache.ldap.server.ContextPartition;
import org.apache.ldap.server.db.IndexRecord;
import org.apache.ldap.server.db.SearchResultEnumeration;

/**
 * @author danilo
 *
 */
public class MyPartition implements ContextPartition {
   
    private boolean isOpen;
    private Name suffix;
   
    public MyPartition(Name upSuffix, Name normalizedSuffix, String 
properties) throws Exception {
        suffix = (Name) normalizedSuffix.clone();
        isOpen = true;
    }

    public boolean isClosed() {
        return !isOpen;
    }

    public void close() throws NamingException {
        isOpen = false;
    }

    public NamingEnumeration search(Name ldapName, Map serverProperties, 
ExprNode presenceNodes, SearchControls searchControls) throws 
NamingException {
        System.out.println("search executed 
["+ldapName+","+serverProperties+""+presenceNodes+","+searchControls+"]");
        IndexRecord record = new IndexRecord();
        Attributes entry = new LockableAttributesImpl();    // this is 
not working right
        entry.put("objectClass","top");
        entry.put("objectClass","domain");
        entry.put("objectClass","extensibleObject");
        entry.put("dc","sigea");
        record.setAttributes(entry);
        SingletonEnumeration ne = new SingletonEnumeration(record);
        SearchResultEnumeration n = new SearchResultEnumeration(new 
String[] {}, ne, null);
        return n;
    }

    public Name getSuffix(boolean arg0) {
        return (Name) suffix.clone();
    }

  .. // all other methods still without implementation
}

  So if you set 'server.db.partitions.suffix.chris=o=chris' the value 
'o=chris' will be the normalizedSuffix parameter of

public MyPartition(Name upSuffix, Name normalizedSuffix, String 
properties) throws Exception

  You will save it to be returned on getSuffix().
  Well this is the way I understand it.
  I am doing a small test project to try this ideas. It is starting to 
work. I can browse some stuff using LdapBrowse.

  Danilo.




Mime
View raw message