directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gokt...@apache.org
Subject svn commit: r1336671 [2/2] - in /directory/apacheds/branches/apacheds-osgi/hub/core: ./ 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/main/j...
Date Thu, 10 May 2012 13:27:48 GMT
Added: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/ApacheDSConfigStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/ApacheDSConfigStore.java?rev=1336671&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/ApacheDSConfigStore.java (added)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/ApacheDSConfigStore.java Thu May 10 13:27:47 2012
@@ -0,0 +1,275 @@
+package org.apache.directory.server.hub.core.store;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.directory.server.core.api.schema.SchemaPartition;
+import org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition;
+import org.apache.directory.server.hub.api.ComponentHub;
+import org.apache.directory.server.hub.api.HubStore;
+import org.apache.directory.server.hub.api.component.DCConfiguration;
+import org.apache.directory.server.hub.api.component.DCProperty;
+import org.apache.directory.server.hub.api.component.DirectoryComponent;
+import org.apache.directory.server.hub.api.exception.HubStoreException;
+import org.apache.directory.server.hub.api.exception.StoreNotValidException;
+import org.apache.directory.server.hub.api.meta.DCMetadataDescriptor;
+import org.apache.directory.server.hub.api.meta.DCPropertyDescription;
+import org.apache.directory.server.hub.api.meta.DCPropertyType;
+import org.apache.directory.shared.ldap.model.csn.CsnFactory;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+
+
+public class ApacheDSConfigStore implements HubStore
+{
+    private ComponentHub hub;
+
+    private SchemaPartition schemaPartition;
+    private SingleFileLdifPartition configPartition;
+
+    private StoreConfigManager configStoreManager;
+    private StoreSchemaManager schemaStoreManager;
+
+    private SchemaManager schemaManager;
+
+    public static CsnFactory csnFactory;
+
+
+    public ApacheDSConfigStore( SchemaPartition schemaPartition, SingleFileLdifPartition configPartition, int replicaId )
+    {
+        this.schemaPartition = schemaPartition;
+        this.configPartition = configPartition;
+        this.schemaManager = schemaPartition.getSchemaManager();
+
+        csnFactory = new CsnFactory( replicaId );
+    }
+
+
+    @Override
+    public void init( ComponentHub hub ) throws StoreNotValidException
+    {
+        this.hub = hub;
+
+        configStoreManager = new StoreConfigManager( hub );
+        schemaStoreManager = new StoreSchemaManager( hub );
+
+        configStoreManager.init( configPartition );
+        schemaStoreManager.init( schemaPartition );
+    }
+
+
+    @Override
+    public List<DCMetadataDescriptor> getMetadataDescriptors() throws HubStoreException
+    {
+        return configStoreManager.getMetadatas();
+    }
+
+
+    @Override
+    public List<DirectoryComponent> getComponents() throws HubStoreException
+    {
+        try
+        {
+            return configStoreManager.getComponents( new Dn( schemaManager, "ou=config" ), SearchScope.SUBTREE );
+        }
+        catch ( LdapInvalidDnException e )
+        {
+            e.printStackTrace();
+
+            return null;
+        }
+    }
+
+
+    @Override
+    public void installMetadataDescriptor( DCMetadataDescriptor metadata ) throws HubStoreException
+    {
+        try
+        {
+            List<DCPropertyDescription> configurables = extractConfigurableDCs( metadata );
+
+            schemaStoreManager.installMetadata( metadata );
+
+            configStoreManager.installMetadata( metadata );
+
+        }
+        catch ( LdapException e )
+        {
+            throw new HubStoreException( "Error occured while installing metadata:" + metadata.getMetadataPID(), e );
+        }
+
+    }
+
+
+    @Override
+    public void updateMetadataDescriptor( DCMetadataDescriptor oldMetadata, DCMetadataDescriptor newMetadata )
+        throws HubStoreException
+    {
+        List<DCPropertyDescription> oldConfigurables = extractConfigurableDCs( oldMetadata );
+        List<DCPropertyDescription> newconfigurables = extractConfigurableDCs( newMetadata );
+
+        List<DCPropertyDescription> dropped = new ArrayList<DCPropertyDescription>();
+        List<DCPropertyDescription> added = new ArrayList<DCPropertyDescription>();
+
+        for ( DCPropertyDescription pd : oldConfigurables )
+        {
+            DCPropertyDescription newDesc = newMetadata.getPropertyDescription( pd.getName() );
+            if ( newDesc == null )
+            {
+                dropped.add( pd );
+            }
+            else
+            {
+                if ( !( pd.getType().equals( newDesc.getType() ) ) )
+                {
+                    dropped.add( pd );
+                    added.add( newDesc );
+                }
+            }
+        }
+
+        for ( DCPropertyDescription pd : newconfigurables )
+        {
+            if ( oldMetadata.getPropertyDescription( pd.getName() ) == null )
+            {
+                added.add( pd );
+            }
+        }
+
+        try
+        {
+            List<DirectoryComponent> attachedComponents = hub.getDCRegistry().getComponents(
+                oldMetadata.getMetadataPID() );
+            if ( attachedComponents != null )
+            {
+                for ( DCPropertyDescription dropping : dropped )
+                {
+                    for ( DirectoryComponent component : attachedComponents )
+                    {
+                        configStoreManager.dropPropertyFromEntry( component, dropping.getName() );
+                    }
+                }
+            }
+
+            schemaStoreManager.uninstallAttributes( dropped );
+            schemaStoreManager.installAttributes( added );
+
+            schemaStoreManager.updateOC( newMetadata );
+
+            if ( attachedComponents != null )
+            {
+                for ( DCPropertyDescription adding : added )
+                {
+                    for ( DirectoryComponent component : attachedComponents )
+                    {
+                        configStoreManager.addPropertyToEntry( component,
+                            new DCProperty( adding.getName(), adding.getDefaultValue() ) );
+                    }
+                }
+            }
+
+            configStoreManager.uninstallMetadata( oldMetadata );
+            configStoreManager.installMetadata( newMetadata );
+        }
+        catch ( LdapException e )
+        {
+            throw new HubStoreException( "Error occured while updating store against new metadata"
+                + newMetadata.getMetadataPID(), e );
+        }
+    }
+
+
+    @Override
+    public void uninstallMetadataDescriptor( DCMetadataDescriptor metadata ) throws HubStoreException
+    {
+        try
+        {
+            configStoreManager.uninstallMetadata( metadata );
+
+            List<DCPropertyDescription> configurables = extractConfigurableDCs( metadata );
+
+            schemaStoreManager.uninstallOC( metadata.getMetadataPID() );
+            schemaStoreManager.uninstallAttributes( configurables );
+        }
+        catch ( LdapException e )
+        {
+            throw new HubStoreException( "Error while uninstalling metadata:" + metadata.getMetadataPID(), e );
+        }
+
+    }
+
+
+    @Override
+    public void installComponent( DirectoryComponent component ) throws HubStoreException
+    {
+        try
+        {
+            configStoreManager.installComponent( component );
+        }
+        catch ( LdapException e )
+        {
+            throw new HubStoreException( "Store threw excepton while adding component:" + component.getComponentPID(),
+                e );
+        }
+    }
+
+
+    @Override
+    public void updateComponent( DirectoryComponent component, DCConfiguration newConfiguration )
+        throws HubStoreException
+    {
+        try
+        {
+            configStoreManager.updateComponent( component, newConfiguration );
+        }
+        catch ( LdapException e )
+        {
+            throw new HubStoreException(
+                "Store threw excepton while updating component:" + component.getComponentPID(),
+                e );
+        }
+    }
+
+
+    @Override
+    public void uninstallComponent( DirectoryComponent component ) throws HubStoreException
+    {
+        try
+        {
+            configStoreManager.uninstallComponent( component );
+        }
+        catch ( LdapException e )
+        {
+            throw new HubStoreException(
+                "Store threw excepton while deleting component:" + component.getComponentPID(),
+                e );
+        }
+    }
+
+
+    public List<DCPropertyDescription> extractConfigurableDCs( DCMetadataDescriptor metadata )
+    {
+        List<DCPropertyDescription> pds = new ArrayList<DCPropertyDescription>();
+
+        for ( DCPropertyDescription pd : metadata.getPropertyDescriptons() )
+        {
+            if ( pd.getPropertyContext() == DCPropertyType.INJECTION )
+            {
+                continue;
+            }
+
+            if ( pd.getPropertyContext() == DCPropertyType.CONSTANT )
+            {
+                continue;
+            }
+
+            pds.add( pd );
+        }
+
+        return pds;
+    }
+
+}

