felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1642172 [1/4] - in /felix/trunk/connect: ./ src/main/java/org/apache/felix/connect/ src/main/java/org/apache/felix/connect/felix/framework/ src/main/java/org/apache/felix/connect/felix/framework/capabilityset/ src/main/java/org/apache/feli...
Date Thu, 27 Nov 2014 15:14:40 GMT
Author: gnodet
Date: Thu Nov 27 15:14:39 2014
New Revision: 1642172

URL: http://svn.apache.org/r1642172
Log:
[FELIX-4712] Upgrade connect to OSGi r5
Upgrade to Java 6
Add support for FrameworkStartLevel, StartLevel and PackageAdmin

Added:
    felix/trunk/connect/src/main/java/org/apache/felix/connect/BundleAware.java
      - copied, changed from r1641786, felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Requirement.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/ExportedPackageImpl.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/RequiredBundleImpl.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableList.java
      - copied, changed from r1641786, felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Attribute.java
Removed:
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Attribute.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Capability.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Directive.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Requirement.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ListenerHookInfoImpl.java
Modified:
    felix/trunk/connect/pom.xml
    felix/trunk/connect/src/main/java/org/apache/felix/connect/DirRevision.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/EntriesEnumeration.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/EntryFilterEnumeration.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/FileEntriesEnumeration.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/JarRevision.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/PojoSR.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/PojoSRBundle.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/PojoSRBundleContext.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/PojoServiceRegistryFactoryImpl.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/Revision.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/URLRevision.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/ServiceRegistrationImpl.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/ServiceRegistry.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/CapabilitySet.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/SimpleFilter.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/EventDispatcher.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ListenerInfo.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/MapToDictionary.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableCollection.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/ShrinkableMap.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/StringComparator.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/StringMap.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/Util.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/util/VersionRange.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/launch/BundleDescriptor.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/launch/ClasspathScanner.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/launch/PojoServiceRegistry.java
    felix/trunk/connect/src/main/java/org/apache/felix/connect/launch/PojoServiceRegistryFactory.java

Modified: felix/trunk/connect/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/connect/pom.xml?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/pom.xml (original)
+++ felix/trunk/connect/pom.xml Thu Nov 27 15:14:39 2014
@@ -49,17 +49,22 @@
             <name>Karl Pauls</name>
             <email>karlpauls@gmail.com</email>
         </developer>
+        <developer>
+            <id>gnodet</id>
+            <name>Guillaume Nodet</name>
+            <email>gnodet@gmail.com</email>
+        </developer>
     </developers>
     <dependencies>
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
-            <version>4.3.1</version>
+            <version>5.0.0</version>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.compendium</artifactId>
-            <version>4.2.0</version>
+            <version>5.0.0</version>
         </dependency>
     </dependencies>
     <repositories/>
@@ -91,8 +96,8 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
-                    <target>1.5</target>
-                    <source>1.5</source>
+                    <target>1.6</target>
+                    <source>1.6</source>
                 </configuration>
             </plugin>
             <plugin>

Copied: felix/trunk/connect/src/main/java/org/apache/felix/connect/BundleAware.java (from r1641786, felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Requirement.java)
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/BundleAware.java?p2=felix/trunk/connect/src/main/java/org/apache/felix/connect/BundleAware.java&p1=felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Requirement.java&r1=1641786&r2=1642172&rev=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/felix/framework/capabilityset/Requirement.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/BundleAware.java Thu Nov 27 15:14:39 2014
@@ -16,19 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.felix.connect.felix.framework.capabilityset;
+package org.apache.felix.connect;
 
-import java.util.List;
+import org.osgi.framework.Bundle;
 
-public interface Requirement
+public interface BundleAware
 {
-    String getNamespace();
 
-    SimpleFilter getFilter();
+    void setBundle(Bundle bundle);
 
-    boolean isOptional();
-
-    Directive getDirective(String name);
-
-    List<Directive> getDirectives();
-}
\ No newline at end of file
+}

Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/DirRevision.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/DirRevision.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/DirRevision.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/DirRevision.java Thu Nov 27 15:14:39 2014
@@ -23,7 +23,7 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Enumeration;
 
-class DirRevision extends Revision
+class DirRevision implements Revision
 {
     private final File m_file;
 
@@ -38,7 +38,8 @@ class DirRevision extends Revision
         return m_file.lastModified();
     }
 
-    public Enumeration getEntries()
+    @Override
+    public Enumeration<String> getEntries()
     {
         return new FileEntriesEnumeration(m_file);
     }
@@ -48,18 +49,20 @@ class DirRevision extends Revision
     {
         try
         {
-		    if (entryName != null) {
-            File file = (new File(m_file, (entryName.startsWith("/")) ? entryName.substring(1) : entryName));
-            if (file.exists()) {
-                return file.toURL();
-            } 
-			}
+            if (entryName != null)
+            {
+                File file = (new File(m_file, (entryName.startsWith("/")) ? entryName.substring(1) : entryName));
+                if (file.exists())
+                {
+                    return file.toURI().toURL();
+                }
+            }
         }
         catch (MalformedURLException e)
         {
             e.printStackTrace();
         }
-            return null;
+        return null;
 
     }
 

Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/EntriesEnumeration.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/EntriesEnumeration.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/EntriesEnumeration.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/EntriesEnumeration.java Thu Nov 27 15:14:39 2014
@@ -19,50 +19,62 @@
 package org.apache.felix.connect;
 
 import java.util.Enumeration;
+import java.util.NoSuchElementException;
 import java.util.zip.ZipEntry;
 
