directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gokt...@apache.org
Subject svn commit: r1336604 - in /directory/shared/branches/shared-osgi/ipojo-manager: ./ 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/shared/ src/main/java/o...
Date Thu, 10 May 2012 11:34:04 GMT
Author: gokturk
Date: Thu May 10 11:34:03 2012
New Revision: 1336604

URL: http://svn.apache.org/viewvc?rev=1336604&view=rev
Log:
IPojo manager to load schema elements in both OSGI and nonOSGI environments.


Added:
    directory/shared/branches/shared-osgi/ipojo-manager/
    directory/shared/branches/shared-osgi/ipojo-manager/pom.xml
    directory/shared/branches/shared-osgi/ipojo-manager/src/
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/
    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/helpers/OSGIHelpersActivator.java
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/schema/
    directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/schema/SchemaElementsManager.java

Added: directory/shared/branches/shared-osgi/ipojo-manager/pom.xml
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-osgi/ipojo-manager/pom.xml?rev=1336604&view=auto
==============================================================================
--- directory/shared/branches/shared-osgi/ipojo-manager/pom.xml (added)
+++ directory/shared/branches/shared-osgi/ipojo-manager/pom.xml Thu May 10 11:34:03 2012
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.directory.shared</groupId>
+    <artifactId>shared-parent</artifactId>
+    <version>1.0.0-M13-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>shared-ipojo-manager</artifactId>
+  <name>Apache Directory Shared OSGI/IPOJO Manager</name>
+  <packaging>bundle</packaging>
+
+  <description>Provides main facility for handling IPojo component management</description>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.ipojo</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>shared-ldap-model</artifactId>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifestFile>META-INF/MANIFEST.MF</manifestFile>
+            <addMavenDescriptor>false</addMavenDescriptor>
+          </archive>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <inherited>true</inherited>
+        <extensions>true</extensions>
+        <configuration>
+          <manifestLocation>META-INF</manifestLocation>
+          <unpackBundle>true</unpackBundle>
+          <instructions>
+            <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
+            <Bundle-SymbolicName>${project.groupId}.ipojo.manager</Bundle-SymbolicName>
+            <Bundle-Activator>org.apache.directory.shared.ipojo.helpers.OSGIHelpersActivator</Bundle-Activator>
+            <Export-Package>
+                {local-packages};version=${project.version};-noimport:=true
+            </Export-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
+

Added: 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=1336604&view=auto
==============================================================================
--- directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/IPojoHelper.java
(added)
+++ directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/IPojoHelper.java
Thu May 10 11:34:03 2012
@@ -0,0 +1,115 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.shared.ipojo.helpers;
+
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.Factory;
+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 );
+            if ( factories == null )
+            {
+                return null;
+            }
+            return factories.get( 0 );
+        }
+        catch ( ClassCastException e )
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * 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 )
+        {
+            return null;
+        }
+
+        if ( instanceName != null )
+        {
+            if ( props == null )
+            {
+                props = new Hashtable<String, String>();
+            }
+
+            props.put( "instance.name", instanceName );
+        }
+
+        try
+        {
+            return factory.createComponentInstance( props );
+        }
+        catch ( UnacceptableConfiguration e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+        catch ( MissingHandlerException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+        catch ( ConfigurationException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+
+    }
+}

Added: 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=1336604&view=auto
==============================================================================
--- directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelper.java
(added)
+++ directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelper.java
Thu May 10 11:34:03 2012
@@ -0,0 +1,125 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.shared.ipojo.helpers;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.InvalidSyntaxException;
+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 )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+
+    /**
+     * 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() )
+        {
+            return null;
+        }
+
+        try
+        {
+            ServiceReference[] serviceReferences = bundleCtx.getServiceReferences( serviceClassName,
filter );
+            List<Object> services = new ArrayList<Object>();
+            for ( ServiceReference ref : serviceReferences )
+            {
+                services.add( bundleCtx.getService( ref ) );
+            }
+
+            return services;
+        }
+        catch ( InvalidSyntaxException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+        catch ( IllegalStateException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+
+    /**
+     * 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() )
+        {
+            return null;
+        }
+
+        ServiceReference ref = bundleCtx.getServiceReference( serviceClassName );
+        if ( ref == null )
+        {
+            return null;
+        }
+
+        try
+        {
+            return bundleCtx.getService( ref );
+        }
+        catch ( IllegalStateException e )
+        {
+            e.printStackTrace();
+            return null;
+        }
+    }
+}

Added: directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelpersActivator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelpersActivator.java?rev=1336604&view=auto
==============================================================================
--- directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelpersActivator.java
(added)
+++ directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/helpers/OSGIHelpersActivator.java
Thu May 10 11:34:03 2012
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.shared.ipojo.helpers;
+
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+
+/**
+ * BundleActivator to keep and release BundleContext reference for further uses by helper
classes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class OSGIHelpersActivator implements BundleActivator
+{
+
+    public void start( BundleContext context ) throws Exception
+    {
+        //Save the BundleContext reference
+        OSGIHelper.bundleCtx = context;
+    }
+
+
+    public void stop( BundleContext context ) throws Exception
+    {
+        //Null the BundleContext reference
+        OSGIHelper.bundleCtx = null;
+    }
+}

Added: 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=1336604&view=auto
==============================================================================
--- directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/schema/SchemaElementsManager.java
(added)
+++ directory/shared/branches/shared-osgi/ipojo-manager/src/main/java/org/apache/directory/shared/ipojo/schema/SchemaElementsManager.java
Thu May 10 11:34:03 2012
@@ -0,0 +1,91 @@
+package org.apache.directory.shared.ipojo.schema;
+
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.directory.shared.ipojo.helpers.IPojoHelper;
+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 );
+
+        ComponentInstance _comparator = IPojoHelper.createIPojoComponent( factoryName, null,
props );
+        if ( _comparator == null )
+        {
+            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
+    {
+        ComponentInstance _normalizer = IPojoHelper.createIPojoComponent( factoryName, null,
null );
+
+        if ( _normalizer == null )
+        {
+            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
+    {
+        ComponentInstance _syntaxer = IPojoHelper.createIPojoComponent( factoryName, null,
null );
+
+        if ( _syntaxer == null )
+        {
+            throw new Exception( "Required Syntax Checker is not registered as IPojo Component"
);
+        }
+
+        SyntaxChecker syntaxer = ( SyntaxChecker ) ( ( InstanceManager ) _syntaxer ).getPojoObject();
+
+        return syntaxer;
+    }
+}



Mime
View raw message