directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gokt...@apache.org
Subject svn commit: r1224709 - in /directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities: ADSSchemaConstants.java LdifConfigHelper.java
Date Mon, 26 Dec 2011 10:47:30 GMT
Author: gokturk
Date: Mon Dec 26 10:47:30 2011
New Revision: 1224709

URL: http://svn.apache.org/viewvc?rev=1224709&view=rev
Log:
* Utility class for conversions between LdifEntry(instance's entry) and Properties(instance's
configuration) is implemented.


Modified:
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSSchemaConstants.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/LdifConfigHelper.java

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSSchemaConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSSchemaConstants.java?rev=1224709&r1=1224708&r2=1224709&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSSchemaConstants.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSSchemaConstants.java
Mon Dec 26 10:47:30 2011
@@ -58,4 +58,10 @@ public class ADSSchemaConstants
      */
     public static final String ADS_COMPONENT_ATTRIB_PURGE = "ads-componentpurgecount";
     public static final String ADS_COMPONENT_ATTRIB_PURGE_OID = "1.3.6.1.4.1.18060.0.4.4.0.1.4";
+
+    /*
+     * Attribute name of component instance name
+     */
+    public static final String ADS_COMPONENT_INSTANCE_ATTRIB_NAME = "ads-instance";
+    public static final String ADS_COMPONENT_INSTANCE_ATTRIB_NAME_OID = "1.3.6.1.4.1.18060.0.4.4.0.1.5";
 }

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/LdifConfigHelper.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/LdifConfigHelper.java?rev=1224709&r1=1224708&r2=1224709&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/LdifConfigHelper.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/LdifConfigHelper.java
Mon Dec 26 10:47:30 2011
@@ -20,10 +20,23 @@
 package org.apache.directory.server.component.utilities;
 
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 import java.util.Properties;
 
+import org.apache.directory.server.component.ADSComponent;
+import org.apache.directory.server.component.hub.ComponentManager;
 import org.apache.directory.server.component.instance.ADSComponentInstance;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.ldif.LdapLdifException;
 import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 public class LdifConfigHelper
@@ -37,7 +50,55 @@ public class LdifConfigHelper
      */
     public static LdifEntry instanceToLdif( ADSComponentInstance instance )
     {
-        return null;
+        ADSComponent parentComponent = instance.getParentComponent();
+        Properties instanceConfiguration = instance.getInstanceConfiguration();
+
+        String instanceName = ( String ) instanceConfiguration.get(
+            ADSConstants.ADS_COMPONENT_INSTANCE_PROP_NAME );
+
+        if ( instanceName == null )
+        {
+            return null;
+        }
+
+        String instancesDn = ADSComponentHelper.getComponentInstancesDn( parentComponent
);
+        String instanceRdn = ADSSchemaConstants.ADS_COMPONENT_INSTANCE_ATTRIB_NAME + "="
+ instanceName;
+        String instanceDn = instanceRdn + "," + instancesDn;
+
+        List<String> attributes = new ArrayList<String>();
+
+        for ( Object key : instanceConfiguration.keySet() )
+        {
+            if ( key.equals( ADSConstants.ADS_COMPONENT_INSTANCE_PROP_NAME ) )
+            {
+                continue;
+            }
+
+            String attribute = ( String ) key + "=" + ( String ) instanceConfiguration.get(
key );
+            attributes.add( attribute );
+        }
+        LdifEntry instanceEntry;
+        try
+        {
+            instanceEntry = new LdifEntry( new Dn( instanceDn ), attributes.toArray() );
+        }
+        catch ( LdapInvalidDnException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+        catch ( LdapInvalidAttributeValueException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+        catch ( LdapLdifException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+
+        return instanceEntry;
     }
 
 
@@ -47,8 +108,43 @@ public class LdifConfigHelper
      * @param entry LdifEntry reference to extract instance configuration
      * @return Extracted instance configuration
      */
-    public static Properties instanceEntryToConfiguration( LdifEntry entry )
+    public static Properties instanceEntryToConfiguration( LdifEntry instanceEntry )
     {
-        return null;
+        Entry entry = instanceEntry.getEntry();
+        Properties configuration = new Properties();
+
+        try
+        {
+            String instanceName = entry.get( ADSSchemaConstants.ADS_COMPONENT_INSTANCE_ATTRIB_NAME
).getString();
+            if ( instanceName == null )
+            {
+                //Entry is not instance entry.
+                return null;
+            }
+
+            configuration.put( ADSConstants.ADS_COMPONENT_INSTANCE_PROP_NAME, instanceName
);
+
+            Collection<Attribute> attributes = entry.getAttributes();
+            for ( Attribute attribute : attributes )
+            {
+                String attribName = attribute.getId();
+                String attribVal = attribute.getString();
+
+                if ( attribName.equals( ADSSchemaConstants.ADS_COMPONENT_INSTANCE_ATTRIB_NAME
) )
+                {
+                    continue;
+                }
+
+                configuration.put( attribName, attribVal );
+            }
+
+        }
+        catch ( LdapInvalidAttributeValueException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+
+        return configuration;
     }
 }



Mime
View raw message