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/12/01 12:41:28 UTC

svn commit: r1209042 - in /directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component: handler/ hub/ComponentCacheManager.java hub/ComponentHub.java

Author: gokturk
Date: Thu Dec  1 11:41:27 2011
New Revision: 1209042

URL: http://svn.apache.org/viewvc?rev=1209042&view=rev
Log:
Changed component type detection mechanism.

Custom annos are hard to use and irrevelant for that matter. It is switched to use the first implemented interface name as component type name.


Removed:
    directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/handler/
Modified:
    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/ComponentHub.java

Modified: 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=1209042&r1=1209041&r2=1209042&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentCacheManager.java (original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentCacheManager.java Thu Dec  1 11:41:27 2011
@@ -323,6 +323,17 @@ public class ComponentCacheManager
      */
     public List<Properties> getCachedInstanceConfigurations( ADSComponent component )
     {
+        if ( !cacheVersionMatch( component ) )
+        {
+            LOG.info( "Version mismatch between the cache and the component:  "
+                + component );
+
+            if ( !validateCache( component ) )
+            {
+                return null;
+            }
+        }
+        
         String instancesDirPath = component.getCacheHandle().getCachedInstanceConfigurationsLocation();
         File instancesDir = new File( instancesDirPath );
 

Modified: 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=1209042&r1=1209041&r2=1209042&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java (original)
+++ directory/apacheds/branches/apacheds-osgi/component-hub/src/main/java/org/apache/directory/server/component/hub/ComponentHub.java Thu Dec  1 11:41:27 2011
@@ -35,6 +35,7 @@ import org.apache.directory.server.compo
 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.directory.server.core.api.interceptor.Interceptor;
 import org.apache.felix.ipojo.Factory;
 import org.apache.felix.ipojo.annotations.Component;
 import org.apache.felix.ipojo.annotations.Invalidate;
@@ -109,6 +110,12 @@ public class ComponentHub
     private ComponentManager componentManager = new ComponentManager( cacheManager, configManager );
 
     /*
+     * Allowed interfaces for components.
+     */
+    private String[] allowedInterfaces = new String[]
+        { Interceptor.class.getName() };
+
+    /*
      * OSGI Logger
      */
     @Requires
@@ -159,34 +166,26 @@ public class ComponentHub
             return;
         }
 
-        try
-        {
-            String componentType = parseComponentType( arrivingFactory );
-
-            //Actual ADSComponent creation
-            ADSComponent component = generateADSComponent( componentType, arrivingFactory );
+        String componentType = parseComponentType( arrivingFactory );
 
-            eventManager.fireComponentCreated( component );
+        //Actual ADSComponent creation
+        ADSComponent component = generateADSComponent( componentType, arrivingFactory );
 
-            //Keep the newly created ADSComponent reference.
-            components.add( component );
+        eventManager.fireComponentCreated( 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 );
-            }
+        //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 );
         }
-        catch ( ParseException e )
+        else
         {
-            e.printStackTrace();
+            componentsByType.add( component );
         }
 
     }
@@ -205,38 +204,31 @@ public class ComponentHub
             return;
         }
 
-        try
-        {
-            String componentType = parseComponentType( leavingFactory );
+        String componentType = parseComponentType( leavingFactory );
 
-            ADSComponent associatedComp = null;
-            for ( ADSComponent _comp : components )
+        ADSComponent associatedComp = null;
+        for ( ADSComponent _comp : components )
+        {
+            if ( _comp.getFactory().getName().equals( leavingFactory.getName() ) )
             {
-                if ( _comp.getFactory().getName().equals( leavingFactory.getName() ) )
-                {
-                    associatedComp = _comp;
-                    break;
-                }
+                associatedComp = _comp;
+                break;
             }
+        }
 
-            if ( associatedComp == null )
-            {
-                logger.log( LogService.LOG_INFO, "Couldn't found an associated ADSComponent for factory:"
-                    + leavingFactory.getName() );
-                return;
-            }
+        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 );
+        // All clients are notified now cache and delete the ADSComponent existence on ApacheDS
+        cacheAndReleaseADSComponent( associatedComp );
 
-            // Fire "Component Deleted" event
-            eventManager.fireComponentDeleted( associatedComp );
+        // Fire "Component Deleted" event
+        eventManager.fireComponentDeleted( associatedComp );
 
-        }
-        catch ( ParseException e )
-        {
-            e.printStackTrace();
-        }
     }
 
 
@@ -270,10 +262,10 @@ public class ComponentHub
      */
     private boolean checkIfADSComponent( Factory factory )
     {
-        List<String> handlers = factory.getRequiredHandlers();
-        for ( String handlerName : handlers )
+        String implementingIface = parseBaseInterface( factory );
+        for ( String iface : allowedInterfaces )
         {
-            if ( handlerName.equals( ADSConstants.ADS_COMPONENT_HANDLER_FULLNAME ) )
+            if ( iface.equals( implementingIface ) )
             {
                 return true;
             }
@@ -283,41 +275,37 @@ public class ComponentHub
     }
 
 
-    private String parseComponentType( Factory factory ) throws ParseException
+    /**
+     * Gets the component type by provided specification of a component.
+     *
+     * @param factory to get its component type
+     * @return component type as interface name.
+     */
+    private String parseComponentType( Factory factory )
     {
-        Dictionary bundleHeaders = factory.getBundleContext().getBundle().getHeaders();
-        String ipojoHeader = ( String ) bundleHeaders.get( ADSConstants.IPOJO_HEADER );
+        String baseInterface = parseBaseInterface( factory ).toLowerCase();
 
-        if ( ipojoHeader == null )
+        if ( baseInterface.contains( "." ) )
         {
-            throw new ParseException( "Null ipojo header returned for factory: " + factory.getName() );
+            return baseInterface.substring( baseInterface.lastIndexOf( '.' ) + 1 );
         }
+        else
+        {
+            return baseInterface;
+        }
+    }
 
-        ManifestMetadataParser parser = new ManifestMetadataParser();
-        parser.parseHeader( ipojoHeader );
-
-        Element[] componentMetas = parser.getComponentsMetadata();
 
-        for ( Element componentMeta : componentMetas )
+    private String parseBaseInterface( Factory factory )
+    {
+        String[] publishedInterfaces = factory.getComponentDescription().getprovidedServiceSpecification();
+        if ( publishedInterfaces.length == 0 )
         {
-            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;
         }
 
-        return null;
+        return publishedInterfaces[publishedInterfaces.length - 1];
+
     }