Apply patches for FELIX-3375 to update example to Java 5.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1297658 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/examples/servicebased.circle/pom.xml b/examples/servicebased.circle/pom.xml
index 71d293a..0f01c5a 100644
--- a/examples/servicebased.circle/pom.xml
+++ b/examples/servicebased.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>
@@ -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/servicebased.circle/src/main/java/org/apache/felix/example/servicebased/circle/Activator.java b/examples/servicebased.circle/src/main/java/org/apache/felix/example/servicebased/circle/Activator.java
index a21a684..f1391e3 100644
--- a/examples/servicebased.circle/src/main/java/org/apache/felix/example/servicebased/circle/Activator.java
+++ b/examples/servicebased.circle/src/main/java/org/apache/felix/example/servicebased/circle/Activator.java
@@ -23,11 +23,13 @@
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Point;
-import java.awt.geom.*;
+import java.awt.geom.Ellipse2D;
+import java.util.Dictionary;
import java.util.Hashtable;
import javax.swing.ImageIcon;
import org.apache.felix.example.servicebased.host.service.SimpleShape;
-import org.osgi.framework.*;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
/**
* This class implements a simple bundle activator for the circle
@@ -47,7 +49,7 @@
public void start(BundleContext context)
{
m_context = context;
- Hashtable dict = new Hashtable();
+ Dictionary<String, Object> dict = new Hashtable<String, Object>();
dict.put(SimpleShape.NAME_PROPERTY, "Circle");
dict.put(SimpleShape.ICON_PROPERTY,
new ImageIcon(this.getClass().getResource("circle.png")));
diff --git a/examples/servicebased.host/pom.xml b/examples/servicebased.host/pom.xml
index 36a8a05..115a72d 100644
--- a/examples/servicebased.host/pom.xml
+++ b/examples/servicebased.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/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 77524c6..4615034 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
@@ -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,14 @@
**/
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() {
+ @Override
public void windowClosing(WindowEvent evt)
{
try
@@ -114,7 +116,7 @@
{
try
{
- javax.swing.SwingUtilities.invokeAndWait(runner);
+ SwingUtilities.invokeAndWait(runner);
}
catch (Exception ex)
{
@@ -140,13 +142,14 @@
final File cachedir = File.createTempFile("felix.example.servicebased", 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.servicebased.host.service; version=1.0.0");
configMap.put(AutoActivator.AUTO_START_PROP + ".1",
@@ -157,7 +160,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/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 82c079b..b2672ff 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
@@ -18,11 +18,23 @@
*/
package org.apache.felix.example.servicebased.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.servicebased.host.service.SimpleShape;
@@ -38,13 +50,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 +95,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;
@@ -261,9 +273,9 @@
**/
private static class ShapeInfo
{
- public String m_name;
- public Icon m_icon;
- public SimpleShape m_shape;
+ private final String m_name;
+ private final Icon m_icon;
+ private final SimpleShape m_shape;
public ShapeInfo(String name, Icon icon, SimpleShape shape)
{
m_name = name;
diff --git a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/ShapeComponent.java b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/ShapeComponent.java
index fbeca54..e7ea189 100644
--- a/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/ShapeComponent.java
+++ b/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/ShapeComponent.java
@@ -18,10 +18,11 @@
*/
package org.apache.felix.example.servicebased.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.servicebased.host.service.SimpleShape;
/**
@@ -31,8 +32,8 @@
public class ShapeComponent extends JComponent
{
private static final long serialVersionUID = 1L;
- private DrawingFrame m_frame;
- private String m_shapeName;
+ private final DrawingFrame m_frame;
+ private final String m_shapeName;
/**
* Construct a component for the specified drawing frame with the specified
@@ -54,7 +55,8 @@
* to account for service dynamism.
* @param g The graphics object to use for painting.
**/
- protected void paintComponent(Graphics g)
+ @Override
+ protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
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 0a76971..5393764 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
@@ -18,11 +18,13 @@
*/
package org.apache.felix.example.servicebased.host;
-import javax.swing.*;
+import javax.swing.Icon;
+import javax.swing.SwingUtilities;
import org.apache.felix.example.servicebased.host.service.SimpleShape;
-import org.osgi.framework.*;
-import org.osgi.util.tracker.*;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
/**
* Extends the <tt>ServiceTracker</tt> to create a tracker for
@@ -35,16 +37,10 @@
**/
public class ShapeTracker extends ServiceTracker
{
- // Flag indicating an added shape.
- private static final int ADDED = 1;
- // Flag indicating a modified shape.
- private static final int MODIFIED = 2;
- // Flag indicating a removed shape.
- private static final int REMOVED = 3;
// The bundle context used for tracking.
- private BundleContext m_context;
+ private final 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
@@ -66,10 +62,11 @@
* @param ref The service reference of the added service.
* @return The service object to be used by the tracker.
**/
+ @Override
public Object addingService(ServiceReference ref)
{
SimpleShape shape = new DefaultShape(m_context, ref);
- processShapeOnEventThread(ADDED, ref, shape);
+ processShapeOnEventThread(ShapeEvent.ADDED, ref, shape);
return shape;
}
@@ -79,9 +76,10 @@
* @param ref The service reference of the modified service.
* @param svc The service object of the modified service.
**/
+ @Override
public void modifiedService(ServiceReference ref, Object svc)
{
- processShapeOnEventThread(MODIFIED, ref, (SimpleShape) svc);
+ processShapeOnEventThread(ShapeEvent.MODIFIED, ref, (SimpleShape) svc);
}
/**
@@ -90,9 +88,10 @@
* @param ref The service reference of the removed service.
* @param svc The service object of the removed service.
**/
+ @Override
public void removedService(ServiceReference ref, Object svc)
{
- processShapeOnEventThread(REMOVED, ref, (SimpleShape) svc);
+ processShapeOnEventThread(ShapeEvent.REMOVED, ref, (SimpleShape) svc);
((DefaultShape) svc).dispose();
}
@@ -100,22 +99,22 @@
* Processes a received service notification from the <tt>ServiceTracker</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 ref The service reference of the corresponding service.
* @param shape The service object of the corresponding service.
**/
private void processShapeOnEventThread(
- int action, ServiceReference ref, SimpleShape shape)
+ ShapeEvent event, ServiceReference ref, SimpleShape shape)
{
try
{
if (SwingUtilities.isEventDispatchThread())
{
- processShape(action, ref, shape);
+ processShape(event, ref, shape);
}
else
{
- SwingUtilities.invokeAndWait(new ShapeRunnable(action, ref, shape));
+ SwingUtilities.invokeAndWait(new ShapeRunnable(event, ref, shape));
}
}
catch (Exception ex)
@@ -128,15 +127,15 @@
* Actually performs the processing of the service 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 ref The service reference of the corresponding service.
* @param shape The service object of the corresponding service.
**/
- private void processShape(int action, ServiceReference ref, SimpleShape shape)
+ private void processShape(ShapeEvent event, ServiceReference ref, SimpleShape shape)
{
String name = (String) ref.getProperty(SimpleShape.NAME_PROPERTY);
- switch (action)
+ switch (event)
{
case MODIFIED:
m_frame.removeShape(name);
@@ -160,20 +159,20 @@
**/
private class ShapeRunnable implements Runnable
{
- private int m_action;
- private ServiceReference m_ref;
- private SimpleShape m_shape;
+ private final ShapeEvent m_event;
+ private final ServiceReference m_ref;
+ private final SimpleShape m_shape;
/**
* Constructs an object with the specified action, service reference,
* and service 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 ref The service reference of the corresponding service.
* @param shape The service object of the corresponding service.
**/
- public ShapeRunnable(int action, ServiceReference ref, SimpleShape shape)
+ public ShapeRunnable(ShapeEvent event, ServiceReference ref, SimpleShape shape)
{
- m_action = action;
+ m_event = event;
m_ref = ref;
m_shape = shape;
}
@@ -183,7 +182,14 @@
**/
public void run()
{
- processShape(m_action, m_ref, m_shape);
+ processShape(m_event, m_ref, m_shape);
}
}
+
+ private static enum ShapeEvent
+ {
+ ADDED,
+ MODIFIED,
+ REMOVED
+ }
}
\ No newline at end of file
diff --git a/examples/servicebased.square/pom.xml b/examples/servicebased.square/pom.xml
index efa78b6..89b241a 100644
--- a/examples/servicebased.square/pom.xml
+++ b/examples/servicebased.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>
@@ -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/servicebased.square/src/main/java/org/apache/felix/example/servicebased/square/Activator.java b/examples/servicebased.square/src/main/java/org/apache/felix/example/servicebased/square/Activator.java
index 5867223..984d1eb 100644
--- a/examples/servicebased.square/src/main/java/org/apache/felix/example/servicebased/square/Activator.java
+++ b/examples/servicebased.square/src/main/java/org/apache/felix/example/servicebased/square/Activator.java
@@ -23,11 +23,13 @@
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Point;
-import java.awt.geom.*;
+import java.awt.geom.Rectangle2D;
+import java.util.Dictionary;
import java.util.Hashtable;
import javax.swing.ImageIcon;
import org.apache.felix.example.servicebased.host.service.SimpleShape;
-import org.osgi.framework.*;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
/**
* This class implements a simple bundle activator for the square
@@ -47,7 +49,7 @@
public void start(BundleContext context)
{
m_context = context;
- Hashtable dict = new Hashtable();
+ Dictionary<String, Object> dict = new Hashtable<String, Object>();
dict.put(SimpleShape.NAME_PROPERTY, "Square");
dict.put(SimpleShape.ICON_PROPERTY,
new ImageIcon(this.getClass().getResource("square.png")));
diff --git a/examples/servicebased.trapezoid/pom.xml b/examples/servicebased.trapezoid/pom.xml
index b52b91b..09b5fa7 100644
--- a/examples/servicebased.trapezoid/pom.xml
+++ b/examples/servicebased.trapezoid/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</groupId>
@@ -57,6 +57,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/servicebased.trapezoid/src/main/java/org/apache/felix/example/servicebased/trapezoid/Activator.java b/examples/servicebased.trapezoid/src/main/java/org/apache/felix/example/servicebased/trapezoid/Activator.java
index 1c94b10..23d628f 100644
--- a/examples/servicebased.trapezoid/src/main/java/org/apache/felix/example/servicebased/trapezoid/Activator.java
+++ b/examples/servicebased.trapezoid/src/main/java/org/apache/felix/example/servicebased/trapezoid/Activator.java
@@ -23,11 +23,13 @@
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Point;
-import java.awt.geom.*;
+import java.awt.geom.GeneralPath;
+import java.util.Dictionary;
import java.util.Hashtable;
import javax.swing.ImageIcon;
import org.apache.felix.example.servicebased.host.service.SimpleShape;
-import org.osgi.framework.*;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
/**
* This class implements a simple bundle activator for the trapezoid
@@ -47,7 +49,7 @@
public void start(BundleContext context)
{
m_context = context;
- Hashtable dict = new Hashtable();
+ Dictionary<String, Object> dict = new Hashtable<String, Object>();
dict.put(SimpleShape.NAME_PROPERTY, "Trapezoid");
dict.put(SimpleShape.ICON_PROPERTY,
new ImageIcon(this.getClass().getResource("trapezoid.png")));
diff --git a/examples/servicebased.triangle/pom.xml b/examples/servicebased.triangle/pom.xml
index 67716ec..1178e18 100644
--- a/examples/servicebased.triangle/pom.xml
+++ b/examples/servicebased.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>
@@ -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/servicebased.triangle/src/main/java/org/apache/felix/example/servicebased/triangle/Activator.java b/examples/servicebased.triangle/src/main/java/org/apache/felix/example/servicebased/triangle/Activator.java
index ade57d1..55efbaa 100644
--- a/examples/servicebased.triangle/src/main/java/org/apache/felix/example/servicebased/triangle/Activator.java
+++ b/examples/servicebased.triangle/src/main/java/org/apache/felix/example/servicebased/triangle/Activator.java
@@ -23,11 +23,13 @@
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Point;
-import java.awt.geom.*;
+import java.awt.geom.GeneralPath;
+import java.util.Dictionary;
import java.util.Hashtable;
import javax.swing.ImageIcon;
import org.apache.felix.example.servicebased.host.service.SimpleShape;
-import org.osgi.framework.*;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
/**
* This class implements a simple bundle activator for the triangle
@@ -47,7 +49,7 @@
public void start(BundleContext context)
{
m_context = context;
- Hashtable dict = new Hashtable();
+ Dictionary<String, Object> dict = new Hashtable<String, Object>();
dict.put(SimpleShape.NAME_PROPERTY, "Triangle");
dict.put(SimpleShape.ICON_PROPERTY,
new ImageIcon(this.getClass().getResource("triangle.png")));