aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r1102660 - in /aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi: ContextHelper.java DirObjectFactoryHelper.java ObjectFactoryHelper.java ServicePair.java Tuple.java Utils.java
Date Fri, 13 May 2011 10:54:33 GMT
Author: mahrwald
Date: Fri May 13 10:54:32 2011
New Revision: 1102660

URL: http://svn.apache.org/viewvc?rev=1102660&view=rev
Log:
ARIES-647: Scope down doPriv blocks

Added:
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Tuple.java
Modified:
    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/DirObjectFactoryHelper.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/ServicePair.java
    aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java

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=1102660&r1=1102659&r2=1102660&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 Fri
May 13 10:54:32 2011
@@ -18,7 +18,8 @@
  */
 package org.apache.aries.jndi;
 
-import java.security.PrivilegedExceptionAction;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Hashtable;
 
 import javax.naming.Context;
@@ -45,27 +46,19 @@ public final class ContextHelper {
         throw new RuntimeException();
     }
 
-    public static ContextProvider createURLContext(final BundleContext context,
-                                           final String urlScheme, 
-                                           final Hashtable<?, ?> env)
-        throws NamingException {
-        return Utils.doPrivilegedNaming(new PrivilegedExceptionAction<ContextProvider>()
{
-            public ContextProvider run() throws Exception {
-                return doCreateURLContext(context, urlScheme, env);
-            }
-        });
-    }
-    
     /**
      * 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
      * @return a Context
      * @throws NamingException
      */
