You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by no...@apache.org on 2010/09/30 11:25:14 UTC

svn commit: r1002974 - in /incubator/aries/trunk/jndi/jndi-legacy-support: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/aries/ src/main/java/org/apache/aries/jndi/ src/main/java/org/apache/aries...

Author: not
Date: Thu Sep 30 09:25:13 2010
New Revision: 1002974

URL: http://svn.apache.org/viewvc?rev=1002974&view=rev
Log:
ARIES-431 Add an InitialContextFactoryBuilder that uses the thread context classloader to load the ICF

Added:
    incubator/aries/trunk/jndi/jndi-legacy-support/   (with props)
    incubator/aries/trunk/jndi/jndi-legacy-support/pom.xml
    incubator/aries/trunk/jndi/jndi-legacy-support/src/
    incubator/aries/trunk/jndi/jndi-legacy-support/src/main/
    incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/
    incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/
    incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/
    incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/
    incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/
    incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/
    incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/
    incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/Activator.java
    incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java

Propchange: incubator/aries/trunk/jndi/jndi-legacy-support/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 30 09:25:13 2010
@@ -0,0 +1 @@
+target

Added: incubator/aries/trunk/jndi/jndi-legacy-support/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-legacy-support/pom.xml?rev=1002974&view=auto
==============================================================================
--- incubator/aries/trunk/jndi/jndi-legacy-support/pom.xml (added)
+++ incubator/aries/trunk/jndi/jndi-legacy-support/pom.xml Thu Sep 30 09:25:13 2010
@@ -0,0 +1,52 @@
+<!--
+ 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.aries.jndi</groupId>
+        <artifactId>jndi</artifactId>
+        <version>0.3-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>org.apache.aries.jndi.legacy.support</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Aries JNDI Support for Legacy Runtimes</name>
+    <description>
+      This bundle contains support for legacy runtimes which rely on the thread context classloader to load JNDI implementations. It is intended for use with OSGi Web Container implementations which do not correctly work with the OSGi JNDI Service specification.
+    </description>
+
+    <properties>
+        <aries.osgi.export.pkg/>
+        <aries.osgi.private.pkg>
+            org.apache.aries.jndi.legacy.support
+        </aries.osgi.private.pkg>
+        <aries.osgi.activator>
+            org.apache.aries.jndi.legacy.support.Activator
+        </aries.osgi.activator>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+</project>

Added: incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/Activator.java?rev=1002974&view=auto
==============================================================================
--- incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/Activator.java (added)
+++ incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/Activator.java Thu Sep 30 09:25:13 2010
@@ -0,0 +1,19 @@
+package org.apache.aries.jndi.legacy.support;
+
+import javax.naming.spi.InitialContextFactoryBuilder;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+	@Override
+	public void start(BundleContext context) throws Exception 
+	{
+		context.registerService(InitialContextFactoryBuilder.class.getName(), new LegacyInitialContextFinder(), null);
+	}
+
+	@Override
+	public void stop(BundleContext context) throws Exception { }
+
+}

Added: incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java?rev=1002974&view=auto
==============================================================================
--- incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java (added)
+++ incubator/aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java Thu Sep 30 09:25:13 2010
@@ -0,0 +1,44 @@
+package org.apache.aries.jndi.legacy.support;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
+
+public class LegacyInitialContextFinder implements InitialContextFactoryBuilder {
+
+	@Override
+	public InitialContextFactory createInitialContextFactory(
+			Hashtable<?, ?> environment) throws NamingException 
+	{
+		String icf = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
+		if (icf != null) {
+			ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+				@Override
+				public ClassLoader run() {
+					return Thread.currentThread().getContextClassLoader();
+				}
+			});
+			
+			try {
+				Class<?> icfClass = Class.forName(icf, false, cl);
+				if (InitialContextFactory.class.isAssignableFrom(icfClass)) {
+					return (InitialContextFactory) icfClass.newInstance();
+				}
+			} catch (ClassNotFoundException e) {
+				// If the ICF doesn't exist this is expected. Should return null so the next builder is queried.
+			} catch (InstantiationException e) {
+				// If the ICF couldn't be created just ignore and return null.
+			} catch (IllegalAccessException e) {
+				// If the default constructor is private, just ignore and return null.
+			}
+		}
+		
+		return null;
+	}
+
+}