-class EntriesEnumeration implements Enumeration
+class EntriesEnumeration implements Enumeration<String>
 {
-    private final Enumeration m_enumeration;
-	private final String m_prefix;
-	private volatile Object current;
+    private final Enumeration<? extends ZipEntry> m_enumeration;
+    private final String m_prefix;
+    private volatile String current;
 
-    public EntriesEnumeration(Enumeration enumeration)
+    public EntriesEnumeration(Enumeration<? extends ZipEntry> enumeration)
     {
         this(enumeration, null);
     }
-	
-	public EntriesEnumeration(Enumeration enumeration, String prefix)
-	{
-	   m_enumeration = enumeration;
-	   m_prefix = prefix;
-	}
-
-    public boolean hasMoreElements() {
-				while ((current == null) && m_enumeration.hasMoreElements()) {
-					String result = (String) ((ZipEntry) m_enumeration.nextElement()).getName();
-					if (m_prefix != null){
-						if (result.startsWith(m_prefix)) {
-							current = result.substring(m_prefix.length());
-						}
-					}
-					else {
-						current = result;
-					}
-				}
-				return (current != null);
-			}
-
-			public Object nextElement() {
-				try {
-					if (hasMoreElements()) {
-						return current;
-					}
-					else {
-						return m_enumeration.nextElement();
-					}
-				} finally { 
-					current = null;
-				}
-			}
+
+    public EntriesEnumeration(Enumeration<? extends ZipEntry> enumeration, String prefix)
+    {
+        m_enumeration = enumeration;
+        m_prefix = prefix;
+    }
+
+    public boolean hasMoreElements()
+    {
+        while ((current == null) && m_enumeration.hasMoreElements())
+        {
+            String result = m_enumeration.nextElement().getName();
+            if (m_prefix != null)
+            {
+                if (result.startsWith(m_prefix))
+                {
+                    current = result.substring(m_prefix.length());
+                }
+            }
+            else
+            {
+                current = result;
+            }
+        }
+        return (current != null);
+    }
+
+    public String nextElement()
+    {
+        try
+        {
+            if (hasMoreElements())
+            {
+                return current;
+            }
+            else
+            {
+                throw new NoSuchElementException();
+            }
+        }
+        finally
+        {
+            current = null;
+        }
+    }
 }
\ No newline at end of file

Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/EntryFilterEnumeration.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/EntryFilterEnumeration.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/EntryFilterEnumeration.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/EntryFilterEnumeration.java Thu Nov 27 15:14:39 2014
@@ -40,8 +40,12 @@ class EntryFilterEnumeration<T> implemen
     private final Set<String> m_dirEntries = new HashSet<String>();
     private final List<T> m_nextEntries = new ArrayList<T>(2);
 
