cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject svn commit: r1491086 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/ main/java/org/apache/cxf/dosgi/dsw/decorator/ main/java/org/apache/cxf/dosgi/dsw/handlers/ main/java/org/apache/cxf/dosgi/dsw/qos/ main/java/org/apache/cxf/...
Date Sat, 08 Jun 2013 22:23:55 GMT
Author: amichai
Date: Sat Jun  8 22:23:55 2013
New Revision: 1491086

URL: http://svn.apache.org/r1491086
Log:
Little refactorings in dsw package

Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRule.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManager.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUnsatisfiedException.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceadminFactory.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/Utils.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java Sat
Jun  8 22:23:55 2013
@@ -52,8 +52,8 @@ import org.slf4j.LoggerFactory;
 // registered as spring bean -> start / stop called accordingly
 public class Activator implements ManagedService, BundleActivator {
 
-    private static final int DEFAULT_INTENT_TIMEOUT = 30000;
     private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
+    private static final int DEFAULT_INTENT_TIMEOUT = 30000;
     private static final String CONFIG_SERVICE_PID = "cxf-dsw";
     private ServiceRegistration rsaFactoryReg;
     private ServiceRegistration decoratorReg;

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRule.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRule.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRule.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRule.java
Sat Jun  8 22:23:55 2013
@@ -74,10 +74,7 @@ public class InterfaceRule implements Ru
             if (m.matches()) {
                 for (Map.Entry<String, String> pm : propMatches.entrySet()) {
                     Object value = sref.getProperty(pm.getKey());
-                    if (value == null) {
-                        return;
-                    }
-                    if (!Pattern.matches(pm.getValue(), value.toString())) {
+                    if (value == null || !Pattern.matches(pm.getValue(), value.toString()))
{
                         return;
                     }
                 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManager.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManager.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManager.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManager.java
Sat Jun  8 22:23:55 2013
@@ -130,7 +130,6 @@ public class HttpServiceManager {
 
         try {
             Filter f = bundleContext.createFilter("(" + org.osgi.framework.Constants.SERVICE_ID
+ "=" + sid + ")");
-
             if (f != null) {
                 bundleContext.addServiceListener(new UnregisterListener(), f.toString());
             } else {
@@ -167,9 +166,9 @@ public class HttpServiceManager {
             final Long sid = (Long) sref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
             final String alias = exportedAliases.remove(sid);
             if (alias == null) {
-                LOG.error("Unable to unexport HTTP servlet for service class ''{0}'',"
-                        + " service-id {1}: no servlet alias found",
-                        new Object[] {sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS),
sid});
+                LOG.error("Unable to unexport HTTP servlet for service class '{}',"
+                        + " service-id {}: no servlet alias found",
+                        sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS), sid);
                 return;
             }
             LOG.debug("Unexporting HTTP servlet for alias '{}'", alias);
@@ -177,8 +176,7 @@ public class HttpServiceManager {
                 HttpService http = getHttpService();
                 http.unregister(alias);
             } catch (Exception e) {
-                LOG.warn("An exception occurred while unregistering service for HTTP servlet
alias '"
-                        + alias + "'", e);
+                LOG.warn("An exception occurred while unregistering service for HTTP servlet
alias '{}'", alias, e);
             }
         }
     }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java
Sat Jun  8 22:23:55 2013
@@ -114,7 +114,7 @@ class Chain implements FilterChain {
     private static final Logger LOG = LoggerFactory.getLogger(Chain.class);
 
     int current;
-    Filter[] filters;
+    final Filter[] filters;
 
     Chain(Filter[] filters) {
         this.filters = filters;

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java
Sat Jun  8 22:23:55 2013
@@ -38,7 +38,7 @@ public class IntentManagerImpl implement
     private static final String PROVIDED_INTENT_VALUE = "PROVIDED";
 
     private final IntentMap intentMap;
-    private long maxIntentWaitTime;
+    private final long maxIntentWaitTime;
 
     public IntentManagerImpl(IntentMap intentMap) {
         this(intentMap, 0);

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
Sat Jun  8 22:23:55 2013
@@ -47,8 +47,8 @@ public class IntentMap extends Concurren
         Object result = super.put(key, value);
         synchronized (this) {
             notifyAll();
-            return result;
         }
+        return result;
     }
 
     @Override

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUnsatisfiedException.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUnsatisfiedException.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUnsatisfiedException.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUnsatisfiedException.java
Sat Jun  8 22:23:55 2013
@@ -22,11 +22,11 @@ public class IntentUnsatisfiedException 
 
     private static final long serialVersionUID = 1L;
 
-    private String intent;
+    private final String intent;
 
-    public IntentUnsatisfiedException(String theIntent) {
-        super(theIntent);
-        intent = theIntent;
+    public IntentUnsatisfiedException(String intent) {
+        super(intent);
+        this.intent = intent;
     }
 
     public String getIntent() {

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
Sat Jun  8 22:23:55 2013
@@ -51,7 +51,7 @@ public class ClientServiceFactory implem
         this.iClass = iClass;
         this.sd = sd;
         this.handler = handler;
-        importRegistration = ir;
+        this.importRegistration = ir;
     }
 
     public Object getService(final Bundle requestingBundle, final ServiceRegistration sreg)
{
@@ -83,12 +83,12 @@ public class ClientServiceFactory implem
     }
 
     public void ungetService(Bundle requestingBundle, ServiceRegistration sreg, Object serviceObject)
{
-        StringBuilder sb = new StringBuilder();
+        StringBuilder sb = new StringBuilder(64);
         sb.append("Releasing a client object");
-        Object objectClass = sreg.getReference().getProperty(org.osgi.framework.Constants.OBJECTCLASS);
+        String[] objectClass = (String[])sreg.getReference().getProperty(org.osgi.framework.Constants.OBJECTCLASS);
         if (objectClass != null) {
             sb.append(", interfaces: ");
-            for (String s : (String[])objectClass) {
+            for (String s : objectClass) {
                 sb.append(' ').append(s);
             }
         }
@@ -97,23 +97,21 @@ public class ClientServiceFactory implem
         synchronized (this) {
             --serviceCounter;
             LOG.debug("Services still provided by this ServiceFactory: {}", serviceCounter);
-
-            if (serviceCounter <= 0 && closeable) {
-                remove();
-            }
+            closeIfUnused();
         }
     }
 
-    private void remove() {
-        importRegistration.closeAll();
+    // called only in synchronized block
+    private void closeIfUnused() {
+        if (serviceCounter <= 0 && closeable) {
+            importRegistration.closeAll();
+        }
     }
 
     public void setCloseable(boolean closeable) {
         synchronized (this) {
             this.closeable = closeable;
-            if (serviceCounter <= 0 && closeable) {
-                remove();
-            }
+            closeIfUnused();
         }
     }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
Sat Jun  8 22:23:55 2013
@@ -50,13 +50,7 @@ public class EventAdminHelper {
         props.put("bundle.symbolicname", bctx.getBundle().getSymbolicName());
 
         String version = (String)bctx.getBundle().getHeaders().get("Bundle-Version");
-
-        Version v;
-        if (version != null) {
-            v = new Version(version);
-        } else {
-            v = Version.emptyVersion;
-        }
+        Version v = version != null ? new Version(version) : Version.emptyVersion;
         setIfNotNull(props, "bundle.version", v);
 
         return new Event(topic, (Dictionary)props);
@@ -92,7 +86,7 @@ public class EventAdminHelper {
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    private void setIfNotNull(Dictionary props, String key, Object o) {
+    private static void setIfNotNull(Dictionary props, String key, Object o) {
         if (o != null) {
             props.put(key, o);
         }
@@ -121,7 +115,7 @@ public class EventAdminHelper {
         }
     }
 
-    static String remoteServiceAdminEventTypeToString(int type) {
+    private static String remoteServiceAdminEventTypeToString(int type) {
         String retval;
         switch (type) {
         case RemoteServiceAdminEvent.EXPORT_ERROR:

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
Sat Jun  8 22:23:55 2013
@@ -33,8 +33,8 @@ import org.slf4j.LoggerFactory;
 public class EventProducer {
 
     private static final Logger LOG = LoggerFactory.getLogger(EventProducer.class);
-    private BundleContext bctx;
-    private EventAdminHelper eaHelper;
+    private final BundleContext bctx;
+    private final EventAdminHelper eaHelper;
 
     public EventProducer(BundleContext bc) {
         bctx = bc;
@@ -51,17 +51,37 @@ public class EventProducer {
         int type = er.getException() == null
             ? RemoteServiceAdminEvent.EXPORT_REGISTRATION
             : RemoteServiceAdminEvent.EXPORT_ERROR;
-        RemoteServiceAdminEvent rsae = new RemoteServiceAdminEvent(type, bctx.getBundle(),
er.getExportReference(),
-                er.getException());
+        notify(type, null, er);
+    }
+
+    protected void publishNotification(ImportRegistration ir) {
+        int type = ir.getException() == null
+            ? RemoteServiceAdminEvent.IMPORT_REGISTRATION
+            : RemoteServiceAdminEvent.IMPORT_ERROR;
+        notify(type, ir, null);
+    }
+
+    public void notifyRemoval(ExportRegistration er) {
+        notify(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, null, er);
+    }
 
-        notifyListeners(rsae);
-        eaHelper.notifyEventAdmin(rsae);
+    public void notifyRemoval(ImportRegistration ir) {
+        notify(RemoteServiceAdminEvent.IMPORT_UNREGISTRATION, ir, null);
+    }
+
+    // only one of ir or er must be set, and the other must be null
+    private void notify(int type, ImportRegistration ir, ExportRegistration er) {
+        RemoteServiceAdminEvent event = ir != null
+            ? new RemoteServiceAdminEvent(type, bctx.getBundle(), ir.getImportReference(),
ir.getException())
+            : new RemoteServiceAdminEvent(type, bctx.getBundle(), er.getExportReference(),
er.getException());
+        notifyListeners(event);
+        eaHelper.notifyEventAdmin(event);
     }
 
     private void notifyListeners(RemoteServiceAdminEvent rsae) {
         try {
-            ServiceReference[] listenerRefs = bctx.getServiceReferences(RemoteServiceAdminListener.class
-                .getName(), null);
+            ServiceReference[] listenerRefs = bctx.getServiceReferences(
+                    RemoteServiceAdminListener.class.getName(), null);
             if (listenerRefs != null) {
                 for (ServiceReference sref : listenerRefs) {
                     RemoteServiceAdminListener rsal = (RemoteServiceAdminListener)bctx.getService(sref);
@@ -80,35 +100,4 @@ public class EventProducer {
             LOG.error(e.getMessage(), e);
         }
     }
-
-    protected void publishNotifcation(ImportRegistration ir) {
-        RemoteServiceAdminEvent rsae;
-        if (ir.getException() != null) {
-            rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.IMPORT_ERROR, bctx.getBundle(),
-                                               ir.getImportReference(), ir.getException());
-        } else {
-            rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.IMPORT_REGISTRATION,
bctx.getBundle(),
-                                               ir.getImportReference(), ir.getException());
-        }
-
-        notifyListeners(rsae);
-        eaHelper.notifyEventAdmin(rsae);
-    }
-
-    public void notifyRemoval(ExportRegistration eri) {
-        RemoteServiceAdminEvent rsae;
-        rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION,
bctx.getBundle(),
-                                           eri.getExportReference(), eri.getException());
-
-        notifyListeners(rsae);
-        eaHelper.notifyEventAdmin(rsae);
-    }
-
-    public void notifyRemoval(ImportRegistration eri) {
-        RemoteServiceAdminEvent rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.IMPORT_UNREGISTRATION,
-                bctx.getBundle(), eri.getImportReference(), eri.getException());
-
-        notifyListeners(rsae);
-        eaHelper.notifyEventAdmin(rsae);
-    }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
Sat Jun  8 22:23:55 2013
@@ -33,8 +33,7 @@ public class ExportReferenceImpl impleme
     }
 
     public ExportReferenceImpl(ExportReference exportReference) {
-        this.serviceReference = exportReference.getExportedService();
-        this.endpointDescription = exportReference.getExportedEndpoint();
+        this(exportReference.getExportedService(), exportReference.getExportedEndpoint());
     }
 
     public EndpointDescription getExportedEndpoint() {
@@ -49,8 +48,8 @@ public class ExportReferenceImpl impleme
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((endpointDescription == null) ? 0 : endpointDescription.hashCode());
-        result = prime * result + ((serviceReference == null) ? 0 : serviceReference.hashCode());
+        result = prime * result + (endpointDescription == null ? 0 : endpointDescription.hashCode());
+        result = prime * result + (serviceReference == null ? 0 : serviceReference.hashCode());
         return result;
     }
 
@@ -59,28 +58,15 @@ public class ExportReferenceImpl impleme
         if (this == obj) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
+        if (obj == null || getClass() != obj.getClass()) {
             return false;
         }
         ExportReferenceImpl other = (ExportReferenceImpl) obj;
-        if (endpointDescription == null) {
-            if (other.endpointDescription != null) {
-                return false;
-            }
-        } else if (!endpointDescription.equals(other.endpointDescription)) {
-            return false;
-        }
-        if (serviceReference == null) {
-            if (other.serviceReference != null) {
-                return false;
-            }
-        } else if (!serviceReference.equals(other.serviceReference)) {
-            return false;
-        }
-        return true;
+        boolean ed = endpointDescription == null ? other.endpointDescription == null
+                : endpointDescription.equals(other.endpointDescription);
+        boolean sr = serviceReference == null ? other.serviceReference == null
+                : serviceReference.equals(other.serviceReference);
+        return ed && sr;
     }
 
     synchronized void close() {

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
Sat Jun  8 22:23:55 2013
@@ -61,8 +61,8 @@ public class ExportRegistrationImpl impl
         rsaCore = parent.getRsaCore();
         parent.instanceAdded();
     }
-    public ExportRegistrationImpl(ServiceReference sref,
-                                  EndpointDescription endpoint,
+
+    public ExportRegistrationImpl(ServiceReference sref, EndpointDescription endpoint,
                                   RemoteServiceAdminCore remoteServiceAdminCore) {
         exportReference = new ExportReferenceImpl(sref, endpoint);
         parent = this;
@@ -112,10 +112,6 @@ public class ExportRegistrationImpl impl
         }
     }
 
-    public Throwable getException() {
-        return closed ? null : exception;
-    }
-
     @Override
     public String toString() {
         if (exportReference == null) {
@@ -140,12 +136,12 @@ public class ExportRegistrationImpl impl
         return r;
     }
 
-    public void setServer(Server server) {
-        this.server = server;
+    public Throwable getException() {
+        return closed ? null : exception;
     }
 
-    public Server getServer() {
-        return server;
+    public void setServer(Server server) {
+        this.server = server;
     }
 
     public void setException(Throwable ex) {
@@ -156,6 +152,10 @@ public class ExportRegistrationImpl impl
         return exportReference;
     }
 
+    public RemoteServiceAdminCore getRsaCore() {
+        return rsaCore;
+    }
+
     /**
      * Start the service tracker that monitors the osgi service that
      * is exported by this exportRegistration
@@ -201,11 +201,4 @@ public class ExportRegistrationImpl impl
         serviceTracker.open();
     }
 
-    public void setRsaCore(RemoteServiceAdminCore rsaCore) {
-        this.rsaCore = rsaCore;
-    }
-
-    public RemoteServiceAdminCore getRsaCore() {
-        return rsaCore;
-    }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
Sat Jun  8 22:23:55 2013
@@ -64,14 +64,13 @@ public class RemoteServiceAdminCore impl
     // Is stored in exportedServices while the export is in progress as a marker
     private final List<ExportRegistration> exportInProgress = Collections.emptyList();
 
-    private BundleContext bctx;
-    private EventProducer eventProducer;
-
-    private ConfigTypeHandlerFactory configTypeHandlerFactory;
+    private final BundleContext bctx;
+    private final EventProducer eventProducer;
+    private final ConfigTypeHandlerFactory configTypeHandlerFactory;
 
     public RemoteServiceAdminCore(BundleContext bc, ConfigTypeHandlerFactory configTypeHandlerFactory)
{
-        bctx = bc;
-        eventProducer = new EventProducer(bctx);
+        this.bctx = bc;
+        this.eventProducer = new EventProducer(bctx);
         this.configTypeHandlerFactory = configTypeHandlerFactory;
     }
 
@@ -245,11 +244,9 @@ public class RemoteServiceAdminCore impl
         Map<String, Object> converted = new HashMap<String, Object>(properties.size());
         for (Map.Entry<String, Object> entry : properties.entrySet()) {
             Object val = entry.getValue();
+            // convert arrays into lists so that they can be compared via equals()
             if (val instanceof Object[]) {
-                Object[] arr = (Object[])val;
-                List<Object> list = new ArrayList<Object>(arr.length);
-                Collections.addAll(list, arr);
-                val = list;
+                val = Arrays.asList((Object[])val);
             }
             converted.put(entry.getKey(), val);
         }
@@ -320,7 +317,7 @@ public class RemoteServiceAdminCore impl
                 ImportRegistrationImpl irParent = imRegs.iterator().next();
                 ImportRegistrationImpl ir = new ImportRegistrationImpl(irParent);
                 imRegs.add(ir);
-                eventProducer.publishNotifcation(ir);
+                eventProducer.publishNotification(ir);
                 return ir;
             }
 
@@ -350,7 +347,7 @@ public class RemoteServiceAdminCore impl
                     importedServices.put(endpoint, imRegs);
                 }
                 imRegs.add(imReg);
-                eventProducer.publishNotifcation(imReg);
+                eventProducer.publishNotification(imReg);
                 return imReg;
             } else {
                 return null;
@@ -418,7 +415,7 @@ public class RemoteServiceAdminCore impl
         }
     }
 
-    // Remove all export registrations associated with the given bundle
+    // remove all export registrations associated with the given bundle
     protected void removeExportRegistrations(Bundle exportingBundle) {
         List<ExportRegistration> bundleExports = getExportsForBundle(exportingBundle);
         for (ExportRegistration export : bundleExports) {
@@ -449,7 +446,7 @@ public class RemoteServiceAdminCore impl
             if (imRegs != null && imRegs.contains(iri)) {
                 imRegs.remove(iri);
             } else {
-                LOG.error("An importRegistration was intended to be removed form internal
management "
+                LOG.error("An importRegistration was intended to be removed from internal
management "
                     + "structure but couldn't be found in it!");
             }
             if (imRegs == null || imRegs.isEmpty()) {

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java
Sat Jun  8 22:23:55 2013
@@ -36,8 +36,8 @@ import org.osgi.service.remoteserviceadm
 
 public class RemoteServiceAdminInstance implements RemoteServiceAdmin {
 
-    private BundleContext bctx;
-    private RemoteServiceAdminCore rsaCore;
+    private final BundleContext bctx;
+    private final RemoteServiceAdminCore rsaCore;
 
     private boolean closed;
 
@@ -57,10 +57,7 @@ public class RemoteServiceAdminInstance 
 
         return AccessController.doPrivileged(new PrivilegedAction<List>() {
             public List<ExportRegistration> run() {
-                if (closed) {
-                    return Collections.emptyList();
-                }
-                return rsaCore.exportService(ref, properties);
+                return closed ? Collections.<ExportRegistration>emptyList() : rsaCore.exportService(ref,
properties);
             }
         });
     }
@@ -73,10 +70,7 @@ public class RemoteServiceAdminInstance 
             sm.checkPermission(epp);
         }
 
-        if (closed) {
-            return null;
-        }
-        return rsaCore.getExportedServices();
+        return closed ? null : rsaCore.getExportedServices();
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
@@ -87,27 +81,20 @@ public class RemoteServiceAdminInstance 
             sm.checkPermission(epp);
         }
 
-        if (closed) {
-            return null;
-        }
-        return rsaCore.getImportedEndpoints();
+        return closed ? null : rsaCore.getImportedEndpoints();
     }
 
     public ImportRegistration importService(EndpointDescription endpoint) {
         final EndpointDescription epd = endpoint;
         SecurityManager sm = System.getSecurityManager();
-        EndpointPermission epp = new EndpointPermission(epd, OsgiUtils.getUUID(bctx),
-                                                        EndpointPermission.IMPORT);
+        EndpointPermission epp = new EndpointPermission(epd, OsgiUtils.getUUID(bctx), EndpointPermission.IMPORT);
         if (sm != null) {
             sm.checkPermission(epp);
         }
 
         return AccessController.doPrivileged(new PrivilegedAction<ImportRegistration>()
{
             public ImportRegistration run() {
-                if (closed) {
-                    return null;
-                }
-                return rsaCore.importService(epd);
+                return closed ? null : rsaCore.importService(epd);
             }
         });
     }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceadminFactory.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceadminFactory.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceadminFactory.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceadminFactory.java
Sat Jun  8 22:23:55 2013
@@ -18,9 +18,6 @@
  */
 package org.apache.cxf.dosgi.dsw.service;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
@@ -30,9 +27,8 @@ import org.slf4j.LoggerFactory;
 public class RemoteServiceadminFactory implements ServiceFactory {
 
     private static final Logger LOG = LoggerFactory.getLogger(RemoteServiceadminFactory.class);
-    private List<RemoteServiceAdminInstance> rsaServiceInstances = new ArrayList<RemoteServiceAdminInstance>();
 
-    private RemoteServiceAdminCore rsaCore;
+    private final RemoteServiceAdminCore rsaCore;
 
     public RemoteServiceadminFactory(RemoteServiceAdminCore rsaCore) {
         this.rsaCore = rsaCore;
@@ -40,17 +36,13 @@ public class RemoteServiceadminFactory i
 
     public Object getService(Bundle b, ServiceRegistration sr) {
         LOG.debug("new RemoteServiceAdmin ServiceInstance created for Bundle {}", b.getSymbolicName());
-        RemoteServiceAdminInstance rsai = new RemoteServiceAdminInstance(b.getBundleContext(),
rsaCore);
-        rsaServiceInstances.add(rsai);
-        return rsai;
+        return new RemoteServiceAdminInstance(b.getBundleContext(), rsaCore);
     }
 
     public void ungetService(Bundle b, ServiceRegistration sr, Object serviceObject) {
         LOG.debug("RemoteServiceAdmin ServiceInstance removed for Bundle {}", b.getSymbolicName());
         if (serviceObject instanceof RemoteServiceAdminInstance) {
-            RemoteServiceAdminInstance rsai = (RemoteServiceAdminInstance)serviceObject;
-            rsai.close();
-            rsaServiceInstances.remove(rsai);
+            ((RemoteServiceAdminInstance)serviceObject).close();
         }
     }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/Utils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/Utils.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/Utils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/Utils.java Sat
Jun  8 22:23:55 2013
@@ -50,6 +50,7 @@ public final class Utils {
         if (object instanceof String[]) {
             return (String[])object;
         }
+        
         if (object instanceof Collection) {
             Collection col = (Collection)object;
             List<String> ar = new ArrayList<String>(col.size());

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java?rev=1491086&r1=1491085&r2=1491086&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
Sat Jun  8 22:23:55 2013
@@ -78,10 +78,11 @@ public class RemoteServiceAdminCoreTest 
         EasyMock.expect(sref.getProperty("service.exported.interfaces")).andReturn("*").anyTimes();
 
         ConfigTypeHandlerFactory configTypeHandlerFactory = c.createMock(ConfigTypeHandlerFactory.class);
-        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, configTypeHandlerFactory);
 
         c.replay();
 
+        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, configTypeHandlerFactory);
+
         // must return an empty List as sref if from the same bundle
         List<ExportRegistration> exRefs = rsaCore.exportService(sref, null);
 
@@ -118,6 +119,9 @@ public class RemoteServiceAdminCoreTest 
         HttpServiceManager httpServiceManager = c.createMock(HttpServiceManager.class);
         ConfigTypeHandlerFactory configTypeHandlerFactory
             = new ConfigTypeHandlerFactory(bc, intentManager, httpServiceManager);
+
+        c.replay();
+
         RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, configTypeHandlerFactory)
{
             @Override
             protected void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl
imReg,
@@ -125,7 +129,6 @@ public class RemoteServiceAdminCoreTest 
                                                     BundleContext requestingContext) {
             }
         };
-        c.replay();
 
         // must be null as the endpoint doesn't contain any usable configurations
         assertNull(rsaCore.importService(endpoint));



Mime
View raw message