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 2012/01/28 18:08:57 UTC

svn commit: r1237096 - in /directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo: helpers/IPojoHelper.java helpers/OSGIHelper.java schema/SchemaElementsManager.java

Author: gokturk
Date: Sat Jan 28 17:08:56 2012
New Revision: 1237096

URL: http://svn.apache.org/viewvc?rev=1237096&view=rev
Log:
* Comments were added to methods and types.
* IPojoHelper method signatures are changed to let broader usage of them.

Modified:
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/IPojoHelper.java
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelper.java
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/schema/SchemaElementsManager.java

Modified: directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/IPojoHelper.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/IPojoHelper.java?rev=1237096&r1=1237095&r2=1237096&view=diff
==============================================================================
--- directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/IPojoHelper.java (original)
+++ directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/IPojoHelper.java Sat Jan 28 17:08:56 2012
@@ -28,19 +28,30 @@ import org.apache.felix.ipojo.ComponentF
 import org.apache.felix.ipojo.ComponentInstance;
 import org.apache.felix.ipojo.ConfigurationException;
 import org.apache.felix.ipojo.Factory;
-import org.apache.felix.ipojo.InstanceManager;
 import org.apache.felix.ipojo.MissingHandlerException;
 import org.apache.felix.ipojo.UnacceptableConfiguration;
 
 