-    public EntryFilterEnumeration(Revision rev, boolean includeFragments,
-            String path, String filePattern, boolean recurse,
+    public EntryFilterEnumeration(
+            Revision rev,
+            boolean includeFragments,
+            String path,
+            String filePattern,
+            boolean recurse,
             boolean isURLValues)
     {
         m_revision = rev;
@@ -52,8 +56,7 @@ class EntryFilterEnumeration<T> implemen
         // Sanity check the parameters.
         if (path == null)
         {
-            throw new IllegalArgumentException(
-                    "The path for findEntries() cannot be null.");
+            throw new IllegalArgumentException("The path for findEntries() cannot be null.");
         }
         // Strip leading '/' if present.
         if ((path.length() > 0) && (path.charAt(0) == '/'))
@@ -170,8 +173,7 @@ class EntryFilterEnumeration<T> implemen
                                                     : entryURL;
                                             try
                                             {
-                                                m_nextEntries.add((T) new URL(
-                                                        entryURL, "/" + dir));
+                                                m_nextEntries.add((T) new URL(entryURL, "/" + dir));
                                             }
                                             catch (MalformedURLException ex)
                                             {
@@ -199,8 +201,7 @@ class EntryFilterEnumeration<T> implemen
                     // is a child (not a grandchild) of the initial path, then
                     // we need
                     // to check if it matches the file pattern.
-                    if (m_recurse || (dirSlashIdx < 0)
-                            || (dirSlashIdx == entryName.length() - 1))
+                    if (m_recurse || (dirSlashIdx < 0) || (dirSlashIdx == entryName.length() - 1))
                     {
                         // See if the file pattern matches the last element of
                         // the path.

Added: felix/trunk/connect/src/main/java/org/apache/felix/connect/ExportedPackageImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/ExportedPackageImpl.java?rev=1642172&view=auto
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/ExportedPackageImpl.java (added)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/ExportedPackageImpl.java Thu Nov 27 15:14:39 2014
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.connect;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+import org.osgi.framework.namespace.BundleNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.service.packageadmin.ExportedPackage;
+
+class ExportedPackageImpl implements ExportedPackage
+{
+    private final BundleCapability m_export;
+
+    public ExportedPackageImpl(BundleCapability export)
+    {
+        m_export = export;
+    }
+
+    public Bundle getExportingBundle()
+    {
+        return m_export.getRevision().getBundle();
+    }
+
+    public Bundle[] getImportingBundles()
+    {
+        // Create set for storing importing bundles.
+        Set<Bundle> result = new HashSet<Bundle>();
+        // Get all importers and requirers for all revisions of the bundle.
+        // The spec says that require-bundle should be returned with importers.
+        for (BundleWire wire : m_export.getRevision().getWiring().getProvidedWires(null))
+        {
+            if (wire.getCapability() == m_export
+                    || BundleNamespace.BUNDLE_NAMESPACE.equals(wire.getCapability().getNamespace()))
+            {
+                result.add( wire.getRequirer().getBundle() );
+            }
+        }
+        // Return the results.
+        return result.toArray(new Bundle[result.size()]);
+    }
+
+    public String getName()
+    {
+        return (String) m_export.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
+    }
+
+    public String getSpecificationVersion()
+    {
+        return getVersion().toString();
+    }
+
+    public Version getVersion()
+    {
+        return m_export.getAttributes().containsKey(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE)
+                ? (Version) m_export.getAttributes().get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE)
+                : Version.emptyVersion;
+    }
+
+    public boolean isRemovalPending()
+    {
+        return false;
+    }
+
+    public String toString()
+    {
+        return getName() + "; version=" + getVersion();
+    }
+}
\ No newline at end of file

Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/FileEntriesEnumeration.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/FileEntriesEnumeration.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/FileEntriesEnumeration.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/FileEntriesEnumeration.java Thu Nov 27 15:14:39 2014
@@ -22,7 +22,7 @@ import java.io.File;
 import java.util.Enumeration;
 import java.util.NoSuchElementException;
 
-class FileEntriesEnumeration implements Enumeration
+class FileEntriesEnumeration implements Enumeration<String>
 {
     private final File m_dir;
     private final File[] m_children;
@@ -39,7 +39,7 @@ class FileEntriesEnumeration implements 
         return (m_children != null) && (m_counter < m_children.length);
     }
 
-    public synchronized Object nextElement()
+    public synchronized String nextElement()
     {
         if ((m_children == null) || (m_counter >= m_children.length))
         {
@@ -52,7 +52,7 @@ class FileEntriesEnumeration implements 
 
         // Remove the leading path of the reference directory, since the
         // entry paths are supposed to be relative to the root.
-        StringBuffer sb = new StringBuffer(abs);
+        StringBuilder sb = new StringBuilder(abs);
         sb.delete(0, m_dir.getAbsolutePath().length() + 1);
         // Add a '/' to the end of directory entries.
         if (m_children[m_counter].isDirectory())
@@ -67,15 +67,14 @@ class FileEntriesEnumeration implements 
     {
         File[] children = dir.listFiles();
         File[] combined = children;
-        for (int i = 0; i < children.length; i++)
+        for (File aChildren : children)
         {
-            if (children[i].isDirectory())
+            if (aChildren.isDirectory())
             {
-                File[] grandchildren = listFilesRecursive(children[i]);
+                File[] grandchildren = listFilesRecursive(aChildren);
                 if (grandchildren.length > 0)
                 {
-                    File[] tmp = new File[combined.length
-                            + grandchildren.length];
+                    File[] tmp = new File[combined.length + grandchildren.length];
                     System.arraycopy(combined, 0, tmp, 0, combined.length);
                     System.arraycopy(grandchildren, 0, tmp, combined.length,
                             grandchildren.length);

Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/JarRevision.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/JarRevision.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/JarRevision.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/JarRevision.java Thu Nov 27 15:14:39 2014
@@ -18,28 +18,29 @@
  */
 package org.apache.felix.connect;
 
-import java.io.*;
-import java.net.URLStreamHandler;
-import java.net.URLConnection;
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
 import java.util.Enumeration;
-import java.util.jar.JarFile;
 import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
 
-class JarRevision extends Revision
+class JarRevision implements Revision
 {
     private final long m_lastModified;
     private final JarFile m_jar;
     private final URL m_url;
-	private final String m_urlString;
-	private final String m_prefix;
+    private final String m_urlString;
+    private final String m_prefix;
 
     public JarRevision(JarFile jar, URL url, String prefix, long lastModified)
     {
         m_jar = jar;
         m_url = url;
-		m_urlString =  m_url.toExternalForm();
-		m_prefix = prefix;
+        m_urlString = m_url.toExternalForm();
+        m_prefix = prefix;
         if (lastModified > 0)
         {
             m_lastModified = lastModified;
@@ -56,7 +57,7 @@ class JarRevision extends Revision
         return m_lastModified;
     }
 
-    public Enumeration getEntries()
+    public Enumeration<String> getEntries()
     {
         return new EntriesEnumeration(m_jar.entries(), m_prefix);
     }
@@ -66,61 +67,69 @@ class JarRevision extends Revision
     {
         try
         {
-		    if("/".equals(entryName) || "".equals(entryName) || " ".equals(entryName)) {
-			    return new URL("jar:" + m_urlString + "!/" + ((m_prefix == null) ? "" : m_prefix));
-			}
+            if ("/".equals(entryName) || "".equals(entryName) || " ".equals(entryName))
+            {
+                return new URL("jar:" + m_urlString + "!/" + ((m_prefix == null) ? "" : m_prefix));
+            }
             if (entryName != null)
-			{ 
-				final String target = ((entryName.startsWith("/")) ? entryName.substring(1) : entryName);
-				final JarEntry entry = m_jar.getJarEntry(((m_prefix == null) ? "" : m_prefix) + target);
-				if ( entry != null) {
-								URL result = new URL(null, "jar:" + m_urlString + "!/" + ((m_prefix == null) ? "" : m_prefix) + target, new URLStreamHandler() {
-									
-									
-									protected URLConnection openConnection(final URL u) throws IOException {
-										return new java.net.JarURLConnection(u) {
-											
-											public JarFile getJarFile() {
-											    return m_jar;
-											}
-											public void connect() throws IOException {
-												// TODO Auto-generated method stub
-												
-											}
-											
-											public InputStream getInputStream()
-													throws IOException {
-													
-												String extF = u.toExternalForm();
-												JarEntry targetEntry = entry;
-												if (!extF.endsWith(target)) {
-												    extF = extF.substring(extF.indexOf('!') + 2);
-												    if (m_prefix != null) {
-														if (!extF.startsWith(m_prefix)) {
-														    extF = m_prefix + extF;
-														}
-													}
-													targetEntry = m_jar.getJarEntry(extF);
-												}
-												return m_jar.getInputStream(targetEntry);
-											}
-										};
-									}
-								});
-								return result;
-							}
-							else {
-								if (entryName.endsWith("/")) {
-								     return new URL("jar:" + m_urlString + "!/" + ((m_prefix == null) ? "" : m_prefix) + target);
-								}
-							}
-			}
+            {
+                final String target = ((entryName.startsWith("/")) ? entryName.substring(1) : entryName);
+                final JarEntry entry = m_jar.getJarEntry(((m_prefix == null) ? "" : m_prefix) + target);
+                if (entry != null)
+                {
+                    URL result = new URL(null, "jar:" + m_urlString + "!/" + ((m_prefix == null) ? "" : m_prefix) + target, new URLStreamHandler()
+                    {
+                        protected URLConnection openConnection(final URL u) throws IOException
+                        {
+                            return new java.net.JarURLConnection(u)
+                            {
+
+                                public JarFile getJarFile()
+                                {
+                                    return m_jar;
+                                }
+
+                                public void connect() throws IOException
+                                {
+                                }
+
+                                public InputStream getInputStream() throws IOException
+                                {
+                                    String extF = u.toExternalForm();
+                                    JarEntry targetEntry = entry;
+                                    if (!extF.endsWith(target))
+                                    {
+                                        extF = extF.substring(extF.indexOf('!') + 2);
+                                        if (m_prefix != null)
+                                        {
+                                            if (!extF.startsWith(m_prefix))
+                                            {
+                                                extF = m_prefix + extF;
+                                            }
+                                        }
+                                        targetEntry = m_jar.getJarEntry(extF);
+                                    }
+                                    return m_jar.getInputStream(targetEntry);
+                                }
+                            };
+                        }
+                    });
+                    return result;
+                }
+                else
+                {
+                    if (entryName.endsWith("/"))
+                    {
+                        return new URL("jar:" + m_urlString + "!/" + ((m_prefix == null) ? "" : m_prefix) + target);
+                    }
+                }
+            }
         }
         catch (IOException e)
         {
             e.printStackTrace();
         }
-            return null;
+        return null;
 
     }
 

Modified: felix/trunk/connect/src/main/java/org/apache/felix/connect/PojoSR.java
URL: http://svn.apache.org/viewvc/felix/trunk/connect/src/main/java/org/apache/felix/connect/PojoSR.java?rev=1642172&r1=1642171&r2=1642172&view=diff
==============================================================================
--- felix/trunk/connect/src/main/java/org/apache/felix/connect/PojoSR.java (original)
+++ felix/trunk/connect/src/main/java/org/apache/felix/connect/PojoSR.java Thu Nov 27 15:14:39 2014
@@ -19,16 +19,21 @@
 package org.apache.felix.connect;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.JarURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
+import java.util.Set;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -37,6 +42,7 @@ import org.osgi.framework.BundleExceptio
 import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceEvent;
@@ -44,6 +50,11 @@ import org.osgi.framework.ServiceListene
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.Version;
+import org.osgi.framework.VersionRange;
+import org.osgi.framework.startlevel.FrameworkStartLevel;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.service.packageadmin.ExportedPackage;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.packageadmin.RequiredBundle;
@@ -59,45 +70,41 @@ import org.apache.felix.connect.launch.P
 public class PojoSR implements PojoServiceRegistry
 {
     private final BundleContext m_context;
-    private final ServiceRegistry m_reg = new ServiceRegistry(
+    private final ServiceRegistry m_registry = new ServiceRegistry(
             new ServiceRegistry.ServiceRegistryCallbacks()
             {
-
-                public void serviceChanged(ServiceEvent event,
-                        Dictionary oldProps)
+                public void serviceChanged(ServiceEvent event, Dictionary<String, ?> oldProps)
                 {
                     m_dispatcher.fireServiceEvent(event, oldProps, null);
                 }
             });
 
-    private final EventDispatcher m_dispatcher = new EventDispatcher(m_reg);
-    private final Map<Long, Bundle> m_bundles =new HashMap<Long, Bundle>();
-    private final Map<String, Bundle> m_symbolicNameToBundle = new HashMap<String, Bundle>();
-    private final Map bundleConfig;
-    public PojoSR(Map config) throws Exception
-    {
+    private final EventDispatcher m_dispatcher = new EventDispatcher(m_registry);
+    private final Map<Long, Bundle> m_bundles = new HashMap<Long, Bundle>();
+    private final Map<String, Object> bundleConfig;
+
+    public static BundleDescriptor createSystemBundle() {
         final Map<String, String> headers = new HashMap<String, String>();
-        headers.put(Constants.BUNDLE_SYMBOLICNAME,
-                "org.apache.felix.connect");
-        headers.put(Constants.BUNDLE_VERSION, "0.1.0-SNAPSHOT");
+        headers.put(Constants.BUNDLE_SYMBOLICNAME, "org.apache.felix.connect");
+        headers.put(Constants.BUNDLE_VERSION, "0.0.0");
         headers.put(Constants.BUNDLE_NAME, "System Bundle");
         headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
-		headers.put(Constants.BUNDLE_VENDOR, "Apache Software Foundation");
-        bundleConfig = new HashMap(config);
-        final Bundle b = new PojoSRBundle(new Revision()
-        {
+        headers.put(Constants.BUNDLE_VENDOR, "Apache Software Foundation");
+
 
+        Revision revision = new Revision()
+        {
+            final long lastModified = System.currentTimeMillis();
             @Override
             public long getLastModified()
             {
-                // TODO Auto-generated method stub
-                return System.currentTimeMillis();
+                return lastModified;
             }
 
             @Override
-            public Enumeration getEntries()
+            public Enumeration<String> getEntries()
             {
-                return new Properties().elements();
+                return Collections.emptyEnumeration();
             }
 
             @Override
@@ -105,26 +112,60 @@ public class PojoSR implements PojoServi
             {
                 return getClass().getClassLoader().getResource(entryName);
             }
-        }, headers, new Version(0, 0, 1), "file:pojosr", m_reg, m_dispatcher,
-                null, 0, "org.apache.felix.connect", m_bundles, getClass()
-                        .getClassLoader(), bundleConfig)
-        {
-        	@Override
-        	public synchronized void start() throws BundleException {
-        		if (m_state != Bundle.RESOLVED) {
-        			return;
-        		}
-        		m_dispatcher.startDispatching();
-        		m_state = Bundle.STARTING;
-
-                m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STARTING,
-                        this));
-                m_context = new PojoSRBundleContext(this, m_reg, m_dispatcher,
-                                m_bundles, bundleConfig);
+        };
+        Map<Class, Object> services = new HashMap<Class, Object>();
+        services.put(FrameworkStartLevel.class, new FrameworkStartLevelImpl());
+        return new BundleDescriptor(
+                PojoSR.class.getClassLoader(),
+                "felix-connect",
+                headers,
+                revision,
+                services
+                );
+    }
+
+    public PojoSR(Map<String, ?> config) throws Exception
+    {
+        this(config, null);
+    }
+
+    public PojoSR(Map<String, ?> config, BundleDescriptor systemBundle) throws Exception
+    {
+        if (systemBundle == null) {
+            systemBundle = createSystemBundle();
+        }
+        bundleConfig = new HashMap<String, Object>(config);
+        final Bundle b = new PojoSRBundle(
+                        m_registry,
+                        m_dispatcher,
+                        m_bundles,
+                        systemBundle.getUrl(),
+                        0,
+                        "org.apache.felix.connect",
+                        new Version(0, 0, 1),
+                                systemBundle.getRevision(),
+                        systemBundle.getClassLoader(),
+                        systemBundle.getHeaders(),
+                        systemBundle.getServices(),
+                        bundleConfig)
+        {
+            @Override
+            public synchronized void start() throws BundleException
+            {
+                if (m_state != Bundle.RESOLVED)
+                {
+                    return;
+                }
+                m_dispatcher.startDispatching();
+                m_state = Bundle.STARTING;
+
+                m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STARTING, this));
+                m_context = new PojoSRBundleContext(this, m_registry, m_dispatcher, m_bundles, bundleConfig);
                 int i = 0;
-                for (Bundle b : m_bundles.values()) {
-                	i++;
-                	try
+                for (Bundle b : m_bundles.values())
+                {
+                    i++;
+                    try
                     {
                         if (b != this)
                         {
@@ -133,327 +174,223 @@ public class PojoSR implements PojoServi
                     }
                     catch (Throwable t)
                     {
-                    	System.out.println("Unable to start bundle: " + i );
-                    	t.printStackTrace();
+                        System.out.println("Unable to start bundle: " + i);
+                        t.printStackTrace();
                     }
                 }
                 m_state = Bundle.ACTIVE;
-                m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STARTED,
-                        this));
+                m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STARTED, this));
 
                 m_dispatcher.fireFrameworkEvent(new FrameworkEvent(FrameworkEvent.STARTED, this, null));
-        		super.start();
-        	};
+                super.start();
+            }
+
             @Override
             public synchronized void stop() throws BundleException
             {
-            	if ((m_state == Bundle.STOPPING) || m_state == Bundle.RESOLVED) {
-            		return;
-
-            	}
-            	else if (m_state != Bundle.ACTIVE) {
-            		throw new BundleException("Can't stop pojosr because it is not ACTIVE");
-            	}
-            	final Bundle systemBundle = this;
-            	Runnable r = new Runnable() {
-
-					public void run() {
-		                m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STOPPING,
-		                		systemBundle));
-		                for (Bundle b : m_bundles.values())
-		                {
-		                    try
-		                    {
-		                        if (b != systemBundle)
-		                        {
-		                            b.stop();
-		                        }
-		                    }
-		                    catch (Throwable t)
-		                    {
-		                        t.printStackTrace();
-		                    }
-		                }
-		                m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STOPPED,
-		                		systemBundle));
-		                m_state = Bundle.RESOLVED;
-		                m_dispatcher.stopDispatching();
-					}
-				};
-				m_state = Bundle.STOPPING;
-				if ("true".equalsIgnoreCase(System.getProperty("org.apache.felix.connect.events.sync"))) {
-					r.run();
-				}
-				else {
-					new Thread(r).start();
-				}
-            }
-        };
-        m_symbolicNameToBundle.put(b.getSymbolicName(), b);
-        b.start();
-        b.getBundleContext().registerService(StartLevel.class.getName(),
-                new StartLevel()
+                if ((m_state == Bundle.STOPPING) || m_state == Bundle.RESOLVED)
                 {
+                    return;
 
-                    public void setStartLevel(int startlevel)
-                    {
-                        // TODO Auto-generated method stub
-
-                    }
-
-                    public void setInitialBundleStartLevel(int startlevel)
-                    {
-                        // TODO Auto-generated method stub
-
-                    }
-
-                    public void setBundleStartLevel(Bundle bundle,
-                            int startlevel)
-                    {
-                        // TODO Auto-generated method stub
-
-                    }
-
-                    public boolean isBundlePersistentlyStarted(Bundle bundle)
-                    {
-                        // TODO Auto-generated method stub
-                        return true;
-                    }
-
-                    public boolean isBundleActivationPolicyUsed(Bundle bundle)
-                    {
-                        // TODO Auto-generated method stub
-                        return false;
-                    }
-
-                    public int getStartLevel()
-                    {
-                        // TODO Auto-generated method stub
-                        return 1;
-                    }
-
-                    public int getInitialBundleStartLevel()
-                    {
-                        // TODO Auto-generated method stub
-                        return 1;
-                    }
-
-                    public int getBundleStartLevel(Bundle bundle)
-                    {
-                        // TODO Auto-generated method stub
-                        return 1;
-                    }
-                }, null);
-
-        b.getBundleContext().registerService(PackageAdmin.class.getName(),
-                new PackageAdmin()
+                }
+                else if (m_state != Bundle.ACTIVE)
+                {
+                    throw new BundleException("Can't stop pojosr because it is not ACTIVE");
+                }
+                final Bundle systemBundle = this;
+                Runnable r = new Runnable()
                 {
 
-                    public boolean resolveBundles(Bundle[] bundles)
-                    {
-                        // TODO Auto-generated method stub
-                        return true;
-                    }
-
-                    public void refreshPackages(Bundle[] bundles)
-                    {
-                        m_dispatcher.fireFrameworkEvent(new FrameworkEvent(
-                                FrameworkEvent.PACKAGES_REFRESHED, b, null));
-                    }
-
-                    public RequiredBundle[] getRequiredBundles(
-                            String symbolicName)
-                    {
-                        return null;
-                    }
-
-                    public Bundle[] getHosts(Bundle bundle)
-                    {
-                        // TODO Auto-generated method stub
-                        return null;
-                    }
-
-                    public Bundle[] getFragments(Bundle bundle)
-                    {
-                        // TODO Auto-generated method stub
-                        return null;
-                    }
-
-                    public ExportedPackage[] getExportedPackages(String name)
-                    {
-                        // TODO Auto-generated method stub
-                        return null;
-                    }
-
-                    public ExportedPackage[] getExportedPackages(Bundle bundle)
-                    {
-                        // TODO Auto-generated method stub
-                        return null;
-                    }
-
-                    public ExportedPackage getExportedPackage(String name)
-                    {
-                        // TODO Auto-generated method stub
-                        return null;
-                    }
-
-                    public Bundle[] getBundles(String symbolicName,
-                            String versionRange)
-                    {
-					    Bundle result = m_symbolicNameToBundle.get((symbolicName != null) ? symbolicName.trim() : symbolicName);
-						if (result != null) {
-							return new Bundle[] {result};
-						}
-						return null;
-                    }
-
-                    public int getBundleType(Bundle bundle)
+                    public void run()
                     {
-                        return 0;
-                    }
+                        m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STOPPING, systemBundle));
+                        for (Bundle b : m_bundles.values())
+                        {
+                            try
+                            {
+                                if (b != systemBundle)
+                                {
+                                    b.stop();
+                                }
+                            }
+                            catch (Throwable t)
+                            {
+                                t.printStackTrace();
+                            }
+                        }
+                        m_dispatcher.fireBundleEvent(new BundleEvent(BundleEvent.STOPPED, systemBundle));
+                        m_state = Bundle.RESOLVED;
+                        m_dispatcher.stopDispatching();
+                    }
+                };
+                m_state = Bundle.STOPPING;
+                if ("true".equalsIgnoreCase(System.getProperty("org.apache.felix.connect.events.sync")))
+                {
+                    r.run();
+                }
+                else
+                {
+                    new Thread(r).start();
+                }
+            }
+        };
+        m_bundles.put(0l, b);
+        b.start();
+        b.getBundleContext().registerService(StartLevel.class.getName(), new StartLevelImpl(), null);
 
-                    public Bundle getBundle(Class clazz)
-                    {
-                        return m_context.getBundle();
-                    }
-                }, null);
+        b.getBundleContext().registerService(PackageAdmin.class.getName(), new PackageAdminImpl(), null);
         m_context = b.getBundleContext();
 
