directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gokt...@apache.org
Subject svn commit: r1222988 - in /directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component: hub/ instance/ utilities/
Date Sat, 24 Dec 2011 15:45:35 GMT
Author: gokturk
Date: Sat Dec 24 15:45:35 2011
New Revision: 1222988

URL: http://svn.apache.org/viewvc?rev=1222988&view=rev
Log:
* Instance generation implemented
* Instance name generation implemented, and name selection and usage schema is implemented
in code.


Modified:
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentManager.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/ComponentInstance.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/DefaultComponentInstanceGenerator.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSConstants.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/hub/ComponentManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentManager.java?rev=1222988&r1=1222987&r2=1222988&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentManager.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentManager.java
Sat Dec 24 15:45:35 2011
@@ -30,6 +30,7 @@ import org.apache.directory.server.compo
 import org.apache.directory.server.component.instance.CachedComponentInstance;
 import org.apache.directory.server.component.instance.ComponentInstance;
 import org.apache.directory.server.component.instance.ComponentInstanceGenerator;
+import org.apache.directory.server.component.utilities.ADSConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -129,6 +130,11 @@ public class ComponentManager
      */
     public ComponentInstance generateInstance( ADSComponent component, Properties properties
)
     {
+        if ( properties.get( ADSConstants.ADS_COMPONENT_INSTANCE_PROP_NAME ) == null )
+        {
+            properties.put( ADSConstants.ADS_COMPONENT_INSTANCE_PROP_NAME, generateInstanceName(
component ) );
+        }
+
         ComponentInstanceGenerator generator = instanceGenerators.get( component.getComponentType()
);
         if ( generator != null )
         {
@@ -189,4 +195,60 @@ public class ComponentManager
         return instance;
     }
 
+
+    /**
+     * It generates the instance name for the given component.
+     * It always choose the correct sequence number for instance name even in case of user

+     * interference with naming scheme. 
+     *
+     * @param component ADSComponent reference to generate an instance name.
+     * @return Generated instance name for the component in the form (componentName + "-"
+ choosenSequence)
+     */
+    private String generateInstanceName( ADSComponent component )
+    {
+        String componentSuffix = component.getComponentName() + "-";
+        int maxNumber = 0;
+
+        for ( CachedComponentInstance cachedIns : component.getCachedInstances() )
+        {
+            String cachedInstanceName = cachedIns.getCachedConfiguration().getProperty(
+                ADSConstants.ADS_COMPONENT_INSTANCE_PROP_NAME );
+
+            try
+            {
+                int instanceNumber = Integer.parseInt( cachedInstanceName.substring( componentSuffix.length()
) );
+                if ( instanceNumber > maxNumber )
+                {
+                    maxNumber = instanceNumber;
+                }
+            }
+            catch ( NumberFormatException e )
+            {
+                continue;
+            }
+
+        }
+
+        for ( ComponentInstance ins : component.getInstances() )
+        {
+            String instanceName = ins.getInstanceConfiguration().getProperty(
+                ADSConstants.ADS_COMPONENT_INSTANCE_PROP_NAME );
+
+            try
+            {
+                int instanceNumber = Integer.parseInt( instanceName.substring( componentSuffix.length()
) );
+                if ( instanceNumber > maxNumber )
+                {
+                    maxNumber = instanceNumber;
+                }
+            }
+            catch ( NumberFormatException e )
+            {
+                continue;
+            }
+        }
+
+        return componentSuffix + ( ++maxNumber );
+    }
+
 }

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/ComponentInstance.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/ComponentInstance.java?rev=1222988&r1=1222987&r2=1222988&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/ComponentInstance.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/ComponentInstance.java
Sat Dec 24 15:45:35 2011
@@ -55,6 +55,22 @@ public class ComponentInstance
 
 
     /**
+     * 
+     * Creates a new instance of ComponentInstance.
+     *
+     * @param component Parent component of the component instance
+     * @param pojo Underlying Pojo object if the component instance
+     * @param configuration Configuration of the Pojo
+     */
+    public ComponentInstance( ADSComponent component, Object pojo, Properties configuration
)
+    {
+        this.parentComponent = component;
+        this.instance = pojo;
+        this.instanceConfiguration = configuration;
+    }
+
+
+    /**
      * @return the instance
      */
     public Object getInstance()

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/DefaultComponentInstanceGenerator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/DefaultComponentInstanceGenerator.java?rev=1222988&r1=1222987&r2=1222988&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/DefaultComponentInstanceGenerator.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/DefaultComponentInstanceGenerator.java
Sat Dec 24 15:45:35 2011
@@ -24,6 +24,7 @@ import java.util.Properties;
 
 import org.apache.directory.server.component.ADSComponent;
 import org.apache.directory.server.component.schema.DefaultComponentSchemaGenerator;
+import org.apache.directory.shared.ipojo.helpers.IPojoHelper;
 import org.apache.felix.ipojo.Factory;
 import org.apache.felix.ipojo.architecture.PropertyDescription;
 import org.slf4j.Logger;
@@ -54,10 +55,14 @@ public class DefaultComponentInstanceGen
             properties = component.getDefaultConfiguration();
         }
 
-        // TODO Auto-generated method stub
+        // We create the IPojo instance using supplied configuration, 
+        // configuration have instance.name property at that point.
+        Object pojo = IPojoHelper.createIPojoComponent( component.getFactory().getName(),
null, properties );
 
-        //Remember to set configuration of the instance here...
-        return null;
+        //Create the ComponentInstance reference using the pojo just created.
+        ComponentInstance instance = new ComponentInstance( component, pojo, properties );
+
+        return instance;
     }
 
 

Modified: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSConstants.java?rev=1222988&r1=1222987&r2=1222988&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSConstants.java
(original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/utilities/ADSConstants.java
Sat Dec 24 15:45:35 2011
@@ -57,6 +57,11 @@ public class ADSConstants
     public static final String ADS_CACHE_VERSION_FILE = "version";
 
     /*
+     * IPojo instance name property
+     */
+    public static final String ADS_COMPONENT_INSTANCE_PROP_NAME = "instance.name";
+
+    /*
      * Component type name of interceptors
      */
     public static final String ADS_COMPONENT_TYPE_INTERCEPTOR = "interceptor";

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=1222988&r1=1222987&r2=1222988&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
Sat Dec 24 15:45:35 2011
@@ -29,18 +29,25 @@ import org.apache.directory.shared.ldap.
 
 public class LdifConfigHelper
 {
-    public static LdifEntry componentToLdifEntry( ADSComponent component )
-    {
-        return null;
-    }
-
 
+    /**
+     * Transforms a component instance into its corresponding entry in ldif format.
+     *
+     * @param instance ComponentInstance to transform into Ldif entry.
+     * @return Generated Ldif entry.
+     */
     public static LdifEntry instanceToLdif( ComponentInstance instance )
     {
         return null;
     }
 
 
+    /**
+     * It extracts the configuration information from Ldif entry.
+     *
+     * @param entry LdifEntry reference to extract instance configuration
+     * @return Extracted instance configuration
+     */
     public static Properties instanceEntryToConfiguration( LdifEntry entry )
     {
         return null;



Mime
View raw message