-    private static ContextProvider doCreateURLContext(BundleContext context, String urlScheme,
Hashtable<?, ?> env)
+    public static ContextProvider createURLContext(final BundleContext context,
+                                           final String urlScheme, 
+                                           final Hashtable<?, ?> env)
         throws NamingException {
       
         ServicePair<ObjectFactory> urlObjectFactory = getURLObjectFactory(context,
urlScheme, env);
@@ -82,7 +75,7 @@ public final class ContextHelper {
         return null;
     }
     
-    public static final ServicePair<ObjectFactory> getURLObjectFactory(BundleContext
ctx, String urlScheme, Hashtable<?, ?> environment)
+    public static final ServicePair<ObjectFactory> getURLObjectFactory(final BundleContext
ctx, String urlScheme, Hashtable<?, ?> environment)
       throws NamingException
     {
       ServicePair<ObjectFactory> result = null;
@@ -90,11 +83,16 @@ public final class ContextHelper {
       ServiceReference ref = ServiceTrackerCustomizers.URL_FACTORY_CACHE.find(urlScheme);
       
       if (ref == null) {
-        ServiceReference[] refs = Activator.getURLObectFactoryFinderServices();
+        ServiceReference[] refs = AccessController.doPrivileged(new PrivilegedAction<ServiceReference[]>()
{
+        	public ServiceReference[] run() {
+        		return Activator.getURLObectFactoryFinderServices();
+        	}
+		});        
         
         if (refs != null) {
-          for (ServiceReference finderRef : refs) {
-            URLObjectFactoryFinder finder = (URLObjectFactoryFinder) ctx.getService(finderRef);
+          for (final ServiceReference finderRef : refs) {
+            URLObjectFactoryFinder finder = (URLObjectFactoryFinder) Utils.getServicePrivileged(ctx,
finderRef);
+            	
             if (finder != null) {
               ObjectFactory f = finder.findFactory(urlScheme, environment);
               
@@ -130,19 +128,10 @@ public final class ContextHelper {
         }
     }
 
-    public static ContextProvider getContextProvider(final BundleContext context,
-                                                     final Hashtable<?, ?> environment)
-        throws NamingException {
-        return Utils.doPrivilegedNaming(new PrivilegedExceptionAction<ContextProvider>()
{
-            public ContextProvider run() throws Exception {
-                return doGetContextProvider(context, environment);
-            }
-        });
-    }
-    
-    private static ContextProvider doGetContextProvider(BundleContext context,
-                                                        Hashtable<?, ?> environment)
+    public static ContextProvider getContextProvider(BundleContext context,
+                                                     Hashtable<?, ?> environment)
         throws NamingException {
+    	
         ContextProvider provider = null;
         String contextFactoryClass = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
         if (contextFactoryClass == null) {
@@ -151,11 +140,17 @@ public final class ContextHelper {
 
             // 2. lookup all ContextFactory services
             if (provider == null) {
-                ServiceReference[] references = Activator.getInitialContextFactoryServices();
+            	
+            	ServiceReference[] references = AccessController.doPrivileged(new PrivilegedAction<ServiceReference[]>()
{
+					public ServiceReference[] run() {
+						return Activator.getInitialContextFactoryServices();
+					}
+				});
+                
                 if (references != null) {
                     Context initialContext = null;
                     for (ServiceReference reference : references) {
-                        InitialContextFactory factory = (InitialContextFactory) context.getService(reference);
+                        InitialContextFactory factory = (InitialContextFactory) Utils.getServicePrivileged(context,
reference);
                         try {
                             initialContext = factory.getInitialContext(environment);
                             if (initialContext != null) {
@@ -173,7 +168,7 @@ public final class ContextHelper {
             
             if (ref != null) {
               Context initialContext = null;
-              InitialContextFactory factory = (InitialContextFactory) context.getService(ref);
+              InitialContextFactory factory = (InitialContextFactory) Utils.getServicePrivileged(context,
ref);
               if (factory != null) {
                 try {
                     initialContext = factory.getInitialContext(environment);
@@ -196,12 +191,18 @@ public final class ContextHelper {
     private static ContextProvider getInitialContextUsingBuilder(BundleContext context,
                                                                  Hashtable<?, ?> environment)
             throws NamingException {
+    	
         ContextProvider provider = null;
-        ServiceReference[] refs = Activator.getInitialContextFactoryBuilderServices();
+        ServiceReference[] refs = AccessController.doPrivileged(new PrivilegedAction<ServiceReference[]>()
{
+			public ServiceReference[] run() {
+				return Activator.getInitialContextFactoryBuilderServices();
+			}        	
+		});
+        	
         if (refs != null) {
             InitialContextFactory factory = null;
             for (ServiceReference ref : refs) {                    
-                InitialContextFactoryBuilder builder = (InitialContextFactoryBuilder) context.getService(ref);
+                InitialContextFactoryBuilder builder = (InitialContextFactoryBuilder) Utils.getServicePrivileged(context,
ref);
                 try {
                   factory = builder.createInitialContextFactory(environment);
                 } catch (NamingException ne) {

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=1102660&r1=1102659&r2=1102660&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
Fri May 13 10:54:32 2011
@@ -18,7 +18,6 @@
  */
 package org.apache.aries.jndi;
 
-import java.security.PrivilegedExceptionAction;
 import java.util.Arrays;
 import java.util.Hashtable;
 
@@ -33,7 +32,6 @@ import javax.naming.spi.ObjectFactory;
 import javax.naming.spi.ObjectFactoryBuilder;
 
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 
 public class DirObjectFactoryHelper extends ObjectFactoryHelper implements DirObjectFactory
{
@@ -42,23 +40,11 @@ public class DirObjectFactoryHelper exte
         super(defaultContext, callerContext);
     }
     
-    public Object getObjectInstance(final Object obj,
-                                    final Name name,
-                                    final Context nameCtx,
-                                    final Hashtable<?, ?> environment,
-                                    final Attributes attrs) throws Exception {
-        return Utils.doPrivileged(new PrivilegedExceptionAction<Object>() {
-            public Object run() throws Exception {
-                return doGetObjectInstance(obj, name, nameCtx, environment, attrs);
-            }            
-        });
-    }
-    
-    private Object doGetObjectInstance(Object obj,
-                                       Name name,
-                                       Context nameCtx,
-                                       Hashtable<?, ?> environment,
-                                       Attributes attrs) throws Exception {
+    public Object getObjectInstance(Object obj,
+                                    Name name,
+                                    Context nameCtx,
+                                    Hashtable<?, ?> environment,
+                                    Attributes attrs) throws Exception {
 
         // Step 1
         if (obj instanceof Referenceable) {
@@ -100,31 +86,27 @@ public class DirObjectFactoryHelper exte
                                                          Hashtable<?, ?> environment,
                                                          Attributes attrs) 
         throws Exception {
+    	
         Object result = null;
-        try {
-            ServiceReference[] refs = callerContext.getServiceReferences(DirObjectFactory.class.getName(),
null);
-            if (refs != null) {
-                Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
-                for (ServiceReference ref : refs) {
-                    DirObjectFactory factory = (DirObjectFactory) callerContext.getService(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;
-                    }
-                }
-            }
-        } catch (InvalidSyntaxException e) {
-            // should not happen
-            throw new RuntimeException("Invalid filter", e);
+        ServiceReference[] refs = Utils.getReferencesPrivileged(callerContext, DirObjectFactory.class);
+        if (refs != null) {
+        	Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
+        	for (ServiceReference ref : refs) {
+        		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;
+        		}
+        	}
         }
 
         if (result == null) {
@@ -142,26 +124,15 @@ public class DirObjectFactoryHelper exte
                                                    Hashtable<?, ?> environment,
                                                    Attributes attrs)
         throws Exception {
-        ServiceReference serviceReference = null;
-
-        try {
-            ServiceReference[] refs = defaultContext.getServiceReferences(className, null);
-            if (refs != null && refs.length > 0) {
-                serviceReference = refs[0];
-            }
-        } catch (InvalidSyntaxException e) {
-            // should not happen
-            throw new RuntimeException("Invalid filter", e);
-        }
 
+        Tuple<ServiceReference, ObjectFactory> tuple = ObjectFactoryHelper.findObjectFactoryByClassName(defaultContext,
className);
         Object result = null;
         
-        if (serviceReference != null) {
-            DirObjectFactory factory = (DirObjectFactory) defaultContext.getService(serviceReference);
-            try {
-                result = factory.getObjectInstance(reference, name, nameCtx, environment,
attrs);
+        if (tuple.second != null) {
+        	try {
+        		result = ((DirObjectFactory) tuple.second).getObjectInstance(reference, name, nameCtx,
environment, attrs);
             } finally {
-                defaultContext.ungetService(serviceReference);
+                defaultContext.ungetService(tuple.first);
             }
         }
 
@@ -175,27 +146,22 @@ public class DirObjectFactoryHelper exte
                                                                Attributes attrs) 
         throws Exception {
         ObjectFactory factory = null;
-        try {
-            ServiceReference[] refs = callerContext.getServiceReferences(ObjectFactoryBuilder.class.getName(),
null);
-            if (refs != null) {
-                Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
-                for (ServiceReference ref : refs) {
-                    ObjectFactoryBuilder builder = (ObjectFactoryBuilder) callerContext.getService(ref);
-                    try {
-                        factory = builder.createObjectFactory(obj, environment);
-                    } catch (NamingException e) {
-                        // TODO: log it
-                    } finally {
-                        callerContext.ungetService(ref);
-                    }
-                    if (factory != null) {
-                        break;
-                    }
-                }
-            }
-        } catch (InvalidSyntaxException e) {
-            // should not happen
-            throw new RuntimeException("Invalid filter", e);
+        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;
+        		}
+        	}
         }
 
         Object result = null;

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=1102660&r1=1102659&r2=1102660&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
Fri May 13 10:54:32 2011
@@ -18,7 +18,8 @@
  */
 package org.apache.aries.jndi;
 
-import java.security.PrivilegedExceptionAction;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.Hashtable;
@@ -47,21 +48,10 @@ public class ObjectFactoryHelper impleme
         this.callerContext = callerContext;
     }
 
-    public Object getObjectInstance(final Object obj,
-                                    final Name name,
-                                    final Context nameCtx,
-                                    final Hashtable<?, ?> environment) throws Exception
{
-        return Utils.doPrivileged(new PrivilegedExceptionAction<Object>() {
-            public Object run() throws Exception {
-                return doGetObjectInstance(obj, name, nameCtx, environment);
-            }            
-        });
-    }
-    
-    private Object doGetObjectInstance(Object obj,
-                                       Name name,
-                                       Context nameCtx,
-                                       Hashtable<?, ?> environment) throws Exception
{
+    public Object getObjectInstance(Object obj,
+                                    Name name,
+                                    Context nameCtx,
+                                    Hashtable<?, ?> environment) throws Exception {
 
         // Step 1
         if (obj instanceof Referenceable) {
@@ -106,30 +96,27 @@ public class ObjectFactoryHelper impleme
                                                            Hashtable<?, ?> environment)

         throws Exception {
         Object result = null;
-        try {
-            ServiceReference[] refs = callerContext.getServiceReferences(ObjectFactory.class.getName(),
null);
-            if (refs != null) {
-                Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
-                for (ServiceReference ref : refs) {
-                    ObjectFactory factory = (ObjectFactory) callerContext.getService(ref);
-
-                    try {
-                        result = factory.getObjectInstance(obj, name, nameCtx, environment);
-                    } 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;
-                    }
-                }
-            }
-        } catch (InvalidSyntaxException e) {
-            // should not happen
-            throw new RuntimeException("Invalid filter", e);
+        ServiceReference[] refs = Utils.getReferencesPrivileged(callerContext, ObjectFactory.class);
+            
+        if (refs != null) {
+        	Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
+        	
+        	for (ServiceReference ref : refs) {
+        		ObjectFactory factory = (ObjectFactory) Utils.getServicePrivileged(callerContext,
ref);
+
+        		try {
+        			result = factory.getObjectInstance(obj, name, nameCtx, environment);
+        		} 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;
+        		}
+        	}
         }
 
         return (result == null) ? obj : result;
@@ -181,6 +168,32 @@ 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("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,
@@ -188,26 +201,15 @@ public class ObjectFactoryHelper impleme
                                                    Context nameCtx,
                                                    Hashtable<?, ?> environment) 
         throws Exception {
-        ServiceReference serviceReference = null;
-
-        try {
-            ServiceReference[] refs = defaultContext.getServiceReferences(className, null);
-            if (refs != null && refs.length > 0) {
-                serviceReference = refs[0];
-            }
-        } catch (InvalidSyntaxException e) {
-            // should not happen
-            throw new RuntimeException("Invalid filter", e);
-        }
-
-        Object result = null;
-        
-        if (serviceReference != null) {
-            ObjectFactory factory = (ObjectFactory) defaultContext.getService(serviceReference);
+    	
+    	Tuple<ServiceReference,ObjectFactory> tuple = findObjectFactoryByClassName(defaultContext,
className);
+    	Object result = null;
+    	
+    	if (tuple.second != null) {
             try {
-                result = factory.getObjectInstance(reference, name, nameCtx, environment);
+                result = tuple.second.getObjectInstance(reference, name, nameCtx, environment);
             } finally {
-                defaultContext.ungetService(serviceReference);
+                defaultContext.ungetService(tuple.first);
             }
         }
 
@@ -219,28 +221,25 @@ public class ObjectFactoryHelper impleme
                                                                Context nameCtx,
                                                                Hashtable<?, ?> environment)

         throws Exception {
+    	
         ObjectFactory factory = null;
-        try {
-            ServiceReference[] refs = callerContext.getServiceReferences(ObjectFactoryBuilder.class.getName(),
null);
-            if (refs != null) {
-                Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
-                for (ServiceReference ref : refs) {
-                    ObjectFactoryBuilder builder = (ObjectFactoryBuilder) callerContext.getService(ref);
-                    try {
-                        factory = builder.createObjectFactory(obj, environment);
-                    } catch (NamingException e) {
-                        // TODO: log it
-                    } finally {
-                        callerContext.ungetService(ref);
-                    }
-                    if (factory != null) {
-                        break;
-                    }
-                }
-            }
-        } catch (InvalidSyntaxException e) {
-            // should not happen
-            throw new RuntimeException("Invalid filter", e);
+        
+        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;
+        		}
+        	}
         }
 
         Object result = null;

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ServicePair.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ServicePair.java?rev=1102660&r1=1102659&r2=1102660&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ServicePair.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ServicePair.java Fri May
13 10:54:32 2011
@@ -45,7 +45,7 @@ public class ServicePair<T>
   public T get()
   {
     if (serviceObject == null && ref.getBundle() != null) {
-      serviceObject = (T) ctx.getService(ref);
+      serviceObject = (T) Utils.getServicePrivileged(ctx, ref);
     }
     
     return serviceObject;

Added: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Tuple.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Tuple.java?rev=1102660&view=auto
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Tuple.java (added)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Tuple.java Fri May 13 10:54:32
2011
@@ -0,0 +1,11 @@
+package org.apache.aries.jndi;
+
+public class Tuple<U,V> {
+	public final U first;
+	public final V second;
+	
+	public Tuple(U first, V second) {
+		this.first = first;
+		this.second = second;
+	}
+}

Modified: aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java?rev=1102660&r1=1102659&r2=1102660&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java (original)
+++ aries/trunk/jndi/jndi-core/src/main/java/org/apache/aries/jndi/Utils.java Fri May 13 10:54:32
2011
@@ -32,6 +32,7 @@ import org.apache.aries.jndi.spi.Environ
 import org.apache.aries.jndi.startup.Activator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleReference;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.jndi.JNDIConstants;
 
@@ -163,6 +164,27 @@ public final class Utils {
             }
         }
     }
+    
+    public static ServiceReference[] getReferencesPrivileged(final BundleContext ctx, final
Class<?> clazz) {
+    	return AccessController.doPrivileged(new PrivilegedAction<ServiceReference[]>()
{
+    		public ServiceReference[] run() {
+    			try {
+    				return ctx.getServiceReferences(clazz.getName(), null);
+    			} catch (InvalidSyntaxException ise) {
+    				// should not happen
+    				throw new RuntimeException("Invalid filter", ise);
+    			}
+    		}    		
+		});
+    }
+    
+    public static Object getServicePrivileged(final BundleContext ctx, final ServiceReference
ref) {
+    	return AccessController.doPrivileged(new PrivilegedAction<Object>() {
+    		public Object run() {
+    			return ctx.getService(ref);
+    		}
+		});
+    }
 
     public static void augmentEnvironment(Hashtable<?, ?> environment) 
     {



Mime
View raw message