You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gn...@apache.org on 2018/02/21 09:04:42 UTC

svn commit: r1824942 [1/4] - in /aries/trunk/jndi: jndi-api/src/main/java/org/apache/aries/jndi/api/ jndi-api/src/main/java/org/apache/aries/jndi/spi/ jndi-api/src/main/java/org/apache/aries/jndi/urls/ jndi-bundle/src/main/java/org/apache/aries/jndi/pr...

Author: gnodet
Date: Wed Feb 21 09:04:41 2018
New Revision: 1824942

URL: http://svn.apache.org/viewvc?rev=1824942&view=rev
Log:
[jndi] Reformat and generify a bit

Modified:
    aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/api/JNDIConstants.java
    aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/AugmenterInvoker.java
    aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/EnvironmentAugmentation.java
    aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/EnvironmentUnaugmentation.java
    aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/urls/URLObjectFactoryFinder.java
    aries/trunk/jndi/jndi-bundle/src/main/java/org/apache/aries/jndi/priv/Activator.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/AugmenterInvokerImpl.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextManagerService.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextManagerServiceFactory.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextProvider.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DirObjectFactoryHelper.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/JREInitialContextFactoryBuilder.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ObjectFactoryHelper.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ProviderAdminService.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ProviderAdminServiceFactory.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/SingleContextProvider.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Tuple.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/URLContextProvider.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/tracker/ServiceTrackerCustomizers.java
    aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java
    aries/trunk/jndi/jndi-core/src/test/java/org/apache/aries/jndi/ObjectFactoryTest.java
    aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/Activator.java
    aries/trunk/jndi/jndi-legacy-support/src/main/java/org/apache/aries/jndi/legacy/support/LegacyInitialContextFinder.java
    aries/trunk/jndi/jndi-rmi/src/main/java/org/apache/aries/jndi/rmi/Activator.java
    aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/JndiUrlItestServlet.java
    aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/beans/ConfigBean.java
    aries/trunk/jndi/jndi-url-itest-web/src/main/java/org/apache/aries/jndiurl/itest/beans/SimpleBean.java
    aries/trunk/jndi/jndi-url-itest/src/test/java/org/apache/aries/jndi/itests/JndiUrlIntegrationTest.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/AbstractName.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/AbstractServiceRegistryContext.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintName.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintNameParser.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContext.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContextFactory.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintURLContextServiceFactory.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiName.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiNameParser.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiURLContextFactory.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java
    aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryListContext.java
    aries/trunk/jndi/jndi-url/src/test/java/org/apache/aries/jndi/services/ServiceHelperTest.java

Modified: aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/api/JNDIConstants.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/api/JNDIConstants.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/api/JNDIConstants.java (original)
+++ aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/api/JNDIConstants.java Wed Feb 21 09:04:41 2018
@@ -19,9 +19,11 @@
 package org.apache.aries.jndi.api;
 
 
