You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by go...@apache.org on 2011/11/22 12:03:29 UTC

svn commit: r1204918 [1/2] - in /directory/apacheds/branches/apacheds-osgi/component-hub: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/server/ src/m...

Author: gokturk
Date: Tue Nov 22 11:03:26 2011
New Revision: 1204918

URL: http://svn.apache.org/viewvc?rev=1204918&view=rev
Log:
Replaced component-hub with the local version.

* ComponentManager is implemented

TODO:

* Implement ConfigurationManager to provide instance reconfiguration from DIT


Added:
    directory/apacheds/branches/apacheds-osgi/component-hub/
    directory/apacheds/branches/apacheds-osgi/component-hub/pom.xml
    directory/apacheds/branches/apacheds-osgi/component-hub/src/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponent.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponentCacheHandle.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponentHelper.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSConstants.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/ADSComponent.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/ADSComponentHandler.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentCacheManager.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentEventManager.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java
    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/hub/client/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/UserComponentInstanceGenerator.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/UserComponentSchemaGenerator.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/AbstractHubListener.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/listener/HubListener.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/ADSComponentInstance.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/instance/ADSComponentInstanceGenerator.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/schema/
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/schema/ADSComponentSchema.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/schema/ComponentOIDGenerator.java
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/schema/ComponentSchemaGenerator.java