+/**
+ * Provides helper methods to access IPojo factories by their name, and instantiate instance of factories.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
 public class IPojoHelper
 {
+    /**
+     * Gets IPojo {@link ComponentFactory} by given factory name.
+     *
+     * @param factoryName factory name to get its equilavent {@link ComponentFactory}
+     * @return IPojo {@link ComponentFactory} reference
+     */
     public static ComponentFactory getFactory( String factoryName )
     {
         try
         {
             String filter = "(factory.name=" + factoryName + ")";
-            List<ComponentFactory> factories = ( List<ComponentFactory> ) OSGIHelper.getServices( Factory.class.getName(), filter );
+            List<ComponentFactory> factories = ( List<ComponentFactory> ) OSGIHelper.getServices(
+                Factory.class.getName(), filter );
             if ( factories == null )
             {
                 return null;
@@ -54,7 +65,15 @@ public class IPojoHelper
     }
 
 
-    public static Object createIPojoComponent( String factoryName, String instanceName, Dictionary props )
+    /**
+     * Creates an instance of given IPojo factory.
+     *
+     * @param factoryName Factory name to create its instance
+     * @param instanceName Name of instance being created. Pass 'null' if its not important.
+     * @param props Configuration to instance being created.
+     * @return {@link ComponentInstance} reference to created instance
+     */
+    public static ComponentInstance createIPojoComponent( String factoryName, String instanceName, Dictionary props )
     {
         ComponentFactory factory = IPojoHelper.getFactory( factoryName );
         if ( factory == null )
@@ -68,15 +87,13 @@ public class IPojoHelper
             {
                 props = new Hashtable<String, String>();
             }
+
             props.put( "instance.name", instanceName );
         }
 
         try
         {
-            ComponentInstance comp = factory.createComponentInstance( props );
-            Object instance = ( ( InstanceManager ) comp ).getPojoObject();
-
-            return instance;
+            return factory.createComponentInstance( props );
         }
         catch ( UnacceptableConfiguration e )
         {

Modified: directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelper.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelper.java?rev=1237096&r1=1237095&r2=1237096&view=diff
==============================================================================
--- directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelper.java (original)
+++ directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelper.java Sat Jan 28 17:08:56 2012
@@ -28,12 +28,22 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 
 
+/**
+ * Provides some OSGI helpers related to Service publication and access.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
 public class OSGIHelper
 {
     /** BundleContext reference which will be assigned through BundleActivator */
     public static BundleContext bundleCtx;
 
 
+    /**
+     * Determines if Shared is launched in OSGI container.
+     *
+     * @return {@link Boolean}
+     */
     public static boolean isAPIInOSGIContainer()
     {
         if ( bundleCtx == null )
@@ -45,6 +55,13 @@ public class OSGIHelper
     }
 
 
+    /**
+     * Gets OSGI Services by given specification and filter.
+     *
+     * @param serviceClassName Name of published service class name.
+     * @param filter Filter to match against services.
+     * @return List of matching services as List<Object>
+     */
     public static List<?> getServices( String serviceClassName, String filter )
     {
         if ( !isAPIInOSGIContainer() )
@@ -76,6 +93,12 @@ public class OSGIHelper
     }
 
 
+    /**
+     * Gets the first service of given specification.
+     *
+     * @param serviceClassName Published OSGI Service class name.
+     * @return The first matched service in service registry.
+     */
     public static Object getService( String serviceClassName )
     {
         if ( !isAPIInOSGIContainer() )
@@ -99,17 +122,4 @@ public class OSGIHelper
             return null;
         }
     }
-    
-    public static Object getServiceObject(ServiceReference ref)
-    {
-        try
-        {
-            return bundleCtx.getService( ref );
-        }
-        catch ( IllegalStateException e )
-        {
-            e.printStackTrace();
-            return null;
-        }
-    }
 }

Modified: directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/schema/SchemaElementsManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/schema/SchemaElementsManager.java?rev=1237096&r1=1237095&r2=1237096&view=diff
==============================================================================
--- directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/schema/SchemaElementsManager.java (original)
+++ directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/schema/SchemaElementsManager.java Sat Jan 28 17:08:56 2012
@@ -8,51 +8,84 @@ import org.apache.directory.shared.ipojo
 import org.apache.directory.shared.ldap.model.schema.LdapComparator;
 import org.apache.directory.shared.ldap.model.schema.Normalizer;
 import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.InstanceManager;
 
 
+/**
+ * Class used to get Schema Elements from IPojo component registry.
+ * Schema Elements must be published without specifying component name, which leaves them published
+ * with their class name.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
 public class SchemaElementsManager
 {
+    /**
+     * Gets {@link LdapComparator} reference by its class name as IPojo component name.
+     *
+     * @param factoryName Class name of a LdapComparator
+     * @param oid OID value to instantiate LdapComparator.
+     * @return {@link LdapComparator} reference fetched from IPojo
+     * @throws Exception
+     */
     public LdapComparator<?> getLdapComparator( String factoryName, String oid ) throws Exception
     {
         Dictionary<String, String> props = new Hashtable<String, String>();
         props.put( "ads.comp.comparator.oid", oid );
 
-        LdapComparator<?> comparator = ( LdapComparator<?> ) IPojoHelper
-            .createIPojoComponent( factoryName, null, props );
-
-        if ( comparator == null )
+        ComponentInstance _comparator = IPojoHelper.createIPojoComponent( factoryName, null, props );
+        if ( _comparator == null )
         {
-            throw new Exception( "Required Comparator is not registered" );
+            throw new Exception( "Required Comparator is not registered as IPojo Component" );
         }
 
+        LdapComparator<?> comparator = ( LdapComparator<?> ) ( ( InstanceManager ) _comparator ).getPojoObject();
+
         return comparator;
     }
 
 
+    /**
+     * Gets {@link Normalizer} reference by its class name as IPojo component name.
+     *
+     * @param factoryName Class name of a Normalizer
+     * @return  {@link Normalizer} reference fetched from IPojo
+     * @throws Exception
+     */
     public Normalizer getNormalizer( String factoryName ) throws Exception
     {
-        Normalizer normalizer = ( Normalizer ) IPojoHelper
-            .createIPojoComponent( factoryName, null, null );
+        ComponentInstance _normalizer = IPojoHelper.createIPojoComponent( factoryName, null, null );
 
-        if ( normalizer == null )
+        if ( _normalizer == null )
         {
-            throw new Exception( "Required Normalizer is not registered" );
+            throw new Exception( "Required Normalizer is not registered as IPojo Component" );
         }
 
+        Normalizer normalizer = ( Normalizer ) ( ( InstanceManager ) _normalizer ).getPojoObject();
+
         return normalizer;
     }
 
 
+    /**
+     * Gets {@link SyntaxChecker} reference by its class name as IPojo component name.
+     *
+     * @param factoryName Class name of a SyntaxChecker
+     * @return  {@link SyntaxChecker} reference fetched from IPojo
+     * @throws Exception
+     */
     public SyntaxChecker getSyntaxChecker( String factoryName ) throws Exception
     {
-        SyntaxChecker syntaxer = ( SyntaxChecker ) IPojoHelper
-            .createIPojoComponent( factoryName, null, null );
+        ComponentInstance _syntaxer = IPojoHelper.createIPojoComponent( factoryName, null, null );
 
-        if ( syntaxer == null )
+        if ( _syntaxer == null )
         {
-            throw new Exception( "Required Syntax Checker is not registered" );
+            throw new Exception( "Required Syntax Checker is not registered as IPojo Component" );
         }
 
+        SyntaxChecker syntaxer = ( SyntaxChecker ) ( ( InstanceManager ) _syntaxer ).getPojoObject();
+
         return syntaxer;
     }
 }