directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szoer...@apache.org
Subject svn commit: r711386 - in /directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env: EnvironmentPartition.java Main.java
Date Tue, 04 Nov 2008 20:39:18 GMT
Author: szoerner
Date: Tue Nov  4 12:39:17 2008
New Revision: 711386

URL: http://svn.apache.org/viewvc?rev=711386&view=rev
Log:
First working version

Added:
    directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env/Main.java
Modified:
    directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env/EnvironmentPartition.java

Modified: directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env/EnvironmentPartition.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env/EnvironmentPartition.java?rev=711386&r1=711385&r2=711386&view=diff
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env/EnvironmentPartition.java
(original)
+++ directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env/EnvironmentPartition.java
Tue Nov  4 12:39:17 2008
@@ -3,7 +3,11 @@
 import javax.naming.OperationNotSupportedException;
 
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.cursor.EmptyCursor;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.filtering.BaseEntryFilteringCursor;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.interceptor.context.BindOperationContext;
@@ -18,6 +22,7 @@
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.interceptor.context.UnbindOperationContext;
 import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,6 +37,10 @@
 
     private String suffix;
 
+    private DirectoryService service;
+
+    private LdapDN suffixDn;
+
     public String getId() {
         return id;
     }
@@ -47,6 +56,13 @@
     public void setSuffix(String suffix) {
         this.suffix = suffix;
     }
+    
+    public int getCacheSize() {
+        return 0;
+    }
+
+    public void setCacheSize(int cacheSize) {
+    }
 
     public void bind(BindOperationContext ctx) throws Exception {
 
@@ -87,6 +103,12 @@
 
     public void init(DirectoryService service) throws Exception {
         LOG.debug("init()");
+
+        this.service = service;
+
+        suffixDn = new LdapDN(suffix);
+        suffixDn.normalize(service.getRegistries().getAttributeTypeRegistry()
+                .getNormalizerMapping());
     }
 
     public boolean isInitialized() {
@@ -98,15 +120,9 @@
         LOG.debug("destroy()");
     }
 
-    public int getCacheSize() {
-        return 0;
-    }
 
     public LdapDN getSuffixDn() throws Exception {
-
-        LOG.debug("getSuffixDn()");
-
-        return new LdapDN(suffix); // TODO: Check, whether OK ...
+        return suffixDn;
     }
 
     @Override
@@ -114,15 +130,17 @@
 
         LOG.debug("getUpSuffixDn()");
 
-        return getSuffixDn();
+        return new LdapDN(suffix);
     }
 
     @Override
     public boolean hasEntry(EntryOperationContext ctx) throws Exception {
 
-        LOG.debug("hasEntry()");
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("hasEntry(dn=" + ctx.getDn() + ")");
+        }
 
-        return false;
+        return this.getSuffixDn().equals(ctx.getDn());
     }
 
     @Override
@@ -137,9 +155,22 @@
     public ClonedServerEntry lookup(LookupOperationContext ctx)
             throws Exception {
 
-        LOG.debug("lookup()");
-
-        return null;
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("lookup(dn=" + ctx.getDn() + ")");
+        }
+
+        if (this.suffixDn.equals(ctx.getDn())) {
+
+            ServerEntry entry = new DefaultServerEntry(service.getRegistries(),
+                    this.suffixDn);
+            entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
+                    SchemaConstants.ORGANIZATIONAL_UNIT_OC);
+            entry.put(SchemaConstants.ORGANIZATIONAL_UNIT_NAME_AT, "env");
+
+            return new ClonedServerEntry(entry);
+        } else {
+            return null;
+        }
     }
 
     @Override
@@ -154,22 +185,23 @@
     @Override
     public EntryFilteringCursor search(SearchOperationContext ctx)
             throws Exception {
-        LOG.debug("search()");
 
-        return null;
-    }
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("search((dn=" + ctx.getDn() + ", filter="
+                    + ctx.getFilter() + ", scope=" + ctx.getScope() + ")");
+        }
 
-    @Override
-    public void setCacheSize(int cacheSize) {
+        return new BaseEntryFilteringCursor(new EmptyCursor<ServerEntry>(), ctx);
     }
 
+
     @Override
     public void sync() throws Exception {
         LOG.debug("sync()");
     }
 
     @Override
-    public void unbind(UnbindOperationContext arg0) throws Exception {
+    public void unbind(UnbindOperationContext ctx) throws Exception {
         LOG.debug("unbind()");
     }
 

Added: directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env/Main.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env/Main.java?rev=711386&view=auto
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env/Main.java
(added)
+++ directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/env/Main.java
Tue Nov  4 12:39:17 2008
@@ -0,0 +1,43 @@
+package org.apache.directory.samples.partition.env;
+
+import java.io.File;
+
+import org.apache.directory.server.core.DefaultDirectoryService;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.ldap.LdapService;
+import org.apache.directory.server.protocol.shared.SocketAcceptor;
+
+public class Main {
+
+    public static void main(String[] args) throws Exception {
+        DirectoryService directoryService;
+
+        SocketAcceptor socketAcceptor;
+        LdapService ldapService;
+
+        directoryService = new DefaultDirectoryService();
+        directoryService.setShutdownHookEnabled(true);
+
+        socketAcceptor = new SocketAcceptor(null);
+        ldapService = new LdapService();
+        ldapService.setSocketAcceptor(socketAcceptor);
+        ldapService.setDirectoryService(directoryService);
+        ldapService.setIpPort(10389);
+
+        // Determine an appropriate working directory
+        File workingDir = new File("work");
+        directoryService.setWorkingDirectory(workingDir);
+                
+        // Create a new partition
+        EnvironmentPartition envPartition = new EnvironmentPartition();
+        envPartition.setId("env");
+        envPartition.setSuffix("ou=env");
+        envPartition.init(directoryService);
+        
+        directoryService.addPartition(envPartition);
+        
+        directoryService.startup();
+        ldapService.start();
+    }
+
+}



Mime
View raw message