aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1597718 - in /aries/trunk/jndi/jndi-url: ./ src/main/java/org/apache/aries/jndi/services/ src/main/java/org/apache/aries/jndi/url/
Date Tue, 27 May 2014 08:28:20 GMT
Author: cschneider
Date: Tue May 27 08:28:19 2014
New Revision: 1597718

URL: http://svn.apache.org/r1597718
Log:
ARIES-1183 Small refactorings in jndi url

Modified:
    aries/trunk/jndi/jndi-url/pom.xml
    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/BlueprintName.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/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

Modified: aries/trunk/jndi/jndi-url/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/pom.xml?rev=1597718&r1=1597717&r2=1597718&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/pom.xml (original)
+++ aries/trunk/jndi/jndi-url/pom.xml Tue May 27 08:28:19 2014
@@ -20,7 +20,7 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.aries</groupId>
-        <artifactId>java5-parent</artifactId>
+        <artifactId>java6-parent</artifactId>
         <version>1.0.0</version>
         <relativePath />
     </parent>

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java?rev=1597718&r1=1597717&r2=1597718&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java
(original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java
Tue May 27 08:28:19 2014
@@ -456,18 +456,14 @@ public final class ServiceHelper
   public static Object getService(BundleContext ctx, ServiceReference ref)
   {
     Object service = ctx.getService(ref);
-
-    Object result = null;
-
-    if (service != null) {
-      ServicePair pair = new ServicePair();
-      pair.ref = ref;
-      pair.service = service;
-
-      result = proxy(null, null, false, ctx, pair, 0);
+    if (service == null) {
+      return null;
     }
 
-    return result;
+    ServicePair pair = new ServicePair();
+    pair.ref = ref;
+    pair.service = service;
+    return proxy(null, null, false, ctx, pair, 0);
   }
  
   static Collection<Class<?>> getAllInterfaces (Class<?>[] baseInterfaces)


Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/AbstractName.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/AbstractName.java?rev=1597718&r1=1597717&r2=1597718&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/AbstractName.java (original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/AbstractName.java Tue
May 27 08:28:19 2014
@@ -29,11 +29,11 @@ import javax.naming.CompositeName;
 @SuppressWarnings("serial")
 public abstract class AbstractName extends CompositeName 
 {
-  public AbstractName (Enumeration<String> e) { 
-    super(e);
+  public AbstractName (String name) { 
+    super(split(name));
   }
 
-  static Enumeration<String> split(String name)
+  protected static Enumeration<String> split(String name)
   {
     List<String> elements = new ArrayList<String>();
 
@@ -64,16 +64,11 @@ public abstract class AbstractName exten
   {
     String part0 = get(0);
     int index = part0.indexOf(':');
-    
-    String result;
-    
     if (index > 0) {
-      result = part0.substring(0, index);
+      return part0.substring(0, index);
     } else {
-      result = null;
+      return null;
     }
-    
-    return result;
   }
   
   public String getSchemePath()

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintName.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintName.java?rev=1597718&r1=1597717&r2=1597718&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintName.java (original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/BlueprintName.java Tue
May 27 08:28:19 2014
@@ -31,7 +31,7 @@ public class BlueprintName extends Abstr
 
   public BlueprintName(String name) throws InvalidNameException
   {
-    super(split(name));
+    super(name);
   }
 
   public BlueprintName(Name name) throws InvalidNameException

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiName.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiName.java?rev=1597718&r1=1597717&r2=1597718&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiName.java (original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiName.java Tue May
27 08:28:19 2014
@@ -44,7 +44,7 @@ public final class OsgiName extends Abst
   
   public OsgiName(String name) throws InvalidNameException
   {
-    super(split(name));
+    super(name);
   }
 
   public OsgiName(Name name) throws InvalidNameException

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiURLContextFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiURLContextFactory.java?rev=1597718&r1=1597717&r2=1597718&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiURLContextFactory.java
(original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiURLContextFactory.java
Tue May 27 08:28:19 2014
@@ -46,38 +46,36 @@ public class OsgiURLContextFactory imple
         if (obj == null) {
             return new ServiceRegistryContext(callerContext, environment);
         } else if (obj instanceof String) {
-            Context ctx = null;
-            try {
-                ctx = new ServiceRegistryContext(callerContext, environment);
-
-                return ctx.lookup((String) obj);
-            } finally {
-                if (ctx != null)
-                    ctx.close();
-            }
+        	return findAny(environment, (String)obj);
         } else if (obj instanceof String[]) {
-            // Try each URL until either lookup succeeds or they all fail
-            String[] urls = (String[]) obj;
-            if (urls.length == 0) {
-                throw new ConfigurationException("0");
-            }
-            Context context = new ServiceRegistryContext(callerContext, environment);
-            try {
-                NamingException ne = null;
-                for (int i = 0; i < urls.length; i++) {
-                    try {
-                        return context.lookup(urls[i]);
-                    } catch (NamingException e) {
-                        ne = e;
-                    }
-                }
-                throw ne;
-            } finally {
-                context.close();
-            }
+            return findAny(environment, (String[]) obj);
+        } else {
+            return null;
         }
-
-        return null;
     }
 
+    /**
+     * Try each URL until either lookup succeeds or they all fail
+     */
+	private Object findAny(Hashtable<?, ?> environment, String ... urls)
+			throws ConfigurationException, NamingException {
+		if (urls.length == 0) {
+		    throw new ConfigurationException("0");
+		}
+		Context context = new ServiceRegistryContext(callerContext, environment);
+		try {
+		    NamingException ne = null;
+		    for (int i = 0; i < urls.length; i++) {
+		        try {
+		            return context.lookup(urls[i]);
+		        } catch (NamingException e) {
+		            ne = e;
+		        }
+		    }
+		    throw ne;
+		} finally {
+		    context.close();
+		}
+	}
+
 }

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java?rev=1597718&r1=1597717&r2=1597718&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java
(original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java
Tue May 27 08:28:19 2014
@@ -117,19 +117,13 @@ public class ServiceRegistryContext exte
     }
 
     private OsgiName convert(Name name) throws NamingException {
-        OsgiName result;
-
         if (name instanceof OsgiName) {
-            result = (OsgiName) name;
+            return (OsgiName) name;
+        } else if (parentName != null) {
+            return new OsgiName(parentName.toString() + "/" + name.toString());
         } else {
-            if (parentName != null) {
-                result = new OsgiName(parentName.toString() + "/" + name.toString());
-            } else {
-                result = (OsgiName) parser.parse(name.toString());
-            }
+            return (OsgiName) parser.parse(name.toString());
         }
-
-        return result;
     }
 
     private Name parse(String name) throws NamingException {

Modified: aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryListContext.java
URL: http://svn.apache.org/viewvc/aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryListContext.java?rev=1597718&r1=1597717&r2=1597718&view=diff
==============================================================================
--- aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryListContext.java
(original)
+++ aries/trunk/jndi/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryListContext.java
Tue May 27 08:28:19 2014
@@ -108,22 +108,14 @@ public class ServiceRegistryListContext 
   public NamingEnumeration<NameClassPair> list(String name) throws NamingException
   {
     if (!!!"".equals(name)) throw new NameNotFoundException(name);
-    
-    final ServiceReference[] refs = ServiceHelper.getServiceReferences(callerContext, parentName.getInterface(),
parentName.getFilter(), parentName.getServiceName(), env);
-    
+    final ServiceReference[] refs = getServiceRefs();
     return new ServiceNamingEnumeration<NameClassPair>(callerContext, refs, new ThingManager<NameClassPair>()
{
       public NameClassPair get(BundleContext ctx, ServiceReference ref)
       {
-        String serviceId = String.valueOf(ref.getProperty(Constants.SERVICE_ID));
-        String className = null;
         Object service = ctx.getService(ref);
-        if (service != null) {
-          className = service.getClass().getName();
-        }
-
+        String className = (service != null) ? service.getClass().getName() : null;
         ctx.ungetService(ref);
-        
-        return new NameClassPair(serviceId, className, true);
+        return new NameClassPair(serviceId(ref), className, true);
       }
 
       public void release(BundleContext ctx, ServiceReference ref)
@@ -140,17 +132,12 @@ public class ServiceRegistryListContext 
   public NamingEnumeration<Binding> listBindings(String name) throws NamingException
   {
     if (!!!"".equals(name)) throw new NameNotFoundException(name);
-    
-    final ServiceReference[] refs = ServiceHelper.getServiceReferences(callerContext, parentName.getInterface(),
parentName.getFilter(), parentName.getServiceName(), env);
-
+    final ServiceReference[] refs = getServiceRefs();
     return new ServiceNamingEnumeration<Binding>(callerContext, refs, new ThingManager<Binding>()
{
       public Binding get(BundleContext ctx, ServiceReference ref)
       {
-        String serviceId = String.valueOf(ref.getProperty(Constants.SERVICE_ID));
-        
         Object service = ServiceHelper.getService(ctx, ref);
-
-        return new Binding(serviceId, service, true);
+        return new Binding(serviceId(ref), service, true);
       }
 
       public void release(BundleContext ctx, ServiceReference ref)
@@ -167,14 +154,19 @@ public class ServiceRegistryListContext 
 
   public Object lookup(String name) throws NamingException
   {
-    Object result = null;
-    
-    result = ServiceHelper.getService(callerContext, parentName, name, false, env, true);
-    
+    Object result = ServiceHelper.getService(callerContext, parentName, name, false, env,
true);
     if (result == null) {
       throw new NameNotFoundException(name.toString());
     }
-    
     return result;
   }
+  
+  private String serviceId(ServiceReference ref) {
+    return String.valueOf(ref.getProperty(Constants.SERVICE_ID));
+  }
+  
+  private ServiceReference[] getServiceRefs() throws NamingException {
+    return ServiceHelper.getServiceReferences(callerContext, parentName.getInterface(), parentName.getFilter(),
parentName.getServiceName(), env);
+  }
+
 }
\ No newline at end of file



Mime
View raw message