-        List<BundleDescriptor> scan = (List<BundleDescriptor>) config
-                .get(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS);
+        Collection<BundleDescriptor> scan = (Collection<BundleDescriptor>) config.get(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS);
 
         if (scan != null)
         {
             startBundles(scan);
-		}
+        }
     }
 
-	public void startBundles(List<BundleDescriptor> scan) throws Exception {
-	 for (BundleDescriptor desc : scan)
+    public void startBundles(Collection<BundleDescriptor> scan) throws Exception
+    {
+        for (BundleDescriptor desc : scan)
+        {
+            Revision revision = desc.getRevision();
+            if (revision == null)
             {
-                URL u = new URL(desc.getUrl().toExternalForm()
-                        + "META-INF/MANIFEST.MF");
-                Revision r;
-                if (u.toExternalForm().startsWith("file:"))
-                {
-                    File root = new File(URLDecoder.decode(desc.getUrl()
-                            .getFile(), "UTF-8"));
-                    u = root.toURL();
-                    r = new DirRevision(root);
-                }
-                else
-                {
-                    URLConnection uc = u.openConnection();
-                    if (uc instanceof JarURLConnection)
-                    {
-					    String target = ((JarURLConnection) uc).getJarFileURL().toExternalForm();
-						String prefix = null;
-						if (!("jar:" + target + "!/").equals(desc.getUrl().toExternalForm())) {
-						    prefix = desc.getUrl().toExternalForm().substring(("jar:" + target + "!/").length());
-						}
-                        r = new JarRevision(
-                                ((JarURLConnection) uc).getJarFile(),
-                                ((JarURLConnection) uc).getJarFileURL(),
-								prefix,
-                                uc.getLastModified());
-                    }
-                    else
-                    {
-                        r = new URLRevision(desc.getUrl(), desc.getUrl()
-                                .openConnection().getLastModified());
-                    }
-                }
-                Map<String, String> bundleHeaders = desc.getHeaders();
-				Version osgiVersion = null;
-				try {
-					osgiVersion = Version.parseVersion(bundleHeaders.get(Constants.BUNDLE_VERSION));
-				} catch (Exception ex) {
-					ex.printStackTrace();
-					osgiVersion = Version.emptyVersion;
-				}
-                String sym = bundleHeaders.get(Constants.BUNDLE_SYMBOLICNAME);
-                    if (sym != null)
-                    {
-                        int idx = sym.indexOf(';');
-                        if (idx > 0)
-                        {
-                            sym = sym.substring(0, idx);
-                        }
-						sym = sym.trim();
-                    }
-
-                if ((sym == null)
-                        || !m_symbolicNameToBundle.containsKey( sym ))
+                revision = buildRevision(desc);
+            }
+            Map<String, String> bundleHeaders = desc.getHeaders();
+            Version osgiVersion;
+            try
+            {
+                osgiVersion = Version.parseVersion(bundleHeaders.get(Constants.BUNDLE_VERSION));
+            }
+            catch (Exception ex)
+            {
+                ex.printStackTrace();
+                osgiVersion = Version.emptyVersion;
+            }
+            String sym = bundleHeaders.get(Constants.BUNDLE_SYMBOLICNAME);
+            if (sym != null)
+            {
+                int idx = sym.indexOf(';');
+                if (idx > 0)
                 {
-                    // TODO: framework - support multiple versions
-                    Bundle bundle = new PojoSRBundle(r, bundleHeaders,
-                            osgiVersion, desc.getUrl().toExternalForm(), m_reg,
-                            m_dispatcher,
-                            bundleHeaders.get(Constants.BUNDLE_ACTIVATOR),
-                            m_bundles.size(),
-                            sym,
-                            m_bundles, desc.getClassLoader(), bundleConfig);
-                    if (sym != null)
-                    {
-                        m_symbolicNameToBundle.put(bundle.getSymbolicName(),
-                                bundle);
-                    }
+                    sym = sym.substring(0, idx);
                 }
-
+                sym = sym.trim();
             }
 
+            Bundle bundle = new PojoSRBundle(
+                    m_registry,
+                    m_dispatcher,
+                    m_bundles,
+                    desc.getUrl(),
+                    m_bundles.size(),
+                    sym,
+                    osgiVersion,
+                    revision,
+                    desc.getClassLoader(),
+                    bundleHeaders,
+                    desc.getServices(),
+                    bundleConfig);
+            m_bundles.put(bundle.getBundleId(), bundle);
+        }
+
 
-        for (long i = 1; i < m_bundles.size(); i++)
+        for (Bundle bundle : m_bundles.values())
         {
             try
             {
-                m_bundles.get(i).start();
+                bundle.start();
             }
             catch (Throwable e)
             {
-                System.out.println("Unable to start bundle: " + i);
+                System.out.println("Unable to start bundle: " + bundle);
                 e.printStackTrace();
             }
         }
 
-	}
+    }
+
+    private Revision buildRevision(BundleDescriptor desc) throws IOException
+    {
+        Revision r;
+        URL url = new URL(desc.getUrl());
+        URL u = new URL(desc.getUrl() + "META-INF/MANIFEST.MF");
+        if (u.toExternalForm().startsWith("file:"))
+        {
+            File root = new File(URLDecoder.decode(url.getFile(), "UTF-8"));
+            r = new DirRevision(root);
+        }
+        else
+        {
+            URLConnection uc = u.openConnection();
+            if (uc instanceof JarURLConnection)
+            {
+                String target = ((JarURLConnection) uc).getJarFileURL().toExternalForm();
+                String prefix = null;
+                if (!("jar:" + target + "!/").equals(desc.getUrl()))
+                {
+                    prefix = desc.getUrl().substring(("jar:" + target + "!/").length());
+                }
+                r = new JarRevision(
+                        ((JarURLConnection) uc).getJarFile(),
+                        ((JarURLConnection) uc).getJarFileURL(),
+                        prefix,
+                        uc.getLastModified());
+            }
+            else
+            {
+                r = new URLRevision(url, url.openConnection().getLastModified());
+            }
+        }
+        return r;
+    }
 
     public static void main(String[] args) throws Exception
     {
-    	Filter filter = null;
-    	Class main = null;
-    	for (int i = 0;(args != null) && (i < args.length) && (i < 2); i++) {
-	    	try {
-	    		filter = FrameworkUtil.createFilter(args[i]);
-	    	} catch (InvalidSyntaxException ie) {
-	    		try {
-	    			main = PojoSR.class.getClassLoader().loadClass(args[i]);
-	    		} catch (Exception ex) {
-	    			throw new IllegalArgumentException("Argument is neither a filter nor a class: " + args[i]);
-	    		}
-	    	}
-    	}
-        Map config = new HashMap();
+        Filter filter = null;
+        Class<?> main = null;
+        for (int i = 0; (args != null) && (i < args.length) && (i < 2); i++)
+        {
+            try
+            {
+                filter = FrameworkUtil.createFilter(args[i]);
+            }
+            catch (InvalidSyntaxException ie)
+            {
+                try
+                {
+                    main = PojoSR.class.getClassLoader().loadClass(args[i]);
+                }
+                catch (Exception ex)
+                {
+                    throw new IllegalArgumentException("Argument is neither a filter nor a class: " + args[i]);
+                }
+            }
+        }
+        Map<String, Object> config = new HashMap<String, Object>();
         config.put(
                 PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS,
                 (filter != null) ? new ClasspathScanner()
                         .scanForBundles(filter.toString()) : new ClasspathScanner()
                         .scanForBundles());
         new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
-        if (main != null) {
-        	int count = 0;
-        	if (filter != null) {
-        		count++;
-        	}
-        	if (main != null) {
-        		count++;
-        	}
-        	String[] newArgs = args;
-        	if (count > 0) {
-        		newArgs = new String[args.length - count];
-        		System.arraycopy(args, count, newArgs, 0, newArgs.length);
-        	}
-        	main.getMethod("main", String[].class).invoke(null, (Object) newArgs );
+        if (main != null)
+        {
+            int count = 0;
+            if (filter != null)
+            {
+                count++;
+            }
+            count++;
+            String[] newArgs = args;
+            if (count > 0)
+            {
+                newArgs = new String[args.length - count];
+                System.arraycopy(args, count, newArgs, 0, newArgs.length);
+            }
+            main.getMethod("main", String[].class).invoke(null, newArgs);
         }
     }
 
@@ -462,52 +399,281 @@ public class PojoSR implements PojoServi
         return m_context;
     }
 
