directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szoer...@apache.org
Subject svn commit: r714033 - in /directory/sandbox/szoerner/envpartition: ./ src/main/java/org/apache/directory/samples/partition/sysprops/ src/main/java/org/apache/directory/samples/partition/sysprops/backend/ src/main/resources/ src/main/resources/org/ src/...
Date Fri, 14 Nov 2008 15:30:13 GMT
Author: szoerner
Date: Fri Nov 14 07:30:11 2008
New Revision: 714033

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

Added:
    directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/BaseReadonlyPartition.java
    directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/Main.java
    directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/
    directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/PropertyNode.java
    directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/PropertyStorage.java
    directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/SystemPropertyGenerator.java
    directory/sandbox/szoerner/envpartition/src/main/resources/org/
    directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/
    directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/directory/
    directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/directory/samples/
    directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/directory/samples/partition/
    directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/directory/samples/partition/sysprops/
    directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/directory/samples/partition/sysprops/backend/
    directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/directory/samples/partition/sysprops/backend/SystemPropertyGenerator.properties
    directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartitionIntegrationTest.java
    directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/backend/
    directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/backend/PropertyStorageTest.java
Modified:
    directory/sandbox/szoerner/envpartition/pom.xml
    directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartition.java
    directory/sandbox/szoerner/envpartition/src/main/resources/log4j.properties
    directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartitionTest.java

Modified: directory/sandbox/szoerner/envpartition/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/pom.xml?rev=714033&r1=714032&r2=714033&view=diff
==============================================================================
--- directory/sandbox/szoerner/envpartition/pom.xml (original)
+++ directory/sandbox/szoerner/envpartition/pom.xml Fri Nov 14 07:30:11 2008
@@ -22,7 +22,7 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.directory.samples</groupId>
-  <artifactId>envPartition</artifactId>
+  <artifactId>syspropPartition</artifactId>
   <packaging>jar</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>A very simly partition implementation</name>

Added: directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/BaseReadonlyPartition.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/BaseReadonlyPartition.java?rev=714033&view=auto
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/BaseReadonlyPartition.java
(added)
+++ directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/BaseReadonlyPartition.java
Fri Nov 14 07:30:11 2008
@@ -0,0 +1,129 @@
+package org.apache.directory.samples.partition.sysprops;
+
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.interceptor.context.BindOperationContext;
+import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
+import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
+import org.apache.directory.server.core.interceptor.context.UnbindOperationContext;
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import static org.apache.directory.shared.ldap.message.ResultCodeEnum.UNWILLING_TO_PERFORM;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class BaseReadonlyPartition implements Partition {
+
+    /** The logger */
+    private static final Logger LOG = LoggerFactory
+            .getLogger(BaseReadonlyPartition.class);
+
+    /** Error message, if someone tries to modify the partition */
+    private static final String MODIFICATION_NOT_ALLOWED_MSG = "Partition does not allow
modification";
+
+    private String id;
+    protected String suffix;
+    protected DirectoryService service;
+    protected LdapDN suffixDn;
+
+    public BaseReadonlyPartition() {
+        super();
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getSuffix() {
+        return suffix;
+    }
+
+    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 {
+        LOG.debug("bind()");
+    }
+
+    public void sync() throws Exception {
+        LOG.debug("sync()");
+    }
+
+    public void unbind(UnbindOperationContext ctx) throws Exception {
+        LOG.debug("unbind()");
+    }
+
+    public void delete(DeleteOperationContext ctx)
+            throws LdapOperationNotSupportedException {
+        throw new LdapOperationNotSupportedException(
+                MODIFICATION_NOT_ALLOWED_MSG, UNWILLING_TO_PERFORM);
+    }
+
+    public void add(AddOperationContext ctx)
+            throws LdapOperationNotSupportedException {
+        throw new LdapOperationNotSupportedException(
+                MODIFICATION_NOT_ALLOWED_MSG, UNWILLING_TO_PERFORM);
+    }
+
+    public void modify(ModifyOperationContext ctx)
+            throws LdapOperationNotSupportedException {
+        throw new LdapOperationNotSupportedException(
+                MODIFICATION_NOT_ALLOWED_MSG, UNWILLING_TO_PERFORM);
+    }
+
+    public void move(MoveOperationContext ctx)
+            throws LdapOperationNotSupportedException {
+        throw new LdapOperationNotSupportedException(
+                MODIFICATION_NOT_ALLOWED_MSG, UNWILLING_TO_PERFORM);
+    }
+
+    public void moveAndRename(MoveAndRenameOperationContext ctx)
+            throws LdapOperationNotSupportedException {
+        throw new LdapOperationNotSupportedException(
+                MODIFICATION_NOT_ALLOWED_MSG, UNWILLING_TO_PERFORM);
+    }
+
+    public void rename(RenameOperationContext ctx)
+            throws LdapOperationNotSupportedException {
+        throw new LdapOperationNotSupportedException(
+                MODIFICATION_NOT_ALLOWED_MSG, UNWILLING_TO_PERFORM);
+    }
+
+    public boolean isInitialized() {
+        LOG.debug("isInitialized()");
+        return true;
+    }
+
+    public void destroy() throws Exception {
+        LOG.debug("destroy()");
+    }
+
+    public LdapDN getSuffixDn() {
+        return suffixDn;
+    }
+
+    @Override
+    public LdapDN getUpSuffixDn() throws Exception {
+
+        LOG.debug("getUpSuffixDn()");
+
+        return new LdapDN(suffix);
+    }
+
+}
\ No newline at end of file

Added: directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/Main.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/Main.java?rev=714033&view=auto
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/Main.java
(added)
+++ directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/Main.java
Fri Nov 14 07:30:11 2008
@@ -0,0 +1,44 @@
+package org.apache.directory.samples.partition.sysprops;
+
+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
+        SystemPropertyPartition envPartition = new SystemPropertyPartition();
+        envPartition.setId("env");
+        envPartition.setSuffix("ou=sysprops");
+        envPartition.init(directoryService);
+        
+        directoryService.addPartition(envPartition);
+        
+        
+        directoryService.startup();
+        ldapService.start();
+    }
+
+}

