aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1152737 - in /aries/trunk: application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ application/application-utils/src/main/java/org/apache/aries/application/utils/service/ util/src/main/java/org/apache/ar...
Date Mon, 01 Aug 2011 11:06:04 GMT
Author: timothyjward
Date: Mon Aug  1 11:06:03 2011
New Revision: 1152737

URL: http://svn.apache.org/viewvc?rev=1152737&view=rev
Log:
ARIES-718: Background changes for EJB modelling

Added:
    aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/service/ExportedServiceHelper.java
Modified:
    aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ExportedServiceImpl.java
    aries/trunk/util/src/main/java/org/apache/aries/util/filesystem/impl/ZipFileImpl.java

Modified: aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ExportedServiceImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ExportedServiceImpl.java?rev=1152737&r1=1152736&r2=1152737&view=diff
==============================================================================
--- aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ExportedServiceImpl.java
(original)
+++ aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ExportedServiceImpl.java
Mon Aug  1 11:06:03 2011
@@ -21,21 +21,18 @@ package org.apache.aries.application.mod
 import static org.apache.aries.application.utils.AppConstants.LOG_ENTRY;
 import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.TreeSet;
 
 import org.apache.aries.application.modelling.ExportedService;
 import org.apache.aries.application.modelling.ModellingConstants;
 import org.apache.aries.application.modelling.ResourceType;
 import org.apache.aries.application.modelling.WrappedServiceMetadata;
+import org.apache.aries.application.utils.service.ExportedServiceHelper;
 import org.osgi.framework.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -159,11 +156,7 @@ public class ExportedServiceImpl impleme
 
   public int compareTo(WrappedServiceMetadata o) {
     logger.debug(LOG_ENTRY, "compareTo", o);
-    if (o == null) {
-      logger.debug(LOG_EXIT, "compareTo", -1);
-      return -1;      // shunt nulls to the end of any lists
-    }
-    int result = this.toString().compareTo(o.toString());
+    int result = ExportedServiceHelper.portableExportedServiceCompareTo(this, o);
     logger.debug(LOG_EXIT,"compareTo", result);
     return result;
   }
@@ -171,18 +164,7 @@ public class ExportedServiceImpl impleme
   @Override
   public boolean equals (Object o) { 
     logger.debug(LOG_ENTRY, "equals", o);
-    // Doubles as a null check
-    if (!(o instanceof WrappedServiceMetadata)) { 
-      logger.debug(LOG_EXIT, "equals", false);
-      return false;
-    }
-
-    if (o==this) { 
-      logger.debug(LOG_EXIT, "equals", true);
-      return true;
-    }
- 
-    boolean eq = this.toString().equals(o.toString());
+    boolean eq = ExportedServiceHelper.portableExportedServiceEquals(this, o);
     logger.debug(LOG_EXIT, "equals", eq);
     return eq;
   }
