aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r1041608 - in /incubator/aries/trunk/jndi/jndi-legacy-support: ./ pom.xml src/main/java/org/apache/aries/jndi/legacy/support/Activator.java src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java
Date Thu, 02 Dec 2010 22:10:00 GMT
Author: not
Date: Thu Dec  2 22:09:59 2010
New Revision: 1041608

URL: http://svn.apache.org/viewvc?rev=1041608&view=rev
Log:
ARIES-431 Reintroducing the jndi-legacy-support which was removed. Tagging with the original
JIRA used to provide the code.

Added:
    incubator/aries/trunk/jndi/jndi-legacy-support/pom.xml
    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
Modified:
    incubator/aries/trunk/jndi/jndi-legacy-support/   (props changed)

Propchange: incubator/aries/trunk/jndi/jndi-legacy-support/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Dec  2 22:09:59 2010
@@ -1 +1,4 @@
 target
+.settings
+.classpath
+.project

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=1041608&view=auto
==============================================================================
--- incubator/aries/trunk/jndi/jndi-legacy-support/pom.xml (added)
+++ incubator/aries/trunk/jndi/jndi-legacy-support/pom.xml Thu Dec  2 22:09:59 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=1041608&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 Dec  2 22:09:59 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=1041608&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 Dec  2 22:09:59 2010
@@ -0,0 +1,54 @@
+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;
+
+/**
+ * Some OSGi based server runtimes, such as jetty OSGi and virgo rely on the thread context
classloader
+ * to make their JNDI InitialContextFactory's available in OSGi, rather than relying on the
OSGi JNDI spec.
+ * This is a little bizare, but perhaps is just a point in time statement. In any case to
support them
+ * using Aries JNDI we have this ICFB which uses the Thread context classloader. We don't
ship it in the
+ * jndi uber bundle because it is only for these runtimes which haven't caught up with the
latest OSGi specs.
+ * Normally we want to enourage the use of the OSGi spec, but this is a backstop for those
wanting to use
+ * Aries JNDI and one of these runtimes.
+ *
+ */
+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;
+	}
+
+}



Mime
View raw message