Modified: directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartition.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartition.java?rev=714033&r1=714032&r2=714033&view=diff
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartition.java
(original)
+++ directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartition.java
Fri Nov 14 07:30:11 2008
@@ -1,107 +1,39 @@
 package org.apache.directory.samples.partition.sysprops;
 
-import javax.naming.OperationNotSupportedException;
+import java.util.ArrayList;
+import java.util.List;
 
+import javax.naming.NamingException;
+
+import org.apache.directory.samples.partition.sysprops.backend.PropertyNode;
+import org.apache.directory.samples.partition.sysprops.backend.PropertyStorage;
+import org.apache.directory.samples.partition.sysprops.backend.SystemPropertyGenerator;
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.cursor.EmptyCursor;
+import org.apache.directory.server.core.cursor.ListCursor;
 import org.apache.directory.server.core.cursor.SingletonCursor;
 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;
-import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
 import org.apache.directory.server.core.interceptor.context.EntryOperationContext;
 import org.apache.directory.server.core.interceptor.context.ListOperationContext;
 import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
-import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
-import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
-import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
-import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
 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.filter.SearchScope;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class SystemPropertyPartition implements Partition {
+public class SystemPropertyPartition extends BaseReadonlyPartition {
 
     /** The logger */
     private static final Logger LOG = LoggerFactory
             .getLogger(SystemPropertyPartition.class);
 
-    private String id;
-
-    private String suffix;
-
-    private DirectoryService service;
-
-    private LdapDN suffixDn;
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getSuffix() {
-        return suffix;
-    }
-
-    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 {
-
-        LOG.debug("bind()");
-
-        // TODO Auto-generated method stub
-    }
-
-    public void delete(DeleteOperationContext ctx)
-            throws OperationNotSupportedException {
-        throw new OperationNotSupportedException();
-    }
-
-    public void add(AddOperationContext ctx)
-            throws OperationNotSupportedException {
-        throw new OperationNotSupportedException();
-    }
-
-    public void modify(ModifyOperationContext ctx)
-            throws OperationNotSupportedException {
-        throw new OperationNotSupportedException();
-    }
-
-    public void move(MoveOperationContext ctx)
-            throws OperationNotSupportedException {
-        throw new OperationNotSupportedException();
-    }
-
-    public void moveAndRename(MoveAndRenameOperationContext ctx)
-            throws OperationNotSupportedException {
-        throw new OperationNotSupportedException();
-    }
-
-    public void rename(RenameOperationContext ctx)
-            throws OperationNotSupportedException {
-        throw new OperationNotSupportedException();
-    }
+    PropertyStorage storage;
 
     public void init(DirectoryService service) throws Exception {
         LOG.debug("init()");
@@ -111,37 +43,34 @@
         suffixDn = new LdapDN(suffix);
         suffixDn.normalize(service.getRegistries().getAttributeTypeRegistry()
                 .getNormalizerMapping());
-    }
-
-    public boolean isInitialized() {
-        LOG.debug("isInitialized()");
-        return true;
-    }
-
-    public void destroy() throws Exception {
-        LOG.debug("destroy()");
-    }
-
-    public LdapDN getSuffixDn() throws Exception {
-        return suffixDn;
-    }
 
-    @Override
-    public LdapDN getUpSuffixDn() throws Exception {
-
-        LOG.debug("getUpSuffixDn()");
-
-        return new LdapDN(suffix);
+        // Create and fill the storage ...
+        storage = new PropertyStorage();
+        SystemPropertyGenerator.fill(storage);
     }
 
     @Override
     public boolean hasEntry(EntryOperationContext ctx) throws Exception {
 
+        boolean result = false;
+
         if (LOG.isDebugEnabled()) {
             LOG.debug("hasEntry(dn=" + ctx.getDn() + ")");
         }
 
-        return this.getSuffixDn().equals(ctx.getDn());
+        if (this.getSuffixDn().equals(ctx.getDn())) {
+            // context entry
+            result = true;
+        } else {
+            String propertyString = this.getPropertyStringForDn(ctx.getDn());
+            LOG.debug("propertyString=" + propertyString);
+
+            PropertyNode node = storage.findByKey(propertyString);
+            if (node != null) {
+                result = true;
+            }
+        }
+        return result;
     }
 
     @Override
@@ -162,24 +91,26 @@
 
         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.OU_AT, "env");
-
+            ServerEntry entry = getContextEntry();
             return new ClonedServerEntry(entry);
+
         } else {
-            return null;
+
+            String propertyString = this.getPropertyStringForDn(ctx.getDn());
+
+            PropertyNode node = storage.findByKey(propertyString);
+
+            if (node != null) {
+                ServerEntry entry = createServerEntryForPropertyNode(node);
+                return new ClonedServerEntry(entry);
+            }
         }