@@ -191,91 +173,26 @@ public class ExportedServiceImpl impleme
   @Override
   public int hashCode() {
     logger.debug(LOG_ENTRY, "hashCode");
-    int result = toString().hashCode();
+    int result = ExportedServiceHelper.portableExportedServiceHashCode(this);
     logger.debug(LOG_EXIT, "hashCode", result);
     return result;
   }
   
   @Override 
   public String toString() { 
-    if (_toString != null) { 
-      return _toString;
-    }
-    
-    List<String> interfaces = new ArrayList<String>(_interfaces);
-    Collections.sort(interfaces);
-    
-    List<String> props = new ArrayList<String>();
-    for (Map.Entry<String, Object> entry : _serviceProperties.entrySet()) {
-      Object entryValue = entry.getValue();
-      String entryText;
-      if (entryValue.getClass().isArray()) { 
-        // Turn arrays into comma separated Strings
-        Object [] entryArray = (Object[]) entryValue;
-        StringBuilder sb = new StringBuilder();
-        for (Object o: entryArray) { 
-          sb.append(String.valueOf(o) + ",");
-        }
-        sb = sb.deleteCharAt(sb.length()-1);
-        entryText = sb.toString();
-      } else { 
-        entryText = String.valueOf(entryValue);
-      }
-      props.add ("<entry> key=\"" + entry.getKey() + "\" value=\"" + entryText + "\"/>");
-    }
-    Collections.sort(props);
-    
-    StringBuffer buf = new StringBuffer("<service>");
-    if(_name != null) {
-      buf.append("<name>" + _name + "</name>");
-    }
-    if (_interfaces.size() > 0) { 
-      buf.append("<interfaces>");
-    }
-    for (String i : interfaces) { 
-      buf.append("<value>" + i + "</value>");
-    }
-    if (_interfaces.size() > 0) { 
-      buf.append("</interfaces>");
+    if (_toString == null) { 
+      _toString = ExportedServiceHelper.generatePortableExportedServiceToString(this);
     }
-    if (_serviceProperties.size() > 0) { 
-      buf.append("<service-properties>");
-    }
-    for (String p : props) { 
-      buf.append(p);
-    }
-    if (_serviceProperties.size() > 0) { 
-      buf.append("</service-properties>");
-    }
-    buf.append("</service>");
-    _toString = buf.toString();
-    return _toString;
+    return _toString;    
   }
   
 
   public boolean identicalOrDiffersOnlyByName(WrappedServiceMetadata wsmi) {
     logger.debug(LOG_ENTRY,"identicalOrDiffersOnlyByName", wsmi);
     
-    if (this.equals(wsmi)) { 
-      logger.debug(LOG_EXIT, "identicalOrDiffersOnlyByName", true);
-      return true;
-    }
-
-    Set<String> myInterfaces = new HashSet<String>(_interfaces);
-    Set<String> cmpInterfaces = new HashSet<String>(wsmi.getInterfaces());
-    if (!myInterfaces.equals(cmpInterfaces)) { 
-      logger.debug(LOG_EXIT, "identicalOrDiffersOnlyByName", false);
-      return false;
-    }
-    
-    boolean propertiesEqual = _serviceProperties.equals(wsmi.getServiceProperties());
-    if (!propertiesEqual) {
-      logger.debug(LOG_EXIT, "identicalOrDiffersOnlyByName", false);
-      return false;
-    }
-    logger.debug(LOG_EXIT, "identicalOrDiffersOnlyByName", true);
-    return true;
+    boolean result = ExportedServiceHelper.
+        portableExportedServiceIdenticalOrDiffersOnlyByName(this, wsmi);
+    logger.debug(LOG_EXIT, "identicalOrDiffersOnlyByName", result);
+    return result;
   }
-
-  
 }

