From 43f11eee07cca55cfe7c38362431371fb265a6e0 Mon Sep 17 00:00:00 2001
From: dugan <dugan@localhost>
Date: Fri, 06 Jul 2007 12:38:14 +0000
Subject: [PATCH] Issue 874 ldifsearch always returns objectclass attribute.

---
 opends/src/server/org/opends/server/tools/LDIFSearch.java |   41 +++++++++++++++++++++++++++++++----------
 1 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/LDIFSearch.java b/opends/src/server/org/opends/server/tools/LDIFSearch.java
index 1d9130d..5d5aa0a 100644
--- a/opends/src/server/org/opends/server/tools/LDIFSearch.java
+++ b/opends/src/server/org/opends/server/tools/LDIFSearch.java
@@ -116,7 +116,7 @@
    */
   public static void main(String[] args)
   {
-    int exitCode = mainSearch(args);
+    int exitCode = mainSearch(args, true);
     if (exitCode != 0)
     {
       System.exit(filterExitCode(exitCode));
@@ -131,11 +131,13 @@
    *
    * @param  args  The command line arguments provided to this program.
    *
+   * @param initializeServer True if server initialization should be done.
+   * 
    * @return  The return code for this operation.  A value of zero indicates
    *          that all processing completed successfully.  A nonzero value
    *          indicates that some problem occurred during processing.
    */
-  public static int mainSearch(String[] args)
+  public static int mainSearch(String[] args, boolean initializeServer)
   {
     LinkedHashSet<String> scopeStrings = new LinkedHashSet<String>(4);
     scopeStrings.add(SCOPE_STRING_BASE);
@@ -272,7 +274,10 @@
     // way.
     boolean            allUserAttrs        = false;
     boolean            allOperationalAttrs = false;
-    LinkedList<String> attributeNames      = new LinkedList<String>();
+    //Return objectclass attribute unless analysis of the arguments determines
+    //otherwise.
+    boolean            includeObjectclassAttrs = true;
+    LinkedList<String> attributeNames;
     LinkedList<String> objectClassNames    = new LinkedList<String>();
     LinkedList<String> filterStrings;
     if (filterFile.isPresent())
@@ -359,20 +364,35 @@
       allUserAttrs = true;
     }
 
+    //Determine if objectclass attribute should be returned.
+    if(!allUserAttrs) {
+      //Single '+', never return objectclass.
+      if(allOperationalAttrs && objectClassNames.isEmpty() &&
+         attributeNames.isEmpty())
+        includeObjectclassAttrs=false;
+      //If "objectclass" isn't specified in the attributes to return, then
+      //don't include objectclass attribiute.
+      if(!attributeNames.isEmpty() && objectClassNames.isEmpty() &&
+         !attributeNames.contains("objectclass"))
+         includeObjectclassAttrs=false;
+    }
+
 
     // Bootstrap the Directory Server configuration for use as a client.
     DirectoryServer directoryServer = DirectoryServer.getInstance();
-    directoryServer.bootstrapClient();
-
 
     // If we're to use the configuration then initialize it, along with the
     // schema.
     boolean checkSchema = configFile.isPresent();
+
+    if(initializeServer) {
+     DirectoryServer.bootstrapClient();
+
     if (checkSchema)
     {
       try
       {
-        directoryServer.initializeJMX();
+        DirectoryServer.initializeJMX();
       }
       catch (Exception e)
       {
@@ -413,7 +433,7 @@
         return 1;
       }
     }
-
+    }
 
     // Choose the desired search scope.
     SearchScope searchScope;
@@ -466,7 +486,6 @@
          new LinkedHashSet<AttributeType>();
     LinkedHashSet<AttributeType> operationalAttributeTypes =
          new LinkedHashSet<AttributeType>();
-
     for (String attributeName : attributeNames)
     {
       AttributeType t = DirectoryServer.getAttributeType(attributeName, true);
@@ -598,12 +617,12 @@
     {
       if (overwriteExisting.isPresent())
       {
-        exportConfig = new LDIFExportConfig(outputFile.getName(),
+        exportConfig = new LDIFExportConfig(outputFile.getValue(),
                                             ExistingFileBehavior.OVERWRITE);
       }
       else
       {
-        exportConfig = new LDIFExportConfig(outputFile.getName(),
+        exportConfig = new LDIFExportConfig(outputFile.getValue(),
                                             ExistingFileBehavior.APPEND);
       }
     }
@@ -612,6 +631,7 @@
       exportConfig = new LDIFExportConfig(System.out);
     }
 
+    exportConfig.setIncludeObjectClasses(includeObjectclassAttrs);
     if (dontWrap.isPresent())
     {
       exportConfig.setWrapColumn(0);
@@ -805,3 +825,4 @@
   }
 }
 
+

--
Gitblit v1.10.0