+        return null;
     }
 
     @Override
     public ClonedServerEntry lookup(Long arg0) throws Exception {
-        // TODO Auto-generated method stub
-
         LOG.debug("lookup()");
-
         return null;
     }
 
@@ -192,31 +123,147 @@
                     + ctx.getFilter() + ", scope=" + ctx.getScope() + ")");
         }
 
-        if (this.suffixDn.equals(ctx.getDn()) && !ctx.getFilter().toString().contains("objectClass=subentry")
&& ctx.getScope().equals(SearchScope.OBJECT)) {
+        if (!ctx.getFilter().toString().contains("objectClass=subentry")) {
+
+            if (this.suffixDn.equals(ctx.getDn())) {
+
+                switch (ctx.getScope()) {
+
+                case OBJECT:
+                    ServerEntry entry = this.getContextEntry();
+                    return new BaseEntryFilteringCursor(
+                            new SingletonCursor<ServerEntry>(entry), ctx);
+
+                case ONELEVEL:
+
+                    List<ServerEntry> list = getChildEntriesForNode(storage
+                            .getRoot());
+                    ListCursor<ServerEntry> listCursor = new ListCursor<ServerEntry>(
+                            list);
+                    return new BaseEntryFilteringCursor(listCursor, ctx);
+                }
+
+            } else {
+
+                String propertyString = this
+                        .getPropertyStringForDn(ctx.getDn());
+
+                PropertyNode node = storage.findByKey(propertyString);
+                if (node != null) {
+
+                    switch (ctx.getScope()) {
+
+                    case OBJECT:
+
+                        ServerEntry entry = createServerEntryForPropertyNode(node);
+                        return new BaseEntryFilteringCursor(
+                                new SingletonCursor<ServerEntry>(entry), ctx);
+
+                    case ONELEVEL:
+
+                        List<ServerEntry> list = getChildEntriesForNode(node);
+                        ListCursor<ServerEntry> listCursor = new ListCursor<ServerEntry>(
+                                list);
+                        return new BaseEntryFilteringCursor(listCursor, ctx);
+
+                    }
+                }
+
+            }
+
+        }
+
+        // return an empty result
+        return new BaseEntryFilteringCursor(new EmptyCursor<ServerEntry>(), ctx);
+    }
+
+    private ServerEntry getContextEntry() {
+        ServerEntry entry = new DefaultServerEntry(service.getRegistries(),
+                this.suffixDn);
+        entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
+                SchemaConstants.ORGANIZATIONAL_UNIT_OC);
+
+        Rdn rdn = getSuffixDn().getRdn();
+        entry.put(SchemaConstants.OU_AT, rdn.getUpValue().toString());
+        entry
+                .put("description",
+                        "A very simple partition, which displays the Java system properties");
+        return entry;
+    }
 