Added: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/OIDManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/OIDManager.java?rev=1336671&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/OIDManager.java (added)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/OIDManager.java Thu May 10 13:27:47 2012
@@ -0,0 +1,179 @@
+package org.apache.directory.server.hub.core.store;
+
+
+import java.util.Hashtable;
+
+import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
+import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.schema.SchemaPartition;
+import org.apache.directory.server.hub.api.exception.StoreNotValidException;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapNoSuchObjectException;
+import org.apache.directory.shared.ldap.model.filter.PresenceNode;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+
+
+public class OIDManager
+{
+
+    private Hashtable<String, Integer> metaOCBases = new Hashtable<String, Integer>();
+    private Integer maxOCOIDBase = 0;
+
+    private Hashtable<String, Integer> metaAttributeBases = new Hashtable<String, Integer>();
+    private Integer maxAttributeOIDBase = 0;
+
+
+    public void init( SchemaPartition schemaPartition ) throws StoreNotValidException
+    {
+        metaOCBases.clear();
+        metaAttributeBases.clear();
+        
+        EntryFilteringCursor cursor = null;
+        
+
+        try
+        {
+            AttributeType oidAttrib = schemaPartition.getSchemaManager().getAttributeType( "m-oid" );
+            AttributeType nameAttrib = schemaPartition.getSchemaManager().getAttributeType( "m-name" );
+
+            SearchOperationContext soc = new SearchOperationContext( null );
+            soc.setScope( SearchScope.SUBTREE );
+            AttributeType moidat = schemaPartition.getSchemaManager().getAttributeType( "m-oid" );
+            soc.setFilter( new PresenceNode( moidat ) );
+            // Set to all/none, because individual names will require CoreSession in OperationContext which we don't have.
+            soc.setReturningAttributes( new String[]
+                { SchemaConstants.ALL_USER_ATTRIBUTES } );
+
+            Dn ocsDn = new Dn( schemaPartition.getSchemaManager(),
+                SchemaConstants.OBJECT_CLASSES_PATH, StoreSchemaManager.METADATAS_SCHEMA_BASE
+                , SchemaConstants.OU_SCHEMA );
+
+            soc.setDn( ocsDn );
+
+            try
+            {
+                cursor = schemaPartition.search( soc );
+
+                int baseOCOIDLen = StoreSchemaManager.OID_BASE.length() + ".2".length();
+
+                while ( cursor.next() )
+                {
+                    Entry currentEntry = cursor.get();
+
+                    Attribute oid = currentEntry.get( oidAttrib );
+                    Attribute name = currentEntry.get( nameAttrib );
+
+                    String _ocBase = oid.getString().substring( baseOCOIDLen + 1 );
+                    Integer ocBase = Integer.parseInt( _ocBase );
+
+                    metaOCBases.put( name.getString(), ocBase );
+
+                    maxOCOIDBase = ( ocBase > maxOCOIDBase ) ? ocBase : maxOCOIDBase;
+                }
+            }
+            catch ( LdapNoSuchObjectException e )
+            {
+                // No OC installed yet.
+            }
+
+            Dn attribsDn = new Dn( schemaPartition.getSchemaManager(),
+                SchemaConstants.ATTRIBUTE_TYPES_PATH, StoreSchemaManager.METADATAS_SCHEMA_BASE
+                , SchemaConstants.OU_SCHEMA );
+
+            soc.setDn( attribsDn );
+
+            try
+            {
+                cursor = schemaPartition.search( soc );
+
+                int baseAttribOIDLen = StoreSchemaManager.OID_BASE.length() + ".1".length();
+
+                while ( cursor.next() )
+                {
+                    Entry currentEntry = cursor.get();
+
+                    Attribute oid = currentEntry.get( oidAttrib );
+                    Attribute name = currentEntry.get( nameAttrib );
+
+                    String _attribBase = oid.getString().substring( baseAttribOIDLen + 1 );
+                    Integer attribBase = Integer.parseInt( _attribBase );
+
+                    metaAttributeBases.put( name.getString(), attribBase );
+
+                    maxAttributeOIDBase = ( attribBase > maxAttributeOIDBase ) ? attribBase : maxAttributeOIDBase;
+                }
+            }
+            catch ( LdapNoSuchObjectException e )
+            {
+                // No attrib installed yet
+            }
+        }
+        catch ( Exception e )
+        {
+            throw new StoreNotValidException( "SchemaPartition couldn't be parsed for OID assignments", e );
+        }
+        finally
+        {
+            if ( cursor != null )
+            {
+                try
+                {
+                    cursor.close();
+                }
+                catch ( Exception e )
+                {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+
+    public String getAttributeOID( String propertyName )
+    {
+        Integer attributeBase = metaAttributeBases.get( propertyName );
+        if ( attributeBase == null )
+        {
+            return null;
+        }
+
+        return StoreSchemaManager.OID_BASE + ".1." + attributeBase;
+    }
+
+
+    public String getOCBase( String metaPID )
+    {
+        Integer ocBase = metaOCBases.get( metaPID );
+        if ( ocBase == null )
+        {
+            return null;
+        }
+
+        return StoreSchemaManager.OID_BASE + ".2." + ocBase;
+    }
+
+
+    public String generateNewOCOID( String metaPID )
+    {
+        Integer ocBase = ( ++maxOCOIDBase );
+
+        metaOCBases.put( metaPID, ocBase );
+
+        return StoreSchemaManager.OID_BASE + ".2." + ocBase;
+    }
+
+
+    public String generateNewAttributeOID( String propertyName )
+    {
+        Integer attribBase = ( ++maxAttributeOIDBase );
+
+        metaAttributeBases.put( propertyName, attribBase );
+
+        return StoreSchemaManager.OID_BASE + ".1." + attribBase;
+    }
+}

Added: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreConfigManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreConfigManager.java?rev=1336671&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreConfigManager.java (added)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreConfigManager.java Thu May 10 13:27:47 2012
@@ -0,0 +1,609 @@
+package org.apache.directory.server.hub.core.store;
+
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.UUID;
+
+import javax.naming.directory.SearchControls;
+
+import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition;
+import org.apache.directory.server.hub.api.ComponentHub;
+import org.apache.directory.server.hub.api.component.DCConfiguration;
+import org.apache.directory.server.hub.api.component.DCProperty;
+import org.apache.directory.server.hub.api.component.DirectoryComponent;
+import org.apache.directory.server.hub.api.component.DirectoryComponentConstants;
+import org.apache.directory.server.hub.api.exception.StoreNotValidException;
+import org.apache.directory.server.hub.api.meta.DCMetadataDescriptor;
+import org.apache.directory.server.hub.api.meta.DCPropertyDescription;
+import org.apache.directory.server.hub.api.meta.DCPropertyType;
+import org.apache.directory.server.xdbm.ForwardIndexEntry;
+import org.apache.directory.server.xdbm.IndexCursor;
+import org.apache.directory.server.xdbm.search.SearchEngine;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Modification;
+import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.model.entry.Value;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.filter.PresenceNode;
+import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.util.DateUtils;
+import org.osgi.framework.Version;
+
+
+public class StoreConfigManager
+{
+    private static final String CONFIG_BASE = "ou=meta,ou=config";
+    private static final String CONFIG_MD_BASE = "ou=handler-descriptions," + CONFIG_BASE;
+    private static final String CONFIG_PD_BASE = "ou=property-descriptions," + CONFIG_BASE;
+
+    private ComponentHub hub;
+    private SingleFileLdifPartition configPartition;
+    private SchemaManager schemaManager;
+
+    private StoreDCBuilder dcBuilder;
+
+
+    public StoreConfigManager( ComponentHub hub )
+    {
+        this.hub = hub;
+    }
+
+
+    public void init( SingleFileLdifPartition configPartition ) throws StoreNotValidException
+    {
+        this.configPartition = configPartition;
+        this.schemaManager = configPartition.getSchemaManager();
+        dcBuilder = new StoreDCBuilder( schemaManager );
+    }
+
+
+    public void installMetadata( DCMetadataDescriptor metadata ) throws LdapException
+    {
+
+        for ( DCPropertyDescription pd : metadata.getPropertyDescriptons() )
+        {
+            if ( pd.getPropertyContext() == DCPropertyType.CONSTANT )
+            {
+                continue;
+            }
+
+            installPropertyDescription( pd );
+        }
+
+        installMetaDescription( metadata );
+
+    }
+
+
+    public void uninstallMetadata( DCMetadataDescriptor metadata ) throws LdapException
+    {
+        for ( DCPropertyDescription pd : metadata.getPropertyDescriptons() )
+        {
+            if ( pd.getPropertyContext() == DCPropertyType.CONSTANT )
+            {
+                continue;
+            }
+
+            uninstallPropertyDescription( pd.getName() );
+        }
+
+        uninstallMetaDescription( metadata.getMetadataPID() );
+    }
+
+
+    public void installPropertyDescription( DCPropertyDescription propertyDescription ) throws LdapException
+    {
+        Entry pdEntry = buildPropertyDescriptionEntry( propertyDescription );
+
+        AddOperationContext addOp = new AddOperationContext( null, pdEntry.getDn(), pdEntry );
+
+        configPartition.add( addOp );
+    }
+
+
+    public void uninstallPropertyDescription( String propertyName ) throws LdapException
+    {
+        Dn pdDn = new Dn( schemaManager, StoreSchemaConstants.HUB_AT_PD_NAME, propertyName, CONFIG_PD_BASE );
+        Long entryId = configPartition.getEntryId( pdDn );
+        if ( entryId != null )
+        {
+            configPartition.delete( entryId );
+        }
+    }
+
+
+    public void installMetaDescription( DCMetadataDescriptor metadata ) throws LdapException
+    {
+        Entry mdEntry = buildComponentDescriptionEntry( metadata );
+
+        AddOperationContext addOp = new AddOperationContext( null, mdEntry.getDn(), mdEntry );
+
+        configPartition.add( addOp );
+    }
+
+
+    public void uninstallMetaDescription( String componentManagerPID ) throws LdapException
+    {
+        Dn pdDn = new Dn( schemaManager, StoreSchemaConstants.HUB_AT_MD_PID, componentManagerPID, CONFIG_MD_BASE );
+
+        Long entryId = configPartition.getEntryId( pdDn );
+        if ( entryId != null )
+        {
+            configPartition.delete( entryId );
+        }
+    }
+
+
+    public Entry buildPropertyDescriptionEntry( DCPropertyDescription propertyDescription ) throws LdapException
+    {
+        Dn pdDn = new Dn( schemaManager, StoreSchemaConstants.HUB_AT_PD_NAME, propertyDescription.getName(),
+            CONFIG_PD_BASE );
+
+        Entry pdEntry = new DefaultEntry( schemaManager, pdDn );
+
+        pdEntry.add( schemaManager.getAttributeType( "objectclass" ), "ads-property-descriptor" );
+        pdEntry.add( schemaManager.getAttributeType( "ads-pd-name" ), propertyDescription.getName() );
+        pdEntry.add( schemaManager.getAttributeType( "ads-pd-type" ), propertyDescription.getType() );
+        pdEntry.add( schemaManager.getAttributeType( "ads-pd-context" ), propertyDescription.getPropertyContext()
+            .name() );
+        pdEntry.add( schemaManager.getAttributeType( "ads-pd-defaultvalue" ), propertyDescription.getDefaultValue() );
+        pdEntry.add( schemaManager.getAttributeType( "ads-pd-description" ), propertyDescription.getDescription() );
+        pdEntry.add( schemaManager.getAttributeType( "ads-pd-containerFor" ), propertyDescription.getContainerFor() );
+        pdEntry.add( schemaManager.getAttributeType( "ads-pd-mandatory" ),
+            ( propertyDescription.isMandatory() ) ? "TRUE" : "FALSE" );
+
+        pdEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+        pdEntry.add( SchemaConstants.ENTRY_CSN_AT, ApacheDSConfigStore.csnFactory.newInstance().toString() );
+        pdEntry.add( SchemaConstants.CREATORS_NAME_AT, StoreSchemaConstants.SYSTEM_ADMIN_DN );
+        pdEntry.add( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+        return pdEntry;
+    }
+
+
+    public Entry buildComponentDescriptionEntry( DCMetadataDescriptor metadata ) throws LdapException
+    {
+        Dn mdDn = new Dn( schemaManager, StoreSchemaConstants.HUB_AT_MD_PID, metadata.getMetadataPID(),
+            CONFIG_MD_BASE );
+
+        Entry mdEntry = new DefaultEntry( schemaManager, mdDn );
+
+        mdEntry.add( schemaManager.getAttributeType( "objectclass" ), "ads-meta-descriptor" );
+        mdEntry.add( schemaManager.getAttributeType( "ads-meta-pid" ), metadata.getMetadataPID() );
+        mdEntry.add( schemaManager.getAttributeType( "ads-meta-version" ), metadata.getMetaVersion().toString() );
+        mdEntry.add( schemaManager.getAttributeType( "ads-meta-factory" ), ( metadata.isFactory() ) ? "TRUE" : "FALSE" );
+        mdEntry.add( schemaManager.getAttributeType( "ads-meta-classname" ), metadata.getClassName() );
+
+        for ( DCPropertyDescription pd : metadata.getPropertyDescriptons() )
+        {
+            if ( pd.getPropertyContext() == DCPropertyType.INJECTION )
+            {
+                continue;
+            }
+
+            mdEntry.add( schemaManager.getAttributeType( "ads-meta-property" ), pd.getName() );
+        }
+
+        for ( String iface : metadata.getImplementedInterfaces() )
+        {
+            mdEntry.add( schemaManager.getAttributeType( "ads-meta-implements" ), iface );
+        }
+
+        for ( String sclass : metadata.getExtendedClasses() )
+        {
+            mdEntry.add( schemaManager.getAttributeType( "ads-meta-extends" ), sclass );
+        }
+
+        mdEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+        mdEntry.add( SchemaConstants.ENTRY_CSN_AT, ApacheDSConfigStore.csnFactory.newInstance().toString() );
+        mdEntry.add( SchemaConstants.CREATORS_NAME_AT, StoreSchemaConstants.SYSTEM_ADMIN_DN );
+        mdEntry.add( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+        return mdEntry;
+    }
+
+
+    public void installComponent( DirectoryComponent component ) throws LdapException
+    {
+        Entry cEntry = buildComponentEntry( component );
+
+        AddOperationContext addOp = new AddOperationContext( null, cEntry.getDn(), cEntry );
+        configPartition.add( addOp );
+    }
+
+
+    public Entry buildComponentEntry( DirectoryComponent component ) throws LdapException
+    {
+        Dn componentDn = new Dn( schemaManager, component.getConfigLocation() );
+
+        Entry componentEntry = new DefaultEntry( schemaManager, componentDn );
+        componentEntry.add( schemaManager.getAttributeType( "objectclass" ), component.getComponentManagerPID() );
+        componentEntry.add( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_COMPONENT_NAME ),
+            component.getComponentName() );
+
+        Integer itemIndex = component.getConfiguration().getCollectionIndex();
+        if ( itemIndex != null )
+        {
+            componentEntry.add( schemaManager.getAttributeType( "objectclass" ),
+                StoreSchemaConstants.HUB_OC_COLLECTION_ITEM );
+            componentEntry.add( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_COLL_ITEM_INDEX ),
+                itemIndex.toString() );
+        }
+
+        DCMetadataDescriptor metadata = hub.getMetaRegistry()
+            .getMetadataDescriptor( component.getComponentManagerPID() );
+        for ( DCProperty prop : component.getConfiguration() )
+        {
+            DCPropertyDescription pd = metadata.getPropertyDescription( prop.getName() );
+            /*
+             * Which is the case when whether there is a error or 
+             * entry is a collection entry with item references(which is against the design)
+             */
+            if ( pd == null )
+            {
+                continue;
+            }
+
+            if ( pd.getPropertyContext() == DCPropertyType.INJECTION
+                || pd.getPropertyContext() == DCPropertyType.CONSTANT )
+            {
+                continue;
+            }
+
+            componentEntry.add( schemaManager.getAttributeType( prop.getName() ), prop.getValue() );
+
+        }
+
+        return componentEntry;
+    }
+
+
+    public void uninstallComponent( DirectoryComponent component ) throws LdapException
+    {
+        Dn removalDn = new Dn( schemaManager, component.getConfigLocation() );
+
+        Long entryID = configPartition.getEntryId( removalDn );
+        if ( entryID != null )
+        {
+            configPartition.delete( entryID );
+        }
+    }
+
+
+    // No meta change.
+    public void updateComponent( DirectoryComponent component, DCConfiguration newConfiguration ) throws LdapException
+    {
+        for ( DCProperty oldProp : component.getConfiguration() )
+        {
+            DCProperty newVersion = newConfiguration.getProperty( oldProp.getName() );
+
+            if ( newVersion == null )
+            {
+                dropPropertyFromEntry( component, oldProp.getName() );
+            }
+            else
+            {
+                if ( !( oldProp.getValue().equals( newVersion.getValue() ) ) )
+                {
+                    dropPropertyFromEntry( component, oldProp.getName() );
+                    addPropertyToEntry( component, newVersion );
+                }
+            }
+        }
+
+        for ( DCProperty newProp : newConfiguration )
+        {
+            if ( component.getConfiguration().getProperty( newProp.getName() ) == null )
+            {
+                addPropertyToEntry( component, newProp );
+            }
+        }
+    }
+
+
+    public void dropPropertyFromEntry( DirectoryComponent component, String propertyName ) throws LdapException
+    {
+        Dn componentDn = new Dn( schemaManager, component.getConfigLocation() );
+
+        ModifyOperationContext modOp = new ModifyOperationContext( null );
+        modOp.setDn( componentDn );
+        List<Modification> mods = new ArrayList<Modification>();
+        Modification removeMod = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, propertyName );
+        mods.add( removeMod );
+        modOp.setModItems( mods );
+
+        configPartition.modify( modOp );
+    }
+
+
+    public void addPropertyToEntry( DirectoryComponent component, DCProperty property ) throws LdapException
+    {
+        Dn componentDn = new Dn( schemaManager, component.getConfigLocation() );
+
+        ModifyOperationContext modOp = new ModifyOperationContext( null );
+        modOp.setDn( componentDn );
+        List<Modification> mods = new ArrayList<Modification>();
+        Attribute attrib = new DefaultAttribute( schemaManager.getAttributeType( property.getName() ),
+            property.getValue() );
+        Modification addMod = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attrib );
+        mods.add( addMod );
+        modOp.setModItems( mods );
+
+        configPartition.modify( modOp );
+    }
+
+
+    public List<DirectoryComponent> getComponents( Dn baseDn, SearchScope scope )
+    {
+        SearchEngine<Entry, Long> se = configPartition.getSearchEngine();
+
+        AttributeType adsInstanceAttrib = schemaManager
+            .getAttributeType( StoreSchemaConstants.HUB_AT_COMPONENT_NAME );
+
+        PresenceNode filter = new PresenceNode( adsInstanceAttrib );
+
+        IndexCursor<Long, Entry, Long> cursor = null;
+
+        List<DirectoryComponent> components = new ArrayList<DirectoryComponent>();
+
+        try
+        {
+            cursor = se.cursor( baseDn, AliasDerefMode.NEVER_DEREF_ALIASES, filter, scope );
+            while ( cursor.next() )
+            {
+                ForwardIndexEntry<Long, Long> forwardEntry = ( ForwardIndexEntry<Long, Long> ) cursor
+                    .get();
+
+                Entry entry = configPartition.lookup( forwardEntry.getId() );
+
+                DirectoryComponent component = dcBuilder.buildComponentFromEntry( entry );
+
+                if ( component == null )
+                {
+                    continue;
+                }
+
+                if ( component.getComponentManagerPID().startsWith( StoreSchemaConstants.HUB_OC_COLLECTION ) )
+                {
+                    List<DirectoryComponent> items = getComponents(
+                        new Dn( schemaManager, component.getConfigLocation() ), SearchScope.ONELEVEL );
+
+                    if ( items != null )
+                    {
+                        for ( DirectoryComponent item : items )
+                        {
+                            Integer itemIndex = item.getConfiguration().getCollectionIndex();
+                            if ( itemIndex != null )
+                            {
+                                String itemID = DirectoryComponentConstants.DC_PROP_ITEM_PREFIX
+                                    + item.getComponentPID();
+
+                                component.getConfiguration().addProperty(
+                                    new DCProperty( itemID, item.getComponentPID() ) );
+                            }
+                        }
+                    }
+                }
+
+                components.add( component );
+            }
+
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+            return components;
+        }
+        finally
+        {
+            if ( cursor != null )
+            {
+                try
+                {
+                    cursor.close();
+                }
+                catch ( Exception e )
+                {
+                    e.printStackTrace();
+                }
+            }
+        }
+
+        return components;
+    }
+
+
+    public List<DCMetadataDescriptor> getMetadatas()
+    {
+        SearchEngine<Entry, Long> se = configPartition.getSearchEngine();
+
+        PresenceNode filter = new PresenceNode( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_PD_NAME ) );
+
+        IndexCursor<Long, Entry, Long> cursor = null;
+
+        List<DCMetadataDescriptor> metadatas = new ArrayList<DCMetadataDescriptor>();
+        Hashtable<String, DCPropertyDescription> pdMap = new Hashtable<String, DCPropertyDescription>();
+
+        try
+        {
+            cursor = se.cursor( new Dn( schemaManager, CONFIG_PD_BASE ), AliasDerefMode.NEVER_DEREF_ALIASES, filter,
+                SearchScope.SUBTREE );
+
+            while ( cursor.next() )
+            {
+                ForwardIndexEntry<Long, Long> forwardEntry = ( ForwardIndexEntry<Long, Long> ) cursor
+                    .get();
+
+                Entry entry = configPartition.lookup( forwardEntry.getId() );
+
+                DCPropertyDescription pd = buildPropertyDescription( entry );
+                if ( pd != null )
+                {
+                    pdMap.put( pd.getName(), pd );
+                }
+            }
+
+            cursor.close();
+
+            filter = new PresenceNode( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_MD_PID ) );
+            cursor = se.cursor( new Dn( schemaManager, CONFIG_MD_BASE ), AliasDerefMode.NEVER_DEREF_ALIASES, filter,
+            		SearchScope.SUBTREE );
+
+            while ( cursor.next() )
+            {
+                ForwardIndexEntry<Long, Long> forwardEntry = ( ForwardIndexEntry<Long, Long> ) cursor
+                    .get();
+
+                Entry entry = configPartition.lookup( forwardEntry.getId() );
+
+                DCMetadataDescriptor md = buildMetaDescription( entry, pdMap );
+                if ( md != null )
+                {
+                    metadatas.add( md );
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+            return metadatas;
+        }
+        finally
+        {
+            if ( cursor != null )
+            {
+                try
+                {
+                    cursor.close();
+                }
+                catch ( Exception e )
+                {
+                    e.printStackTrace();
+                    return metadatas;
+                }
+            }
+        }
+
+        return metadatas;
+    }
+
+
+    private DCPropertyDescription buildPropertyDescription( Entry entry )
+    {
+        Attribute name = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_PD_NAME ) );
+        Attribute type = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_PD_TYPE ) );
+        Attribute defaultVal = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_PD_DEFAULTVAL ) );
+        Attribute desc = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_PD_DESCRIPTION ) );
+        Attribute mandatory = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_PD_MANDATORY ) );
+        Attribute container = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_PD_CONTAINERFOR ) );
+        Attribute context = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_PD_CONTEXT ) );
+
+        try
+        {
+            String pdDefaultValue = null;
+            if ( defaultVal != null )
+            {
+                pdDefaultValue = defaultVal.getString();
+            }
+
+            String containerFor = null;
+            if ( container != null )
+            {
+                containerFor = container.getString();
+            }
+
+            String pdDescription = null;
+            if ( desc != null )
+            {
+                pdDescription = desc.getString();
+            }
+
+            boolean isMandatory = Boolean.parseBoolean( mandatory.getString() );
+            DCPropertyType pdtype = DCPropertyType.valueOf( context.getString() );
+
+            DCPropertyDescription pd = new DCPropertyDescription( name.getString(), type.getString(),
+                pdDefaultValue, pdDescription, isMandatory, containerFor );
+
+            pd.setPropertyContext( pdtype );
+
+            return pd;
+        }
+        catch ( Exception e )
+        {
+            return null;
+        }
+
+    }
+
+
+    private DCMetadataDescriptor buildMetaDescription( Entry entry, Hashtable<String, DCPropertyDescription> pdMap )
+    {
+        Attribute pid = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_MD_PID ) );
+        Attribute version = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_MD_VERSION ) );
+        Attribute classname = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_MD_CLASSNAME ) );
+        Attribute extended = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_MD_EXTENDS ) );
+        Attribute implemented = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_MD_IMPLEMENTS ) );
+        Attribute props = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_MD_PROP ) );
+        Attribute factory = entry.get( schemaManager.getAttributeType( StoreSchemaConstants.HUB_AT_MD_FACTORY ) );
+
+        try
+        {
+            List<String> extendedList = new ArrayList<String>();
+            if ( extended != null )
+            {
+                for ( Value<?> val : extended )
+                {
+                    extendedList.add( val.getString() );
+                }
+            }
+
+            List<String> implementedList = new ArrayList<String>();
+            if ( implemented != null )
+            {
+                for ( Value<?> val : implemented )
+                {
+                    implementedList.add( val.getString() );
+                }
+            }
+
+            List<DCPropertyDescription> pds = new ArrayList<DCPropertyDescription>();
+            if ( props != null )
+            {
+                for ( Value<?> val : props )
+                {
+                    DCPropertyDescription pd = pdMap.get( val.getString() );
+                    if ( pd == null )
+                    {
+                        throw new Exception( "Non existing property description:" + val.getString() );
+                    }
+                    pds.add( pd );
+                }
+            }
+            boolean isFactory = Boolean.parseBoolean( factory.getString() );
+
+            return new DCMetadataDescriptor( pid.getString(), isFactory, new Version(
+                version.getString() ), classname.getString(),
+                implementedList.toArray( new String[0] ), extendedList.toArray( new String[0] ),
+                pds.toArray( new DCPropertyDescription[0] ) );
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+
+    }
+}

