Apply patch FELIX-3382 to adapt example to use Java 5 features and to eliminate
Felix-specific API.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1300251 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/examples/servicebased.circle/pom.xml b/examples/servicebased.circle/pom.xml
index 0f01c5a..0c00ce6 100644
--- a/examples/servicebased.circle/pom.xml
+++ b/examples/servicebased.circle/pom.xml
@@ -34,11 +34,6 @@
   <version>1.0.0</version>
   <dependencies>
     <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.osgi.core</artifactId>
-      <version>1.0.0</version>
-    </dependency>
-    <dependency>
       <groupId>org.apache.felix.example</groupId>
       <artifactId>servicebased.host</artifactId>
       <version>1.0.0</version>
diff --git a/examples/servicebased.host/pom.xml b/examples/servicebased.host/pom.xml
index 115a72d..bca21d1 100644
--- a/examples/servicebased.host/pom.xml
+++ b/examples/servicebased.host/pom.xml
@@ -36,7 +36,9 @@
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.main</artifactId>
-      <version>1.8.0</version>
+      <version>4.0.2</version>
+      <type>zip</type>
+      <classifier>source-release</classifier>
     </dependency>
   </dependencies>
   <build>
@@ -49,7 +51,7 @@
         <configuration>
           <instructions>
             <_donotcopy>(CVS|.svn|config.properties)</_donotcopy>
-            <Main-Class>org.apache.felix.example.servicebased.host.Activator</Main-Class>
+            <Main-Class>org.apache.felix.example.servicebased.host.launch.Application</Main-Class>
             <Import-Package>!android.*,!dalvik.*,org.osgi.framework,org.osgi.service.packageadmin,org.osgi.service.url,org.osgi.service.startlevel,org.osgi.util.tracker,*</Import-Package>
             <Export-Package>org.apache.felix.example.servicebased.host.service.*</Export-Package>
             <Private-Package>org.apache.felix.example.servicebased.host.*</Private-Package>
@@ -63,8 +65,8 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <source>1.5</source>
-          <target>1.5</target>
+          <source>1.6</source>
+          <target>1.6</target>
         </configuration>
       </plugin>
     </plugins>
diff --git a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/Activator.java b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/Activator.java
index 4615034..38b4506 100644
--- a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/Activator.java
+++ b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/Activator.java
@@ -20,20 +20,11 @@
 
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 import javax.swing.JFrame;
 import javax.swing.SwingUtilities;