-public final class JNDIConstants
-{
-  public static final String REBIND_TIMEOUT = "org.apache.aries.jndi.rebind.timeout";
-  
-  private JNDIConstants() {}
+public final class JNDIConstants {
+
+    public static final String REBIND_TIMEOUT = "org.apache.aries.jndi.rebind.timeout";
+
+    private JNDIConstants() {
+    }
+
 }

Modified: aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/AugmenterInvoker.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/AugmenterInvoker.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/AugmenterInvoker.java (original)
+++ aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/AugmenterInvoker.java Wed Feb 21 09:04:41 2018
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -20,8 +20,10 @@ package org.apache.aries.jndi.spi;
 
 import java.util.Hashtable;
 
-public interface AugmenterInvoker 
-{
-  public void augmentEnvironment(Hashtable<?, ?> environment);
-  public void unaugmentEnvironment(Hashtable<?, ?> environment);
+public interface AugmenterInvoker {
+
+    void augmentEnvironment(Hashtable<?, ?> environment);
+
+    void unaugmentEnvironment(Hashtable<?, ?> environment);
+
 }

Modified: aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/EnvironmentAugmentation.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/EnvironmentAugmentation.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/EnvironmentAugmentation.java (original)
+++ aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/EnvironmentAugmentation.java Wed Feb 21 09:04:41 2018
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -20,7 +20,8 @@ package org.apache.aries.jndi.spi;
 
 import java.util.Hashtable;
 
-public interface EnvironmentAugmentation 
-{
-  public void augmentEnvironment(Hashtable<?, ?> env);
+public interface EnvironmentAugmentation {
+
+    void augmentEnvironment(Hashtable<?, ?> env);
+
 }

Modified: aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/EnvironmentUnaugmentation.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/EnvironmentUnaugmentation.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/EnvironmentUnaugmentation.java (original)
+++ aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/spi/EnvironmentUnaugmentation.java Wed Feb 21 09:04:41 2018
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -20,7 +20,8 @@ package org.apache.aries.jndi.spi;
 
 import java.util.Hashtable;
 
-public interface EnvironmentUnaugmentation 
-{
-  public void unaugmentEnvironment(Hashtable<?, ?> env);
+public interface EnvironmentUnaugmentation {
+
+    void unaugmentEnvironment(Hashtable<?, ?> env);
+
 }

Modified: aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/urls/URLObjectFactoryFinder.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/urls/URLObjectFactoryFinder.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/urls/URLObjectFactoryFinder.java (original)
+++ aries/trunk/jndi/jndi-api/src/main/java/org/apache/aries/jndi/urls/URLObjectFactoryFinder.java Wed Feb 21 09:04:41 2018
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -18,12 +18,12 @@
  */
 package org.apache.aries.jndi.urls;
 
-import java.util.Hashtable;
-
 import javax.naming.NamingException;
 import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+
+public interface URLObjectFactoryFinder {
+
+    ObjectFactory findFactory(String url, Hashtable<?, ?> env) throws NamingException;
 
-public interface URLObjectFactoryFinder 
-{
-  public ObjectFactory findFactory(String url, Hashtable<?, ?> env) throws NamingException;
 }

Modified: aries/trunk/jndi/jndi-bundle/src/main/java/org/apache/aries/jndi/priv/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-bundle/src/main/java/org/apache/aries/jndi/priv/Activator.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-bundle/src/main/java/org/apache/aries/jndi/priv/Activator.java (original)
+++ aries/trunk/jndi/jndi-bundle/src/main/java/org/apache/aries/jndi/priv/Activator.java Wed Feb 21 09:04:41 2018
@@ -1,4 +1,4 @@
-/**
+/*
  * 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

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/AugmenterInvokerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/AugmenterInvokerImpl.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/AugmenterInvokerImpl.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/AugmenterInvokerImpl.java Wed Feb 21 09:04:41 2018
@@ -18,49 +18,47 @@
  */
 package org.apache.aries.jndi;
 
-import java.util.Hashtable;
-
+import org.apache.aries.jndi.spi.AugmenterInvoker;
 import org.apache.aries.jndi.spi.EnvironmentAugmentation;
 import org.apache.aries.jndi.spi.EnvironmentUnaugmentation;
-import org.apache.aries.jndi.spi.AugmenterInvoker;
 import org.apache.aries.jndi.startup.Activator;
 
+import java.util.Hashtable;
+
 
 public class AugmenterInvokerImpl implements AugmenterInvoker {
-  
+
     private static AugmenterInvokerImpl instance = null;
-    
+
     public static AugmenterInvokerImpl getInstance() {
-      if (instance == null) {
-        instance = new AugmenterInvokerImpl();
-      }
-      return instance;
+        if (instance == null) {
+            instance = new AugmenterInvokerImpl();
+        }
+        return instance;
     }
 
 
-    public void augmentEnvironment(Hashtable<?, ?> environment) 
-    {
-      Object[] objects = Activator.getEnvironmentAugmentors();
-      
-      if (objects != null) {
-        for (Object obj : objects) {
-          if (obj instanceof EnvironmentAugmentation) {
-            ((EnvironmentAugmentation)obj).augmentEnvironment(environment);
-          }
+    public void augmentEnvironment(Hashtable<?, ?> environment) {
+        Object[] objects = Activator.getEnvironmentAugmentors();
+
+        if (objects != null) {
+            for (Object obj : objects) {
+                if (obj instanceof EnvironmentAugmentation) {
+                    ((EnvironmentAugmentation) obj).augmentEnvironment(environment);
+                }
+            }
         }
-      }
     }
-    
-    public void unaugmentEnvironment(Hashtable<?, ?> environment) 
-    {
-      Object[] objects = Activator.getEnvironmentUnaugmentors();
-      
-      if (objects != null) {
-        for (Object obj : objects) {
-          if (obj instanceof EnvironmentUnaugmentation) {
-            ((EnvironmentUnaugmentation)obj).unaugmentEnvironment(environment);
-          }
+
+    public void unaugmentEnvironment(Hashtable<?, ?> environment) {
+        Object[] objects = Activator.getEnvironmentUnaugmentors();
+
+        if (objects != null) {
+            for (Object obj : objects) {
+                if (obj instanceof EnvironmentUnaugmentation) {
+                    ((EnvironmentUnaugmentation) obj).unaugmentEnvironment(environment);
+                }
+            }
         }
-      }
     }
 }

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java Wed Feb 21 09:04:41 2018
@@ -18,19 +18,6 @@
  */
 package org.apache.aries.jndi;
 
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Hashtable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.NoInitialContextException;
-import javax.naming.spi.InitialContextFactory;
-import javax.naming.spi.InitialContextFactoryBuilder;
-import javax.naming.spi.ObjectFactory;
-
 import org.apache.aries.jndi.startup.Activator;
 import org.apache.aries.jndi.tracker.ServiceTrackerCustomizers;
 import org.apache.aries.jndi.urls.URLObjectFactoryFinder;
@@ -40,13 +27,29 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.ServiceReference;
 
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.ObjectFactory;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Hashtable;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 /**
  * Provides helper methods for the DelegateContext. This provides the methods so
  * there can be many DelegateContexts, but few service trackers.
  */
 public final class ContextHelper {
 
-    /** Ensure no one constructs us */
+    private static final Logger logger = Logger.getLogger(ContextHelper.class.getName());
+
+    /**
+     * Ensure no one constructs us
+     */
     private ContextHelper() {
         throw new RuntimeException();
     }
@@ -54,7 +57,7 @@ public final class ContextHelper {
     /**
      * This method is used to create a URL Context. It does this by looking for
      * the URL context's ObjectFactory in the service registry.
-     * 
+     *
      * @param context
      * @param urlScheme
      * @param env
@@ -62,15 +65,15 @@ public final class ContextHelper {
      * @throws NamingException
      */
     public static ContextProvider createURLContext(final BundleContext context,
-                                           final String urlScheme, 
-                                           final Hashtable<?, ?> env)
-        throws NamingException {
-      
+                                                   final String urlScheme,
+                                                   final Hashtable<?, ?> env)
+            throws NamingException {
+
         ServicePair<ObjectFactory> urlObjectFactory = getURLObjectFactory(context, urlScheme, env);
-        
+
         if (urlObjectFactory != null) {
             ObjectFactory factory = urlObjectFactory.get();
-            
+
             if (factory != null) {
                 return new URLContextProvider(context, urlObjectFactory.getReference(), factory, env);
             }
@@ -79,83 +82,81 @@ public final class ContextHelper {
         // if we got here then we couldn't find a URL context factory so return null.
         return null;
     }
-    
-    public static final ServicePair<ObjectFactory> getURLObjectFactory(final BundleContext ctx, String urlScheme, Hashtable<?, ?> environment)
-      throws NamingException
-    {
-      ServicePair<ObjectFactory> result = null;
-      
-      ServiceReference ref = ServiceTrackerCustomizers.URL_FACTORY_CACHE.find(urlScheme);
-      
-      if (ref == null) {
-        ServiceReference[] refs = AccessController.doPrivileged(new PrivilegedAction<ServiceReference[]>() {
-            public ServiceReference[] run() {
-                return Activator.getURLObectFactoryFinderServices();
+
+    public static ServicePair<ObjectFactory> getURLObjectFactory(final BundleContext ctx, String urlScheme, Hashtable<?, ?> environment)
+            throws NamingException {
+        ServicePair<ObjectFactory> result = null;
+
+        ServiceReference ref = ServiceTrackerCustomizers.URL_FACTORY_CACHE.find(urlScheme);
+
+        if (ref == null) {
+            ServiceReference<URLObjectFactoryFinder>[] refs = AccessController.doPrivileged(new PrivilegedAction<ServiceReference<URLObjectFactoryFinder>[]>() {
+                public ServiceReference<URLObjectFactoryFinder>[] run() {
+                    return Activator.getURLObjectFactoryFinderServices();
+                }
+            });
+
+            if (refs != null) {
+                for (final ServiceReference<URLObjectFactoryFinder> finderRef : refs) {
+                    URLObjectFactoryFinder finder = Utils.getServicePrivileged(ctx, finderRef);
+
+                    if (finder != null) {
+                        ObjectFactory f = finder.findFactory(urlScheme, environment);
+
+                        if (f != null) {
+                            result = new ServicePair<ObjectFactory>(ctx, finderRef, f);
+                            break;
+                        } else {
+                            ctx.ungetService(finderRef);
+                        }
+                    }
+                }
             }
-        });        
-        
-        if (refs != null) {
-          for (final ServiceReference finderRef : refs) {
-            URLObjectFactoryFinder finder = (URLObjectFactoryFinder) Utils.getServicePrivileged(ctx, finderRef);
-                
-            if (finder != null) {
-              ObjectFactory f = finder.findFactory(urlScheme, environment);
-              
-              if (f != null) {
-                result = new ServicePair<ObjectFactory>(ctx, finderRef, f);
-                break;
-              } else {
-                ctx.ungetService(finderRef);
-              }
-            }
-          }
-        }
-      } else {
-        result = new ServicePair<ObjectFactory>(ctx, ref);
-      }
-      
-      return result;
+        } else {
+            result = new ServicePair<ObjectFactory>(ctx, ref);
+        }
+
+        return result;
     }
-        
+
     public static Context getInitialContext(BundleContext context, Hashtable<?, ?> environment)
-        throws NamingException {
-      
-      final Bundle jndiBundle = FrameworkUtil.getBundle(ContextHelper.class);
-      // if we are outside OSGi (like in our unittests) then we would get Null back here, so just make sure we don't.
-      if (jndiBundle != null) {
-        
-        BundleContext jndiBundleContext = AccessController.doPrivileged(new PrivilegedAction<BundleContext>() {
-          public BundleContext run()
-          {
-            return jndiBundle.getBundleContext();
-          }
-        });
-        
-        if (!!!jndiBundleContext.getClass().equals(context.getClass())){
-          //the context passed in must have come from a child framework
-          //use the parent context instead
-          context = jndiBundleContext;
+            throws NamingException {
+
+        final Bundle jndiBundle = FrameworkUtil.getBundle(ContextHelper.class);
+        // if we are outside OSGi (like in our unittests) then we would get Null back here, so just make sure we don't.
+        if (jndiBundle != null) {
+
+            BundleContext jndiBundleContext = AccessController.doPrivileged(new PrivilegedAction<BundleContext>() {
+                public BundleContext run() {
+                    return jndiBundle.getBundleContext();
+                }
+            });
+
+            if (!jndiBundleContext.getClass().equals(context.getClass())) {
+                //the context passed in must have come from a child framework
+                //use the parent context instead
+                context = jndiBundleContext;
+            }
         }
-      }
-      
+
         ContextProvider provider = getContextProvider(context, environment);
-        
+
         if (provider != null) {
-          return new DelegateContext(context, provider);
+            return new DelegateContext(context, provider);
         } else {
-          String contextFactoryClass = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
-          if (contextFactoryClass == null) {
-            return new DelegateContext(context, environment);
-          } else {
-            throw new NoInitialContextException(Utils.MESSAGES.getMessage("no.initial.context.factory", contextFactoryClass));
-          }
+            String contextFactoryClass = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
+            if (contextFactoryClass == null) {
+                return new DelegateContext(context, environment);
+            } else {
+                throw new NoInitialContextException(Utils.MESSAGES.getMessage("no.initial.context.factory", contextFactoryClass));
+            }
         }
     }
-    
+
     public static ContextProvider getContextProvider(BundleContext context,
                                                      Hashtable<?, ?> environment)
-        throws NamingException {
-        
+            throws NamingException {
+
         ContextProvider provider = null;
         String contextFactoryClass = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
         if (contextFactoryClass == null) {
@@ -164,23 +165,23 @@ public final class ContextHelper {
 
             // 2. lookup all ContextFactory services
             if (provider == null) {
-                
-                ServiceReference[] references = AccessController.doPrivileged(new PrivilegedAction<ServiceReference[]>() {
-                    public ServiceReference[] run() {
+
+                ServiceReference<InitialContextFactory>[] references = AccessController.doPrivileged(new PrivilegedAction<ServiceReference<InitialContextFactory>[]>() {
+                    public ServiceReference<InitialContextFactory>[] run() {
                         return Activator.getInitialContextFactoryServices();
                     }
                 });
-                
+
                 if (references != null) {
-                    Context initialContext = null;
-                    for (ServiceReference reference : references) {
-                        InitialContextFactory factory = (InitialContextFactory) Utils.getServicePrivileged(context, reference);
+                    Context initialContext;
+                    for (ServiceReference<InitialContextFactory> reference : references) {
+                        InitialContextFactory factory = Utils.getServicePrivileged(context, reference);
                         try {
                             initialContext = factory.getInitialContext(environment);
                             if (initialContext != null) {
-                              provider = new SingleContextProvider(context, reference, initialContext);
-                              break;
-                          }
+                                provider = new SingleContextProvider(context, reference, initialContext);
+                                break;
+                            }
                         } finally {
                             if (provider == null) context.ungetService(reference);
                         }
@@ -188,66 +189,65 @@ public final class ContextHelper {
                 }
             }
         } else {
-            ServiceReference ref = ServiceTrackerCustomizers.ICF_CACHE.find(contextFactoryClass);
-            
+            ServiceReference<InitialContextFactory> ref = ServiceTrackerCustomizers.ICF_CACHE.find(contextFactoryClass);
+
             if (ref != null) {
-              Context initialContext = null;
-              InitialContextFactory factory = (InitialContextFactory) Utils.getServicePrivileged(context, ref);
-              if (factory != null) {
-                try {
-                    initialContext = factory.getInitialContext(environment);
-                    provider = new SingleContextProvider(context, ref, initialContext);
-                } finally {
-                    if (provider == null) context.ungetService(ref);
+                Context initialContext;
+                InitialContextFactory factory = Utils.getServicePrivileged(context, ref);
+                if (factory != null) {
+                    try {
+                        initialContext = factory.getInitialContext(environment);
+                        provider = new SingleContextProvider(context, ref, initialContext);
+                    } finally {
+                        if (provider == null) context.ungetService(ref);
+                    }
                 }
-              }
             }
-            
+
             // 2. get ContextFactory using builder
             if (provider == null) {
                 provider = getInitialContextUsingBuilder(context, environment);
             }
         }
-        
+
         return provider;
     }
 
-    private static final Logger logger = Logger.getLogger(ContextHelper.class.getName());
-    
     private static ContextProvider getInitialContextUsingBuilder(BundleContext context,
                                                                  Hashtable<?, ?> environment)
             throws NamingException {
-        
+
         ContextProvider provider = null;
-        ServiceReference[] refs = AccessController.doPrivileged(new PrivilegedAction<ServiceReference[]>() {
-            public ServiceReference[] run() {
+        ServiceReference<InitialContextFactoryBuilder>[] refs = AccessController.doPrivileged(new PrivilegedAction<ServiceReference<InitialContextFactoryBuilder>[]>() {
+            public ServiceReference<InitialContextFactoryBuilder>[] run() {
                 return Activator.getInitialContextFactoryBuilderServices();
-            }            
+            }
         });
-            
+
         if (refs != null) {
             InitialContextFactory factory = null;
-            for (ServiceReference ref : refs) {                    
-                InitialContextFactoryBuilder builder = (InitialContextFactoryBuilder) Utils.getServicePrivileged(context, ref);
+            for (ServiceReference<InitialContextFactoryBuilder> ref : refs) {
+                InitialContextFactoryBuilder builder = Utils.getServicePrivileged(context, ref);
                 try {
-                  factory = builder.createInitialContextFactory(environment);
+                    factory = builder.createInitialContextFactory(environment);
                 } catch (NamingException ne) {
-                  // TODO: log
-                  // ignore this, if the builder fails we want to move onto the next one
-                } catch (NullPointerException npe) { 
-                	logger.log(Level.SEVERE,  "NPE caught in ContextHelper.getInitialContextUsingBuilder. context=" + context + " ref=" + ref);
-                	throw npe;
+                    // TODO: log
+                    // ignore this, if the builder fails we want to move onto the next one
+                } catch (NullPointerException npe) {
+                    logger.log(Level.SEVERE, "NPE caught in ContextHelper.getInitialContextUsingBuilder. context=" + context + " ref=" + ref);
+                    throw npe;
                 }
-                
+
                 if (factory != null) {
-                  try {
-                    provider = new SingleContextProvider(context, ref, factory.getInitialContext(environment));
-                  } finally {
-                    if (provider == null) context.ungetService(ref); // we didn't get something back, so this was no good.
-                  }
-                  break;
+                    try {
+                        provider = new SingleContextProvider(context, ref, factory.getInitialContext(environment));
+                    } finally {
+                        if (provider == null)
+                            context.ungetService(ref); // we didn't get something back, so this was no good.
+                    }
+                    break;
                 } else {
-                  context.ungetService(ref); // we didn't get something back, so this was no good.
+                    context.ungetService(ref); // we didn't get something back, so this was no good.
                 }
             }
         }

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextManagerService.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextManagerService.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextManagerService.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextManagerService.java Wed Feb 21 09:04:41 2018
@@ -18,29 +18,24 @@
  */
 package org.apache.aries.jndi;
 
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Set;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.jndi.JNDIContextManager;
 
 import javax.naming.Context;
 import javax.naming.NamingException;
 import javax.naming.directory.DirContext;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.service.jndi.JNDIContextManager;
+import java.util.*;
 
 public class ContextManagerService implements JNDIContextManager {
 
     private Set<Context> contexts = Collections.synchronizedSet(new HashSet<Context>());
     private BundleContext callerContext;
-    
+
     public ContextManagerService(BundleContext callerContext) {
         this.callerContext = callerContext;
     }
-    
-    public void close() {      
+
+    public void close() {
         synchronized (contexts) {
             for (Context context : contexts) {
                 try {
@@ -52,12 +47,12 @@ public class ContextManagerService imple
             contexts.clear();
         }
     }
-    
+
     public Context newInitialContext() throws NamingException {
         return newInitialContext(new Hashtable<Object, Object>());
     }
 
-    public Context newInitialContext(Map<?,?> environment) throws NamingException {
+    public Context newInitialContext(Map<?, ?> environment) throws NamingException {
         return getInitialContext(environment);
     }
 
@@ -65,12 +60,12 @@ public class ContextManagerService imple
         return newInitialDirContext(new Hashtable<Object, Object>());
     }
 
-    public DirContext newInitialDirContext(Map<?,?> environment) throws NamingException {
-        return DirContext.class.cast( getInitialContext(environment) );
+    public DirContext newInitialDirContext(Map<?, ?> environment) throws NamingException {
+        return DirContext.class.cast(getInitialContext(environment));
     }
-    
-    private Context getInitialContext(Map<?,?> environment) throws NamingException {        
-        Hashtable<?,?> env = Utils.toHashtable(environment);
+
+    private Context getInitialContext(Map<?, ?> environment) throws NamingException {
+        Hashtable<?, ?> env = Utils.toHashtable(environment);
         Context context = ContextHelper.getInitialContext(callerContext, env);
         contexts.add(context);
         return context;

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextManagerServiceFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextManagerServiceFactory.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextManagerServiceFactory.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextManagerServiceFactory.java Wed Feb 21 09:04:41 2018
@@ -22,14 +22,14 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
 
-public class ContextManagerServiceFactory implements ServiceFactory {
+public class ContextManagerServiceFactory implements ServiceFactory<ContextManagerService> {
 
-    public Object getService(Bundle bundle, ServiceRegistration registration) {
+    public ContextManagerService getService(Bundle bundle, ServiceRegistration<ContextManagerService> registration) {
         return new ContextManagerService(bundle.getBundleContext());
     }
 
-    public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
-        ((ContextManagerService) service).close();
+    public void ungetService(Bundle bundle, ServiceRegistration<ContextManagerService> registration, ContextManagerService service) {
+        service.close();
     }
 
 }

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextProvider.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextProvider.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextProvider.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextProvider.java Wed Feb 21 09:04:41 2018
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -18,27 +18,27 @@
  */
 package org.apache.aries.jndi;
 
-import javax.naming.Context;
-import javax.naming.NamingException;
-
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 
+import javax.naming.Context;
+import javax.naming.NamingException;
+
 public abstract class ContextProvider {
-    private final ServiceReference reference;
+    private final ServiceReference<?> reference;
     private final BundleContext bc;
-    
-    public ContextProvider(BundleContext ctx, ServiceReference reference) {
+
+    public ContextProvider(BundleContext ctx, ServiceReference<?> reference) {
         bc = ctx;
         this.reference = reference;
     }
-    
+
     public boolean isValid() {
         return (reference.getBundle() != null);
     }
 
     public void close() throws NamingException {
-       if (bc != null) bc.ungetService(reference);
+        if (bc != null) bc.ungetService(reference);
     }
 
     public abstract Context getContext() throws NamingException;

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java Wed Feb 21 09:04:41 2018
@@ -18,38 +18,26 @@
  */
 package org.apache.aries.jndi;
 
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Map;
+import org.osgi.framework.BundleContext;
 
-import javax.naming.Binding;
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NameClassPair;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.NoInitialContextException;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
+import javax.naming.*;
+import javax.naming.directory.*;
 import javax.naming.ldap.Control;
 import javax.naming.ldap.ExtendedRequest;
 import javax.naming.ldap.ExtendedResponse;
 import javax.naming.ldap.LdapContext;
-
-import org.osgi.framework.BundleContext;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
 
 public class DelegateContext implements DirContext, LdapContext {
-    
+
     private final Hashtable<Object, Object> env = new Hashtable<Object, Object>();
 
     private final BundleContext bundleContext;
-    private ContextProvider contextProvider;
     private final Map<String, ContextProvider> urlContexts = new HashMap<String, ContextProvider>();
     private final boolean rebind;
+    private ContextProvider contextProvider;
 
     public DelegateContext(BundleContext bundleContext, Hashtable<?, ?> theEnv) {
         this.bundleContext = bundleContext;
@@ -70,7 +58,7 @@ public class DelegateContext implements
         if (ctx != null) {
             ctx.addToEnvironment(propName, propVal);
         }
-        
+
         return env.put(propName, propVal);
     }
 
@@ -86,11 +74,11 @@ public class DelegateContext implements
         if (contextProvider != null) {
             contextProvider.close();
         }
-        
+
         for (ContextProvider provider : urlContexts.values()) {
-          provider.close();
+            provider.close();
         }
-        
+
         urlContexts.clear();
         env.clear();
     }
@@ -183,7 +171,7 @@ public class DelegateContext implements
         if (ctx != null) {
             ctx.removeFromEnvironment(propName);
         }
-        
+
         return env.remove(propName);
     }
 
@@ -243,12 +231,12 @@ public class DelegateContext implements
             String scheme = name.substring(0, index);
 
             ContextProvider provider = urlContexts.get(scheme);
-            
-            if (provider == null || !!!provider.isValid()) {
-              provider = ContextHelper.createURLContext(bundleContext, scheme, env);
-              if (provider != null) urlContexts.put(scheme, provider);
+
+            if (provider == null || !provider.isValid()) {
+                provider = ContextHelper.createURLContext(bundleContext, scheme, env);
+                if (provider != null) urlContexts.put(scheme, provider);
             }
-            
+
             if (provider != null) ctx = provider.getContext();
         }
 
@@ -332,15 +320,15 @@ public class DelegateContext implements
     }
 
     public NamingEnumeration<SearchResult> search(Name name,
-                                    Attributes matchingAttributes,
-                                    String[] attributesToReturn) throws NamingException {
+                                                  Attributes matchingAttributes,
+                                                  String[] attributesToReturn) throws NamingException {
         return ((DirContext) findContext(name))
                 .search(name, matchingAttributes, attributesToReturn);
     }
 
     public NamingEnumeration<SearchResult> search(String name,
-                                    Attributes matchingAttributes,
-                                    String[] attributesToReturn) throws NamingException {
+                                                  Attributes matchingAttributes,
+                                                  String[] attributesToReturn) throws NamingException {
         return ((DirContext) findContext(name))
                 .search(name, matchingAttributes, attributesToReturn);
     }
@@ -366,47 +354,47 @@ public class DelegateContext implements
     }
 
     public NamingEnumeration<SearchResult> search(Name name,
-                                    String filterExpr,
-                                    Object[] filterArgs,
-                                    SearchControls cons) throws NamingException {
+                                                  String filterExpr,
+                                                  Object[] filterArgs,
+                                                  SearchControls cons) throws NamingException {
         return ((DirContext) findContext(name)).search(name, filterExpr, filterArgs, cons);
     }
 
     public NamingEnumeration<SearchResult> search(String name,
-                                    String filterExpr,
-                                    Object[] filterArgs,
-                                    SearchControls cons) throws NamingException {
+                                                  String filterExpr,
+                                                  Object[] filterArgs,
+                                                  SearchControls cons) throws NamingException {
         return ((DirContext) findContext(name)).search(name, filterExpr, filterArgs, cons);
     }
 
     public ExtendedResponse extendedOperation(ExtendedRequest request)
-        throws NamingException {
-      return ((LdapContext) getDefaultContext()).extendedOperation(request);
+            throws NamingException {
+        return ((LdapContext) getDefaultContext()).extendedOperation(request);
     }
 
     public Control[] getConnectControls() throws NamingException {
-      return ((LdapContext) getDefaultContext()).getConnectControls();
+        return ((LdapContext) getDefaultContext()).getConnectControls();
     }
 
     public Control[] getRequestControls() throws NamingException {
-      return ((LdapContext) getDefaultContext()).getRequestControls();
+        return ((LdapContext) getDefaultContext()).getRequestControls();
+    }
+
+    public void setRequestControls(Control[] requestControls)
+            throws NamingException {
+        ((LdapContext) getDefaultContext()).setRequestControls(requestControls);
     }
 
     public Control[] getResponseControls() throws NamingException {
-      return ((LdapContext) getDefaultContext()).getResponseControls();
+        return ((LdapContext) getDefaultContext()).getResponseControls();
     }
 
     public LdapContext newInstance(Control[] requestControls)
-        throws NamingException {
-      return ((LdapContext) getDefaultContext()).newInstance(requestControls);
+            throws NamingException {
+        return ((LdapContext) getDefaultContext()).newInstance(requestControls);
     }
 
     public void reconnect(Control[] connCtls) throws NamingException {
-      ((LdapContext) getDefaultContext()).reconnect(connCtls);
-    }
-
-    public void setRequestControls(Control[] requestControls)
-        throws NamingException {
-      ((LdapContext) getDefaultContext()).setRequestControls(requestControls);
+        ((LdapContext) getDefaultContext()).reconnect(connCtls);
     }
 }
\ No newline at end of file

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DirObjectFactoryHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DirObjectFactoryHelper.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DirObjectFactoryHelper.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DirObjectFactoryHelper.java Wed Feb 21 09:04:41 2018
@@ -18,28 +18,23 @@
  */
 package org.apache.aries.jndi;
 
-import java.util.Arrays;
-import java.util.Hashtable;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import javax.naming.Referenceable;
+import javax.naming.*;
 import javax.naming.directory.Attributes;
 import javax.naming.spi.DirObjectFactory;
 import javax.naming.spi.ObjectFactory;
 import javax.naming.spi.ObjectFactoryBuilder;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
+import java.util.Collection;
+import java.util.Hashtable;
 
 public class DirObjectFactoryHelper extends ObjectFactoryHelper implements DirObjectFactory {
 
     public DirObjectFactoryHelper(BundleContext defaultContext, BundleContext callerContext) {
         super(defaultContext, callerContext);
     }
-    
+
     public Object getObjectInstance(Object obj,
                                     Name name,
                                     Context nameCtx,
@@ -68,11 +63,10 @@ public class DirObjectFactoryHelper exte
         if (result == null || result == obj) {
             result = getObjectInstanceUsingObjectFactoryBuilders(obj, name, nameCtx, environment, attrs);
         }
-        
+
         // Step 5
-        if (result == null || result == obj) {                
-            if ((obj instanceof Reference && ((Reference) obj).getFactoryClassName() == null) ||
-                !(obj instanceof Reference)) {
+        if (result == null || result == obj) {
+            if (!(obj instanceof Reference) || ((Reference) obj).getFactoryClassName() == null) {
                 result = getObjectInstanceUsingObjectFactories(obj, name, nameCtx, environment, attrs);
             }
         }
@@ -83,8 +77,8 @@ public class DirObjectFactoryHelper exte
         // to https://www.osgi.org/bugzilla/show_bug.cgi?id=138 
         if (result == null || result == obj) {
             result = getObjectInstanceViaContextDotObjectFactories(obj, name, nameCtx, environment, attrs);
-        } 
-        
+        }
+
         return (result == null) ? obj : result;
     }
 
@@ -92,30 +86,27 @@ public class DirObjectFactoryHelper exte
                                                          Name name,
                                                          Context nameCtx,
                                                          Hashtable<?, ?> environment,
-                                                         Attributes attrs) 
-        throws Exception {
-        
+                                                         Attributes attrs)
+            throws Exception {
+
         Object result = null;
-        ServiceReference[] refs = Utils.getReferencesPrivileged(callerContext, DirObjectFactory.class);
-        if (refs != null) {
-            Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
-            for (ServiceReference ref : refs) {
-              
-                if (canCallObjectFactory(obj, ref)) {
-                    DirObjectFactory factory = (DirObjectFactory) Utils.getServicePrivileged(callerContext, ref);
-    
-                    try {
-                        result = factory.getObjectInstance(obj, name, nameCtx, environment, attrs);
-                    } finally {
-                        callerContext.ungetService(ref);
-                    }
-    
-                    // if the result comes back and is not null and not the reference
-                    // object then we should return the result, so break out of the
-                    // loop we are in.
-                    if (result != null && result != obj) {
-                        break;
-                    }
+        Collection<ServiceReference<DirObjectFactory>> refs = Utils.getReferencesPrivileged(callerContext, DirObjectFactory.class);
+        for (ServiceReference<DirObjectFactory> ref : refs) {
+
+            if (canCallObjectFactory(obj, ref)) {
+                DirObjectFactory factory = Utils.getServicePrivileged(callerContext, ref);
+
+                try {
+                    result = factory.getObjectInstance(obj, name, nameCtx, environment, attrs);
+                } finally {
+                    callerContext.ungetService(ref);
+                }
+
+                // if the result comes back and is not null and not the reference
+                // object then we should return the result, so break out of the
+                // loop we are in.
+                if (result != null && result != obj) {
+                    break;
                 }
             }
         }
@@ -123,21 +114,20 @@ public class DirObjectFactoryHelper exte
         if (result == null) {
             result = getObjectInstanceUsingObjectFactories(obj, name, nameCtx, environment);
         }
-        
+
         return (result == null) ? obj : result;
     }
 
-    private boolean canCallObjectFactory(Object obj, ServiceReference ref)
-    {
-      if (obj instanceof Reference) return true;
-      
-      Object prop = ref.getProperty("aries.object.factory.requires.reference");
-      
-      if (prop == null) return true;
-      
-      if (prop instanceof Boolean) return !!!(Boolean) prop; // if set to true we don't call.
-      
-      return true;
+    private boolean canCallObjectFactory(Object obj, ServiceReference ref) {
+        if (obj instanceof Reference) return true;
+
+        Object prop = ref.getProperty("aries.object.factory.requires.reference");
+
+        if (prop == null) return true;
+
+        if (prop instanceof Boolean) return !(Boolean) prop; // if set to true we don't call.
+
+        return true;
     }
 
     private Object getObjectInstanceUsingClassName(Object reference,
@@ -147,11 +137,11 @@ public class DirObjectFactoryHelper exte
                                                    Context nameCtx,
                                                    Hashtable<?, ?> environment,
                                                    Attributes attrs)
-        throws Exception {
+            throws Exception {
 
-        Tuple<ServiceReference, ObjectFactory> tuple = ObjectFactoryHelper.findObjectFactoryByClassName(defaultContext, className);
+        Tuple<ServiceReference<ObjectFactory>, ObjectFactory> tuple = ObjectFactoryHelper.findObjectFactoryByClassName(defaultContext, className);
         Object result = null;
-        
+
         if (tuple.second != null) {
             try {
                 result = ((DirObjectFactory) tuple.second).getObjectInstance(reference, name, nameCtx, environment, attrs);
@@ -162,42 +152,39 @@ public class DirObjectFactoryHelper exte
 
         return (result == null) ? obj : result;
     }
-  
+
     private Object getObjectInstanceUsingObjectFactoryBuilders(Object obj,
                                                                Name name,
                                                                Context nameCtx,
                                                                Hashtable<?, ?> environment,
-                                                               Attributes attrs) 
-        throws Exception {
+                                                               Attributes attrs)
+            throws Exception {
         ObjectFactory factory = null;
-        ServiceReference[] refs = Utils.getReferencesPrivileged(callerContext, ObjectFactoryBuilder.class);
-        if (refs != null) {
-            Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
-            for (ServiceReference ref : refs) {
-                ObjectFactoryBuilder builder = (ObjectFactoryBuilder) Utils.getServicePrivileged(callerContext, ref);
-                try {
-                    factory = builder.createObjectFactory(obj, environment);
-                } catch (NamingException e) {
-                    // TODO: log it
-                } finally {
-                    callerContext.ungetService(ref);
-                }
-                if (factory != null) {
-                    break;
-                }
+        Collection<ServiceReference<ObjectFactoryBuilder>> refs = Utils.getReferencesPrivileged(callerContext, ObjectFactoryBuilder.class);
+        for (ServiceReference<ObjectFactoryBuilder> ref : refs) {
+            ObjectFactoryBuilder builder = Utils.getServicePrivileged(callerContext, ref);
+            try {
+                factory = builder.createObjectFactory(obj, environment);
+            } catch (NamingException e) {
+                // TODO: log it
+            } finally {
+                callerContext.ungetService(ref);
+            }
+            if (factory != null) {
+                break;
             }
         }
 
         Object result = null;
-        
+
         if (factory != null) {
-            if (factory instanceof DirObjectFactory) {       
+            if (factory instanceof DirObjectFactory) {
                 result = ((DirObjectFactory) factory).getObjectInstance(obj, name, nameCtx, environment, attrs);
             } else {
                 result = factory.getObjectInstance(obj, name, nameCtx, environment);
             }
         }
-        
+
         return (result == null) ? obj : result;
     }
 

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/JREInitialContextFactoryBuilder.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/JREInitialContextFactoryBuilder.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/JREInitialContextFactoryBuilder.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/JREInitialContextFactoryBuilder.java Wed Feb 21 09:04:41 2018
@@ -18,19 +18,18 @@
  */
 package org.apache.aries.jndi;
 
-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;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Hashtable;
 
 public class JREInitialContextFactoryBuilder implements InitialContextFactoryBuilder {
 
     public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment)
-        throws NamingException {
+            throws NamingException {
         final String contextFactoryClass = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
         if (contextFactoryClass != null) {
             return AccessController.doPrivileged(new PrivilegedAction<InitialContextFactory>() {
@@ -38,7 +37,7 @@ public class JREInitialContextFactoryBui
                     try {
                         @SuppressWarnings("unchecked")
                         Class<? extends InitialContextFactory> clazz = (Class<? extends InitialContextFactory>) ClassLoader.
-                            getSystemClassLoader().loadClass(contextFactoryClass);
+                                getSystemClassLoader().loadClass(contextFactoryClass);
                         return InitialContextFactory.class.cast(clazz.newInstance());
                     } catch (Exception e) {
                         return null;
@@ -47,5 +46,5 @@ public class JREInitialContextFactoryBui
             });
         }
         return null;
-    }   
+    }
 }

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java Wed Feb 21 09:04:41 2018
@@ -18,7 +18,7 @@
  */
 package org.apache.aries.jndi;
 
-import java.util.Hashtable;
+import org.osgi.framework.BundleContext;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -26,28 +26,27 @@ import javax.naming.NamingException;
 import javax.naming.NoInitialContextException;
 import javax.naming.spi.InitialContextFactory;
 import javax.naming.spi.InitialContextFactoryBuilder;
-
-import org.osgi.framework.BundleContext;
+import java.util.Hashtable;
 
 public class OSGiInitialContextFactoryBuilder implements InitialContextFactoryBuilder, InitialContextFactory {
 
-	public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment) 
-	    throws NamingException {
-	    return this;
-	}
-  
-	public Context getInitialContext(Hashtable<?, ?> environment) 
-	    throws NamingException {
-	    
-	    AugmenterInvokerImpl.getInstance().augmentEnvironment(environment);
-	  
-	    BundleContext context = Utils.getBundleContext(environment, InitialContext.class);	    
-	    if (context == null) {
+    public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment)
+            throws NamingException {
+        return this;
+    }
+
+    public Context getInitialContext(Hashtable<?, ?> environment)
+            throws NamingException {
+
+        AugmenterInvokerImpl.getInstance().augmentEnvironment(environment);
+
+        BundleContext context = Utils.getBundleContext(environment, InitialContext.class);
+        if (context == null) {
             throw new NoInitialContextException(Utils.MESSAGES.getMessage("cannot.find.callers.bundlecontext"));
-	    }
-	    	    
-      AugmenterInvokerImpl.getInstance().unaugmentEnvironment(environment);
+        }
+
+        AugmenterInvokerImpl.getInstance().unaugmentEnvironment(environment);
 
-	    return ContextHelper.getInitialContext(context, environment);
-	}
+        return ContextHelper.getInitialContext(context, environment);
+    }
 }

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java Wed Feb 21 09:04:41 2018
@@ -18,30 +18,25 @@
  */
 package org.apache.aries.jndi;
 
-import java.util.Hashtable;
+import org.osgi.framework.BundleContext;
 
 import javax.naming.Context;
 import javax.naming.Name;
 import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
-import javax.naming.spi.DirObjectFactory;
-import javax.naming.spi.DirectoryManager;
-import javax.naming.spi.NamingManager;
-import javax.naming.spi.ObjectFactory;
-import javax.naming.spi.ObjectFactoryBuilder;
-
-import org.osgi.framework.BundleContext;
+import javax.naming.spi.*;
+import java.util.Hashtable;
 
 public class OSGiObjectFactoryBuilder implements ObjectFactoryBuilder, ObjectFactory, DirObjectFactory {
 
     private BundleContext defaultContext;
-    
+
     public OSGiObjectFactoryBuilder(BundleContext ctx) {
         defaultContext = ctx;
     }
 
     public ObjectFactory createObjectFactory(Object obj, Hashtable<?, ?> environment)
-        throws NamingException {
+            throws NamingException {
         return this;
     }
 
@@ -49,11 +44,11 @@ public class OSGiObjectFactoryBuilder im
                                     Name name,
                                     Context nameCtx,
                                     Hashtable<?, ?> environment) throws Exception {
-        
+
         if (environment == null) {
             environment = new Hashtable();
         }
-        
+
         BundleContext callerContext = getCallerBundleContext(environment);
         if (callerContext == null) {
             return obj;
@@ -67,11 +62,11 @@ public class OSGiObjectFactoryBuilder im
                                     Context nameCtx,
                                     Hashtable<?, ?> environment,
                                     Attributes attrs) throws Exception {
-        
+
         if (environment == null) {
             environment = new Hashtable();
         }
-        
+
         BundleContext callerContext = getCallerBundleContext(environment);
         if (callerContext == null) {
             return obj;
@@ -82,7 +77,7 @@ public class OSGiObjectFactoryBuilder im
 
     private BundleContext getCallerBundleContext(Hashtable<?, ?> environment) throws NamingException {
         AugmenterInvokerImpl.getInstance().augmentEnvironment(environment);
-        BundleContext context = Utils.getBundleContext(environment, NamingManager.class);        
+        BundleContext context = Utils.getBundleContext(environment, NamingManager.class);
         if (context == null) {
             context = Utils.getBundleContext(environment, DirectoryManager.class);
         }

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ObjectFactoryHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ObjectFactoryHelper.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ObjectFactoryHelper.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ObjectFactoryHelper.java Wed Feb 21 09:04:41 2018
@@ -18,42 +18,70 @@
  */
 package org.apache.aries.jndi;
 
+import org.apache.aries.util.service.registry.ServicePair;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+import javax.naming.*;
+import javax.naming.directory.Attributes;
+import javax.naming.spi.DirObjectFactory;
+import javax.naming.spi.ObjectFactory;
+import javax.naming.spi.ObjectFactoryBuilder;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-import java.util.Arrays;
+import java.util.Collection;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-import javax.naming.Referenceable;
-import javax.naming.StringRefAddr;
-import javax.naming.directory.Attributes;
-import javax.naming.spi.DirObjectFactory;
-import javax.naming.spi.ObjectFactory;
-import javax.naming.spi.ObjectFactoryBuilder;
-
-import org.apache.aries.util.service.registry.ServicePair;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-
 public class ObjectFactoryHelper implements ObjectFactory {
-    
+
+    private static final Logger logger = Logger.getLogger(ObjectFactoryHelper.class.getName());
     protected BundleContext defaultContext;
     protected BundleContext callerContext;
-    private static final Logger logger = Logger.getLogger(ObjectFactoryHelper.class.getName());
 
     public ObjectFactoryHelper(BundleContext defaultContext, BundleContext callerContext) {
         this.defaultContext = defaultContext;
         this.callerContext = callerContext;
     }
 
+    protected static String getUrlScheme(String name) {
+        String scheme = name;
+        int index = name.indexOf(':');
+        if (index != -1) {
+            scheme = name.substring(0, index);
+        }
+        return scheme;
+    }
+
+    static Tuple<ServiceReference<ObjectFactory>, ObjectFactory> findObjectFactoryByClassName(final BundleContext ctx, final String className) {
+        return AccessController.doPrivileged(new PrivilegedAction<Tuple<ServiceReference<ObjectFactory>, ObjectFactory>>() {
+            public Tuple<ServiceReference<ObjectFactory>, ObjectFactory> run() {
+                ServiceReference<ObjectFactory> serviceReference = null;
+
+                try {
+                    ServiceReference<?>[] refs = ctx.getServiceReferences(className, null);
+                    if (refs != null && refs.length > 0) {
+                        serviceReference = (ServiceReference<ObjectFactory>) refs[0];
+                    }
+                } catch (InvalidSyntaxException e) {
+                    // should not happen
+                    throw new RuntimeException(Utils.MESSAGES.getMessage("null.is.invalid.filter"), e);
+                }
+
+                ObjectFactory factory = null;
+
+                if (serviceReference != null) {
+                    factory = ctx.getService(serviceReference);
+                }
+
+                return new Tuple<ServiceReference<ObjectFactory>, ObjectFactory>(serviceReference, factory);
+            }
+        });
+    }
+
     public Object getObjectInstance(Object obj,
                                     Name name,
                                     Context nameCtx,
@@ -63,7 +91,7 @@ public class ObjectFactoryHelper impleme
         if (obj instanceof Referenceable) {
             obj = ((Referenceable) obj).getReference();
         }
-        
+
         if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "obj = " + obj);
 
         Object result = obj;
@@ -81,118 +109,108 @@ public class ObjectFactoryHelper impleme
                 result = getObjectInstanceUsingRefAddress(ref.getAll(), obj, name, nameCtx, environment);
             }
         }
-        
-		if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Step 4: result = " + result);
+
+        if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Step 4: result = " + result);
 
         // Step 5 - if we still don't have a resolved object goto the object factory builds in the SR.
         if (result == null || result == obj) {
             result = getObjectInstanceUsingObjectFactoryBuilders(obj, name, nameCtx, environment);
         }
 
-		if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Step 5: result = " + result);
+        if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Step 5: result = " + result);
 
         // Step 6 - Attempt to use all the registered ObjectFactories in the SR.
-        if (result == null || result == obj) {                
-            if ((obj instanceof Reference && ((Reference) obj).getFactoryClassName() == null) ||
-                !(obj instanceof Reference)) {
+        if (result == null || result == obj) {
+            if (!(obj instanceof Reference) || ((Reference) obj).getFactoryClassName() == null) {
                 result = getObjectInstanceUsingObjectFactories(obj, name, nameCtx, environment);
             }
         }
- 
-		if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Step 6: result = " + result);
 
-		// Extra, non-standard, bonus step 7. If javax.naming.OBJECT_FACTORIES is set as 
-		// a property in the environment, use its value to construct additional object factories. 
-		// Added under Aries-822, with reference 
-		// to https://www.osgi.org/bugzilla/show_bug.cgi?id=138 
-		if (result == null || result == obj) {
-			result = getObjectInstanceViaContextDotObjectFactories(obj, name, nameCtx, environment);
-		} 
-		
-		if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Step 7: result = " + result);
+        if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Step 6: result = " + result);
+
+        // Extra, non-standard, bonus step 7. If javax.naming.OBJECT_FACTORIES is set as
+        // a property in the environment, use its value to construct additional object factories.
+        // Added under Aries-822, with reference
+        // to https://www.osgi.org/bugzilla/show_bug.cgi?id=138
+        if (result == null || result == obj) {
+            result = getObjectInstanceViaContextDotObjectFactories(obj, name, nameCtx, environment);
+        }
+
+        if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Step 7: result = " + result);
 
         return (result == null) ? obj : result;
     }
- 
+
     /*
      * Attempt to obtain an Object instance via the java.naming.factory.object property
      */
     protected Object getObjectInstanceViaContextDotObjectFactories(Object obj,
-            Name name,
-            Context nameCtx,
-            Hashtable<?, ?> environment) throws Exception
-    {
-    	return getObjectInstanceViaContextDotObjectFactories(obj, name, nameCtx, environment, null);
+                                                                   Name name,
+                                                                   Context nameCtx,
+                                                                   Hashtable<?, ?> environment) throws Exception {
+        return getObjectInstanceViaContextDotObjectFactories(obj, name, nameCtx, environment, null);
     }
-    
+
     /*
      * Attempt to obtain an Object instance via the java.naming.factory.object property
      */
     protected Object getObjectInstanceViaContextDotObjectFactories(Object obj,
-            Name name,
-            Context nameCtx,
-            Hashtable<?, ?> environment,
-            Attributes attrs) throws Exception
-    {
-    	Object result = null;
-    	String factories = (String) environment.get(Context.OBJECT_FACTORIES);
-		if (factories != null && factories.length() > 0) {
-			String[] candidates = factories.split(":");
-			ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
-				public ClassLoader run() {
-					return Thread.currentThread().getContextClassLoader();
-				}
-			});
-			for (String cand : candidates) {
-				ObjectFactory factory = null;
-				try {
-					@SuppressWarnings("unchecked")
-					Class<ObjectFactory> clz = (Class<ObjectFactory>) cl.loadClass(cand);
-					factory = clz.newInstance();
-				} catch (Exception e) {
-					if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Exception instantiating factory: " + e);
-					continue;
-				}
-				if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "cand=" + cand + " factory=" + factory);
-				if (factory != null) {
-					if(factory instanceof DirObjectFactory)
-					{
-						if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "its a DirObjectFactory");
-						final DirObjectFactory dirFactory = (DirObjectFactory) factory;
-						result = dirFactory.getObjectInstance(obj, name, nameCtx, environment, attrs);
-					}
-					else
-					{
-						if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "its an ObjectFactory");
-						result = factory.getObjectInstance(obj, name, nameCtx, environment);
-					}
-				}
-				if (result != null && result != obj) break;
-			}
-		}
-		if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "result = " + result);
-		return (result == null) ? obj : result;
+                                                                   Name name,
+                                                                   Context nameCtx,
+                                                                   Hashtable<?, ?> environment,
+                                                                   Attributes attrs) throws Exception {
+        Object result = null;
+        String factories = (String) environment.get(Context.OBJECT_FACTORIES);
+        if (factories != null && factories.length() > 0) {
+            String[] candidates = factories.split(":");
+            ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+                public ClassLoader run() {
+                    return Thread.currentThread().getContextClassLoader();
+                }
+            });
+            for (String cand : candidates) {
+                ObjectFactory factory;
+                try {
+                    @SuppressWarnings("unchecked")
+                    Class<ObjectFactory> clz = (Class<ObjectFactory>) cl.loadClass(cand);
+                    factory = clz.newInstance();
+                } catch (Exception e) {
+                    if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "Exception instantiating factory: " + e);
+                    continue;
+                }
+                if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "cand=" + cand + " factory=" + factory);
+                if (factory != null) {
+                    if (factory instanceof DirObjectFactory) {
+                        if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "its a DirObjectFactory");
+                        final DirObjectFactory dirFactory = (DirObjectFactory) factory;
+                        result = dirFactory.getObjectInstance(obj, name, nameCtx, environment, attrs);
+                    } else {
+                        if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "its an ObjectFactory");
+                        result = factory.getObjectInstance(obj, name, nameCtx, environment);
+                    }
+                }
+                if (result != null && result != obj) break;
+            }
+        }
+        if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "result = " + result);
+        return (result == null) ? obj : result;
     }
 
     protected Object getObjectInstanceUsingObjectFactories(Object obj,
                                                            Name name,
                                                            Context nameCtx,
-                                                           Hashtable<?, ?> environment) 
-        throws Exception {
+                                                           Hashtable<?, ?> environment)
+            throws Exception {
         Object result = null;
-        ServiceReference[] refs = Utils.getReferencesPrivileged(callerContext, ObjectFactory.class);
-            
-        if (refs != null) {
-            Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
-            
-            for (ServiceReference ref : refs) {
-              if (canCallObjectFactory(obj, ref)) {
-                ObjectFactory factory = (ObjectFactory) Utils.getServicePrivileged(callerContext, ref);
+        Collection<ServiceReference<ObjectFactory>> refs = Utils.getReferencesPrivileged(callerContext, ObjectFactory.class);
+        for (ServiceReference<ObjectFactory> ref : refs) {
+            if (canCallObjectFactory(obj, ref)) {
+                ObjectFactory factory = Utils.getServicePrivileged(callerContext, ref);
 
                 try {
                     result = factory.getObjectInstance(obj, name, nameCtx, environment);
                 } catch (NamingException ne) {
-                  // Ignore this since we are doing last ditch finding, another OF might work.
+                    // Ignore this since we are doing last ditch finding, another OF might work.
                 } finally {
                     callerContext.ungetService(ref);
                 }
@@ -203,59 +221,48 @@ public class ObjectFactoryHelper impleme
                 if (result != null && result != obj) {
                     break;
                 }
-              }
             }
         }
 
         return (result == null) ? obj : result;
     }
 
-    private boolean canCallObjectFactory(Object obj, ServiceReference ref)
-    {
-      if (obj instanceof Reference) return true;
-      
-      Object prop = ref.getProperty("aries.object.factory.requires.reference");
-      
-      if (prop == null) return true;
-      
-      if (prop instanceof Boolean) return !!!(Boolean) prop; // if set to true we don't call.
-      
-      return true;
-    }
+    private boolean canCallObjectFactory(Object obj, ServiceReference ref) {
+        if (obj instanceof Reference) return true;
 
-    protected static String getUrlScheme(String name) {
-        String scheme = name;   
-        int index = name.indexOf(':');
-        if (index != -1) {
-            scheme = name.substring(0, index);
-        }
-        return scheme;
+        Object prop = ref.getProperty("aries.object.factory.requires.reference");
+
+        if (prop == null) return true;
+
+        if (prop instanceof Boolean) return !(Boolean) prop; // if set to true we don't call.
+
+        return true;
     }
-        
+
     private Object getObjectInstanceUsingRefAddress(Enumeration<RefAddr> addresses,
                                                     Object obj,
                                                     Name name,
                                                     Context nameCtx,
                                                     Hashtable<?, ?> environment)
-        throws Exception {       
+            throws Exception {
         Object result = null;
         while (addresses.hasMoreElements()) {
             RefAddr address = addresses.nextElement();
             if (address instanceof StringRefAddr && "URL".equals(address.getType())) {
-                String urlScheme = getUrlScheme( (String) address.getContent() );
-                
+                String urlScheme = getUrlScheme((String) address.getContent());
+
                 ServicePair<ObjectFactory> factoryService = ContextHelper.getURLObjectFactory(callerContext, urlScheme, environment);
-                
+
                 if (factoryService != null) {
                     ObjectFactory factory = factoryService.get();
-                    
+
                     String value = (String) address.getContent();
                     try {
                         result = factory.getObjectInstance(value, name, nameCtx, environment);
                     } finally {
                         factoryService.unget();
                     }
-                    
+
                     // if the result comes back and is not null and not the reference
                     // object then we should return the result, so break out of the
                     // loop we are in.
@@ -269,43 +276,17 @@ public class ObjectFactoryHelper impleme
         return (result == null) ? obj : result;
     }
 
-    static Tuple<ServiceReference,ObjectFactory> findObjectFactoryByClassName(final BundleContext ctx, final String className) {
-        return AccessController.doPrivileged(new PrivilegedAction<Tuple<ServiceReference,ObjectFactory>>() {
-            public Tuple<ServiceReference,ObjectFactory> run() {
-                ServiceReference serviceReference = null;
-                
-                try {
-                    ServiceReference[] refs = ctx.getServiceReferences(className, null);
-                    if (refs != null && refs.length > 0) {
-                        serviceReference = refs[0];
-                    }
-                } catch (InvalidSyntaxException e) {
-                    // should not happen
-                    throw new RuntimeException(Utils.MESSAGES.getMessage("null.is.invalid.filter"), e);
-                }
-
-                ObjectFactory factory = null;
-                
-                if (serviceReference != null) {
-                    factory = (ObjectFactory) ctx.getService(serviceReference);            
-                }
-                
-                return new Tuple<ServiceReference, ObjectFactory>(serviceReference, factory);
-            }
-        });        
-    }
-    
     private Object getObjectInstanceUsingClassName(Object reference,
                                                    String className,
                                                    Object obj,
                                                    Name name,
                                                    Context nameCtx,
-                                                   Hashtable<?, ?> environment) 
-        throws Exception {
-        
-        Tuple<ServiceReference,ObjectFactory> tuple = findObjectFactoryByClassName(defaultContext, className);
+                                                   Hashtable<?, ?> environment)
+            throws Exception {
+
+        Tuple<ServiceReference<ObjectFactory>, ObjectFactory> tuple = findObjectFactoryByClassName(defaultContext, className);
         Object result = null;
-        
+
         if (tuple.second != null) {
             try {
                 result = tuple.second.getObjectInstance(reference, name, nameCtx, environment);
@@ -316,39 +297,36 @@ public class ObjectFactoryHelper impleme
 
         return (result == null) ? obj : result;
     }
-  
+
     private Object getObjectInstanceUsingObjectFactoryBuilders(Object obj,
                                                                Name name,
                                                                Context nameCtx,
-                                                               Hashtable<?, ?> environment) 
-        throws Exception {
-        
+                                                               Hashtable<?, ?> environment)
+            throws Exception {
+
         ObjectFactory factory = null;
-        
-        ServiceReference[] refs = Utils.getReferencesPrivileged(callerContext, ObjectFactoryBuilder.class);
-        if (refs != null) {
-            Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
-            for (ServiceReference ref : refs) {
-                ObjectFactoryBuilder builder = (ObjectFactoryBuilder) Utils.getServicePrivileged(callerContext, ref);
-                try {
-                    factory = builder.createObjectFactory(obj, environment);
-                } catch (NamingException e) {
-                    // TODO: log it
-                } finally {
-                    callerContext.ungetService(ref);
-                }
-                if (factory != null) {
-                    break;
-                }
+
+        Collection<ServiceReference<ObjectFactoryBuilder>> refs = Utils.getReferencesPrivileged(callerContext, ObjectFactoryBuilder.class);
+        for (ServiceReference<ObjectFactoryBuilder> ref : refs) {
+            ObjectFactoryBuilder builder = Utils.getServicePrivileged(callerContext, ref);
+            try {
+                factory = builder.createObjectFactory(obj, environment);
+            } catch (NamingException e) {
+                // TODO: log it
+            } finally {
+                callerContext.ungetService(ref);
+            }
+            if (factory != null) {
+                break;
             }
         }
 
         Object result = null;
-        
+
         if (factory != null) {
             result = factory.getObjectInstance(obj, name, nameCtx, environment);
         }
-        
+
         return (result == null) ? obj : result;
     }
 

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ProviderAdminService.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ProviderAdminService.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ProviderAdminService.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ProviderAdminService.java Wed Feb 21 09:04:41 2018
@@ -18,43 +18,42 @@
  */
 package org.apache.aries.jndi;
 
-import java.util.Hashtable;
-import java.util.Map;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.jndi.JNDIProviderAdmin;
 
 import javax.naming.Context;
 import javax.naming.Name;
 import javax.naming.directory.Attributes;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.service.jndi.JNDIProviderAdmin;
+import java.util.Hashtable;
+import java.util.Map;
 
 public class ProviderAdminService implements JNDIProviderAdmin {
 
     private DirObjectFactoryHelper helper;
-    
+
     public ProviderAdminService(BundleContext defaultContext, BundleContext callerContext) {
         helper = new DirObjectFactoryHelper(defaultContext, callerContext);
     }
-    
-    public Object getObjectInstance(Object obj, 
-                                    Name name, 
-                                    Context context, 
-                                    Map<?,?> environment)
-        throws Exception {
-        Hashtable<?,?> env = Utils.toHashtable(environment);
+
+    public Object getObjectInstance(Object obj,
+                                    Name name,
+                                    Context context,
+                                    Map<?, ?> environment)
+            throws Exception {
+        Hashtable<?, ?> env = Utils.toHashtable(environment);
         return helper.getObjectInstance(obj, name, context, env);
     }
 
     public Object getObjectInstance(Object obj,
                                     Name name,
                                     Context context,
-                                    Map<?,?> environment,
-                                    Attributes attributes) 
-        throws Exception {
-        Hashtable<?,?> env = Utils.toHashtable(environment);
+                                    Map<?, ?> environment,
+                                    Attributes attributes)
+            throws Exception {
+        Hashtable<?, ?> env = Utils.toHashtable(environment);
         return helper.getObjectInstance(obj, name, context, env, attributes);
     }
 
-    public void close() {        
+    public void close() {
     }
 }

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ProviderAdminServiceFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ProviderAdminServiceFactory.java?rev=1824942&r1=1824941&r2=1824942&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ProviderAdminServiceFactory.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ProviderAdminServiceFactory.java Wed Feb 21 09:04:41 2018
@@ -26,11 +26,11 @@ import org.osgi.framework.ServiceRegistr
 public class ProviderAdminServiceFactory implements ServiceFactory {
 
     private BundleContext defaultContext;
-    
+
     public ProviderAdminServiceFactory(BundleContext defaultContext) {
         this.defaultContext = defaultContext;
     }
-    
+
     public Object getService(Bundle bundle, ServiceRegistration registration) {
         return new ProviderAdminService(defaultContext, bundle.getBundleContext());
     }