-            ServerEntry entry = new DefaultServerEntry(service.getRegistries(),
-                    this.suffixDn);
+    private ServerEntry createServerEntryForPropertyNode(PropertyNode node)
+            throws NamingException {
+
+        LdapDN dn = createLdapDnForPropertyNode(node);
+        ServerEntry entry = new DefaultServerEntry(service.getRegistries(), dn);
+
+        entry.put(SchemaConstants.OU_AT, node.getName());
+
+        if (node.getValue() != null) {
             entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
-                    SchemaConstants.ORGANIZATIONAL_UNIT_OC);
-            entry.put(SchemaConstants.OU_AT, "env");
+                    SchemaConstants.ORGANIZATIONAL_UNIT_OC,
+                    SchemaConstants.EXTENSIBLE_OBJECT_OC);
 
-            return new BaseEntryFilteringCursor(
-                    new SingletonCursor<ServerEntry>(entry), ctx);
+            entry.put(SchemaConstants.CN_AT, node.getKey());
+            entry.put("info", node.getValue());
 
         } else {
-            return new BaseEntryFilteringCursor(new EmptyCursor<ServerEntry>(),
-                    ctx);
+            entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
+                    SchemaConstants.ORGANIZATIONAL_UNIT_OC);
         }
+
+        // Attribute for description, if any
+        if (node.getDescription() != null) {
+            entry.put("description", node.getDescription());
+        }
+
+        return entry;
     }
 