-import org.apache.felix.framework.Felix;
-import org.apache.felix.framework.util.FelixConstants;
-import org.apache.felix.main.AutoActivator;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
 
 /**
  * The activator of the host application bundle. The activator creates the
@@ -42,13 +33,6 @@
  * synchronization and repainting issues. Closing the application window
  * will result in <tt>Bundle.stop()</tt> being called on the system bundle,
  * which will cause the framework to shutdown and the JVM to exit.
- * <p>
- * This class also provides a static <tt>main()</tt> method so that it can be
- * run as a stand-alone host application. In such a scenario, the application
- * creates its own embedded Felix framework instance and interacts with the
- * internal services to providing drawing functionality. To successfully
- * launch the stand-alone application, it must be run from this bundle's
- * installation directory using "<tt>java -jar</tt>".
 **/
 public class Activator implements BundleActivator
 {
@@ -61,10 +45,12 @@
      * and repainting issues.
      * @param context The context of the bundle.
     **/
+    @Override
     public void start(final BundleContext context)
     {
         SwingUtilities.invokeLater(new Runnable() {
             // This creates of the application window.
+            @Override
             public void run()
             {
                 m_frame = new DrawingFrame();
@@ -96,10 +82,12 @@
      * Stops service tracking and disposes of the application window.
      * @param context The context of the bundle.
     **/
+    @Override
     public void stop(BundleContext context)
     {
         Runnable runner = new Runnable() {
             // This disposes of the application window.
+            @Override
             public void run()
             {
                 m_shapetracker.close();
@@ -124,79 +112,4 @@
             }
         }
     }
-
-    /**
-     * Enables the bundle to run as a stand-alone application. When this
-     * static <tt>main()</tt> method is invoked, the application creates
-     * its own embedded Felix framework instance and interacts with the
-     * internal services to provide drawing functionality. To successfully
-     * launch as a stand-alone application, this method should be invoked from
-     * the bundle's installation directory using "<tt>java -jar</tt>".
-     * @param argv The command-line arguments.
-     * @throws Exception If anything goes wrong.
-    **/
-    public static void main(String[] argv) throws Exception
-    {
-        // Create a temporary bundle cache directory and
-        // make sure to clean it up on exit.
-        final File cachedir = File.createTempFile("felix.example.servicebased", null);
-        cachedir.delete();
-        Runtime.getRuntime().addShutdownHook(new Thread() {
-            @Override
-            public void run()
-            {
-                deleteFileOrDir(cachedir);
-            }
-        });
-
-        Map<String, Object> configMap = new HashMap<String, Object>();
-        configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
-            "org.apache.felix.example.servicebased.host.service; version=1.0.0");
-        configMap.put(AutoActivator.AUTO_START_PROP + ".1",
-            "file:../servicebased.circle/target/servicebased.circle-1.0.0.jar " +
-            "file:../servicebased.square/target/servicebased.square-1.0.0.jar " +
-            "file:../servicebased.triangle/target/servicebased.triangle-1.0.0.jar");
-        configMap.put(FelixConstants.LOG_LEVEL_PROP, "4");
-        configMap.put(Constants.FRAMEWORK_STORAGE, cachedir.getAbsolutePath());
-
-        // Create list to hold custom framework activators.
-        List<BundleActivator> list = new ArrayList<BundleActivator>();
-        // Add activator to process auto-start/install properties.
-        list.add(new AutoActivator(configMap));
-        // Add our own activator.
-        list.add(new Activator());
-        // Add our custom framework activators to the configuration map.
-        configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
-
-        try
-        {
-            // Now create an instance of the framework.
-            Felix felix = new Felix(configMap);
-            felix.start();
-        }
-        catch (Exception ex)
-        {
-            System.err.println("Could not create framework: " + ex);
-            ex.printStackTrace();
-            System.exit(-1);
-        }
-    }
-
-    /**
-     * Utility method used to delete the profile directory when run as
-     * a stand-alone application.
-     * @param file The file to recursively delete.
-    **/
-    private static void deleteFileOrDir(File file)
-    {
-        if (file.isDirectory())
-        {
-            File[] childs = file.listFiles();
-            for (int i = 0;i < childs.length;i++)
-            {
-                deleteFileOrDir(childs[i]);
-            }
-        }
-        file.delete();
-    }
 }
\ No newline at end of file
diff --git a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/DefaultShape.java b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/DefaultShape.java
index 61c0118..f9598d2 100644
--- a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/DefaultShape.java
+++ b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/DefaultShape.java
@@ -50,7 +50,7 @@
     private SimpleShape m_shape;
     private ImageIcon m_icon;
     private BundleContext m_context;
-    private ServiceReference m_ref;
+    private ServiceReference<SimpleShape> m_ref;
 
     /**
      * This constructs a placeholder shape that draws a default
@@ -67,7 +67,7 @@
      * @param context The bundle context to use for retrieving the shape service.
      * @param ref The service reference of the service.
     **/
-    public DefaultShape(BundleContext context, ServiceReference ref)
+    public DefaultShape(BundleContext context, ServiceReference<SimpleShape> ref)
     {
         m_context = context;
         m_ref = ref;
@@ -96,6 +96,7 @@
      * @param g2 The graphics object used for painting.
      * @param p The position to paint the triangle.
     **/
+    @Override
     public void draw(Graphics2D g2, Point p)
     {
         // If this is a proxy shape, instantiate the shape class
@@ -107,7 +108,7 @@
                 if (m_shape == null)
                 {
                     // Get the shape service.
-                    m_shape = (SimpleShape) m_context.getService(m_ref);
+                    m_shape = m_context.getService(m_ref);
                 }
                 // Draw the shape.
                 m_shape.draw(g2, p);
diff --git a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/DrawingFrame.java b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/DrawingFrame.java
index b2672ff..2046ed7 100644
--- a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/DrawingFrame.java
+++ b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/DrawingFrame.java
@@ -35,7 +35,6 @@
 import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.JToolBar;
-
 import org.apache.felix.example.servicebased.host.service.SimpleShape;
 
 /**
@@ -166,6 +165,7 @@
      * draw the selected shape into the drawing canvas.
      * @param evt The associated mouse event.
     **/
+    @Override
     public void mouseClicked(MouseEvent evt)
     {
         if (m_selected == null)
@@ -187,6 +187,7 @@
      * Implements an empty method for the <tt>MouseListener</tt> interface.
      * @param evt The associated mouse event.
     **/
+    @Override
     public void mouseEntered(MouseEvent evt)
     {
     }
@@ -195,6 +196,7 @@
      * Implements an empty method for the <tt>MouseListener</tt> interface.
      * @param evt The associated mouse event.
     **/
+    @Override
     public void mouseExited(MouseEvent evt)
     {
     }
@@ -204,6 +206,7 @@
      * shape dragging.
      * @param evt The associated mouse event.
     **/
+    @Override
     public void mousePressed(MouseEvent evt)
     {
         Component c = m_panel.getComponentAt(evt.getPoint());
@@ -221,6 +224,7 @@
      * shape dragging.
      * @param evt The associated mouse event.
     **/
+    @Override
     public void mouseReleased(MouseEvent evt)
     {
         if (m_selectedComponent != null)
@@ -239,6 +243,7 @@
      * move a dragged shape.
      * @param evt The associated mouse event.
     **/
+    @Override
     public void mouseDragged(MouseEvent evt)
     {
         m_selectedComponent.setBounds(
@@ -250,6 +255,7 @@
      * interface.
      * @param evt The associated mouse event.
     **/
+    @Override
     public void mouseMoved(MouseEvent evt)
     {
     }
@@ -261,6 +267,7 @@
     **/
     private class ShapeActionListener implements ActionListener
     {
+        @Override
         public void actionPerformed(ActionEvent evt)
         {
             selectShape(evt.getActionCommand());
diff --git a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/ShapeTracker.java b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/ShapeTracker.java
index 5393764..6ea4bac 100644
--- a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/ShapeTracker.java
+++ b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/ShapeTracker.java
@@ -20,7 +20,6 @@
 
 import javax.swing.Icon;
 import javax.swing.SwingUtilities;
-
 import org.apache.felix.example.servicebased.host.service.SimpleShape;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -35,7 +34,7 @@
  * on the Swing event thread to avoid synchronization and redraw
  * issues.
 **/
-public class ShapeTracker extends ServiceTracker
+public class ShapeTracker extends ServiceTracker<SimpleShape, SimpleShape>
 {
     // The bundle context used for tracking.
     private final BundleContext m_context;
@@ -63,7 +62,7 @@
      * @return The service object to be used by the tracker.
     **/
     @Override
-    public Object addingService(ServiceReference ref)
+    public SimpleShape addingService(ServiceReference<SimpleShape> ref)
     {
         SimpleShape shape = new DefaultShape(m_context, ref);
         processShapeOnEventThread(ShapeEvent.ADDED, ref, shape);
@@ -77,9 +76,9 @@
      * @param svc The service object of the modified service.
     **/
     @Override
-    public void modifiedService(ServiceReference ref, Object svc)
+    public void modifiedService(ServiceReference<SimpleShape> ref, SimpleShape svc)
     {
-        processShapeOnEventThread(ShapeEvent.MODIFIED, ref, (SimpleShape) svc);
+        processShapeOnEventThread(ShapeEvent.MODIFIED, ref, svc);
     }
 
     /**
@@ -89,9 +88,9 @@
      * @param svc The service object of the removed service.
     **/
     @Override
-    public void removedService(ServiceReference ref, Object svc)
+    public void removedService(ServiceReference<SimpleShape> ref, SimpleShape svc)
     {
-        processShapeOnEventThread(ShapeEvent.REMOVED, ref, (SimpleShape) svc);
+        processShapeOnEventThread(ShapeEvent.REMOVED, ref, svc);
         ((DefaultShape) svc).dispose();
     }
 
@@ -104,7 +103,7 @@
      * @param shape The service object of the corresponding service.
     **/
     private void processShapeOnEventThread(
-        ShapeEvent event, ServiceReference ref, SimpleShape shape)
+        ShapeEvent event, ServiceReference<SimpleShape> ref, SimpleShape shape)
     {
         try
         {
@@ -131,7 +130,7 @@
      * @param ref The service reference of the corresponding service.
      * @param shape The service object of the corresponding service.
     **/
-    private void processShape(ShapeEvent event, ServiceReference ref, SimpleShape shape)
+    private void processShape(ShapeEvent event, ServiceReference<SimpleShape> ref, SimpleShape shape)
     {
         String name = (String) ref.getProperty(SimpleShape.NAME_PROPERTY);
 
@@ -160,7 +159,7 @@
     private class ShapeRunnable implements Runnable
     {
         private final ShapeEvent m_event;
-        private final ServiceReference m_ref;
+        private final ServiceReference<SimpleShape> m_ref;
         private final SimpleShape m_shape;
 
         /**
@@ -170,7 +169,7 @@
          * @param ref The service reference of the corresponding service.
          * @param shape The service object of the corresponding service.
         **/
-        public ShapeRunnable(ShapeEvent event, ServiceReference ref, SimpleShape shape)
+        public ShapeRunnable(ShapeEvent event, ServiceReference<SimpleShape> ref, SimpleShape shape)
         {
             m_event = event;
             m_ref = ref;
@@ -180,6 +179,7 @@
         /**
          * Calls the <tt>processShape()</tt> method.
         **/
+        @Override
         public void run()
         {
             processShape(m_event, m_ref, m_shape);
diff --git a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/launch/Application.java b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/launch/Application.java
new file mode 100644
index 0000000..52d163a
--- /dev/null
+++ b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/launch/Application.java
@@ -0,0 +1,131 @@
+/*
+ * 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.example.servicebased.host.launch;
+
+import java.util.Map;
+import java.util.ServiceLoader;
+import org.apache.felix.example.servicebased.host.Activator;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+/**
+ * This class provides a static {@code main()} method so that the bundle can be
+ * run as a stand-alone host application. In such a scenario, the application
+ * creates its own embedded OSGi framework instance and interacts with the
+ * internal extensions to providing drawing functionality. To successfully
+ * launch the stand-alone application, it must be run from this bundle's
+ * installation directory using "{@code java -jar}".
+ * The locations of any additional extensions that have to be started, have to
+ * be passed as command line arguments to this method.
+ */
+public class Application
+{
+    private static Framework m_framework = null;
+
+    /**
+     * Enables the bundle to run as a stand-alone application. When this
+     * static {@code main()} method is invoked, the application creates
+     * its own embedded OSGi framework instance and interacts with the
+     * internal extensions to provide drawing functionality. To successfully
+     * launch as a stand-alone application, this method should be invoked from
+     * the bundle's installation directory using "{@code java -jar}".
+     * The location of any extension that shall be installed can be passed
+     * as parameters.
+     * <p>
+     * For example if you build the bundles inside your workspace, maven will
+     * create a target directory in every project. To start the application
+     * from within your IDE you should pass:
+     * <p>
+     * <pre>
+     * {@code file:../servicebased.circle/target/servicebased.circle-1.0.0.jar
+     * file:../servicebased.square/target/servicebased.square-1.0.0.jar
+     * file:../servicebased.triangle/target/servicebased.triangle-1.0.0.jar}
+     * </pre>
+     *
+     * @param args The locations of additional bundles to start.
+    **/
+    public static void main(String[] args)
+    {
+        // Args should never be null if the application is run from the command line.
+        // Check it anyway.
+        String[] locations = args != null ? args : new String[0];
+
+        // Print welcome banner.
+        System.out.println("\nWelcome to My Launcher");
+        System.out.println("======================\n");
+
+        try
+        {
+            Map<String, String> config = ConfigUtil.createConfig();
+            m_framework = createFramework(config);
+            m_framework.init();
+            m_framework.start();
+            installAndStartBundles(locations);
+            m_framework.waitForStop(0);
+            System.exit(0);
+        }
+        catch (Exception ex)
+        {
+            System.err.println("Could not create framework: " + ex);
+            ex.printStackTrace();
+            System.exit(-1);
+        }
+    }
+
+    /**
+     * Util method for creating an embedded Framework. Tries to create a
+     * {@link FrameworkFactory} which is then be used to create the framework.
+     *
+     * @param config the configuration to create the framework with
+     * @return a Framework with the given configuration
+     */
+    private static Framework createFramework(Map<String, String> config)
+    {
+        ServiceLoader<FrameworkFactory> factoryLoader = ServiceLoader.load(FrameworkFactory.class);
+        for(FrameworkFactory factory : factoryLoader)
+        {
+            return factory.newFramework(config);
+        }
+        throw new IllegalStateException("Unable to load FrameworkFactory service.");
+    }
+
+    /**
+     * Installs and starts all bundles used by the application. Therefore the host bundle
+     * will be started. The locations of extensions for the host bundle can be passed in
+     * as parameters.
+     *
+     * @param bundleLocations the locations where extension for the host bundle are located.
+     *        Must not be {@code null}!
+     * @throws BundleException if something went wrong while installing or starting the bundles.
+     */
+    private static void installAndStartBundles(String... bundleLocations) throws BundleException
+    {
+        BundleContext bundleContext = m_framework.getBundleContext();
+        Activator hostActivator = new Activator();
+        hostActivator.start(bundleContext);
+        for (String location : bundleLocations)
+        {
+            Bundle addition = bundleContext.installBundle(location);
+            addition.start();
+        }
+    }
+}
\ No newline at end of file
diff --git a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/launch/ConfigUtil.java b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/launch/ConfigUtil.java
new file mode 100644
index 0000000..415c140
--- /dev/null
+++ b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/launch/ConfigUtil.java
@@ -0,0 +1,115 @@
+/*
+ * 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.example.servicebased.host.launch;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import org.osgi.framework.Constants;
+
+/**
+ * Util class for creating the framework configuration
+ */
+final class ConfigUtil
+{
+    /**
+     * Creates a configuration for the framework. Therefore this method attempts to create
+     * a temporary cache dir. If creation of the cache dir is successful, it will be added
+     * to the configuration.
+     *
+     * @return
+     */
+    public static Map<String, String> createConfig()
+    {
+        final File cachedir = createCacheDir();
+
+        Map<String, String> configMap = new HashMap<String, String>();
+        // Tells the framework to export the extension package, making it accessible
+        // for the other shape bundles
+        configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
+            "org.apache.felix.example.servicebased.host.service; version=1.0.0");
+
+        // if we could create a cache dir, we use it. Otherwise the platform default will be used
+        if (cachedir != null)
+        {
+            configMap.put(Constants.FRAMEWORK_STORAGE, cachedir.getAbsolutePath());
+        }
+
+        return configMap;
+    }
+
+    /**
+     * Tries to create a temporay cache dir. If creation of the cache dir is successful,
+     * it will be returned. If creation fails, null will be returned.
+     *
+     * @return a {@code File} object representing the cache dir
+     */
+    private static File createCacheDir()
+    {
+        final File cachedir;
+        try
+        {
+            cachedir = File.createTempFile("felix.example.extenderbased", null);
+            cachedir.delete();
+            createShutdownHook(cachedir);
+            return cachedir;
+        }
+        catch (IOException e)
+        {
+            // temp dir creation failed, return null
+            return null;
+        }
+    }
+
+    /**
+     * Adds a shutdown hook to the runtime, that will make sure, that the cache dir will
+     * be deleted after the application has been terminated.
+     */
+    private static void createShutdownHook(final File cachedir)
+    {
+        Runtime.getRuntime().addShutdownHook(new Thread()
+        {
+            @Override
+            public void run()
+            {
+                deleteFileOrDir(cachedir);
+            }
+        });
+    }
+
+
+    /**
+     * Utility method used to delete the profile directory when run as
+     * a stand-alone application.
+     * @param file The file to recursively delete.
+    **/
+    private static void deleteFileOrDir(File file)
+    {
+        if (file.isDirectory())
+        {
+            File[] childs = file.listFiles();
+            for (File child : childs)
+            {
+                deleteFileOrDir(child);
+            }
+        }
+        file.delete();
+    }
+}
\ No newline at end of file
diff --git a/examples/servicebased.square/pom.xml b/examples/servicebased.square/pom.xml
index 89b241a..18a7583 100644
--- a/examples/servicebased.square/pom.xml
+++ b/examples/servicebased.square/pom.xml
@@ -34,11 +34,6 @@
   <version>1.0.0</version>
   <dependencies>
     <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.osgi.core</artifactId>
-      <version>1.0.0</version>
-    </dependency>
-    <dependency>
       <groupId>org.apache.felix.example</groupId>
       <artifactId>servicebased.host</artifactId>
       <version>1.0.0</version>
diff --git a/examples/servicebased.trapezoid/pom.xml b/examples/servicebased.trapezoid/pom.xml
index 09b5fa7..7ca86fc 100644
--- a/examples/servicebased.trapezoid/pom.xml
+++ b/examples/servicebased.trapezoid/pom.xml
@@ -33,11 +33,6 @@
   <version>1.0.0</version>
   <dependencies>
     <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.osgi.core</artifactId>
-      <version>1.0.0</version>
-    </dependency>
-    <dependency>
       <groupId>org.apache.felix.example</groupId>
       <artifactId>servicebased.host</artifactId>
       <version>1.0.0</version>
diff --git a/examples/servicebased.triangle/pom.xml b/examples/servicebased.triangle/pom.xml
index 1178e18..cb3c268 100644
--- a/examples/servicebased.triangle/pom.xml
+++ b/examples/servicebased.triangle/pom.xml
@@ -34,11 +34,6 @@
   <version>1.0.0</version>
   <dependencies>
     <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.osgi.core</artifactId>
-      <version>1.0.0</version>
-    </dependency>
-    <dependency>
       <groupId>org.apache.felix.example</groupId>
       <artifactId>servicebased.host</artifactId>
       <version>1.0.0</version>