Apply patches for FELIX-3376 to adapt example to Java 5.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1298008 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/examples/extenderbased.circle/pom.xml b/examples/extenderbased.circle/pom.xml
index 44ead53..a9888e5 100644
--- a/examples/extenderbased.circle/pom.xml
+++ b/examples/extenderbased.circle/pom.xml
@@ -16,8 +16,8 @@
specific language governing permissions and limitations
under the License.
-->
-<project>
-
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
<parent>
<groupId>org.apache.felix</groupId>
<artifactId>felix</artifactId>
@@ -61,6 +61,14 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/examples/extenderbased.circle/src/main/java/org/apache/felix/example/extenderbased/circle/Circle.java b/examples/extenderbased.circle/src/main/java/org/apache/felix/example/extenderbased/circle/Circle.java
index 6d5dc6a..ee24c61 100644
--- a/examples/extenderbased.circle/src/main/java/org/apache/felix/example/extenderbased/circle/Circle.java
+++ b/examples/extenderbased.circle/src/main/java/org/apache/felix/example/extenderbased/circle/Circle.java
@@ -23,9 +23,8 @@
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Point;
-import java.awt.geom.*;
+import java.awt.geom.Ellipse2D;
import org.apache.felix.example.extenderbased.host.extension.SimpleShape;
-import org.osgi.framework.*;
/**
* This class implements the circle <tt>SimpleShape</tt> extension.
diff --git a/examples/extenderbased.host/pom.xml b/examples/extenderbased.host/pom.xml
index 1818d58..aff58b2 100644
--- a/examples/extenderbased.host/pom.xml
+++ b/examples/extenderbased.host/pom.xml
@@ -16,7 +16,7 @@
specific language governing permissions and limitations
under the License.
-->
-<project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.apache.felix</groupId>
@@ -59,6 +59,14 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/Activator.java b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/Activator.java
index 9d49538..c2ad46d 100644
--- a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/Activator.java
+++ b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/Activator.java
@@ -22,17 +22,18 @@
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.*;
-
-import org.osgi.framework.*;
+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.framework.util.StringMap;
-import org.apache.felix.framework.cache.BundleCache;
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
@@ -62,13 +63,15 @@
**/
public void start(final BundleContext context)
{
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ SwingUtilities.invokeLater(new Runnable() {
// This creates of the application window.
public void run()
{
m_frame = new DrawingFrame();
m_frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- m_frame.addWindowListener(new WindowAdapter() {
+ m_frame.addWindowListener(new WindowAdapter()
+ {
+ @Override
public void windowClosing(WindowEvent evt)
{
try
@@ -140,13 +143,14 @@
final File cachedir = File.createTempFile("felix.example.extenderbased", null);
cachedir.delete();
Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
public void run()
{
deleteFileOrDir(cachedir);
}
});
- Map configMap = new StringMap(false);
+ Map<String, Object> configMap = new HashMap<String, Object>();
configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"org.apache.felix.example.extenderbased.host.extension; version=1.0.0");
configMap.put(AutoActivator.AUTO_START_PROP + ".1",
@@ -157,7 +161,7 @@
configMap.put(Constants.FRAMEWORK_STORAGE, cachedir.getAbsolutePath());
// Create list to hold custom framework activators.
- List list = new ArrayList();
+ List<BundleActivator> list = new ArrayList<BundleActivator>();
// Add activator to process auto-start/install properties.
list.add(new AutoActivator(configMap));
// Add our own activator.
diff --git a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/BundleTracker.java b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/BundleTracker.java
index f180fbd..a25750f 100644
--- a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/BundleTracker.java
+++ b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/BundleTracker.java
@@ -19,6 +19,7 @@
package org.apache.felix.example.extenderbased.host;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -41,8 +42,8 @@
**/
public abstract class BundleTracker
{
- final Set m_bundleSet = new HashSet();
- final BundleContext m_context;
+ final Set<Bundle> m_bundles = new HashSet<Bundle>();
+ protected final BundleContext m_context;
final SynchronousBundleListener m_listener;
boolean m_open;
@@ -66,17 +67,17 @@
if (evt.getType() == BundleEvent.STARTED)
{
- if (!m_bundleSet.contains(evt.getBundle()))
+ if (!m_bundles.contains(evt.getBundle()))
{
- m_bundleSet.add(evt.getBundle());
+ m_bundles.add(evt.getBundle());
addedBundle(evt.getBundle());
}
}
else if (evt.getType() == BundleEvent.STOPPED)
{
- if (m_bundleSet.contains(evt.getBundle()))
+ if (m_bundles.contains(evt.getBundle()))
{
- m_bundleSet.remove(evt.getBundle());
+ m_bundles.remove(evt.getBundle());
removedBundle(evt.getBundle());
}
}
@@ -91,7 +92,7 @@
**/
public synchronized Bundle[] getBundles()
{
- return (Bundle[]) m_bundleSet.toArray(new Bundle[m_bundleSet.size()]);
+ return m_bundles.toArray(new Bundle[m_bundles.size()]);
}
/**
@@ -106,12 +107,12 @@
m_context.addBundleListener(m_listener);
Bundle[] bundles = m_context.getBundles();
- for (int i = 0; i < bundles.length; i++)
+ for (Bundle bundle : bundles)
{
- if (bundles[i].getState() == Bundle.ACTIVE)
+ if (bundle.getState() == Bundle.ACTIVE)
{
- m_bundleSet.add(bundles[i]);
- addedBundle(bundles[i]);
+ m_bundles.add(bundle);
+ addedBundle(bundle);
}
}
}
@@ -128,13 +129,11 @@
m_context.removeBundleListener(m_listener);
- Bundle[] bundles = (Bundle[]) m_bundleSet.toArray(new Bundle[m_bundleSet.size()]);
- for (int i = 0; i < bundles.length; i++)
+ for (Iterator<Bundle> itr = m_bundles.iterator(); itr.hasNext();)
{
- if (m_bundleSet.remove(bundles[i]))
- {
- removedBundle(bundles[i]);
- }
+ Bundle bundle = itr.next();
+ itr.remove();
+ removedBundle(bundle);
}
}
}
diff --git a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/DefaultShape.java b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/DefaultShape.java
index e889fbb..4d542c9 100644
--- a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/DefaultShape.java
+++ b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/DefaultShape.java
@@ -90,7 +90,7 @@
// Get the bundle.
Bundle bundle = m_context.getBundle(m_bundleId);
// Load the class and instantiate it.
- Class clazz = bundle.loadClass(m_className);
+ Class<?> clazz = bundle.loadClass(m_className);
m_shape = (SimpleShape) clazz.newInstance();
}
// Draw the shape.
diff --git a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/DrawingFrame.java b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/DrawingFrame.java
index 1b4ce60..3b0d7d4 100644
--- a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/DrawingFrame.java
+++ b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/DrawingFrame.java
@@ -18,12 +18,23 @@
*/
package org.apache.felix.example.extenderbased.host;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-
-import javax.swing.*;
-
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.util.HashMap;
+import java.util.Map;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JToolBar;
import org.apache.felix.example.extenderbased.host.extension.SimpleShape;
/**
@@ -38,13 +49,13 @@
{
private static final long serialVersionUID = 1L;
private static final int BOX = 54;
- private JToolBar m_toolbar;
+ private final JToolBar m_toolbar;
private String m_selected;
- private JPanel m_panel;
+ private final JPanel m_panel;
private ShapeComponent m_selectedComponent;
- private Map m_shapes = new HashMap();
- private SimpleShape m_defaultShape = new DefaultShape();
- private ActionListener m_reusableActionListener = new ShapeActionListener();
+ private final Map<String, ShapeInfo> m_shapes = new HashMap<String, ShapeInfo>();
+ private final SimpleShape m_defaultShape = new DefaultShape();
+ private final ActionListener m_reusableActionListener = new ShapeActionListener();
/**
* Default constructor that populates the main window.
@@ -83,7 +94,7 @@
**/
public SimpleShape getShape(String name)
{
- ShapeInfo info = (ShapeInfo) m_shapes.get(name);
+ ShapeInfo info = m_shapes.get(name);
if (info == null)
{
return m_defaultShape;
diff --git a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/ShapeComponent.java b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/ShapeComponent.java
index abd7011..a3d0f4a 100644
--- a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/ShapeComponent.java
+++ b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/ShapeComponent.java
@@ -18,10 +18,11 @@
*/
package org.apache.felix.example.extenderbased.host;
-import java.awt.*;
-
-import javax.swing.*;
-
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.RenderingHints;
+import javax.swing.JComponent;
import org.apache.felix.example.extenderbased.host.extension.SimpleShape;
/**
diff --git a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/ShapeTracker.java b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/ShapeTracker.java
index 5f8390a..6f4baf4 100644
--- a/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/ShapeTracker.java
+++ b/examples/extenderbased.host/src/main/java/org/apache/felix/example/extenderbased/host/ShapeTracker.java
@@ -19,7 +19,9 @@
package org.apache.felix.example.extenderbased.host;
import java.util.Dictionary;
-import javax.swing.*;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.SwingUtilities;
import org.apache.felix.example.extenderbased.host.extension.SimpleShape;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -34,14 +36,8 @@
**/
public class ShapeTracker extends BundleTracker
{
- // Flag indicating an added shape.
- private static final int ADDED = 1;
- // Flag indicating a removed shape.
- private static final int REMOVED = 2;
- // The bundle context used for tracking.
- private BundleContext m_context;
// The application object to notify.
- private DrawingFrame m_frame;
+ private final DrawingFrame m_frame;
/**
* Constructs a tracker that uses the specified bundle context to
@@ -53,7 +49,6 @@
public ShapeTracker(BundleContext context, DrawingFrame frame)
{
super(context);
- m_context = context;
m_frame = frame;
}
@@ -62,9 +57,10 @@
* the application object about the added extensions.
* @param bundle The activated bundle.
**/
+ @Override
protected void addedBundle(Bundle bundle)
{
- processBundleOnEventThread(ADDED, bundle);
+ processBundleOnEventThread(ShapeEvent.ADDED, bundle);
}
/**
@@ -72,29 +68,30 @@
* the application object about removed extensions.
* @param bundle The inactivated bundle.
**/
+ @Override
protected void removedBundle(Bundle bundle)
{
- processBundleOnEventThread(REMOVED, bundle);
+ processBundleOnEventThread(ShapeEvent.REMOVED, bundle);
}
/**
* Processes a received bundle notification from the <tt>BundleTracker</tt>,
* forcing the processing of the notification onto the Swing event thread
* if it is not already on it.
- * @param action The type of action associated with the notification.
+ * @param event The type of action associated with the notification.
* @param bundle The bundle of the corresponding extension.
**/
- private void processBundleOnEventThread(int action, Bundle bundle)
+ private void processBundleOnEventThread(ShapeEvent event, Bundle bundle)
{
try
{
if (SwingUtilities.isEventDispatchThread())
{
- processBundle(action, bundle);
+ processBundle(event, bundle);
}
else
{
- SwingUtilities.invokeAndWait(new BundleRunnable(action, bundle));
+ SwingUtilities.invokeAndWait(new BundleRunnable(event, bundle));
}
}
catch (Exception ex)
@@ -107,29 +104,31 @@
* Actually performs the processing of the bundle notification. Invokes
* the appropriate callback method on the application object depending on
* the action type of the notification.
- * @param action The type of action associated with the notification.
+ * @param event The type of action associated with the notification.
* @param bundle The bundle of the corresponding extension.
**/
- private void processBundle(int action, Bundle bundle)
+ private void processBundle(ShapeEvent event, Bundle bundle)
{
- Dictionary dict = bundle.getHeaders();
+ // see http://www.osgi.org/javadoc/r4v43/org/osgi/framework/Bundle.html#getHeaders()
+ @SuppressWarnings("unchecked")
+ Dictionary<String, String> dict = bundle.getHeaders();
// Try to get the name of the extension.
- String name = (String) dict.get(SimpleShape.NAME_PROPERTY);
+ String name = dict.get(SimpleShape.NAME_PROPERTY);
// Return immediately if the bundle is not an extension.
if (name == null)
{
return;
}
- switch (action)
+ switch (event)
{
case ADDED:
// Get the icon resource of the extension.
- String iconPath = (String) dict.get(SimpleShape.ICON_PROPERTY);
+ String iconPath = dict.get(SimpleShape.ICON_PROPERTY);
Icon icon = new ImageIcon(bundle.getResource(iconPath));
// Get the class of the extension.
- String className = (String) dict.get(SimpleShape.CLASS_PROPERTY);
+ String className = dict.get(SimpleShape.CLASS_PROPERTY);
m_frame.addShape(
name,
icon,
@@ -148,18 +147,18 @@
**/
private class BundleRunnable implements Runnable
{
- private int m_action;
- private Bundle m_bundle;
+ private final ShapeEvent m_event;
+ private final Bundle m_bundle;
/**
* Constructs an object with the specified action and bundle
* object for processing on the Swing event thread.
- * @param action The type of action associated with the notification.
+ * @param event The type of action associated with the notification.
* @param bundle The bundle of the corresponding extension.
**/
- public BundleRunnable(int action, Bundle bundle)
+ public BundleRunnable(ShapeEvent event, Bundle bundle)
{
- m_action = action;
+ m_event = event;
m_bundle = bundle;
}
@@ -168,7 +167,13 @@
**/
public void run()
{
- processBundle(m_action, m_bundle);
+ processBundle(m_event, m_bundle);
}
}
+
+ private static enum ShapeEvent
+ {
+ ADDED,
+ REMOVED
+ }
}
\ No newline at end of file
diff --git a/examples/extenderbased.square/pom.xml b/examples/extenderbased.square/pom.xml
index a3a73fa..4874f23 100644
--- a/examples/extenderbased.square/pom.xml
+++ b/examples/extenderbased.square/pom.xml
@@ -16,7 +16,7 @@
specific language governing permissions and limitations
under the License.
-->
-<project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.apache.felix</groupId>
@@ -61,6 +61,14 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/examples/extenderbased.square/src/main/java/org/apache/felix/example/extenderbased/square/Square.java b/examples/extenderbased.square/src/main/java/org/apache/felix/example/extenderbased/square/Square.java
index caa820a..daa5b99 100644
--- a/examples/extenderbased.square/src/main/java/org/apache/felix/example/extenderbased/square/Square.java
+++ b/examples/extenderbased.square/src/main/java/org/apache/felix/example/extenderbased/square/Square.java
@@ -23,9 +23,8 @@
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Point;
-import java.awt.geom.*;
+import java.awt.geom.Rectangle2D;
import org.apache.felix.example.extenderbased.host.extension.SimpleShape;
-import org.osgi.framework.*;
/**
* This class implements the square <tt>SimpleShape</tt> extension.
diff --git a/examples/extenderbased.triangle/pom.xml b/examples/extenderbased.triangle/pom.xml
index df96b3c..c28cff3 100644
--- a/examples/extenderbased.triangle/pom.xml
+++ b/examples/extenderbased.triangle/pom.xml
@@ -16,7 +16,7 @@
specific language governing permissions and limitations
under the License.
-->
-<project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.apache.felix</groupId>
@@ -61,6 +61,14 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/examples/extenderbased.triangle/src/main/java/org/apache/felix/example/extenderbased/triangle/Triangle.java b/examples/extenderbased.triangle/src/main/java/org/apache/felix/example/extenderbased/triangle/Triangle.java
index 742b6c7..c65e94f 100644
--- a/examples/extenderbased.triangle/src/main/java/org/apache/felix/example/extenderbased/triangle/Triangle.java
+++ b/examples/extenderbased.triangle/src/main/java/org/apache/felix/example/extenderbased/triangle/Triangle.java
@@ -23,9 +23,8 @@
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Point;
-import java.awt.geom.*;
+import java.awt.geom.GeneralPath;
import org.apache.felix.example.extenderbased.host.extension.SimpleShape;
-import org.osgi.framework.*;
/**
* This inner class implements the triangle <tt>SimpleShape</tt> service.