-    public void addServiceListener(ServiceListener listener, String filter)
-            throws InvalidSyntaxException
+    @Override
+    public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
     {
         m_context.addServiceListener(listener, filter);
     }
 
+    @Override
     public void addServiceListener(ServiceListener listener)
     {
         m_context.addServiceListener(listener);
     }
 
+    @Override
     public void removeServiceListener(ServiceListener listener)
     {
         m_context.removeServiceListener(listener);
     }
 
-    public ServiceRegistration registerService(String[] clazzes,
-            Object service, Dictionary properties)
+    @Override
+    public ServiceRegistration<?> registerService(String[] clazzes, Object service, Dictionary<String, ?> properties)
     {
         return m_context.registerService(clazzes, service, properties);
     }
 
-    public ServiceRegistration registerService(String clazz, Object service,
-            Dictionary properties)
+    @Override
+    public ServiceRegistration<?> registerService(String clazz, Object service, Dictionary<String, ?> properties)
     {
         return m_context.registerService(clazz, service, properties);
     }
 
-    public ServiceReference[] getServiceReferences(String clazz, String filter)
-            throws InvalidSyntaxException
+    @Override
+    public ServiceReference<?>[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
     {
         return m_context.getServiceReferences(clazz, filter);
     }
 
-    public ServiceReference getServiceReference(String clazz)
+    @Override
+    public ServiceReference<?> getServiceReference(String clazz)
     {
         return m_context.getServiceReference(clazz);
     }
 
-    public Object getService(ServiceReference reference)
+    @Override
+    public <S> S getService(ServiceReference<S> reference)
     {
         return m_context.getService(reference);
     }
 
-    public boolean ungetService(ServiceReference reference)
+    @Override
+    public boolean ungetService(ServiceReference<?> reference)
     {
         return m_context.ungetService(reference);
     }
+
+    private static class FrameworkStartLevelImpl implements FrameworkStartLevel, BundleAware
+    {
+
+        private Bundle bundle;
+
+        @Override
+        public void setBundle(Bundle bundle)
+        {
+            this.bundle = bundle;
+        }
+
+        @Override
+        public int getStartLevel()
+        {
+            return 0;
+        }
+
+        @Override
+        public void setStartLevel(int startlevel, FrameworkListener... listeners)
+        {
+        }
+
+        @Override
+        public int getInitialBundleStartLevel()
+        {
+            return 0;
+        }
+
+        @Override
+        public void setInitialBundleStartLevel(int startlevel)
+        {
+        }
+
+        @Override
+        public Bundle getBundle()
+        {
+            return bundle;
+        }
+    }
+
+    private static class StartLevelImpl implements StartLevel
+    {
+        @Override
+        public void setStartLevel(int startlevel)
+        {
+            // TODO Auto-generated method stub
+        }
+
+        @Override
+        public void setInitialBundleStartLevel(int startlevel)
+        {
+            // TODO Auto-generated method stub
+        }
+
+        @Override
+        public void setBundleStartLevel(Bundle bundle, int startlevel)
+        {
+            // TODO Auto-generated method stub
+        }
+
+        @Override
+        public boolean isBundlePersistentlyStarted(Bundle bundle)
+        {
+            // TODO Auto-generated method stub
+            return true;
+        }
+
+        @Override
+        public boolean isBundleActivationPolicyUsed(Bundle bundle)
+        {
+            // TODO Auto-generated method stub
+            return false;
+        }
+
+        @Override
+        public int getStartLevel()
+        {
+            // TODO Auto-generated method stub
+            return 1;
+        }
+
+        @Override
+        public int getInitialBundleStartLevel()
+        {
+            // TODO Auto-generated method stub
+            return 1;
+        }
+
+        @Override
+        public int getBundleStartLevel(Bundle bundle)
+        {
+            // TODO Auto-generated method stub
+            return 1;
+        }
+    }
+
+    private class PackageAdminImpl implements PackageAdmin
+    {
+
+        @Override
+        public boolean resolveBundles(Bundle[] bundles)
+        {
+            return true;
+        }
+
+        @Override
+        public void refreshPackages(Bundle[] bundles)
+        {
+            FrameworkEvent event = new FrameworkEvent(FrameworkEvent.PACKAGES_REFRESHED, m_bundles.get(0l), null);
+            m_dispatcher.fireFrameworkEvent(event);
+        }
+
+        @Override
+        public RequiredBundle[] getRequiredBundles(String symbolicName)
+        {
+            List list = new ArrayList();
+            for (Bundle bundle : PojoSR.this.m_bundles.values())
+            {
+                if ((symbolicName == null) || (symbolicName.equals(bundle.getSymbolicName())))
+                {
+                    list.add(new RequiredBundleImpl(bundle));
+                }
+            }
+            return (list.isEmpty())
+                    ? null
+                    : (RequiredBundle[]) list.toArray(new RequiredBundle[list.size()]);
+        }
+
+        @Override
+        public Bundle[] getHosts(Bundle bundle)
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        @Override
+        public Bundle[] getFragments(Bundle bundle)
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        @Override
+        public ExportedPackage[] getExportedPackages(String name)
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        @Override
+        public ExportedPackage[] getExportedPackages(Bundle bundle)
+        {
+            List<ExportedPackage> list = new ArrayList<ExportedPackage>();
+            // If a bundle is specified, then return its
+            // exported packages.
+            if (bundle != null)
+            {
+                getExportedPackages(bundle, list);
+            }
+            // Otherwise return all exported packages.
+            else
+            {
+                for (Bundle b : m_bundles.values())
+                {
+                    getExportedPackages(b, list);
+                }
+            }
+            return list.isEmpty() ? null : list.toArray(new ExportedPackage[list.size()]);
+        }
+
+        private void getExportedPackages(Bundle bundle, List<ExportedPackage> list)
+        {
+            // Since a bundle may have many revisions associated with it,
+            // one for each revision in the cache, search each revision
+            // to get all exports.
+            for (BundleCapability cap : bundle.adapt(BundleWiring.class).getCapabilities(null))
+            {
+                if (cap.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE))
+                {
+                    list.add(new ExportedPackageImpl(cap));
+                }
+            }
+        }
+
+        @Override
+        public ExportedPackage getExportedPackage(String name)
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        @Override
+        public Bundle[] getBundles(String symbolicName, String versionRange)
+        {
+            Set<Bundle> result = new HashSet<Bundle>();
+            VersionRange range = versionRange != null ? new VersionRange(versionRange) : null;
+            for (Bundle bundle : m_bundles.values())
+            {
+                if (symbolicName != null && !bundle.getSymbolicName().equals(symbolicName))
+                {
+                    continue;
+                }
+                if (range != null && !range.includes(bundle.getVersion()))
+                {
+                    continue;
+                }
+                result.add(bundle);
+            }
+            return result.isEmpty() ? null : result.toArray(new Bundle[result.size()]);
+        }
+
+        @Override
+        public int getBundleType(Bundle bundle)
+        {
+            return bundle.adapt(BundleRevision.class).getTypes();
+        }
+
+        @Override
+        public Bundle getBundle(Class clazz)
+        {
+            return m_context.getBundle();
+        }
+    }
 }



Mime
View raw message