-    @Override
-    public void sync() throws Exception {
-        LOG.debug("sync()");
+    protected String getDnForPropertyNode(PropertyNode node) {
+        String path = node.getKey();
+        String[] parts = path.split("\\.");
+
+        StringBuilder sb = new StringBuilder(suffix);
+        for (String part : parts) {
+            sb.insert(0, "ou=" + part + ",");
+        }
+
+        return sb.toString();
     }
 
-    @Override
-    public void unbind(UnbindOperationContext ctx) throws Exception {
-        LOG.debug("unbind()");
+    protected String getPropertyStringForDn(LdapDN dn) {
+        StringBuilder sb = new StringBuilder();
+        List<Rdn> rdns = dn.getRdns();
+        for (int i = 0; i < rdns.size() - 1; ++i) {
+            if (i > 0) {
+                sb.insert(0, '.');
+            }
+            sb.insert(0, rdns.get(i).getValue());
+        }
+        return sb.toString();
+    }
+
+    protected LdapDN createLdapDnForPropertyNode(PropertyNode node)
+            throws NamingException {
+
+        LdapDN dn = new LdapDN(getDnForPropertyNode(node));
+        dn.normalize(service.getRegistries().getAttributeTypeRegistry()
+                .getNormalizerMapping());
+
+        return dn;
+    }
+
+    protected List<ServerEntry> getChildEntriesForNode(PropertyNode node)
+            throws NamingException {
+        List<ServerEntry> list = new ArrayList<ServerEntry>();
+
+        List<PropertyNode> children = node.getChildren();
+        for (PropertyNode child : children) {
+            list.add(createServerEntryForPropertyNode(child));
+        }
+
+        return list;
     }
 
 }

Added: directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/PropertyNode.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/PropertyNode.java?rev=714033&view=auto
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/PropertyNode.java
(added)
+++ directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/PropertyNode.java
Fri Nov 14 07:30:11 2008
@@ -0,0 +1,91 @@
+package org.apache.directory.samples.partition.sysprops.backend;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PropertyNode {
+
+    public PropertyNode() {
+        this.children = new ArrayList<PropertyNode>();
+    }
+
+    public PropertyNode(String name, String key, String value) {
+        this.name = name;
+        this.key = key;
+        this.value = value;
+        this.children = new ArrayList<PropertyNode>();
+    }
+
+    public PropertyNode(String name, String key) {
+        this(name, key, null);
+    }
+
+    private String key = "";
+    private String value;
+    private String name;
+    private String description;
+
+    List<PropertyNode> children;
+
+    public String getKey() {
+        return key;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public void addChild(PropertyNode node) {
+        this.children.add(node);
+    }
+
+    public List<PropertyNode> getChildren() {
+        return children;
+    }
+
+    public int hashCode() {
+        int result = 31 + ((key == null) ? 0 : key.hashCode());
+        return result;
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+
+        PropertyNode other = (PropertyNode) obj;
+        if (key == null) {
+            if (other.key != null)
+                return false;
+        } else if (!key.equals(other.key))
+            return false;
+        return true;
+    }
+
+    public String toString() {
+        if (value != null) {
+            return key + "=" + value;
+        } else {
+            return key;
+        }
+    }
+}

Added: directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/PropertyStorage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/PropertyStorage.java?rev=714033&view=auto
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/PropertyStorage.java
(added)
+++ directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/PropertyStorage.java
Fri Nov 14 07:30:11 2008
@@ -0,0 +1,81 @@
+package org.apache.directory.samples.partition.sysprops.backend;
+
+import java.util.Iterator;
+
+
+public class PropertyStorage {
+
+    PropertyNode root = new PropertyNode();
+
+    public final void addProperty(String property, String value) {
+        this.addProperty(property, value, null);
+    }
+    
+    public final void addProperty(String property, String value, String description) {
+        PropertyNode node = ensureNodeExists(property);
+        node.setValue(value);
+        if (description != null) {
+            node.setDescription(description);
+        }
+    }
+    
+    /**
+     * Finds a propertyNode fpr a given property, or creates one if necessary
+     * 
+     * @param property a property in dot notation
+     * @return the property node for the given proverty
+     */
+    PropertyNode ensureNodeExists(String property) {
+
+        PropertyNode current = root;
+
+        String[] pathElems = property.split("\\.");
+        String targetName = "";
+
+        for (String name : pathElems) {
+
+            if (!targetName.equals("")) {
+                targetName += ".";
+            }
+            targetName += name;
+
+            PropertyNode next = null;
+            for (PropertyNode child : current.getChildren()) {
+                if (child.getName().equals(name)) {
+                    next = child;
+                }
+            }
+            if (next == null) {
+                next = new PropertyNode(name, targetName);
+                current.addChild(next);
+            }
+            current = next;
+        }
+
+        return current;
+    }
+
+    public PropertyNode getRoot() {
+        return root;
+    }
+
+    public final PropertyNode findByKey(String key) {
+        return findByKey(this.getRoot(), key);
+    }
+
+    PropertyNode findByKey(PropertyNode node, String key) {
+        PropertyNode result = null;
+
+        if (node.getKey().equals(key)) {
+            return node;
+        } else {
+            Iterator<PropertyNode> iter = node.getChildren().iterator();
+            while (iter.hasNext() && result == null) {
+                result = this.findByKey(iter.next(), key);
+            }
+        }
+        return result;
+    }
+
+
+}

Added: directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/SystemPropertyGenerator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/SystemPropertyGenerator.java?rev=714033&view=auto
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/SystemPropertyGenerator.java
(added)
+++ directory/sandbox/szoerner/envpartition/src/main/java/org/apache/directory/samples/partition/sysprops/backend/SystemPropertyGenerator.java
Fri Nov 14 07:30:11 2008
@@ -0,0 +1,42 @@
+package org.apache.directory.samples.partition.sysprops.backend;
+
+import java.util.Properties;
+import java.util.ResourceBundle;
+import java.util.TreeSet;
+
+/**
+ * A tool class to fill zhe System properties into a property storage 
+ */
+public class SystemPropertyGenerator {
+
+    static final ResourceBundle bundle = ResourceBundle
+            .getBundle(SystemPropertyGenerator.class.getName());
+
+    /**
+     * Private constructor, this is a tool class
+     */
+    private SystemPropertyGenerator() {
+    }
+
+    /**
+     * Fill a property storage with all system properties
+     * 
+     * @param storage the target property storage
+     */
+    public static void fill(PropertyStorage storage) {
+        Properties props = System.getProperties();
+
+        TreeSet<Object> keys = new TreeSet<Object>(props.keySet());
+        for (Object object : keys) {
+
+            String key = (String) object;
+            String value = props.getProperty(key);
+            String desc = null;
+            if (bundle.containsKey(key)) {
+                desc = bundle.getString(key);
+            }
+
+            storage.addProperty(key, value, desc);
+        }
+    }
+}

Modified: directory/sandbox/szoerner/envpartition/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/main/resources/log4j.properties?rev=714033&r1=714032&r2=714033&view=diff
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/main/resources/log4j.properties (original)
+++ directory/sandbox/szoerner/envpartition/src/main/resources/log4j.properties Fri Nov 14
07:30:11 2008
@@ -28,5 +28,5 @@
 log4j.appender.R.layout=org.apache.log4j.PatternLayout
 log4j.appender.R.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
 
-log4j.logger.org.apache.directory.samples.partition.env=DEBUG
+log4j.logger.org.apache.directory.samples.partition.sysprops=WARN
 

Added: directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/directory/samples/partition/sysprops/backend/SystemPropertyGenerator.properties
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/directory/samples/partition/sysprops/backend/SystemPropertyGenerator.properties?rev=714033&view=auto
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/directory/samples/partition/sysprops/backend/SystemPropertyGenerator.properties
(added)
+++ directory/sandbox/szoerner/envpartition/src/main/resources/org/apache/directory/samples/partition/sysprops/backend/SystemPropertyGenerator.properties
Fri Nov 14 07:30:11 2008
@@ -0,0 +1,28 @@
+java.version=Java Runtime Environment version
+java.vendor=Java Runtime Environment vendor
+java.vendor.url=Java vendor URL
+java.home=Java installation directory
+java.vm.specification.version=Java Virtual Machine specification version
+java.vm.specification.vendor=Java Virtual Machine specification vendor
+java.vm.specification.name=Java Virtual Machine specification name
+java.vm.version=Java Virtual Machine implementation version
+java.vm.vendor=Java Virtual Machine implementation vendor
+java.vm.name=Java Virtual Machine implementation name
+java.specification.version=Java Runtime Environment specification version
+java.specification.vendor=Java Runtime Environment specification vendor
+java.specification.name=Java Runtime Environment specification name
+java.class.version=Java class format version number
+java.class.path=Java class path
+java.library.path=List of paths to search when loading libraries
+java.io.tmpdir=Default temp file path
+java.compiler=Name of JIT compiler to use
+java.ext.dirs=Path of extension directory or directories
+os.name=Operating system name
+os.arch=Operating system architecture
+os.version=Operating system version
+file.separator=File separator ("/" on UNIX)
+path.separator=Path separator (":" on UNIX)
+line.separator=Line separator ("\n" on UNIX)
+user.name=User's account name
+user.home=User's home directory
+user.dir=User's current working directory
\ No newline at end of file

Added: directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartitionIntegrationTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartitionIntegrationTest.java?rev=714033&view=auto
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartitionIntegrationTest.java
(added)
+++ directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartitionIntegrationTest.java
Fri Nov 14 07:30:11 2008
@@ -0,0 +1,34 @@
+package org.apache.directory.samples.partition.sysprops;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.directory.server.core.DefaultDirectoryService;
+import org.apache.directory.server.core.DirectoryService;
+
+public class SystemPropertyPartitionIntegrationTest extends TestCase {
+
+    public void testAddPartition() throws Exception {
+        DirectoryService directoryService;
+
+        directoryService = new DefaultDirectoryService();
+        directoryService.setShutdownHookEnabled(true);
+
+        // Determine an appropriate working directory
+        File workingDir = new File("work");
+        directoryService.setWorkingDirectory(workingDir);
+
+        // Create a new partition
+        SystemPropertyPartition envPartition = new SystemPropertyPartition();
+        envPartition.setId("env");
+        envPartition.setSuffix("ou=env");
+        envPartition.init(directoryService);
+
+        directoryService.addPartition(envPartition);
+        directoryService.startup();
+        
+        directoryService.shutdown();
+    }
+
+}

Modified: directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartitionTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartitionTest.java?rev=714033&r1=714032&r2=714033&view=diff
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartitionTest.java
(original)
+++ directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/SystemPropertyPartitionTest.java
Fri Nov 14 07:30:11 2008
@@ -1,34 +1,18 @@
 package org.apache.directory.samples.partition.sysprops;
 
-import java.io.File;
 
-import junit.framework.TestCase;
+import org.apache.directory.samples.partition.sysprops.backend.PropertyNode;
 
-import org.apache.directory.server.core.DefaultDirectoryService;
-import org.apache.directory.server.core.DirectoryService;
+import junit.framework.TestCase;
 
 public class SystemPropertyPartitionTest extends TestCase {
 
-    public void testAddPartition() throws Exception {
-        DirectoryService directoryService;
-
-        directoryService = new DefaultDirectoryService();
-        directoryService.setShutdownHookEnabled(true);
-
-        // Determine an appropriate working directory
-        File workingDir = new File("work");
-        directoryService.setWorkingDirectory(workingDir);
-
-        // Create a new partition
-        SystemPropertyPartition envPartition = new SystemPropertyPartition();
-        envPartition.setId("env");
-        envPartition.setSuffix("ou=env");
-        envPartition.init(directoryService);
-
-        directoryService.addPartition(envPartition);
-        directoryService.startup();
+    public void testGetDnForPropertyNode() {
+        SystemPropertyPartition partition = new SystemPropertyPartition();
+        partition.setSuffix("ou=sysprops");
         
-        directoryService.shutdown();
+        PropertyNode node = new PropertyNode("node", "this.is.a.node");
+        System.out.println(partition.getDnForPropertyNode(node));
     }
 
 }

Added: directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/backend/PropertyStorageTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/backend/PropertyStorageTest.java?rev=714033&view=auto
==============================================================================
--- directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/backend/PropertyStorageTest.java
(added)
+++ directory/sandbox/szoerner/envpartition/src/test/java/org/apache/directory/samples/partition/sysprops/backend/PropertyStorageTest.java
Fri Nov 14 07:30:11 2008
@@ -0,0 +1,67 @@
+package org.apache.directory.samples.partition.sysprops.backend;
+
+import org.apache.directory.samples.partition.sysprops.backend.PropertyNode;
+import org.apache.directory.samples.partition.sysprops.backend.PropertyStorage;
+
+import junit.framework.TestCase;
+
+public class PropertyStorageTest extends TestCase {
+    
+    public void testSimpleAddition() {
+        
+        PropertyStorage s = new PropertyStorage();
+        s.addProperty("a", "1");        
+        s.addProperty("b", "2");
+        
+        assertEquals(2, s.getRoot().getChildren().size());
+        
+        PropertyNode a = s.findByKey("a");
+        assertNotNull(a);
+        assertEquals("1", a.getValue());
+        
+        PropertyNode b = s.findByKey("b");
+        assertNotNull(b);
+        assertEquals("2", b.getValue());
+    }
+    
+    public void testAdvancedAddition() {
+        
+        PropertyStorage s = new PropertyStorage();
+        s.addProperty("a.a", "11");
+        s.addProperty("a.b", "12");        
+              
+        assertEquals(1, s.getRoot().getChildren().size());
+        assertEquals("a", s.getRoot().getChildren().get(0).getName());
+        
+        PropertyNode a = s.getRoot().getChildren().get(0);
+        System.out.println(a.getChildren());
+        assertEquals(2, a.getChildren().size());
+    }
+    
+    public void testAdditionReverseOrder() {
+        
+        PropertyStorage s = new PropertyStorage();
+        s.addProperty("a.b.c", "123");
+        s.addProperty("a.b", "12");        
+        s.addProperty("a", "1");
+        
+        assertEquals(1, s.getRoot().getChildren().size());        
+        PropertyNode a = s.getRoot().getChildren().get(0);
+        assertEquals(1, a.getChildren().size());
+    }
+    
+    public void testFindByKey() {
+        PropertyStorage s = new PropertyStorage();
+        s.addProperty("a.a", "11");
+        s.addProperty("a.b", "12"); 
+
+        assertNotNull(s.findByKey("a"));
+        assertNotNull(s.findByKey("a.a"));
+        assertNotNull(s.findByKey("a.b"));
+        
+        assertNull(s.findByKey("b"));
+        assertNull(s.findByKey("a.c"));
+        
+    }
+
+}



Mime
View raw message