adding first example of tutorial using the new maven-osgi-plugin
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@383778 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.examples.eventlistener/pom.xml b/org.apache.felix.examples.eventlistener/pom.xml
new file mode 100644
index 0000000..fda2b74
--- /dev/null
+++ b/org.apache.felix.examples.eventlistener/pom.xml
@@ -0,0 +1,43 @@
+<project>
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix</artifactId>
+ <version>0.8-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>osgi-bundle</packaging>
+ <name>Apache Felix Examples: Service Event Listener</name>
+ <artifactId>org.apache.felix.examples.eventlistener</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix.plugins</groupId>
+ <artifactId>maven-osgi-plugin</artifactId>
+ <version>${pom.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <osgiManifest>
+ <bundleName>Service listener example</bundleName>
+ <bundleDescription>
+ Bundle listening for service events: displays a message on startup and when service events occur.
+ </bundleDescription>
+ <bundleActivator>
+ org.apache.felix.examples.eventlistener.Activator
+ </bundleActivator>
+ <bundleSymbolicName>
+ org.apache.felix.examples.eventlistener
+ </bundleSymbolicName>
+ </osgiManifest>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/org.apache.felix.examples.eventlistener/src/main/java/org/apache/felix/examples/eventlistener/Activator.java b/org.apache.felix.examples.eventlistener/src/main/java/org/apache/felix/examples/eventlistener/Activator.java
new file mode 100644
index 0000000..20c95b3
--- /dev/null
+++ b/org.apache.felix.examples.eventlistener/src/main/java/org/apache/felix/examples/eventlistener/Activator.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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.examples.eventlistener;
+
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceEvent;
+
+
+/**
+ * This class implements a simple bundle that utilizes the OSGi framework's
+ * event mechanism to listen for service events. Upon receiving a service event,
+ * it prints out the event's details.
+ *
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class Activator implements BundleActivator, ServiceListener
+{
+ /**
+ * Implements BundleActivator.start(). Prints a message and adds itself to
+ * the bundle context as a service listener.
+ *
+ * @param context
+ * the framework context for the bundle.
+ */
+ public void start( BundleContext context )
+ {
+ System.out.println( "Starting to listen for service events." );
+ context.addServiceListener( this );
+ }
+
+
+ /**
+ * Implements BundleActivator.stop(). Prints a message and removes itself
+ * from the bundle context as a service listener.
+ *
+ * @param context
+ * the framework context for the bundle.
+ */
+ public void stop( BundleContext context )
+ {
+ context.removeServiceListener( this );
+ System.out.println( "Stopped listening for service events." );
+
+ // Note: It is not required that we remove the listener here,
+ // since the framework will do it automatically anyway.
+ }
+
+
+ /**
+ * Implements ServiceListener.serviceChanged(). Prints the details of any
+ * service event from the framework.
+ *
+ * @param event
+ * the fired service event.
+ */
+ public void serviceChanged( ServiceEvent event )
+ {
+ String[] objectClass = ( String[] ) event.getServiceReference().getProperty( "objectClass" );
+
+ if ( event.getType() == ServiceEvent.REGISTERED )
+ {
+ System.out.println( "Ex1: Service of type " + objectClass[0] + " registered." );
+ }
+ else if ( event.getType() == ServiceEvent.UNREGISTERING )
+ {
+ System.out.println( "Ex1: Service of type " + objectClass[0] + " unregistered." );
+ }
+ else if ( event.getType() == ServiceEvent.MODIFIED )
+ {
+ System.out.println( "Ex1: Service of type " + objectClass[0] + " modified." );
+ }
+ }
+}
diff --git a/pom.xml b/pom.xml
index 600d0fe..8fd5e0e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,6 +14,7 @@
<module>org.apache.felix.shell.tui</module>
<module>org.apache.felix.daemon</module>
<module>org.apache.felix.main</module>
+ <module>org.apache.felix.examples.eventlistener</module>
</modules>
<repositories>
@@ -40,7 +41,7 @@
</snapshotRepository>
<repository>
<name>ASF Mirrored M2 Distributions</name>
- <id>apache.snapshots</id>
+ <id>apache.releases</id>
<url>
scpexe://minotaur.apache.org/www/www.apache.org/dist/maven-repository
</url>
@@ -52,7 +53,7 @@
<id>apache.snapshots</id>
<name>snapshot plugins</name>
<url>
- scpexe://apache.org/www/cvs.apache.org/maven-snapshot-repository
+ http://cvs.apache.org/maven-snapshot-repository
</url>
</pluginRepository>
</pluginRepositories>