Added: directory/apacheds/branches/apacheds-osgi/component-hub/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/pom.xml?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/pom.xml (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/pom.xml Tue Nov 22 11:03:26 2011
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.directory.server</groupId>
+    <artifactId>apacheds-parent</artifactId>
+    <version>2.0.0-M4-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>apacheds-component-hub</artifactId>
+  <name>ApacheDS Component Hub</name>
+  <packaging>bundle</packaging>
+  <description>Provides main plugin-layer for ApacheDS</description>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-core-api</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-model</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.ipojo.annotations</artifactId>
+      <version>1.8.0</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.ipojo.handler.whiteboard</artifactId>
+      <version>1.6.0</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>4.3.0</version>
+    </dependency>
+
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <inherited>true</inherited>
+        <extensions>true</extensions>
+        <configuration>
+          <manifestLocation>META-INF</manifestLocation>
+          <instructions>
+            <Bundle-SymbolicName>${project.groupId}.component.hub</Bundle-SymbolicName>
+          </instructions>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-ipojo-plugin</artifactId>
+        <version>1.8.0</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>ipojo-bundle</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>      
+    </plugins>
+  </build>
+</project>
+

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponent.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponent.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponent.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponent.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,261 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.component;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.directory.server.component.hub.ComponentCacheManager;
+import org.apache.directory.server.component.hub.ComponentManager;
+import org.apache.directory.server.component.instance.ADSComponentInstance;
+import org.apache.directory.server.component.schema.ADSComponentSchema;
+import org.apache.felix.ipojo.Factory;
+
+
+/**
+ * Class that represents a component for ApacheDS use.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ADSComponent
+{
+    /*
+     * IPojo factory reference for component
+     */
+    private Factory factory;
+
+    /*
+     * Component's type
+     */
+    private String componentType = "user";
+
+    /*
+     * Name of the component(Its IPojo factory name in normalized form).
+     */
+    private String componentName;
+
+    /*
+     * Version of the component.
+     * (Implementing factory's Bundle version/Subject to change).
+     */
+    private String componentVersion;
+
+    /*
+     * List holding all the created instances of that component
+     */
+    private List<ADSComponentInstance> instances;
+
+    /*
+     * cache handle for pointing places in the cache for that component.
+     */
+    private ADSComponentCacheHandle cacheHandle;
+
+    /*
+     * Generated/Choosed schema information
+     */
+    private ADSComponentSchema schema;
+
+    /*
+     * Default configuration to instantiate instances of that component.
+     */
+    private Properties defaultConfiguration;
+
+    /*
+     * internal component manager
+     */
+    private ComponentManager componentManager;
+
+
+    public ADSComponent( ComponentManager componentManager )
+    {
+        this.componentManager = componentManager;
+
+        instances = new ArrayList<ADSComponentInstance>();
+    }
+
+
+    /**
+     * Adds an instance to a instances list
+     *
+     * @param instance instance reference to add to a list
+     */
+    public void addInstance( ADSComponentInstance instance )
+    {
+        instances.add( instance );
+    }
+
+
+    /**
+     * Removes an instance from instances list
+     *
+     * @param instance to remove from the list
+     */
+    public void removeInstance( ADSComponentInstance instance )
+    {
+        instances.remove( instance );
+    }
+
+
+    /**
+     * Gets the current instances of the component
+     *
+     * @return Cloned ADSComponentInstance list.
+     */
+    public List<ADSComponentInstance> getInstances()
+    {
+        return new ArrayList<ADSComponentInstance>( instances );
+    }
+
+
+    /**
+     * @return the cacheHandle
+     */
+    public ADSComponentCacheHandle getCacheHandle()
+    {
+        return cacheHandle;
+    }
+
+
+    /**
+     * @param cacheHandle the cacheHandle to set
+     */
+    public void setCacheHandle( ADSComponentCacheHandle cacheHandle )
+    {
+        this.cacheHandle = cacheHandle;
+    }
+
+
+    /**
+     * @return the factory
+     */
+    public Factory getFactory()
+    {
+        return factory;
+    }
+
+
+    /**
+     * @param factory the factory to set
+     */
+    public void setFactory( Factory factory )
+    {
+        this.factory = factory;
+    }
+
+
+    /**
+     * @return the componentType
+     */
+    public String getComponentType()
+    {
+        return componentType;
+    }
+
+
+    /**
+     * @param componentType the componentType to set
+     */
+    public void setComponentType( String componentType )
+    {
+        this.componentType = componentType;
+    }
+
+
+    /**
+     * @return the schema
+     */
+    public ADSComponentSchema getSchema()
+    {
+        return schema;
+    }
+
+
+    /**
+     * @param schema the schema to set
+     */
+    public void setSchema( ADSComponentSchema schema )
+    {
+        this.schema = schema;
+    }
+
+
+    /**
+     * @return the componentName
+     */
+    public String getComponentName()
+    {
+        return componentName;
+    }
+
+
+    /**
+     * @param componentName the componentName to set
+     */
+    public void setComponentName( String componentName )
+    {
+        this.componentName = componentName;
+    }
+
+
+    /**
+     * @return the componentVersion
+     */
+    public String getComponentVersion()
+    {
+        return componentVersion;
+    }
+
+
+    /**
+     * @param componentVersion the componentVersion to set
+     */
+    public void setComponentVersion( String componentVersion )
+    {
+        this.componentVersion = componentVersion;
+    }
+
+
+    @Override
+    public String toString()
+    {
+        return getComponentType() + ":" + getComponentName() + ":" + getComponentVersion();
+    }
+
+
+    /**
+     * @return the defaultConfiguration
+     */
+    public Properties getDefaultConfiguration()
+    {
+        return defaultConfiguration;
+    }
+
+
+    /**
+     * @param defaultConfiguration the defaultConfiguration to set
+     */
+    public void setDefaultConfiguration( Properties defaultConfiguration )
+    {
+        this.defaultConfiguration = defaultConfiguration;
+    }
+
+}

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponentCacheHandle.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponentCacheHandle.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponentCacheHandle.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponentCacheHandle.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,91 @@
+package org.apache.directory.server.component;
+
+
+public class ADSComponentCacheHandle
+{
+    /*
+     * Dir path for cache
+     */
+    private String cacheBaseDir;
+
+    /*
+     * File path containing cached schema of the component.
+     */
+    private String cachedSchemaFileLocation;
+
+    /*
+     * Directory path containing cached instance configurations of the component.
+     */
+    private String cachedInstanceConfigurationsLocation;
+
+    /*
+     * Component version of the cache. Used for validating of invalidating the cache in case of
+     * component updates.
+     */
+    private String cachedVersion;
+
+
+    public ADSComponentCacheHandle( String base, String schema, String configurations, String version )
+    {
+        cacheBaseDir = base;
+        cachedSchemaFileLocation = schema;
+        cachedInstanceConfigurationsLocation = configurations;
+        cachedVersion = version;
+    }
+
+
+    /**
+     * Getter for cache base dir
+     *
+     * @return String Location of the base cache path
+     */
+    public String getCacheBaseDir()
+    {
+        return cacheBaseDir;
+    }
+
+
+    /**
+     * Getter for cached schema handle
+     *
+     * @return String containing file location of cached schema
+     */
+    public String getCachedSchemaLocation()
+    {
+        return cachedSchemaFileLocation;
+    }
+
+
+    /**
+     * Getter for cached instance configurations
+     *
+     * @return String containing directory location of cached instance configurations
+     */
+    public String getCachedInstanceConfigurationsLocation()
+    {
+        return cachedInstanceConfigurationsLocation;
+    }
+
+
+    /**
+     * Getter for cached version of cache
+     *
+     * @return version of cache.
+     */
+    public String getCachedVersion()
+    {
+        return cachedVersion;
+    }
+
+
+    /**
+     * Setter for cached version of cache
+     *
+     *@param ver Version set on cache.
+     */
+    public void setCachedVersion( String ver )
+    {
+        cachedVersion = ver;
+    }
+
+}

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponentHelper.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponentHelper.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponentHelper.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSComponentHelper.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,54 @@
+package org.apache.directory.server.component;
+
+
+import org.apache.commons.io.IOUtils;
+import org.apache.felix.ipojo.Factory;
+
+
+/**
+ * This class has static helper methods that will be used by the other parts of the program.
+ * These methods mainly affects the layout of the program. So by using these methods, program parts 
+ * can be work in uniform design.
+ * 
+ *
+ * @author gokturk
+ */
+public class ADSComponentHelper
+{
+    /**
+     * Gets the component name of an IPojo Component. If IPojo Component does not define its factory name
+     * its default factory name is the class name that implements that component. In this case this method leaves out
+     * the package name and only takes the class name.
+     *
+     * @param componentFactory An IPojo Component Factory reference
+     * @return component name of an IPojo Component
+     */
+    public static String getComponentName( Factory componentFactory )
+    {
+        String factoryName = componentFactory.getName();
+        if ( factoryName.contains( "." ) )
+        {
+            return factoryName.substring( factoryName.lastIndexOf( '.' ) + 1 );
+        }
+        else
+        {
+            return factoryName;
+        }
+    }
+
+
+    /**
+     * Gets the version of the component. This version is the bundle version of the bundle that
+     * contains specified component. 
+     *
+     * @param componentFactory An IPojo Component Factory reference
+     * @return version of an IPojo Component
+     */
+    public static String getComponentVersion( Factory componentFactory )
+    {
+        return ( String ) componentFactory.getBundleContext().getBundle().getHeaders().get( "Bundle-Version" );
+
+    }
+
+
+}

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSConstants.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSConstants.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/ADSConstants.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,131 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.component;
+
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+
+/**
+ * Class to hold constants for ApacheDS component management.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ADSConstants
+{
+
+    /*
+     * base directory path for component cache
+     */
+    public static final String ADS_CACHE_BASE_DIR = "adscache";
+
+    /*
+     * default file name for caching schemas inside for components
+     */
+    public static final String ADS_CACHE_SCHEMA_FILE = "schema-elements.ldif";
+
+    /*
+     * default file name for caching instance entries inside for components
+     */
+    public static final String ADS_CACHE_INSTANCES_DIR = "instance-configs";
+
+    /*
+     * default file name for caching version information for components
+     */
+    public static final String ADS_CACHE_VERSION_FILE = "version";
+
+    /*
+     * IPojo Handler name for ADSComponent annotation.
+     */
+    public static final String ADS_COMPONENT_HANDLER_NS = "org.apache.directory.server.component.handler";
+
+    /*
+     * IPojo Handler name for ADSComponent annotation.
+     */
+    public static final String ADS_COMPONENT_HANDLER_NAME = "ADSComponentHandler";
+
+    /*
+     * IPojo Handler name for ADSComponent annotation.
+     */
+    public static final String ADS_COMPONENT_HANDLER_FULLNAME = "org.apache.directory.server.component.handler:ADSComponentHandler";
+
+    /*
+     * iPOJO Component Type and Instance declaration header.
+     */
+    public static final String IPOJO_HEADER = "iPOJO-Components";
+
+    /*
+     * Base OID value for ApacheDS component schemas.
+     */
+    public static final String ADS_COMPONENT_BASE_OID = "1.3.6.1.4.1.18060.0.4.4";
+
+    /*
+     * Component type name of user defined components.
+     */
+    public static final String ADS_COMPONENT_TYPE_USER = "user";
+
+    /*
+     * Hash table for mapping property type name to its syntax in ApacheDS
+     */
+    public static Dictionary<String, String> syntaxMappings;
+
+    /*
+     * Hash table for mapping property type name to its equality matching rule in ApacheDS
+     */
+    public static Dictionary<String, String> equalityMappings;
+
+    /*
+     * Hash table for mapping property type name to its ordering rule in ApacheDS
+     */
+    public static Dictionary<String, String> orderingMappings;
+
+    /*
+     * Hash table for mapping property type name to its substring matching in ApacheDS
+     */
+    public static Dictionary<String, String> substringMappings;
+
+    /**
+     * Static constructor that initializes the values of the type mapping Hash tables.
+     */
+    static
+    {
+        syntaxMappings = new Hashtable<String, String>();
+        syntaxMappings.put( "int", "1.3.6.1.4.1.1466.115.121.1.27" );
+        syntaxMappings.put( "java.lang.String", "1.3.6.1.4.1.1466.115.121.1.15" );
+        syntaxMappings.put( "boolean", "1.3.6.1.4.1.1466.115.121.1.7" );
+
+        equalityMappings = new Hashtable<String, String>();
+        equalityMappings.put( "int", "integerMatch" );
+        equalityMappings.put( "java.lang.String", "caseExactMatch" );
+        equalityMappings.put( "boolean", "booleanMatch" );
+
+        orderingMappings = new Hashtable<String, String>();
+        orderingMappings.put( "int", "integerOrderingMatch" );
+        orderingMappings.put( "java.lang.String", "caseExactOrderingMatch" );
+        orderingMappings.put( "boolean", "caseIgnoreOrderingMatch" );
+
+        substringMappings = new Hashtable<String, String>();
+        substringMappings.put( "int", "numericStringSubstringsMatch" );
+        substringMappings.put( "java.lang.String", "caseExactSubstringsMatch" );
+        substringMappings.put( "boolean", "caseIgnoreSubstringsMatch" );
+    }
+
+}

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/ADSComponent.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/ADSComponent.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/ADSComponent.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/ADSComponent.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,31 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.component.handler;
+
+
+/**
+ * Used to annotate ApacheDS components with their component type.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public @interface ADSComponent
+{
+    String componentType() default "user";
+}

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/ADSComponentHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/ADSComponentHandler.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/ADSComponentHandler.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/ADSComponentHandler.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,65 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.component.handler;
+
+
+import java.util.Dictionary;
+
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.annotations.Handler;
+import org.apache.felix.ipojo.metadata.Element;
+
+
+/**
+ * IPojo handler for ADSComponent annotation.
+ * It does not supposed to do anything. It is just to validate the custom-annotated component.
+ *  
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@Handler(namespace = "org.apache.directory.server.component.handler", name = "ADSComponent")
+public class ADSComponentHandler extends PrimitiveHandler
+{
+
+    @Override
+    public void configure( Element metadata, Dictionary configuration ) throws ConfigurationException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public void stop()
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+
+    @Override
+    public void start()
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentCacheManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentCacheManager.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentCacheManager.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentCacheManager.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,477 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.server.component.hub;
+
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.directory.server.component.ADSComponent;
+import org.apache.directory.server.component.ADSComponentCacheHandle;
+import org.apache.directory.server.component.ADSConstants;
+import org.apache.directory.server.component.instance.ADSComponentInstance;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+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.ldif.LdifReader;
+import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/*
+ * Class to manage schema and instance cache for ADSComponents.
+ */
+public class ComponentCacheManager
+{
+    /*
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger( ComponentCacheManager.class );
+
+    /*
+     * List to keep track of uncached ADSComponents which wants automatic caching.
+     */
+    private Set<ADSComponent> uncachedComponents;
+
+
+    public ComponentCacheManager()
+    {
+        uncachedComponents = new HashSet<ADSComponent>();
+    }
+
+
+    /**
+     * Adds component to watch list.
+     *
+     * @param component ADSComponent to watch its cache for.
+     */
+    public void addCacheWatch( ADSComponent component )
+    {
+        uncachedComponents.add( component );
+    }
+
+
+    /**
+     * Removes component from watch list.
+     * Also called by cacheComponent()
+     *
+     * @param component ADSComponent release watch.
+     */
+    public void removeCacheWatch( ADSComponent component )
+    {
+        uncachedComponents.remove( component );
+    }
+
+
+    /**
+     * Caches all the ADSComponents in the watch list, which are registered but didn't cached.
+     * It is called by ComponentHub when it is being invalidated.
+     */
+    public void cacheRemaningComponents()
+    {
+        for ( ADSComponent component : uncachedComponents )
+        {
+            cacheSchema( component );
+            cacheInstanceConfigurations( component );
+        }
+    }
+
+
+    /**
+     * Returns the cache handle for specified component.
+     *
+     * @param component Component to get cache handle for.
+     * @return cache handle.
+     */
+    public ADSComponentCacheHandle getCacheHandle( ADSComponent component )
+    {
+        String componentCachePath = getComponentCacheBaseDir( component );
+        String schemaFile = componentCachePath + IOUtils.DIR_SEPARATOR + ADSConstants.ADS_CACHE_SCHEMA_FILE;
+        String instancesDir = componentCachePath + IOUtils.DIR_SEPARATOR + ADSConstants.ADS_CACHE_INSTANCES_DIR;
+
+        String version = getCacheVersion( component );
+
+        return new ADSComponentCacheHandle( componentCachePath, schemaFile, instancesDir, version );
+
+    }
+
+
+    /**
+     * Caches the schema, instance configurations and set the version for a component.
+     *
+     * @param component ADSComponent reference to cache.
+     */
+    public void cacheComponent( ADSComponent component )
+    {
+        cacheSchema( component );
+        cacheInstanceConfigurations( component );
+        cacheVersion( component );
+
+        removeCacheWatch( component );
+    }
+
+
+    /**
+     * Cache the schema for component.
+     *
+     * @param component ADSComponent reference to cache its schema.
+     */
+    public void cacheSchema( ADSComponent component )
+    {
+        List<LdifEntry> schema = component.getSchema().getSchemaElements();
+        if ( schema == null )
+        {
+            LOG.info( "Component does not have custom schema elements:  "
+                + component );
+            return;
+        }
+
+        String componentPath = component.getCacheHandle().getCacheBaseDir();
+        String filePath = component.getCacheHandle().getCachedSchemaLocation();
+
+        File cacheDirectory = new File( componentPath );
+
+        try
+        {
+            FileUtils.forceMkdir( cacheDirectory );
+            BufferedWriter writer = new BufferedWriter( new FileWriter( filePath ) );
+
+            for ( LdifEntry ldif : schema )
+            {
+                writer.write( LdifUtils.convertToLdif( ldif ) );
+                writer.write( IOUtils.LINE_SEPARATOR + IOUtils.LINE_SEPARATOR );
+            }
+
+            writer.flush();
+            writer.close();
+
+            cacheVersion( component );
+        }
+        catch ( IOException e )
+        {
+            LOG.info( " I/O Error while caching schema for component" + component );
+        }
+        catch ( LdapException e )
+        {
+            LOG.info( "LdifConvert Error while caching schema for component " + component );
+        }
+    }
+
+
+    /**
+     * Caches the current configuration of instances of an ADSComponent.
+     *
+     * @param component ADSComponent reference to cache its instance configurations.
+     */
+    public void cacheInstanceConfigurations( ADSComponent component )
+    {
+        String instancesDirPath = component.getCacheHandle().getCachedInstanceConfigurationsLocation();
+        File instancesDir = new File( instancesDirPath );
+        try
+        {
+            if ( instancesDir.exists() )
+            {
+                //Delete existing configuration cache.
+                FileUtils.deleteDirectory( instancesDir );
+            }
+
+            FileUtils.forceMkdir( instancesDir );
+
+            int counter = 1;
+            for ( ADSComponentInstance instance : component.getInstances() )
+            {
+                Properties props = instance.getInstanceConfiguration();
+
+                String fileName = instancesDirPath + IOUtils.DIR_SEPARATOR + component.getComponentName() + "-"
+                    + counter++ + ".config";
+
+                props.store( new FileOutputStream( fileName ), "Instance Configuration for" + component );
+            }
+        }
+        catch ( IOException exc )
+        {
+            LOG.info( "I/O error occured while caching instance configuration as Properties for component:"
+                + component );
+        }
+    }
+
+
+    /**
+     * Set the cache version for the specified component
+     *
+     * @param component ADSComponent reference to set version on cache for.
+     */
+    public void cacheVersion( ADSComponent component )
+    {
+        String componentPath = component.getCacheHandle().getCacheBaseDir();
+        String versionFilePath = componentPath + IOUtils.DIR_SEPARATOR + ADSConstants.ADS_CACHE_VERSION_FILE;
+
+        File cacheDirectory = new File( componentPath );
+
+        try
+        {
+            if ( cacheDirectory.exists() )
+            {
+                BufferedWriter writer = new BufferedWriter( new FileWriter( versionFilePath ) );
+                String version = component.getComponentVersion();
+
+                writer.write( version );
+
+                writer.flush();
+                writer.close();
+
+                component.getCacheHandle().setCachedVersion( version );
+            }
+        }
+        catch ( IOException e )
+        {
+            LOG.info( "  Error while setting version under cache for component:" + component );
+        }
+    }
+
+
+    /**
+     * Gets the cached schema of the component.
+     * Returning list is in the from it can loaded into ApacheDS without any sorting.
+     *
+     * @param component ADSComponent reference to search cache for its schema
+     * @return The cached schema in the form of LdifEntry list.
+     */
+    public List<LdifEntry> getCachedSchema( ADSComponent component )
+    {
+
+        if ( !cacheVersionMatch( component ) )
+        {
+            LOG.info( "Version mismatch between the cache and the component:  "
+                + component );
+
+            if ( !validateCache( component ) )
+            {
+                return null;
+            }
+        }
+
+        String schemaFilePath = component.getCacheHandle().getCachedSchemaLocation();
+        List<LdifEntry> schema = null;
+
+        try
+        {
+            File schemaFile = new File( schemaFilePath );
+
+            if ( !schemaFile.exists() )
+            {
+                return null;
+            }
+
+            LdifReader reader = new LdifReader( schemaFile );
+            schema = new ArrayList<LdifEntry>();
+
+            for ( LdifEntry entry : reader )
+            {
+                schema.add( entry );
+            }
+
+        }
+        catch ( LdapLdifException e )
+        {
+            LOG.info( "Error while readering cached schema file for component:  "
+                + component );
+            return null;
+        }
+
+        return schema;
+    }
+
+
+    /**
+     * Gets the cached instance configurations from the cache as list.
+     *
+     * @param component ADSComponent reference to search cache for its instance configurations
+     * @return List of Properties describing cached instance configurations.
+     */
+    public List<Properties> getCachedInstanceConfigurations( ADSComponent component )
+    {
+        String instancesDirPath = component.getCacheHandle().getCachedInstanceConfigurationsLocation();
+        File instancesDir = new File( instancesDirPath );
+
+        if ( !instancesDir.exists() )
+        {
+            return null;
+        }
+
+        File[] configFiles = instancesDir.listFiles( new FileFilter()
+        {
+
+            @Override
+            public boolean accept( File pathname )
+            {
+                return pathname.toString().matches( "*-*.config" );
+            }
+        } );
+
+        List<Properties> instanceConfigurations = new ArrayList<Properties>();
+
+        for ( File configFile : configFiles )
+        {
+            try
+            {
+                Properties prop = new Properties();
+                prop.load( new FileInputStream( configFile ) );
+
+                instanceConfigurations.add( prop );
+            }
+            catch ( IOException exc )
+            {
+                LOG.info( "I/O Error while loading properties from file:" + configFile );
+            }
+        }
+
+        if ( instanceConfigurations.size() == 0 )
+        {
+            return null;
+        }
+
+        return instanceConfigurations;
+
+    }
+
+
+    /**
+     * Gets the version of cache for the component.
+     *
+     * @param component ADSComponent reference to get its cache version
+     * @return version of the cache.
+     */
+    public String getCacheVersion( ADSComponent component )
+    {
+        String componentPath = component.getCacheHandle().getCacheBaseDir();
+        String versionFilePath = componentPath + IOUtils.DIR_SEPARATOR + ADSConstants.ADS_CACHE_VERSION_FILE;
+        String version = null;
+
+        File versionFile = new File( versionFilePath );
+        if ( !versionFile.exists() )
+        {
+            return null;
+        }
+
+        try
+        {
+            BufferedReader reader = new BufferedReader( new FileReader( versionFile ) );
+            version = reader.readLine();
+            reader.close();
+        }
+        catch ( IOException e )
+        {
+            LOG.info( "Error occured while reading version file of the cached component:  "
+                + component );
+        }
+
+        return version;
+    }
+
+
+    /**
+     * Checks whether specified component's version is compatible with the cached version.
+     *
+     * TODO It looks for exact match for now, change it to some elegant match policy.
+     *
+     * @param component ADSComponent reference to check cache against.
+     * @return result of the test.
+     */
+    public boolean cacheVersionMatch( ADSComponent component )
+    {
+        String cachedVersion = component.getCacheHandle().getCachedVersion();
+        String currentVersion = component.getComponentVersion();
+
+        if ( !currentVersion.equals( cachedVersion ) && cachedVersion != null )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+
+    /**
+     * It is used to validate the cache for the given component.
+     * TODO validateCache will be implemented later.
+     *
+     * @param component ADSComponent to validate cache against.
+     * @return whether validation is successfull or not.
+     */
+    public boolean validateCache( ADSComponent component )
+    {
+        return false;
+    }
+
+
+    /**
+     * It removes all the cache for given component.
+     *
+     * @param component ADSComponent reference to purge its cache.
+     */
+    public void purgeCache( ADSComponent component )
+    {
+        File baseCacheDir = new File( component.getCacheHandle().getCacheBaseDir() );
+        if ( baseCacheDir.exists() )
+        {
+            try
+            {
+                FileUtils.forceDelete( baseCacheDir );
+            }
+            catch ( IOException e )
+            {
+                LOG.info( "I/O Error occured while purging the cache for component" + component );
+            }
+        }
+    }
+
+
+    /**
+     * Gets the base dir in cache for specified component.
+     *
+     * @param component ADSComponent to get cache location for.
+     * @return cache location as String.
+     */
+    private String getComponentCacheBaseDir( ADSComponent component )
+    {
+        String componentType = component.getComponentType();
+        String componentName = component.getComponentName();
+
+        return ADSConstants.ADS_CACHE_BASE_DIR + IOUtils.DIR_SEPARATOR + componentType + IOUtils.DIR_SEPARATOR
+            + componentName;
+    }
+
+}

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentEventManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentEventManager.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentEventManager.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentEventManager.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,202 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.component.hub;
+
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.directory.server.component.ADSComponent;
+import org.apache.directory.server.component.hub.listener.HubListener;
+
+
+/**
+ * Manages component install, uninstall events for listeners.
+ * Provides listeners an ability to get passed events by holding an event cache.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ComponentEventManager
+{
+
+    /*
+     * Map to keep "component type" -> "listeners" mapping
+     */
+    private Dictionary<String, List<HubListener>> listenersMap;
+
+    /*
+     * Map to keep all passed events.
+     */
+    private Dictionary<String, List<ADSComponent>> eventCache;
+
+
+    public ComponentEventManager()
+    {
+        listenersMap = new Hashtable<String, List<HubListener>>();
+        eventCache = new Hashtable<String, List<ADSComponent>>();
+    }
+
+
+    /**
+     * Registers a HubListener for specified component type.
+     *
+     * @param componentType component type to get notifications for.
+     * @param listener HubListener implementation
+     */
+    public synchronized void registerListener( String componentType, HubListener listener )
+    {
+        List<HubListener> listenersForComp = listenersMap.get( componentType );
+        if ( listenersForComp == null )
+        {
+            ArrayList<HubListener> list = new ArrayList<HubListener>();
+            list.add( listener );
+            listenersMap.put( componentType, list );
+        }
+        else
+        {
+            if ( !listenersForComp.contains( listener ) )
+            {
+                listenersForComp.add( listener );
+            }
+        }
+
+        // Make listener receive the passed creation events.
+        List<ADSComponent> passedCreations = eventCache.get( componentType );
+        if ( passedCreations != null )
+        {
+            for ( ADSComponent comp : passedCreations )
+            {
+                listener.onComponentCreation( comp );
+            }
+        }
+    }
+
+
+    /**
+     * Removes the specified listener from the notification chain.
+     *
+     * @param listener HubListener implementation
+     */
+    public synchronized void removeListener( HubListener listener )
+    {
+        Enumeration<List<HubListener>> it = listenersMap.elements();
+        while ( it.hasMoreElements() )
+        {
+            List<HubListener> list = it.nextElement();
+            if ( list.contains( listener ) )
+            {
+                list.remove( listener );
+            }
+        }
+    }
+
+
+    /**
+     * Iterates through listeners for specified ADSComponent's component type.
+     * Calls their onComponentCreation() method. 
+     * 
+     * Reference is passed without cloning. So individual listeners can change
+     * the provided ADSComponent. It will affect the all component hub.
+     *
+     * @param component ADSComponent reference to be used for notification
+     */
+    public synchronized void fireComponentCreated( ADSComponent component )
+    {
+        List<HubListener> listenersByType = listenersMap.get( component.getComponentType() );
+
+        // Iterate over listeners for 'component created' event. Apply the changes applied by them.
+        if ( listenersByType != null )
+        {
+            for ( HubListener listener : listenersByType )
+            {
+                listener.onComponentCreation( component );
+            }
+        }
+
+        cacheCreation( component );
+    }
+
+
+    /**
+     * Iterates through listeners for specified ADSComponent's component type.
+     * Calls their onComponentDeletion() method.
+     * 
+     * In the time callbacks are executed, the ADSComponent's existence on ApacheDS
+     * is terminated. So use the reference just for statistical purposes.
+     *
+     * @param component ADSComponent reference to be used for notification
+     */
+    public synchronized void fireComponentDeleted( ADSComponent component )
+    {
+        List<HubListener> listenersByType = listenersMap.get( component.getComponentType() );
+
+        // Iterate over listeners for 'component deleting' event.
+        if ( listenersByType != null )
+        {
+            for ( HubListener listener : listenersByType )
+            {
+                listener.onComponentDeletion( component );
+            }
+        }
+
+        unCacheCreation( component );
+    }
+
+
+    /**
+     * Caches ADSComponent to notify late-coming listeners.
+     *
+     * @param comp ADSComponent reference to cache
+     */
+    private void cacheCreation( ADSComponent component )
+    {
+        String compType = component.getComponentType();
+        List<ADSComponent> passedEvents = eventCache.get( compType );
+        if ( passedEvents == null )
+        {
+            passedEvents = new ArrayList<ADSComponent>();
+            passedEvents.add( component );
+        }
+        else
+        {
+            passedEvents.add( component );
+        }
+    }
+
+
+    /**
+     * Removes ADSComponent from the cache. So late-coming listeners
+     * won't be notified.
+     *
+     * @param comp ADSComponent reference to cache
+     */
+    private void unCacheCreation( ADSComponent component )
+    {
+        String compType = component.getComponentType();
+        List<ADSComponent> passedEvents = eventCache.get( compType );
+        if ( passedEvents != null && passedEvents.contains( component ) )
+        {
+            passedEvents.remove( component );
+        }
+    }
+}

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,372 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.component.hub;
+
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.directory.server.component.ADSComponent;
+import org.apache.directory.server.component.ADSComponentHelper;
+import org.apache.directory.server.component.ADSConstants;
+import org.apache.directory.server.component.hub.client.user.UserComponentInstanceGenerator;
+import org.apache.directory.server.component.hub.client.user.UserComponentSchemaGenerator;
+import org.apache.directory.server.component.hub.listener.HubListener;
+import org.apache.directory.server.component.instance.ADSComponentInstanceGenerator;
+import org.apache.directory.server.component.schema.ADSComponentSchema;
+import org.apache.directory.server.component.schema.ComponentSchemaGenerator;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Invalidate;
+import org.apache.felix.ipojo.annotations.Requires;
+import org.apache.felix.ipojo.annotations.Validate;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.parser.ManifestMetadataParser;
+import org.apache.felix.ipojo.parser.ParseException;
+import org.apache.felix.ipojo.whiteboard.Wbp;
+import org.apache.felix.ipojo.whiteboard.Whiteboards;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+
+/**
+ * An IPojo component that listens for incoming factories and instances.
+ * Creating or destroying corresponding ADSComponent from them.
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@Component
+@Whiteboards(whiteboards =
+    {
+        @Wbp(onArrival = "onFactoryArrival",
+            onDeparture = "onFactoryDeparture",
+            filter = "(objectClass=org.apache.felix.ipojo.Factory)"),
+        @Wbp(onArrival = "onInstanceArrival",
+            onDeparture = "onInstanceDeparture",
+            filter = "(objectClass=org.apache.felix.ipojo.architecture.Architecture)")
+})
+public class ComponentHub
+{
+    /*
+     * boolean value to check for deferred writes to schema partition
+     */
+    private boolean schemaReady = false;
+
+    /*
+     * boolean value to check for deferred writes to config partition
+     */
+    private boolean configReady = false;
+
+    /*
+     * Map to keep "component type" -> "components" mapping.
+     */
+    private Dictionary<String, List<ADSComponent>> componentMap;
+
+    /*
+     * List to keep all active ApacheDS components.
+     */
+    private List<ADSComponent> components;
+
+    /*
+     * Used to manage listeners.
+     */
+    private ComponentEventManager eventManager = new ComponentEventManager();
+
+    /*
+     * Used to manage component caches.
+     */
+    private ComponentCacheManager cacheManager = new ComponentCacheManager();
+
+    /*
+     * Used to manage components
+     */
+    private ComponentManager componentManager = new ComponentManager( cacheManager );
+
+    /*
+     * OSGI Logger
+     */
+    @Requires
+    private LogService logger;
+
+
+    public ComponentHub()
+    {
+        componentMap = new Hashtable<String, List<ADSComponent>>();
+        components = new ArrayList<ADSComponent>();
+    }
+
+
+    /**
+     * Called when ADSComponentHub instance is validated by IPojo
+     *
+     */
+    @Validate
+    public void hubValidated()
+    {
+        logger.log( LogService.LOG_INFO, "ADSComponentHub validated." );
+    }
+
+
+    /**
+     * Called when ADSComponentHub instance is invalidated by IPojo
+     *
+     */
+    @Invalidate
+    public void hubInvalidated()
+    {
+        logger.log( LogService.LOG_INFO, "ADSComponentHub being invalidated." );
+
+        cacheManager.cacheRemaningComponents();
+    }
+
+
+    /**
+     * Factory arrival callback, registered by whiteboard handler.
+     *
+     * @param ref Reference to IPojo Factory
+     */
+    public void onFactoryArrival( ServiceReference ref )
+    {
+        Factory arrivingFactory = ( Factory ) ref.getBundle().getBundleContext().getService( ref );
+        if ( !checkIfADSComponent( arrivingFactory ) )
+        {
+            return;
+        }
+
+        try
+        {
+            String componentType = parseComponentType( arrivingFactory );
+
+            //Actual ADSComponent creation
+            ADSComponent component = generateADSComponent( componentType, arrivingFactory );
+
+            eventManager.fireComponentCreated( component );
+
+            //Keep the newly created ADSComponent reference.
+            components.add( component );
+
+            List<ADSComponent> componentsByType = componentMap.get( componentType );
+            if ( componentsByType == null )
+            {
+                List<ADSComponent> newCompList = new ArrayList<ADSComponent>();
+                newCompList.add( component );
+                componentMap.put( componentType, newCompList );
+            }
+            else
+            {
+                componentsByType.add( component );
+            }
+
+        }
+        catch ( ParseException e )
+        {
+            e.printStackTrace();
+        }
+
+    }
+
+
+    /**
+     * Factory departure callback, registered by whiteboard handler.
+     *
+     * @param ref Reference to IPojo Factory
+     */
+    public void onFactoryDeparture( ServiceReference ref )
+    {
+        Factory leavingFactory = ( Factory ) ref.getBundle().getBundleContext().getService( ref );
+        if ( !checkIfADSComponent( leavingFactory ) )
+        {
+            return;
+        }
+
+        try
+        {
+            String componentType = parseComponentType( leavingFactory );
+
+            ADSComponent associatedComp = null;
+            for ( ADSComponent _comp : components )
+            {
+                if ( _comp.getFactory().getName().equals( leavingFactory.getName() ) )
+                {
+                    associatedComp = _comp;
+                    break;
+                }
+            }
+
+            if ( associatedComp == null )
+            {
+                logger.log( LogService.LOG_INFO, "Couldn't found an associated ADSComponent for factory:"
+                    + leavingFactory.getName() );
+                return;
+            }
+
+            // All clients are notified now cache and delete the ADSComponent existence on ApacheDS
+            cacheAndReleaseADSComponent( associatedComp );
+
+            // Fire "Component Deleted" event
+            eventManager.fireComponentDeleted( associatedComp );
+
+        }
+        catch ( ParseException e )
+        {
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * IPojo instance arrival callback, registered by whiteboard handler.
+     *
+     * @param ref Reference to IPojo instance
+     */
+    public void onInstanceArrival( ServiceReference ref )
+    {
+
+    }
+
+
+    /**
+     * IPojo instance departure callback, registered by whiteboard handler.
+     *
+     * @param ref Reference to IPojo instance
+     */
+    public void onInstanceDeparture( ServiceReference ref )
+    {
+
+    }
+
+
+    /**
+     * Check whether the argument is ADSComponent annotated.
+     *
+     * @param factory
+     * @return
+     */
+    private boolean checkIfADSComponent( Factory factory )
+    {
+        List<String> handlers = factory.getRequiredHandlers();
+        for ( String handlerName : handlers )
+        {
+            if ( handlerName.equals( ADSConstants.ADS_COMPONENT_HANDLER_FULLNAME ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+
+    private String parseComponentType( Factory factory ) throws ParseException
+    {
+        Dictionary bundleHeaders = factory.getBundleContext().getBundle().getHeaders();
+        String ipojoHeader = ( String ) bundleHeaders.get( ADSConstants.IPOJO_HEADER );
+
+        if ( ipojoHeader == null )
+        {
+            throw new ParseException( "Null ipojo header returned for factory: " + factory.getName() );
+        }
+
+        ManifestMetadataParser parser = new ManifestMetadataParser();
+        parser.parseHeader( ipojoHeader );
+
+        Element[] componentMetas = parser.getComponentsMetadata();
+
+        for ( Element componentMeta : componentMetas )
+        {
+            String compName = componentMeta.getAttribute( "name" );
+            if ( compName.equals( factory.getName() ) )
+            {
+                Element[] adsElements = componentMeta.getElements(
+                    ADSConstants.ADS_COMPONENT_HANDLER_NAME,
+                    ADSConstants.ADS_COMPONENT_HANDLER_NS );
+
+                if ( adsElements == null || adsElements.length == 0 )
+                {
+                    throw new ParseException( "ADSComponent element couldn't be found for factory: "
+                        + factory.getName() );
+                }
+
+                return adsElements[0].getAttribute( "componentType" );
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Generates a new ADSComponent with its schema and cache handle. 
+     *
+     * @param componentType Type of a component being created
+     * @param factory a factory reference to create a ADSComponent for.
+     * @return
+     */
+    private ADSComponent generateADSComponent( String componentType, Factory factory )
+    {
+        ADSComponent component = new ADSComponent( componentManager );
+
+        component.setFactory( factory );
+        component.setComponentType( componentType );
+        component.setComponentName( ADSComponentHelper.getComponentName( component.getFactory() ) );
+        component.setComponentVersion( ADSComponentHelper.getComponentVersion( component.getFactory() ) );
+        component.setCacheHandle( cacheManager.getCacheHandle( component ) );
+
+        return component;
+    }
+
+
+    /**
+     * Cache the ADSComponent existence on ApacheDS with all of its DIT entries. And then release it from hub.
+     *
+     * @param leavingComp ADSComponent reference to cache and release.
+     */
+    private void cacheAndReleaseADSComponent( ADSComponent leavingComp )
+    {
+
+    }
+
+
+    /**
+     * Registers a HubListener for specified component type.
+     *
+     * @param componentType component type to get notifications for.
+     * @param listener HubListener implementation
+     */
+    public void registerListener( String componentType, HubListener listener )
+    {
+        eventManager.registerListener( componentType, listener );
+    }
+
+
+    /**
+     * Removes the specified listener from the notification chain.
+     *
+     * @param listener HubListener implementation
+     */
+    public void removeListener( HubListener listener )
+    {
+        eventManager.removeListener( listener );
+    }
+}

Added: 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=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentManager.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentManager.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,328 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.server.component.hub;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+import java.util.Queue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.apache.directory.server.component.ADSComponent;
+import org.apache.directory.server.component.instance.ADSComponentInstance;
+import org.apache.directory.server.component.instance.ADSComponentInstanceGenerator;
+import org.apache.directory.server.component.schema.ComponentSchemaGenerator;
+import org.apache.directory.server.core.api.LdapCoreSessionConnection;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.model.message.AddRequest;
+import org.apache.directory.shared.ldap.model.message.AddRequestImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Provides methods to create instances, deploy schemas and create instance entries on DIT.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ComponentManager
+{
+    /*
+     * Logger
+     */
+    private final Logger LOG = LoggerFactory.getLogger( ComponentManager.class );
+
+    /*
+     * Schema generators
+     */
+    private Dictionary<String, ComponentSchemaGenerator> schemaGenerators;
+
+    /*
+     * Instance Generators
+     */
+    private Dictionary<String, ADSComponentInstanceGenerator> instanceGenerators;
+
+    /*
+     * Cache Manager
+     */
+    private ComponentCacheManager cacheManager;
+
+    /*
+     * Ldif deferred writing queue.
+     */
+    private Queue<LdifEntry> ldifQueue = new LinkedBlockingQueue<LdifEntry>();
+
+    /*
+     * Connection reference to access ApacheDS
+     */
+    private LdapCoreSessionConnection ldapConn;
+
+
+    public ComponentManager( ComponentCacheManager cacheManager )
+    {
+        schemaGenerators = new Hashtable<String, ComponentSchemaGenerator>();
+        instanceGenerators = new Hashtable<String, ADSComponentInstanceGenerator>();
+        this.cacheManager = cacheManager;
+    }
+
+
+    /**
+     * Used to set internal connection. All write operations to the schema will be deferred
+     * until reference is set.
+     *
+     * @param conn LdapCoreSessionConnection reference to set.
+     */
+    public synchronized void setConnectionReady( LdapCoreSessionConnection conn )
+    {
+        ldapConn = conn;
+
+        flushCache();
+    }
+
+
+    /**
+     * Adds new schema generator for specified component type.
+     * Keeps the first added generator as default.
+     *
+     * @param componentType component type to register schema generator
+     * @param generator schema generator instance
+     */
+    public void addSchemaGenerator( String componentType, ComponentSchemaGenerator generator )
+    {
+        if ( schemaGenerators.get( componentType ) == null )
+        {
+            schemaGenerators.put( componentType, generator );
+        }
+    }
+
+
+    /**
+     * Adds new instance generator for specified component type.
+     * Keeps the first added generator as default.
+     *
+     * @param componentType component type to register instance generator
+     * @param generator instance generator instance
+     */
+    public void addInstanceGenerator( String componentType, ADSComponentInstanceGenerator generator )
+    {
+        if ( instanceGenerators.get( componentType ) == null )
+        {
+            instanceGenerators.put( componentType, generator );
+        }
+    }
+
+
+    /**
+     * Create and return the instance of the given component
+     * using ADSComponentInstanceGenerator registered for its type.
+     *
+     * @param component ADSComponent reference to instantiate
+     * @return created ADSComponentInstance reference
+     */
+    public ADSComponentInstance createInstance( ADSComponent component, Properties properties )
+    {
+        ADSComponentInstanceGenerator generator = instanceGenerators.get( component.getComponentType() );
+        if ( generator != null )
+        {
+            ADSComponentInstance instance = generator.createInstance( component, properties );
+
+            if ( instance != null )
+            {
+                component.addInstance( instance );
+            }
+
+            return instance;
+        }
+        else
+        {
+            LOG.info( "No instance generator found for component:" + component );
+            return null;
+        }
+    }
+
+
+    /**
+     * Loads the schema of the component into ApacheDS for
+     * further instance entry mappings and configuration hooks.
+     *
+     * @param component ADSComponent reference for schema loading
+     */
+    public void loadComponentSchema( ADSComponent component )
+    {
+        try
+        {
+            checkAndGenerateBaseSchema( component );
+            if ( component.getSchema().getSchemaElements() != null )
+            {
+                loadLdifs( component.getSchema().getSchemaElements() );
+            }
+        }
+        catch ( LdapException exc )
+        {
+            LOG.info( "An error occured while loading schema for component: " + component );
+        }
+    }
+
+
+    /**
+     * Load LdifEntry list into ApacheDS.
+     * Loads them into the cache if the connection is not set yet.
+     *
+     * @param ldifs LdifEntry list to load.
+     * @throws LdapException
+     */
+    private synchronized void loadLdifs( List<LdifEntry> ldifs ) throws LdapException
+    {
+        if ( ldapConn == null )
+        {
+            for ( LdifEntry ldif : ldifs )
+            {
+                ldifQueue.add( ldif );
+            }
+        }
+        else
+        {
+            for ( LdifEntry ldif : ldifs )
+            {
+                AddRequest addReq = new AddRequestImpl();
+                addReq.setEntry( ldif.getEntry() );
+
+                ldapConn.add( addReq );
+            }
+        }
+    }
+
+
+    /**
+     * Loads all the cached entries into ApacheDS
+     *
+     */
+    private void flushCache()
+    {
+        List<LdifEntry> cache = new ArrayList<LdifEntry>();
+
+        for ( LdifEntry ldif : ldifQueue )
+        {
+            cache.add( ldif );
+        }
+
+        try
+        {
+            loadLdifs( cache );
+        }
+        catch ( LdapException exc )
+        {
+            LOG.info( "Error while flushing the Ldif cache." );
+        }
+    }
+
+
+    /**
+     * Checks for the base schema which will hold the schema elements for the
+     * given component. 
+     * 
+     * Generates an empty one, if none is exist.
+     *
+     * @param component ADSComponent reference to check base schema against.
+     * @throws LdapException
+     */
+    private void checkAndGenerateBaseSchema( ADSComponent component ) throws LdapException
+    {
+        String parentSchemaDn = "cn=" + component.getSchema().getParentSchemaName() + ",ou=schema";
+        String attribsDn = "ou=attributeTypes," + parentSchemaDn;
+        String ocsDn = "ou=objectClasses," + parentSchemaDn;
+
+        boolean schemaExists = ldapConn.exists( parentSchemaDn );
+        boolean attribsExists = ldapConn.exists( attribsDn );
+        boolean ocsExists = ldapConn.exists( ocsDn );
+
+        if ( schemaExists && attribsExists && ocsExists )
+        {
+            return;
+        }
+
+        List<LdifEntry> ldifs = new ArrayList<LdifEntry>();
+
+        if ( !schemaExists )
+        {
+            ldifs.add( new LdifEntry( parentSchemaDn,
+                "objectClass:metaSchema",
+                "objectClass:top",
+                "cn:" + component.getSchema().getParentSchemaName(),
+                "m-dependencies: system",
+                "m-dependencies: core" ) );
+        }
+
+        if ( !attribsExists )
+        {
+            ldifs.add( new LdifEntry( attribsDn,
+                "objectclass:organizationalUnit",
+                "objectClass:top",
+                "ou:attributetypes" ) );
+        }
+
+        if ( ocsExists )
+        {
+            ldifs.add( new LdifEntry( ocsDn,
+                "objectclass:organizationalUnit",
+                "objectClass:top",
+                "ou:objectClasses" ) );
+        }
+
+        loadLdifs( ldifs );
+    }
+
+
+    /**
+     * Deletes the schema elements for the component.
+     *
+     * @param component ADSComponent reference to delete its schema elements from ApacheDS
+     */
+    public void deleteSchemaElements( ADSComponent component )
+    {
+        List<LdifEntry> schemaElements = component.getSchema().getSchemaElements();
+
+        //We reverse the order here for deletion.
+        //List was originally in add order.
+        Collections.reverse( schemaElements );
+
+        if ( ldapConn == null )
+        {
+            return;
+        }
+        try
+        {
+            for ( LdifEntry ldif : schemaElements )
+            {
+                ldapConn.delete( ldif.getDn() );
+            }
+        }
+        catch ( LdapException exc )
+        {
+            LOG.info( "Error occured while deleting component's schema elements" );
+        }
+    }
+
+}

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/UserComponentInstanceGenerator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/UserComponentInstanceGenerator.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/UserComponentInstanceGenerator.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/UserComponentInstanceGenerator.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,96 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.component.hub.client.user;
+
+
+import java.util.Properties;
+
+import org.apache.directory.server.component.ADSComponent;
+import org.apache.directory.server.component.instance.ADSComponentInstance;
+import org.apache.directory.server.component.instance.ADSComponentInstanceGenerator;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Class that generates an instances of "user" typed components.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class UserComponentInstanceGenerator implements ADSComponentInstanceGenerator
+{
+
+    private final Logger LOG = LoggerFactory.getLogger( UserComponentSchemaGenerator.class );
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.directory.server.component.instance.ADSComponentInstanceGenerator#createInstance(org.apache.directory.server.component.ADSComponent)
+     */
+    @Override
+    public ADSComponentInstance createInstance( ADSComponent component, Properties properties )
+    {
+        if ( properties == null && component.getDefaultConfiguration() == null )
+        {
+            component.setDefaultConfiguration( extractDefaultConfiguration( component ) );
+            properties = component.getDefaultConfiguration();
+        }
+
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    @Override
+    public Properties extractDefaultConfiguration( ADSComponent component )
+    {
+        Properties defaultConf = new Properties();
+
+        for ( PropertyDescription prop : component.getFactory().getComponentDescription().getProperties() )
+        {
+
+            //Must be lower case, alphanumeric+'-' only
+            String propname = prop.getName();
+
+            String propvalue = prop.getValue();
+            String proptype = prop.getType();
+
+            if ( !( proptype.equals( "int" ) || proptype.equals( "java.lang.String" ) || proptype
+                .equals( "boolean" ) ) )
+            {
+                LOG.info( "Property found with an incompatible type:  "
+                    + propname + ":" + proptype );
+                continue;
+            }
+
+            if ( propvalue != null )
+            {
+                defaultConf.put( propname, propvalue );
+            }
+
+        }
+
+        return defaultConf;
+
+    }
+
+}

Added: directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/UserComponentSchemaGenerator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/UserComponentSchemaGenerator.java?rev=1204918&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/UserComponentSchemaGenerator.java (added)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/client/user/UserComponentSchemaGenerator.java Tue Nov 22 11:03:26 2011
@@ -0,0 +1,160 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.component.hub.client.user;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.server.component.ADSComponentHelper;
+import org.apache.directory.server.component.ADSConstants;
+import org.apache.directory.server.component.schema.ADSComponentSchema;
+import org.apache.directory.server.component.schema.ComponentOIDGenerator;
+import org.apache.directory.server.component.schema.ComponentSchemaGenerator;
+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.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class UserComponentSchemaGenerator implements ComponentSchemaGenerator
+{
+    private final Logger LOG = LoggerFactory.getLogger( UserComponentSchemaGenerator.class );
+
+    private final String ADS_USER_COMPONENTS_SCHEMA_DN = "cn=usercomponents,ou=schema";
+    private final String ADS_USER_COMPONENTS_SCHEMA_NAME = "usercomponents";
+
+
+    @Override
+    public ADSComponentSchema generateADSComponentSchema( Factory componentFactory )
+    {
+        List<LdifEntry> schemaElements = new ArrayList<LdifEntry>();
+
+        String componentName = ADSComponentHelper.getComponentName( componentFactory );
+
+        String attribsDn = "ou=attributeTypes," + ADS_USER_COMPONENTS_SCHEMA_DN;
+        String ocsDn = "ou=objectClasses," + ADS_USER_COMPONENTS_SCHEMA_DN;
+
+        //Will hold the m-must attributes while iterating over properties of the component
+        List<String> ocAttribs = new ArrayList<String>();
+
+        // Creating schema elements with proper order and pushing them into the list
+        try
+        {
+
+            String componentBaseOID = ComponentOIDGenerator.generateComponentOID();
+
+            for ( PropertyDescription prop : componentFactory.getComponentDescription().getProperties() )
+            {
+
+                //Must be lower case, alphanumeric+'-' only
+                String propname = prop.getName();
+
+                String proptype = prop.getType();
+                String propoid = ComponentOIDGenerator.generateAttribOID( componentBaseOID );
+                String propdn = "m-oid=" + propoid + "," + attribsDn;
+
+                if ( !( proptype.equals( "int" ) || proptype.equals( "java.lang.String" ) || proptype
+                    .equals( "boolean" ) ) )
+                {
+                    LOG.info( "Property found with an incompatible type:  "
+                        + propname + ":" + proptype );
+                    continue;
+                }
+
+                String syntax = ADSConstants.syntaxMappings.get( proptype );
+                String equality = ADSConstants.equalityMappings.get( proptype );
+                String ordering = ADSConstants.orderingMappings.get( proptype );
+                String substr = ADSConstants.substringMappings.get( proptype );
+
+                schemaElements.add( new LdifEntry( propdn,
+                    "objectclass:metaAttributeType",
+                    "objectclass:metaTop",
+                    "objectclass:top",
+                    "m-oid:" + propoid,
+                    "m-name:" + propname,
+                    "m-description:Property of component type " + componentName,
+                    "m-equality:" + equality,
+                    "m-ordering:" + ordering,
+                    "m-substr:" + substr,
+                    "m-syntax:" + syntax,
+                    "m-length:0",
+                    "m-singleValue:TRUE" ) );
+
+                if ( prop.isMandatory() )
+                {
+                    ocAttribs.add( "m-must:" + propname );
+                }
+                else
+                {
+                    ocAttribs.add( "m-may:" + propname );
+                }
+
+            }
+
+            schemaElements.add( new LdifEntry( ocsDn,
+                "objectclass:organizationalUnit",
+                "objectClass:top",
+                "ou:objectClasses" ) );
+
+            String ocoid = ComponentOIDGenerator.generateOCOID( componentBaseOID );
+            String ocDn = "m-oid=" + ocoid + "," + ocsDn;
+
+            ocAttribs.add( 0, "m-may:cached" );
+            ocAttribs.add( 0, "m-must:ins" );
+            ocAttribs.add( 0, "m-must:active" );
+            ocAttribs.add( 0, "m-supObjectClass: top" );
+            ocAttribs.add( 0, "m-description:Object Class for generating instances of:" + componentName );
+            ocAttribs.add( 0, "m-name:" + componentName );
+            ocAttribs.add( 0, "m-oid:" + ocoid );
+            ocAttribs.add( 0, "objectclass: top" );
+            ocAttribs.add( 0, "objectclass: metaTop" );
+            ocAttribs.add( 0, "objectclass: metaObjectClass" );
+
+            schemaElements.add( new LdifEntry( ocDn, ocAttribs.toArray() ) );
+
+        }
+        catch ( LdapInvalidAttributeValueException e )
+        {
+            LOG.info( "ADSSchemaManager#generateSchema:  Error(LdapInvalidAttributeValueException) while creating LdifEntry for:  "
+                + componentFactory );
+        }
+        catch ( LdapInvalidDnException e )
+        {
+            LOG.info( "ADSSchemaManager#generateSchema:  Error(LdapInvalidDnException) while creating LdifEntry for:  "
+                + componentFactory );
+        }
+        catch ( LdapLdifException e )
+        {
+            LOG.info( "ADSSchemaManager#generateSchema:  Error(LdapLdifException) while creating LdifEntry for:  "
+                + componentFactory );
+        }
+
+        ADSComponentSchema compSchema = new ADSComponentSchema( ADS_USER_COMPONENTS_SCHEMA_NAME,
+            schemaElements, componentName );
+
+        return compSchema;
+    }
+
+}