geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r892313 - in /geronimo/server/trunk/framework/modules/geronimo-kernel/src: main/java/org/apache/geronimo/kernel/osgi/ test/java/org/apache/geronimo/kernel/osgi/
Date Fri, 18 Dec 2009 16:59:35 GMT
Author: gawor
Date: Fri Dec 18 16:59:35 2009
New Revision: 892313

URL: http://svn.apache.org/viewvc?rev=892313&view=rev
Log:
a few more parsing improvments

Modified:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleDescription.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/BundleDescriptionTest.java

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java?rev=892313&r1=892312&r2=892313&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleClassLoader.java
Fri Dec 18 16:59:35 2009
@@ -137,7 +137,7 @@
         // handle static wire via Import-Package
         List<BundleDescription.ImportPackage> imports = description.getExternalImports();
         LinkedHashSet<Bundle> wiredBundles = new LinkedHashSet<Bundle>();
-        for (BundleDescription.Package packageImport : imports) {
+        for (BundleDescription.ImportPackage packageImport : imports) {
             ExportedPackage[] exports = packageAdmin.getExportedPackages(packageImport.getName());
             Bundle wiredBundle = getWiredBundle(exports);
             if (wiredBundle != null) {

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleDescription.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleDescription.java?rev=892313&r1=892312&r2=892313&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleDescription.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleDescription.java
Fri Dec 18 16:59:35 2009
@@ -20,8 +20,11 @@
 
 import java.util.ArrayList;
 import java.util.Dictionary;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
 
 import org.apache.geronimo.kernel.osgi.HeaderParser.HeaderElement;
 import org.osgi.framework.Constants;
@@ -34,6 +37,10 @@
 
     private Map headers;
     
+    public BundleDescription(Manifest manifest) {
+        this.headers = manifestToMap(manifest);
+    }
+    
     public BundleDescription(Dictionary dictionary) {
         this.headers = new DictionaryMap(dictionary);
     }
@@ -87,8 +94,8 @@
         return realImports;
     }
     
-    private static boolean isExported(List<ExportPackage> exports, Package p) {
-        for (Package export : exports) {
+    private static boolean isExported(List<ExportPackage> exports, ImportPackage p)
{
+        for (ExportPackage export : exports) {            
             if (export.getName().equals(p.getName())) {
                 return true;
             }
@@ -109,34 +116,51 @@
     /**
      * Returns a list of packages that are listed in <i>DynamicImport-Package</i>
header.
      */
-    public List<Package> getDynamicImportPackage() {
+    public List<HeaderEntry> getDynamicImportPackage() {
         String headerValue = (String) headers.get(Constants.DYNAMICIMPORT_PACKAGE);
-        List<Package> imports = new ArrayList<Package>();
+        List<HeaderEntry> imports = new ArrayList<HeaderEntry>();
         List<HeaderElement> elements = HeaderParser.parseHeader(headerValue);
         for (HeaderElement element : elements) {
-            Package p = new Package(element.getName(), element.getAttributes(), element.getDirectives());
+            HeaderEntry p = new HeaderEntry(element.getName(), element.getAttributes(), element.getDirectives());
             imports.add(p);
         }
         return imports;
     }
     
-    public String getSymbolicName() {
-        return (String) headers.get(Constants.BUNDLE_SYMBOLICNAME);
+    public SymbolicName getSymbolicName() {
+        String headerValue = (String) headers.get(Constants.BUNDLE_SYMBOLICNAME);
+        List<HeaderElement> elements = HeaderParser.parseHeader(headerValue);
+        if (elements.size() == 1) {
+            HeaderElement element = elements.get(0);
+            return new SymbolicName(element.getName(), element.getAttributes(), element.getDirectives());
+        }
+        return null;
     }
     
     public Map getHeaders() {
         return headers;
     }
     
-    public static class Package {
+    private static Map<String, String> manifestToMap(Manifest manifest) {
+        Attributes attributes = manifest.getMainAttributes();
+        Map<String, String> headers = new HashMap<String, String>();
+        for (Map.Entry<Object, Object> entry : attributes.entrySet()) {
+            String key = entry.getKey().toString();
+            String value = entry.getValue().toString();
+            headers.put(key, value);
+        }
+        return headers;
+    }
+    
+    public static class HeaderEntry {
     
         private String name;
         private Map<String, String> attributes;
         private Map<String, String> directives;
         
-        public Package(String name, 
-                       Map<String, String> attributes, 
-                       Map<String, String> directives) {
+        public HeaderEntry(String name, 
+                          Map<String, String> attributes, 
+                          Map<String, String> directives) {
             this.name = name;
             this.attributes = attributes;
             this.directives = directives;
@@ -171,7 +195,7 @@
         }
     }
     
-    public class ExportPackage extends Package {
+    public static class ExportPackage extends HeaderEntry {
 
         private Version version;
         
@@ -187,7 +211,7 @@
         }
     }
         
-    public class ImportPackage extends Package {
+    public static class ImportPackage extends HeaderEntry {
 
         private boolean optional;
         private VersionRange versionRange;
@@ -215,4 +239,14 @@
             return versionRange;
         }
     }
+    
+    public static class SymbolicName extends HeaderEntry {
+
+        public SymbolicName(String name,
+                            Map<String, String> attributes,
+                            Map<String, String> directives) {
+            super(name, attributes, directives);
+        }
+        
+    }
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/BundleDescriptionTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/BundleDescriptionTest.java?rev=892313&r1=892312&r2=892313&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/BundleDescriptionTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/osgi/BundleDescriptionTest.java
Fri Dec 18 16:59:35 2009
@@ -58,5 +58,20 @@
         assertEquals("1.3", externalImports.get(0).getAttributes().get("version"));
         assertEquals("com.thoughtworks.xstream.converters", externalImports.get(1).getName());
       
     }
+    
+    public void testSymbolicName() throws Exception {
+        Map<String, String> headers = new HashMap<String, String>();
+        
+        BundleDescription desc = new BundleDescription(headers);
+                
+        // test simple
+        headers.put(Constants.BUNDLE_SYMBOLICNAME, "foo1");
+        assertEquals("foo1", desc.getSymbolicName().getName());
+        
+        // test with  a directive
+        headers.put(Constants.BUNDLE_SYMBOLICNAME, "foo2; singleton:=true");
+        assertEquals("foo2", desc.getSymbolicName().getName());
+        assertEquals("true", desc.getSymbolicName().getDirectives().get("singleton"));
+    }
 }
 



Mime
View raw message