Added: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreDCBuilder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreDCBuilder.java?rev=1336671&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreDCBuilder.java (added)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreDCBuilder.java Thu May 10 13:27:47 2012
@@ -0,0 +1,97 @@
+package org.apache.directory.server.hub.core.store;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.directory.server.hub.api.component.DCConfiguration;
+import org.apache.directory.server.hub.api.component.DCProperty;
+import org.apache.directory.server.hub.api.component.DirectoryComponent;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Value;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.schema.ObjectClass;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+
+
+public class StoreDCBuilder
+{
+    private SchemaManager schemaManager;
+
+
+    public StoreDCBuilder( SchemaManager schemaManager )
+    {
+        this.schemaManager = schemaManager;
+    }
+
+
+    public DirectoryComponent buildComponentFromEntry( Entry componentEntry ) throws LdapException
+    {
+        String componentName = null;
+        String managerPID = null;
+        Integer collectionIndex = null;
+
+        Attribute ocAttrib = componentEntry.get( schemaManager.getAttributeType( "objectclass" ) );
+        for ( Value<?> val : ocAttrib )
+        {
+            String ocName = val.getString();
+            String ocOID = schemaManager.getObjectClassRegistry().getOidByName( ocName );
+
+            ObjectClass oc = schemaManager.getObjectClassRegistry().get( ocOID );
+
+            if ( oc.isStructural() )
+            {
+                managerPID = ocName;
+            }
+
+            if ( oc.isAuxiliary() )
+            {
+                if ( ocName.equals( StoreSchemaConstants.HUB_OC_COLLECTION_ITEM ) )
+                {
+                    collectionIndex = 0;
+                }
+            }
+        }
+
+        List<DCProperty> properties = new ArrayList<DCProperty>();
+
+        Collection<Attribute> attribs = componentEntry.getAttributes();
+        for ( Attribute attrib : attribs )
+        {
+            if ( attrib.getUpId().equals( StoreSchemaConstants.HUB_AT_COMPONENT_NAME.toLowerCase() ) )
+            {
+                componentName = attrib.getString();
+            }
+            else if ( attrib.getUpId().equals( StoreSchemaConstants.HUB_AT_COLL_ITEM_INDEX.toLowerCase() ) )
+            {
+                collectionIndex = Integer.parseInt( attrib.getString() );
+            }
+            else if ( attrib.getUpId().equals( SchemaConstants.ENTRY_UUID_AT.toLowerCase() )
+                || attrib.getUpId().equals( SchemaConstants.ENTRY_CSN_AT.toLowerCase() )
+                || attrib.getUpId().equals( SchemaConstants.CREATORS_NAME_AT.toLowerCase() )
+                || attrib.getUpId().equals( SchemaConstants.CREATE_TIMESTAMP_AT.toLowerCase() )
+                || attrib.getUpId().equals( SchemaConstants.OBJECT_CLASS_AT.toLowerCase() )
+                || attrib.getUpId().equals( SchemaConstants.MODIFIERS_NAME_AT.toLowerCase() )
+                || attrib.getUpId().equals( SchemaConstants.MODIFY_TIMESTAMP_AT.toCharArray() )
+                || attrib.getUpId().equals( SchemaConstants.ENTRY_PARENT_ID_AT ) )
+            {
+                continue;
+            }
+            else
+            {
+                properties.add( new DCProperty( attrib.getUpId(), attrib.getString() ) );
+            }
+        }
+
+        DCConfiguration componentConf = new DCConfiguration( properties );
+        componentConf.setCollectionIndex( collectionIndex );
+
+        DirectoryComponent component = new DirectoryComponent( managerPID, componentName, componentConf );
+        component.setConfigLocation( componentEntry.getDn().getName() );
+
+        return component;
+    }
+}