Added: aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/service/ExportedServiceHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/service/ExportedServiceHelper.java?rev=1152737&view=auto
==============================================================================
--- aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/service/ExportedServiceHelper.java
(added)
+++ aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/service/ExportedServiceHelper.java
Mon Aug  1 11:06:03 2011
@@ -0,0 +1,114 @@
+package org.apache.aries.application.utils.service;
+
+import static org.apache.aries.application.utils.AppConstants.LOG_ENTRY;
+import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.aries.application.modelling.ExportedService;
+import org.apache.aries.application.modelling.WrappedServiceMetadata;
+
+public class ExportedServiceHelper {
+
+  public static String generatePortableExportedServiceToString(ExportedService svc) {
+    List<String> interfaces = new ArrayList<String>(svc.getInterfaces());
+    Collections.sort(interfaces);
+    
+    List<String> props = new ArrayList<String>();
+    for (Map.Entry<String, Object> entry : svc.getServiceProperties().entrySet()) {
+      Object entryValue = entry.getValue();
+      String entryText;
+      if (entryValue.getClass().isArray()) { 
+        // Turn arrays into comma separated Strings
+        Object [] entryArray = (Object[]) entryValue;
+        StringBuilder sb = new StringBuilder();
+        for (Object o: entryArray) { 
+          sb.append(String.valueOf(o) + ",");
+        }
+        sb = sb.deleteCharAt(sb.length()-1);
+        entryText = sb.toString();
+      } else { 
+        entryText = String.valueOf(entryValue);
+      }
+      props.add ("<entry> key=\"" + entry.getKey() + "\" value=\"" + entryText + "\"/>");
+    }
+    Collections.sort(props);
+    
+    StringBuffer buf = new StringBuffer("<service>");
+    if(svc.getName() != null) {
+      buf.append("<name>" + svc.getName() + "</name>");
+    }
+    if (interfaces.size() > 0) { 
+      buf.append("<interfaces>");
+    }
+    for (String i : interfaces) { 
+      buf.append("<value>" + i + "</value>");
+    }
+    if (interfaces.size() > 0) { 
+      buf.append("</interfaces>");
+    }
+    if (svc.getServiceProperties().size() > 0) { 
+      buf.append("<service-properties>");
+    }
+    for (String p : props) { 
+      buf.append(p);
+    }
+    if (svc.getServiceProperties().size() > 0) { 
+      buf.append("</service-properties>");
+    }
+    buf.append("</service>");
+    return buf.toString();
+  }
+  
+
+  public static boolean portableExportedServiceIdenticalOrDiffersOnlyByName(ExportedService
svc, WrappedServiceMetadata wsmi) {
+    if (svc.equals(wsmi)) { 
+      return true;
+    }
+
+    Set<String> svcInterfaces = new HashSet<String>(svc.getInterfaces());
+    Set<String> cmpInterfaces = new HashSet<String>(wsmi.getInterfaces());
+    if (!svcInterfaces.equals(cmpInterfaces)) { 
+      return false;
+    }
+    
+    boolean propertiesEqual = svc.getServiceProperties().equals(wsmi.getServiceProperties());
+    if (!propertiesEqual) {
+      return false;
+    }
+    return true;
+  }
+  
+  public static boolean portableExportedServiceEquals (ExportedService left, Object right)
{ 
+    // Doubles as a null check
+    if (!(right instanceof WrappedServiceMetadata)) { 
+      return false;
+    }
+
+    if (right == left) { 
+      return true;
+    }
+ 
+    boolean eq = left.toString().equals(right.toString());
+    return eq;
+  }
+  
+  public static int portableExportedServiceHashCode(ExportedService svc) {
+    int result = svc.toString().hashCode();
+    return result;
+  }
+  
+  public static int portableExportedServiceCompareTo(ExportedService svc, WrappedServiceMetadata
o) {
+    if (o == null) {
+      return -1;      // shunt nulls to the end of any lists
+    }
+    int result = svc.toString().compareTo(o.toString());
+    return result;
+  }
+  
+}

Modified: aries/trunk/util/src/main/java/org/apache/aries/util/filesystem/impl/ZipFileImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/util/src/main/java/org/apache/aries/util/filesystem/impl/ZipFileImpl.java?rev=1152737&r1=1152736&r2=1152737&view=diff
==============================================================================
--- aries/trunk/util/src/main/java/org/apache/aries/util/filesystem/impl/ZipFileImpl.java
(original)
+++ aries/trunk/util/src/main/java/org/apache/aries/util/filesystem/impl/ZipFileImpl.java
Mon Aug  1 11:06:03 2011
@@ -199,8 +199,21 @@ public class ZipFileImpl implements IFil
 
   public URL toURL() throws MalformedURLException
   {
-    String entryURL = "jar:" + url + "!/" + entry.getName();
-    URL result = new URL(entryURL);
+    URL result;
+    
+    if(name.equals(zipPathToRoot))
+      result = new URL(url);
+    else {
+      
+      String entryURL = "jar:" + url + "!/";
+      if(entry != null)
+        entryURL += entry.getName();
+      else {
+        entryURL += name.substring(zipPathToRoot.length());
+      }
+      result = new URL(entryURL);
+    }
+      
     return result;
   }
 



Mime
View raw message