You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ga...@apache.org on 2010/05/12 23:08:56 UTC
svn commit: r943689 - in /incubator/aries/trunk/jndi: ./ jndi-api/
jndi-api/src/ jndi-api/src/main/ jndi-api/src/main/java/
jndi-api/src/main/java/org/ jndi-api/src/main/java/org/osgi/
jndi-api/src/main/java/org/osgi/service/ jndi-api/src/main/java/org...
Author: gawor
Date: Wed May 12 21:08:55 2010
New Revision: 943689
URL: http://svn.apache.org/viewvc?rev=943689&view=rev
Log:
ARIES-311: Some initial JNDI spec updates. Still more to do
Added:
incubator/aries/trunk/jndi/jndi-api/
incubator/aries/trunk/jndi/jndi-api/pom.xml (with props)
incubator/aries/trunk/jndi/jndi-api/src/
incubator/aries/trunk/jndi/jndi-api/src/main/
incubator/aries/trunk/jndi/jndi-api/src/main/java/
incubator/aries/trunk/jndi/jndi-api/src/main/java/org/
incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/
incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/
incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/
incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIConstants.java (with props)
incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIContextManager.java (with props)
incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIProviderAdmin.java (with props)
incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/package.html (with props)
incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/packageinfo
Removed:
incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContextFactory.java
Modified:
incubator/aries/trunk/jndi/jndi-core/pom.xml
incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java
incubator/aries/trunk/jndi/jndi-url/pom.xml
incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java
incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java
incubator/aries/trunk/jndi/pom.xml
Added: incubator/aries/trunk/jndi/jndi-api/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-api/pom.xml?rev=943689&view=auto
==============================================================================
--- incubator/aries/trunk/jndi/jndi-api/pom.xml (added)
+++ incubator/aries/trunk/jndi/jndi-api/pom.xml Wed May 12 21:08:55 2010
@@ -0,0 +1,42 @@
+<!--
+ 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.2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>org.apache.aries.jndi.api</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Aries JNDI API</name>
+ <description>
+ This bundle contains the JNDI 1.0.0 API
+ </description>
+
+ <properties>
+ <aries.osgi.export>
+ org.osgi.service.jndi;version="1.0.0"
+ </aries.osgi.export>
+ <aries.osgi.import>
+ !org.osgi.service.jndi*,
+ *
+ </aries.osgi.import>
+ </properties>
+
+</project>
Propchange: incubator/aries/trunk/jndi/jndi-api/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jndi/jndi-api/pom.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jndi/jndi-api/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIConstants.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIConstants.java?rev=943689&view=auto
==============================================================================
--- incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIConstants.java (added)
+++ incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIConstants.java Wed May 12 21:08:55 2010
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) OSGi Alliance (2009, 2010). All Rights Reserved.
+ *
+ * Licensed 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.osgi.service.jndi;
+
+/**
+ * Constants for the JNDI implementation.
+ *
+ * @version $Revision$
+ * @Immutable
+ */
+public class JNDIConstants {
+ /**
+ * This service property is set by JNDI Providers that publish URL Context
+ * Factories as OSGi Services. The value of this property should be the URL
+ * scheme that is supported by the published service.
+ */
+ public static final String JNDI_URLSCHEME = "osgi.jndi.url.scheme";
+
+ /**
+ * This service property is set on an OSGi service to provide a name that
+ * can be used to locate the service other than the service interface name.
+ */
+ public static final String JNDI_SERVICENAME = "osgi.jndi.service.name";
+
+ /**
+ * This JNDI environment property can be used by a JNDI client to indicate
+ * the caller's BundleContext. This property can be set and passed to an
+ * InitialContext constructor. This property is only useful in the
+ * "traditional" mode of JNDI.
+ */
+ public static final String BUNDLE_CONTEXT = "osgi.service.jndi.bundleContext";
+
+ private JNDIConstants() {
+ // non-instantiable
+ }
+}
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIConstants.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIConstants.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIContextManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIContextManager.java?rev=943689&view=auto
==============================================================================
--- incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIContextManager.java (added)
+++ incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIContextManager.java Wed May 12 21:08:55 2010
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) OSGi Alliance (2009, 2010). All Rights Reserved.
+ *
+ * Licensed 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.osgi.service.jndi;
+
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+
+/**
+ * This interface defines the OSGi service interface for the JNDIContextManager.
+ *
+ * This service provides the ability to create new JNDI Context instances
+ * without relying on the InitialContext constructor.
+ *
+ * @version $Revision$
+ * @ThreadSafe
+ */
+public interface JNDIContextManager {
+
+ /**
+ * Creates a new JNDI initial context with the default JNDI environment
+ * properties.
+ *
+ * @return an instance of javax.naming.Context
+ * @throws NamingException upon any error that occurs during context
+ * creation
+ */
+ public Context newInitialContext() throws NamingException;
+
+ /**
+ * Creates a new JNDI initial context with the specified JNDI environment
+ * properties.
+ *
+ * @param environment JNDI environment properties specified by caller
+ * @return an instance of javax.naming.Context
+ * @throws NamingException upon any error that occurs during context
+ * creation
+ */
+ public Context newInitialContext(Map environment) throws NamingException;
+
+ /**
+ * Creates a new initial DirContext with the default JNDI environment
+ * properties.
+ *
+ * @return an instance of javax.naming.directory.DirContext
+ * @throws NamingException upon any error that occurs during context
+ * creation
+ */
+ public DirContext newInitialDirContext() throws NamingException;
+
+ /**
+ * Creates a new initial DirContext with the specified JNDI environment
+ * properties.
+ *
+ * @param environment JNDI environment properties specified by the caller
+ * @return an instance of javax.naming.directory.DirContext
+ * @throws NamingException upon any error that occurs during context
+ * creation
+ */
+ public DirContext newInitialDirContext(Map environment)
+ throws NamingException;
+}
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIContextManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIContextManager.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIContextManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIProviderAdmin.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIProviderAdmin.java?rev=943689&view=auto
==============================================================================
--- incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIProviderAdmin.java (added)
+++ incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIProviderAdmin.java Wed May 12 21:08:55 2010
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) OSGi Alliance (2009, 2010). All Rights Reserved.
+ *
+ * Licensed 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.osgi.service.jndi;
+
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.directory.Attributes;
+
+/**
+ * This interface defines the OSGi service interface for the JNDIProviderAdmin
+ * service.
+ *
+ * This service provides the ability to resolve JNDI References in a dynamic
+ * fashion that does not require calls to
+ * <code>NamingManager.getObjectInstance()</code>. The methods of this service
+ * provide similar reference resolution, but rely on the OSGi Service Registry
+ * in order to find <code>ObjectFactory</code> instances that can convert a
+ * Reference to an Object.
+ *
+ * This service will typically be used by OSGi-aware JNDI Service Providers.
+ *
+ * @version $Revision$
+ * @ThreadSafe
+ */
+public interface JNDIProviderAdmin {
+
+ /**
+ * Resolve the object from the given reference.
+ *
+ * @param refInfo Reference info
+ * @param name the JNDI name associated with this reference
+ * @param context the JNDI context associated with this reference
+ * @param environment the JNDI environment associated with this JNDI context
+ * @return an Object based on the reference passed in, or the original
+ * reference object if the reference could not be resolved.
+ * @throws Exception in the event that an error occurs while attempting to
+ * resolve the JNDI reference.
+ */
+ public Object getObjectInstance(Object refInfo, Name name, Context context,
+ Map environment) throws Exception;
+
+ /**
+ * Resolve the object from the given reference.
+ *
+ * @param refInfo Reference info
+ * @param name the JNDI name associated with this reference
+ * @param context the JNDI context associated with this reference
+ * @param environment the JNDI environment associated with this JNDI context
+ * @param attributes the naming attributes to use when resolving this object
+ * @return an Object based on the reference passed in, or the original
+ * reference object if the reference could not be resolved.
+ * @throws Exception in the event that an error occurs while attempting to
+ * resolve the JNDI reference.
+ */
+ public Object getObjectInstance(Object refInfo, Name name, Context context,
+ Map environment, Attributes attributes) throws Exception;
+}
\ No newline at end of file
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIProviderAdmin.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIProviderAdmin.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/JNDIProviderAdmin.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/package.html
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/package.html?rev=943689&view=auto
==============================================================================
--- incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/package.html (added)
+++ incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/package.html Wed May 12 21:08:55 2010
@@ -0,0 +1,10 @@
+<!-- $Revision$ -->
+<BODY>
+<P>JNDI Package Version 1.0.
+<p>Bundles wishing to use this package must list the package
+in the Import-Package header of the bundle's manifest.
+For example:
+<pre>
+Import-Package: org.osgi.service.jndi; version="[1.0,2.0)"
+</pre>
+</BODY>
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/package.html
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/package.html
------------------------------------------------------------------------------
svn:mime-type = text/html
Added: incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/packageinfo
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/packageinfo?rev=943689&view=auto
==============================================================================
--- incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/packageinfo (added)
+++ incubator/aries/trunk/jndi/jndi-api/src/main/java/org/osgi/service/jndi/packageinfo Wed May 12 21:08:55 2010
@@ -0,0 +1 @@
+version 1.0
Modified: incubator/aries/trunk/jndi/jndi-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-core/pom.xml?rev=943689&r1=943688&r2=943689&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/jndi-core/pom.xml (original)
+++ incubator/aries/trunk/jndi/jndi-core/pom.xml Wed May 12 21:08:55 2010
@@ -45,6 +45,10 @@
<dependencies>
<dependency>
+ <groupId>org.apache.aries.jndi</groupId>
+ <artifactId>org.apache.aries.jndi.api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<scope>provided</scope>
Modified: incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java?rev=943689&r1=943688&r2=943689&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java (original)
+++ incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java Wed May 12 21:08:55 2010
@@ -30,6 +30,7 @@ import javax.naming.spi.ObjectFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.jndi.JNDIConstants;
/**
* Provides helper methods for the DelegateContext. This provides the methods so
@@ -208,7 +209,7 @@ public final class ContextHelper
try {
ServiceReference[] services = context.getServiceReferences(ObjectFactory.class.getName(),
- "(|(osgi.jndi.urlScheme=" + urlScheme + ")(urlScheme=" + urlScheme + "))");
+ "(" + JNDIConstants.JNDI_URLSCHEME + "=" + urlScheme + ")");
if (services != null) {
ref = services[0];
Modified: incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java?rev=943689&r1=943688&r2=943689&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java (original)
+++ incubator/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java Wed May 12 21:08:55 2010
@@ -18,57 +18,136 @@
*/
package org.apache.aries.jndi;
+import java.util.Arrays;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
import javax.naming.spi.InitialContextFactory;
import javax.naming.spi.InitialContextFactoryBuilder;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+public class OSGiInitialContextFactoryBuilder implements InitialContextFactoryBuilder, InitialContextFactory {
-public class OSGiInitialContextFactoryBuilder implements InitialContextFactoryBuilder,
- InitialContextFactory
-{
private BundleContext _context;
- public OSGiInitialContextFactoryBuilder(BundleContext context)
- {
+ public OSGiInitialContextFactoryBuilder(BundleContext context) {
_context = context;
}
- public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment)
- throws NamingException
- {
- return this;
- }
- public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException
- {
- Context toReturn = null;
-
- ServiceReference ref = _context.getServiceReference(DelegateContextFactory.class.getName());
-
- //TODO: is the custom interface DelegateContextFactory the right way to go about things
- // or is there a more generic way in RFC 142
- if (ref != null) {
- try {
- DelegateContextFactory dcf = (DelegateContextFactory) _context.getService(ref);
-
- if (dcf != null) {
- toReturn = dcf.getInitialContext(environment);
- }
- }
- finally {
- _context.ungetService(ref);
- }
- }
-
- if (toReturn == null) {
- toReturn = new DelegateContext(environment);
- }
-
- return toReturn;
- }
+ public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment)
+ throws NamingException {
+ return this;
+ }
+
+ public Context getInitialContext(Hashtable<?, ?> environment)
+ throws NamingException {
+
+ // TODO: use caller's bundle context
+
+ Context initialContext = null;
+
+ String contextFactoryClass = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
+ if (contextFactoryClass == null) {
+ // 1. get ContextFactory using builder
+ initialContext = getInitialContextUsingBuilder(_context, environment);
+
+ // 2. lookup all ContextFactory services
+ if (initialContext == null) {
+ String filter = "(&(objectClass=javax.naming.spi.InitialContextFactory))";
+ ServiceReference[] references = null;
+ try {
+ references = _context.getAllServiceReferences(InitialContextFactory.class.getName(), filter);
+ } catch (InvalidSyntaxException e) {
+ NamingException ex = new NamingException("Bad filter: " + filter);
+ ex.initCause(e);
+ throw ex;
+ }
+ if (references != null) {
+ for (int i = 0; i < references.length && initialContext == null; i++) {
+ ServiceReference reference = references[i];
+ InitialContextFactory factory = (InitialContextFactory) _context.getService(reference);
+ try {
+ initialContext = factory.getInitialContext(environment);
+ } finally {
+ _context.ungetService(reference);
+ }
+ }
+ }
+ }
+
+ if (initialContext == null) {
+ // TODO: only url based lookups are allowed
+ return new DelegateContext(environment);
+ } else {
+ return new DelegateContext(initialContext);
+ }
+ } else {
+ // 1. lookup ContextFactory using the factory class
+ String filter = "(&(objectClass=javax.naming.spi.InitialContextFactory)(objectClass=" + contextFactoryClass + "))";
+ ServiceReference[] references = null;
+ try {
+ references = _context.getServiceReferences(InitialContextFactory.class.getName(), filter);
+ } catch (InvalidSyntaxException e) {
+ NamingException ex = new NamingException("Bad filter: " + filter);
+ ex.initCause(e);
+ throw ex;
+ }
+
+ if (references != null && references.length > 0) {
+ Arrays.sort(references);
+ ServiceReference factoryReference = references[0];
+ InitialContextFactory factory = (InitialContextFactory)_context.getService(factoryReference);
+ try {
+ initialContext = factory.getInitialContext(environment);
+ } finally {
+ _context.ungetService(factoryReference);
+ }
+ }
+
+ // 2. get ContextFactory using builder
+ if (initialContext == null) {
+ initialContext = getInitialContextUsingBuilder(_context, environment);
+ }
+
+ if (initialContext == null) {
+ throw new NoInitialContextException("We could not find an InitialContextFactory to use");
+ } else {
+ return new DelegateContext(initialContext);
+ }
+ }
+ }
+
+ private static Context getInitialContextUsingBuilder(BundleContext context, Hashtable<?, ?> environment)
+ throws NamingException {
+ InitialContextFactory factory = getInitialContextFactoryBuilder(context, environment);
+ return (factory == null) ? null : factory.getInitialContext(environment);
+ }
+
+ private static InitialContextFactory getInitialContextFactoryBuilder(BundleContext context, Hashtable<?, ?> environment)
+ throws NamingException {
+ InitialContextFactory factory = null;
+ try {
+ ServiceReference[] refs = context.getAllServiceReferences(InitialContextFactoryBuilder.class.getName(), null);
+ if (refs != null) {
+ Arrays.sort(refs);
+ for (int i = 0; i < refs.length && factory == null; i++) {
+ ServiceReference ref = refs[i];
+ InitialContextFactoryBuilder builder = (InitialContextFactoryBuilder) context.getService(ref);
+ try {
+ factory = builder.createInitialContextFactory(environment);
+ } finally {
+ context.ungetService(ref);
+ }
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ // ignore - should never happen
+ }
+ return factory;
+ }
}
Modified: incubator/aries/trunk/jndi/jndi-url/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-url/pom.xml?rev=943689&r1=943688&r2=943689&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/jndi-url/pom.xml (original)
+++ incubator/aries/trunk/jndi/jndi-url/pom.xml Wed May 12 21:08:55 2010
@@ -45,6 +45,10 @@
<dependencies>
<dependency>
+ <groupId>org.apache.aries.jndi</groupId>
+ <artifactId>org.apache.aries.jndi.api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.aries</groupId>
<artifactId>org.apache.aries.util</artifactId>
</dependency>
Modified: incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java?rev=943689&r1=943688&r2=943689&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java (original)
+++ incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java Wed May 12 21:08:55 2010
@@ -43,6 +43,7 @@ import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceException;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.jndi.JNDIConstants;
/**
* This helper provides access to services registered in the OSGi service registry.
@@ -86,9 +87,12 @@ public final class ServiceHelper
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
- if (pair.ref.getBundle() == null) {
- if (dynamic) pair = findService(ctx, interfaceName, filter);
- else pair = null;
+ if (pair == null || pair.ref.getBundle() == null) {
+ if (dynamic) {
+ pair = findService(ctx, interfaceName, filter);
+ } else {
+ pair = null;
+ }
}
if (pair == null) {
@@ -118,7 +122,7 @@ public final class ServiceHelper
{
BundleContext result = null;
- Object bc = env.get("osgi.service.jndi.bundleContext");
+ Object bc = env.get(JNDIConstants.BUNDLE_CONTEXT);
if (bc != null && bc instanceof BundleContext) result = (BundleContext) bc;
else {
@@ -215,9 +219,9 @@ public final class ServiceHelper
if (pair == null) {
interfaceName = null;
if (id == null) {
- filter = "(osgi.jndi.service.name=" + serviceName + ')';
+ filter = "(" + JNDIConstants.JNDI_SERVICENAME + "=" + serviceName + ')';
} else {
- filter = "(&(" + Constants.SERVICE_ID + '=' + id + ")(osgi.jndi.service.name=" + serviceName + "))";
+ filter = "(&(" + Constants.SERVICE_ID + '=' + id + ")(" + JNDIConstants.JNDI_SERVICENAME + "=" + serviceName + "))";
}
pair = findService(ctx, interfaceName, filter);
}
@@ -332,7 +336,7 @@ public final class ServiceHelper
refs = ctx.getServiceReferences(interface1, filter);
if (refs == null || refs.length == 0) {
- refs = ctx.getServiceReferences(null, "(osgi.jndi.service.name=" + serviceName + ')');
+ refs = ctx.getServiceReferences(null, "(" + JNDIConstants.JNDI_SERVICENAME + "=" + serviceName + ')');
}
} catch (InvalidSyntaxException e) {
throw (NamingException) new NamingException(e.getFilter()).initCause(e);
Modified: incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java?rev=943689&r1=943688&r2=943689&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java (original)
+++ incubator/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java Wed May 12 21:08:55 2010
@@ -25,6 +25,7 @@ import javax.naming.spi.ObjectFactory;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.jndi.JNDIConstants;
public class Activator implements BundleActivator {
@@ -33,7 +34,7 @@ public class Activator implements Bundle
public void start(BundleContext context)
{
Hashtable<Object, Object> props = new Hashtable<Object, Object>();
- props.put("osgi.jndi.urlScheme", new String[] {"osgi", "aries"} );
+ props.put(JNDIConstants.JNDI_URLSCHEME, new String[] {"osgi", "aries"} );
reg = context.registerService(ObjectFactory.class.getName(), new OsgiURLContextFactory(), props);
}
Modified: incubator/aries/trunk/jndi/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi/pom.xml?rev=943689&r1=943688&r2=943689&view=diff
==============================================================================
--- incubator/aries/trunk/jndi/pom.xml (original)
+++ incubator/aries/trunk/jndi/pom.xml Wed May 12 21:08:55 2010
@@ -46,6 +46,11 @@
<!-- internal dependencies -->
<dependency>
<groupId>org.apache.aries.jndi</groupId>
+ <artifactId>org.apache.aries.jndi.api</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.jndi</groupId>
<artifactId>org.apache.aries.jndi.core</artifactId>
<version>${version}</version>
</dependency>
@@ -82,6 +87,7 @@
</dependencies>
<modules>
+ <module>jndi-api</module>
<module>jndi-core</module>
<module>jndi-url</module>
<module>jndi-bundle</module>