Added: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreSchemaConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreSchemaConstants.java?rev=1336671&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreSchemaConstants.java (added)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreSchemaConstants.java Thu May 10 13:27:47 2012
@@ -0,0 +1,38 @@
+package org.apache.directory.server.hub.core.store;
+
+
+public class StoreSchemaConstants
+{
+    public static final String SYSTEM_ADMIN_DN = "uid=admin,ou=system";
+
+    public static final String HUB_AT_COLL_CONTAINING = "ads-containing";
+    public static final String HUB_AT_COLL_ITEM_INDEX = "ads-itemindex";
+    public static final String HUB_AT_COMPONENT_NAME = "ads-instance";
+
+    public static final String HUB_AT_MD_PID = "ads-meta-pid";
+    public static final String HUB_AT_MD_VERSION = "ads-meta-version";
+    public static final String HUB_AT_MD_CLASSNAME = "ads-meta-classname";
+    public static final String HUB_AT_MD_IMPLEMENTS = "ads-meta-implements";
+    public static final String HUB_AT_MD_EXTENDS = "ads-meta-extends";
+    public static final String HUB_AT_MD_FACTORY = "ads-meta-factory";
+    public static final String HUB_AT_MD_PROP = "ads-meta-property";
+
+    public static final String HUB_AT_PD_CONTEXT = "ads-pd-context";
+    public static final String HUB_AT_PD_NAME = "ads-pd-name";
+    public static final String HUB_AT_PD_TYPE = "ads-pd-type";
+    public static final String HUB_AT_PD_DEFAULTVAL = "ads-pd-defaultvalue";
+    public static final String HUB_AT_PD_DESCRIPTION = "ads-pd-description";
+    public static final String HUB_AT_PD_MANDATORY = "ads-pd-mandatory";
+    public static final String HUB_AT_PD_CONSTANT = "ads-pd-constant";
+    public static final String HUB_AT_PD_CONTAINERFOR = "ads-pd-containerFor";
+
+    public static final String HUB_OC_COMPONENT = "ads-component";
+    public static final String HUB_OC_COLLECTION = "ads-collection";
+    public static final String HUB_OC_COLLECTION_ITEM = "ads-collection-item";
+    public static final String HUB_OC_COLL_LIST = "ads-collection-list";
+    public static final String HUB_OC_COLL_SET = "ads-collection-set";
+    public static final String HUB_OC_COLL_ARRAT = "ads-collection-array";
+
+    public static final String HUB_OC_METADESC = "ads-meta-descriptor";
+    public static final String HUB_OC_PROPERTYDESC = "ads-property-descriptor";
+}

Added: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreSchemaManager.java?rev=1336671&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreSchemaManager.java (added)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/store/StoreSchemaManager.java Thu May 10 13:27:47 2012
@@ -0,0 +1,398 @@
+package org.apache.directory.server.hub.core.store;
+
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.schema.SchemaPartition;
+import org.apache.directory.server.hub.api.ComponentHub;
+import org.apache.directory.server.hub.api.component.util.ComponentConstants;
+import org.apache.directory.server.hub.api.exception.HubAbortException;
+import org.apache.directory.server.hub.api.exception.StoreNotValidException;
+import org.apache.directory.server.hub.api.meta.DCMetadataDescriptor;
+import org.apache.directory.server.hub.api.meta.DCPropertyDescription;
+import org.apache.directory.server.hub.api.meta.DCPropertyType;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.message.DeleteRequestImpl;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.util.DateUtils;
+
+
+public class StoreSchemaManager
+{
+    public static final String OID_BASE = "1.3.6.1.4.1.18060.0.4.4";
+    public static final String METADATAS_SCHEMA_BASE = "cn=components";
+
+    private static Dictionary<String, String> syntaxMappings;
+    private static Dictionary<String, String> equalityMappings;
+    private static Dictionary<String, String> orderingMappings;
+    private static Dictionary<String, String> substringMappings;
+
+    private ComponentHub hub;
+    private SchemaPartition schemaPartition;
+    private OIDManager oidManager;
+
+
+    public StoreSchemaManager( ComponentHub hub )
+    {
+        this.hub = hub;
+    }
+
+
+    public void init( SchemaPartition schemaPartition ) throws StoreNotValidException
+    {
+        this.schemaPartition = schemaPartition;
+
+        oidManager = new OIDManager();
+        oidManager.init( schemaPartition );
+
+        syntaxMappings = new Hashtable<String, String>();
+        equalityMappings = new Hashtable<String, String>();
+        orderingMappings = new Hashtable<String, String>();
+        substringMappings = new Hashtable<String, String>();
+
+        syntaxMappings = new Hashtable<String, String>();
+        syntaxMappings.put( ComponentConstants.PRIMITIVE_INT, "1.3.6.1.4.1.1466.115.121.1.27" );
+        syntaxMappings.put( ComponentConstants.PRIMITIVE_FLOAT, "1.3.6.1.4.1.1466.115.121.1.15" );//using String syntax
+        syntaxMappings.put( ComponentConstants.PRIMITIVE_STR, "1.3.6.1.4.1.1466.115.121.1.15" );
+        syntaxMappings.put( ComponentConstants.PRIMITIVE_BOOL, "1.3.6.1.4.1.1466.115.121.1.7" );
+
+        equalityMappings = new Hashtable<String, String>();
+        equalityMappings.put( ComponentConstants.PRIMITIVE_INT, "integerMatch" );
+        equalityMappings.put( ComponentConstants.PRIMITIVE_FLOAT, "caseExactMatch" );
+        equalityMappings.put( ComponentConstants.PRIMITIVE_STR, "caseExactMatch" );
+        equalityMappings.put( ComponentConstants.PRIMITIVE_BOOL, "booleanMatch" );
+
+        orderingMappings = new Hashtable<String, String>();
+        orderingMappings.put( ComponentConstants.PRIMITIVE_INT, "integerOrderingMatch" );
+        orderingMappings.put( ComponentConstants.PRIMITIVE_FLOAT, "caseExactOrderingMatch" );
+        orderingMappings.put( ComponentConstants.PRIMITIVE_STR, "caseExactOrderingMatch" );
+        orderingMappings.put( ComponentConstants.PRIMITIVE_BOOL, "caseIgnoreOrderingMatch" );
+
+        substringMappings = new Hashtable<String, String>();
+        substringMappings.put( ComponentConstants.PRIMITIVE_INT, "numericStringSubstringsMatch" );
+        substringMappings.put( ComponentConstants.PRIMITIVE_FLOAT, "caseExactSubstringsMatch" );
+        substringMappings.put( ComponentConstants.PRIMITIVE_STR, "caseExactSubstringsMatch" );
+        substringMappings.put( ComponentConstants.PRIMITIVE_BOOL, "caseIgnoreSubstringsMatch" );
+    }
+
+
+    public void installMetadata( DCMetadataDescriptor metadata ) throws LdapException
+    {
+        for ( DCPropertyDescription pd : metadata.getPropertyDescriptons() )
+        {
+            if ( pd.getPropertyContext() == DCPropertyType.INJECTION )
+            {
+                continue;
+            }
+
+            if ( pd.getPropertyContext() == DCPropertyType.CONSTANT )
+            {
+                continue;
+            }
+
+            installAttribute( pd );
+        }
+
+        installOCEntry( generateOC( metadata, installNamers( metadata ) ) );
+    }
+
+
+    public void installAttribute( DCPropertyDescription propertyDescription ) throws LdapException
+    {
+
+        if ( attributeExists( propertyDescription.getName() ) )
+        {
+            throw new LdapException( propertyDescription.getName() + "already registered with the schema" );
+        }
+
+        Entry attribEntry = generateAttributeEntry( propertyDescription );
+        AddOperationContext addOp = new AddOperationContext( null, attribEntry.getDn(), attribEntry );
+
+        schemaPartition.getRegistrySynchronizerAdaptor().add( addOp );
+        schemaPartition.getWrappedPartition().add( addOp );
+
+    }
+
+
+    public void installAttributes( List<DCPropertyDescription> propertyDescriptions ) throws LdapException
+    {
+        for ( DCPropertyDescription pd : propertyDescriptions )
+        {
+            if ( attributeExists( pd.getName() ) )
+            {
+                throw new LdapException( pd.getName() + "already registered with the schema" );
+            }
+        }
+
+        for ( DCPropertyDescription pd : propertyDescriptions )
+        {
+            installAttribute( pd );
+        }
+    }
+
+
+    public List<String> installNamers( DCMetadataDescriptor metadata ) throws LdapException
+    {
+        String[] types = metadata.getImplementedInterfaces();
+
+        List<String> registered = new ArrayList<String>();
+        try
+        {
+            for ( String type : types )
+            {
+                String fixedName = null;
+                if ( type.contains( "." ) )
+                {
+                    fixedName = "ads--" + type.substring( type.lastIndexOf( '.' ) + 1 ).toLowerCase();
+                }
+
+                if ( attributeExists( fixedName ) )
+                {
+                    registered.add( fixedName );
+                    continue;
+                }
+
+                SchemaManager sm = schemaPartition.getSchemaManager();
+
+                String attribOID = oidManager.generateNewAttributeOID( fixedName );
+                Dn attribDn = new Dn( sm, "m-oid", attribOID, SchemaConstants.ATTRIBUTE_TYPES_PATH,
+                    METADATAS_SCHEMA_BASE,
+                    SchemaConstants.OU_SCHEMA );
+
+                Entry attribEntry = new DefaultEntry( schemaPartition.getSchemaManager(), attribDn );
+
+                attribEntry.add( sm.getAttributeType( "objectclass" ), "metaAttributeType" );
+                attribEntry.add( sm.getAttributeType( "m-oid" ), attribOID );
+                attribEntry.add( sm.getAttributeType( "m-name" ), fixedName );
+                attribEntry.add( sm.getAttributeType( "m-description" ), "To help better naming an entry." );
+                attribEntry.add( sm.getAttributeType( "m-singleValue" ), "TRUE" );
+                attribEntry.add( sm.getAttributeType( "m-syntax" ), "1.3.6.1.4.1.1466.115.121.1.15" );
+                attribEntry.add( sm.getAttributeType( "m-equality" ), "caseExactMatch" );
+                attribEntry.add( sm.getAttributeType( "m-ordering" ), "caseExactOrderingMatch" );
+                attribEntry.add( sm.getAttributeType( "m-substr" ), "caseExactSubstringsMatch" );
+                attribEntry.add( sm.getAttributeType( "m-length" ), "0" );
+
+                attribEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+                attribEntry.add( SchemaConstants.ENTRY_CSN_AT, ApacheDSConfigStore.csnFactory.newInstance().toString() );
+                attribEntry.add( SchemaConstants.CREATORS_NAME_AT, StoreSchemaConstants.SYSTEM_ADMIN_DN );
+                attribEntry.add( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+                AddOperationContext addOp = new AddOperationContext( null, attribDn, attribEntry );
+
+                schemaPartition.getRegistrySynchronizerAdaptor().add( addOp );
+                schemaPartition.getWrappedPartition().add( addOp );
+
+                registered.add( fixedName );
+            }
+        }
+        catch ( LdapException e )
+        {
+            // Do nothing.
+        }
+        return registered;
+    }
+
+
+    public Entry generateAttributeEntry( DCPropertyDescription propertyDescription ) throws LdapException
+    {
+        SchemaManager sm = schemaPartition.getSchemaManager();
+
+        String attribOID = oidManager.generateNewAttributeOID( propertyDescription.getName() );
+        Dn attribDn = new Dn( sm, "m-oid", attribOID, SchemaConstants.ATTRIBUTE_TYPES_PATH, METADATAS_SCHEMA_BASE,
+            SchemaConstants.OU_SCHEMA );
+
+        String syntax, equality, substr, ordering;
+        String selectingType = ( propertyDescription.getPropertyContext() == DCPropertyType.PRIMITIVE ) ? propertyDescription
+            .getType()
+            : ComponentConstants.PRIMITIVE_STR;
+
+        syntax = syntaxMappings.get( selectingType );
+        equality = equalityMappings.get( selectingType );
+        substr = substringMappings.get( selectingType );
+        ordering = orderingMappings.get( selectingType );
+
+        Entry attribEntry = new DefaultEntry( schemaPartition.getSchemaManager(), attribDn );
+
+        attribEntry.add( sm.getAttributeType( "objectclass" ), "metaAttributeType" );
+        attribEntry.add( sm.getAttributeType( "m-oid" ), attribOID );
+        attribEntry.add( sm.getAttributeType( "m-name" ), propertyDescription.getName() );
+        if ( propertyDescription.getDescription() != null )
+        {
+            attribEntry.add( sm.getAttributeType( "m-description" ), propertyDescription.getDescription() );
+        }
+        attribEntry.add( sm.getAttributeType( "m-singleValue" ),
+            ( propertyDescription.getPropertyContext() == DCPropertyType.PRIMITIVE_COLLECTION ) ? "TRUE"
+                : "FALSE" );
+        attribEntry.add( sm.getAttributeType( "m-syntax" ), syntax );
+        attribEntry.add( sm.getAttributeType( "m-equality" ), equality );
+        attribEntry.add( sm.getAttributeType( "m-ordering" ), ordering );
+        attribEntry.add( sm.getAttributeType( "m-substr" ), substr );
+        attribEntry.add( sm.getAttributeType( "m-length" ), "0" );
+
+        attribEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+        attribEntry.add( SchemaConstants.ENTRY_CSN_AT, ApacheDSConfigStore.csnFactory.newInstance().toString() );
+        attribEntry.add( SchemaConstants.CREATORS_NAME_AT, StoreSchemaConstants.SYSTEM_ADMIN_DN );
+        attribEntry.add( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+        return attribEntry;
+    }
+
+
+    public void uninstallAttribute( String propertyName ) throws LdapException
+    {
+        String attribOID = oidManager.getAttributeOID( propertyName );
+        if ( attribOID == null )
+        {
+            return;
+        }
+
+        Dn attribDn = new Dn( schemaPartition.getSchemaManager(), "m-oid", attribOID,
+            SchemaConstants.ATTRIBUTE_TYPES_PATH, METADATAS_SCHEMA_BASE
+            , SchemaConstants.OU_SCHEMA );
+
+        Entry attribEntry = schemaPartition.getWrappedPartition().lookup( new LookupOperationContext( null, attribDn ) );
+        if ( attribEntry != null )
+        {
+            DeleteOperationContext deleteOp = new DeleteOperationContext( null, attribDn );
+
+            // Necessary because synchronizer directly access the entry.
+            deleteOp.setEntry( attribEntry );
+
+            schemaPartition.getRegistrySynchronizerAdaptor().delete( deleteOp, false );
+            schemaPartition.getWrappedPartition().delete( deleteOp );
+        }
+
+    }
+
+
+    public void uninstallAttributes( List<DCPropertyDescription> configurables ) throws LdapException
+    {
+        for ( DCPropertyDescription pd : configurables )
+        {
+            uninstallAttribute( pd.getName() );
+        }
+    }
+
+
+    public Entry generateOC( DCMetadataDescriptor metadata, List<String> auxiliaryNaming ) throws LdapException
+    {
+        SchemaManager sm = schemaPartition.getSchemaManager();
+
+        String ocOID = oidManager.generateNewOCOID( metadata.getMetadataPID() );
+        Dn ocDn = new Dn( sm, "m-oid", ocOID, SchemaConstants.OBJECT_CLASSES_PATH, METADATAS_SCHEMA_BASE,
+            SchemaConstants.OU_SCHEMA );
+
+        Entry ocEntry = new DefaultEntry( sm, ocDn );
+
+        ocEntry.add( sm.getAttributeType( "objectclass" ), "metaObjectClass" );
+        ocEntry.add( sm.getAttributeType( "m-oid" ), ocOID );
+        ocEntry.add( sm.getAttributeType( "m-name" ), metadata.getMetadataPID() );
+        ocEntry.add( sm.getAttributeType( "m-description" ),
+            "OC for generating instances of" + metadata.getMetadataPID() );
+        ocEntry.add( sm.getAttributeType( "m-supObjectClass" ), StoreSchemaConstants.HUB_OC_COMPONENT );
+
+        for ( DCPropertyDescription pd : metadata.getPropertyDescriptons() )
+        {
+            if ( pd.getPropertyContext() == DCPropertyType.INJECTION )
+            {
+                continue;
+            }
+
+            if ( pd.getPropertyContext() == DCPropertyType.CONSTANT )
+            {
+                continue;
+            }
+
+            if ( pd.isMandatory() )
+            {
+                ocEntry.add( sm.getAttributeType( "m-must" ), pd.getName() );
+            }
+            else
+            {
+                ocEntry.add( sm.getAttributeType( "m-may" ), pd.getName() );
+            }
+        }
+
+        if ( auxiliaryNaming != null )
+        {
+            for ( String namingAttrib : auxiliaryNaming )
+            {
+                ocEntry.add( sm.getAttributeType( "m-may" ), namingAttrib );
+            }
+        }
+
+        ocEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+        ocEntry.add( SchemaConstants.ENTRY_CSN_AT, ApacheDSConfigStore.csnFactory.newInstance().toString() );
+        ocEntry.add( SchemaConstants.CREATORS_NAME_AT, StoreSchemaConstants.SYSTEM_ADMIN_DN );
+        ocEntry.add( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+        return ocEntry;
+    }
+
+
+    public void installOCEntry( Entry ocEntry ) throws LdapException
+    {
+        AddOperationContext addOp = new AddOperationContext( null, ocEntry.getDn(), ocEntry );
+
+        schemaPartition.getRegistrySynchronizerAdaptor().add( addOp );
+        schemaPartition.getWrappedPartition().add( addOp );
+    }
+
+
+    public void uninstallOC( String metaPID ) throws LdapException
+    {
+        String metaOID = oidManager.getOCBase( metaPID );
+        if ( metaOID == null )
+        {
+            return;
+        }
+
+        Dn ocDn = new Dn( schemaPartition.getSchemaManager(), "m-oid", metaOID, SchemaConstants.OBJECT_CLASSES_PATH,
+            METADATAS_SCHEMA_BASE,
+            SchemaConstants.OU_SCHEMA );
+
+        Entry ocEntry = schemaPartition.getWrappedPartition().lookup( new LookupOperationContext( null, ocDn ) );
+        if ( ocEntry != null )
+        {
+            DeleteOperationContext deleteOp = new DeleteOperationContext( null, ocDn );
+
+            // Necessary because synchronizer directly access the entry.
+            deleteOp.setEntry( ocEntry );
+
+            schemaPartition.getRegistrySynchronizerAdaptor().delete( deleteOp, false );
+            schemaPartition.getWrappedPartition().delete( deleteOp );
+        }
+    }
+
+
+    public boolean attributeExists( String attributeName )
+    {
+        return oidManager.getAttributeOID( attributeName ) != null;
+    }
+
+
+    public boolean ocExists( String metaPID )
+    {
+        return oidManager.getOCBase( metaPID ) != null;
+    }
+
+
+    public void updateOC( DCMetadataDescriptor metadata ) throws LdapException
+    {
+        Entry ocEntry = generateOC( metadata, installNamers( metadata ) );
+
+        uninstallOC( metadata.getMetadataPID() );
+        installOCEntry( ocEntry );
+    }
+}

Added: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/DCDependency.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/DCDependency.java?rev=1336671&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/DCDependency.java (added)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/DCDependency.java Thu May 10 13:27:47 2012
@@ -0,0 +1,55 @@
+package org.apache.directory.server.hub.core.util;
+
+
+public class DCDependency
+{
+    private DCDependencyType dependencyType;
+    private String dependencyId;
+
+
+    public DCDependency( DCDependencyType dependencyType, String dependencyId )
+    {
+        this.dependencyType = dependencyType;
+        this.dependencyId = dependencyId;
+    }
+
+
+    public DCDependencyType getType()
+    {
+        return dependencyType;
+    }
+
+
+    public String getId()
+    {
+        return dependencyId;
+    }
+
+
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( !( obj instanceof DCDependency ) )
+        {
+            return false;
+        }
+
+        DCDependency dep = ( DCDependency ) obj;
+
+        return dependencyType.equals( dep.getType() ) && dependencyId.equals( dep.getId() );
+    }
+
+
+    @Override
+    public int hashCode()
+    {
+        return ( dependencyType.name() + dependencyId ).hashCode();
+    }
+
+    public enum DCDependencyType
+    {
+        MANAGER,
+        INJECTION,
+        REFERENCE
+    }
+}
\ No newline at end of file

Added: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/DCDependencyType.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/DCDependencyType.java?rev=1336671&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/DCDependencyType.java (added)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/DCDependencyType.java Thu May 10 13:27:47 2012
@@ -0,0 +1,7 @@
+
+package org.apache.directory.server.hub.core.util;
+
+public enum DCDependencyType
+{
+    
+}

Added: directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/ParentLink.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/ParentLink.java?rev=1336671&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/ParentLink.java (added)
+++ directory/apacheds/branches/apacheds-osgi/hub/core/src/main/java/org/apache/directory/server/hub/core/util/ParentLink.java Thu May 10 13:27:47 2012
@@ -0,0 +1,51 @@
+package org.apache.directory.server.hub.core.util;
+
+
+import org.apache.directory.server.hub.api.component.DirectoryComponent;
+
+
+public class ParentLink
+{
+    private DirectoryComponent parent;
+    private String linkPoint;
+
+
+    public ParentLink( DirectoryComponent parent, String linkPoint )
+    {
+        this.parent = parent;
+        this.linkPoint = linkPoint;
+    }
+
+
+    public DirectoryComponent getParent()
+    {
+        return parent;
+    }
+
+
+    public String getLinkPoint()
+    {
+        return linkPoint;
+    }
+
+
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( !( obj instanceof ParentLink ) )
+        {
+            return false;
+        }
+
+        ParentLink pl = ( ParentLink ) obj;
+
+        return parent.equals( pl.getParent() ) && linkPoint.equals( pl.getLinkPoint() );
+    }
+
+
+    @Override
+    public int hashCode()
+    {
+        return ( parent.getComponentPID() + linkPoint ).hashCode();
+    }
+}



Mime
View raw message