Commit 9952fddb authored by Philippe Merle's avatar Philippe Merle

Added a new helloworld example illustrating how to embed OSGi bundles into an SCA composite,

i.e., use of <frascati:implementation.osgi bundle="..."/> implemented with Apache Felix.

Directory 'bundles' contains three OSGi bundles.
Directory 'sca' contains an SCA composite embedding the three OSGi bundles.

TBC:
* Allow to deploy on both Eclipse Equinox and Apache Felix.
* Support for Maven profiles 'run' and 'explorer'.
parent a2b10298
......@@ -11,8 +11,7 @@ Assembly Factory 1.3
- /trunk/frascati/modules/frascati-implementation-osgi/
- /trunk/frascati/modules/frascati-implementation-osgi-felix/
- /trunk/frascati/modules/frascati-implementation-osgi-equinox/ (TBC)
TODO: AN EXAMPLE MUST BE PROVIDED SOON.
- /trunk/examples/helloworld-osgi/
* Big bang reengineering of the OW2 FraSCAti Assembly Factory
- split modules 'parser', 'core-factory', 'generate-factory', and 'runtime-factory'
......
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld OSGi
*
* Copyright (c) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-bundles-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-api</artifactId>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: HelloWorld OSGi API Bundle</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-Activator>org.ow2.frascati.examples.helloworld.osgi.api.Activator</Bundle-Activator>
<Export-Package>org.ow2.frascati.examples.helloworld.osgi.api</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
/**
* OW2 FraSCAti Examples: HelloWorld OSGi
* Copyright (C) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
*
*/
package org.ow2.frascati.examples.helloworld.osgi.api;
import java.util.Dictionary;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public void start( BundleContext context ) {
Bundle bundle = context.getBundle();
Dictionary dict = bundle.getHeaders();
String name = (String) dict.get("Bundle-Name");
System.err.println("Bundle <"+name+"> started.");
}
public void stop( BundleContext context ) {
Bundle bundle = context.getBundle();
Dictionary dict = bundle.getHeaders();
String name = (String) dict.get("Bundle-Name");
System.err.println("Bundle <"+name+"> stopped.");
}
}
/**
* OW2 FraSCAti Examples: HelloWorld OSGi
* Copyright (C) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
*
*/
package org.ow2.frascati.examples.helloworld.osgi.api;
/**
* A basic service used to print messages.
*/
public interface PrintService {
void print(String msg);
}
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld OSGi
*
* Copyright (c) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-bundles-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-client</artifactId>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: HelloWorld OSGi Client Bundle</name>
<dependencies>
<dependency>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-api</artifactId>
<version>${frascati.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-Activator>org.ow2.frascati.examples.helloworld.osgi.client.Activator</Bundle-Activator>
<Export-Package>org.ow2.frascati.examples.helloworld.osgi.client</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
/**
* OW2 FraSCAti Examples: HelloWorld OSGi
* Copyright (C) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
*
*/
package org.ow2.frascati.examples.helloworld.osgi.client;
import java.util.Dictionary;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.ow2.frascati.examples.helloworld.osgi.api.PrintService;
public class Activator implements BundleActivator {
public void start( BundleContext context ) throws InvalidSyntaxException {
ServiceReference[] refs =
context.getServiceReferences(PrintService.class.getName(), null);
PrintService printService = (PrintService) context.getService(refs[0]);
ClientImpl client = new ClientImpl();
client.setPrintService(printService);
context.registerService(Runnable.class.getName(), client, null);
Bundle bundle = context.getBundle();
Dictionary dict = bundle.getHeaders();
String name = (String) dict.get("Bundle-Name");
System.err.println("Bundle <"+name+"> started.");
}
public void stop( BundleContext context ) {
Bundle bundle = context.getBundle();
Dictionary dict = bundle.getHeaders();
String name = (String) dict.get("Bundle-Name");
System.err.println("Bundle <"+name+"> stopped.");
}
}
/**
* OW2 FraSCAti Examples: HelloWorld OSGi
* Copyright (C) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
*
*/
package org.ow2.frascati.examples.helloworld.osgi.client;
import org.ow2.frascati.examples.helloworld.osgi.api.PrintService;
public class ClientImpl implements Runnable {
public void run() {
s.print("Hello World");
}
public void setPrintService(PrintService s) {
this.s = s;
}
private PrintService s;
}
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld OSGi
*
* Copyright (c) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-bundles-parent</artifactId>
<packaging>pom</packaging>
<name>OW2 FraSCAti Examples: HelloWorld OSGi Bundles</name>
<properties>
<felix.mojo.version>2.0.1</felix.mojo.version>
<osgi.version>4.2.0</osgi.version>
</properties>
<dependencies>
<!-- not required
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>${osgi.version}</version>
<scope>provided</scope>
</dependency>
-->
<!-- required to deploy bundles on Apache Felix -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${felix.mojo.version}</version>
<executions>
<execution>
<id>bundle-bundle</id>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${pom.name}</Bundle-Name>
<Bundle-Vendor>INRIA - USTL</Bundle-Vendor>
<Bundle-Description>${pom.name}</Bundle-Description>
</instructions>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<modules>
<module>api</module>
<module>client</module>
<module>server</module>
</modules>
</project>
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld OSGi
*
* Copyright (c) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-bundles-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-server</artifactId>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: HelloWorld OSGi Server Bundle</name>
<dependencies>
<dependency>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-api</artifactId>
<version>${frascati.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-Activator>org.ow2.frascati.examples.helloworld.osgi.server.Activator</Bundle-Activator>
<Export-Package>org.ow2.frascati.examples.helloworld.osgi.server</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
/**
* OW2 FraSCAti Examples: HelloWorld OSGi
* Copyright (C) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
*
*/
package org.ow2.frascati.examples.helloworld.osgi.server;
import java.util.Dictionary;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.ow2.frascati.examples.helloworld.osgi.api.PrintService;
public class Activator implements BundleActivator {
public void start( BundleContext context ) {
ServerImpl server = new ServerImpl();
context.registerService(PrintService.class.getName(), server, null);
Bundle bundle = context.getBundle();
Dictionary dict = bundle.getHeaders();
String name = (String) dict.get("Bundle-Name");
System.err.println("Bundle <"+name+"> started.");
}
public void stop( BundleContext context ) {
Bundle bundle = context.getBundle();
Dictionary dict = bundle.getHeaders();
String name = (String) dict.get("Bundle-Name");
System.err.println("Bundle <"+name+"> stopped.");
}
}
/**
* OW2 FraSCAti Examples: HelloWorld OSGi
* Copyright (C) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
*
*/
package org.ow2.frascati.examples.helloworld.osgi.server;
import org.ow2.frascati.examples.helloworld.osgi.api.PrintService;
public class ServerImpl implements PrintService {
private String header = "-> ";
private int count = 1;
public void print(final String msg) {
System.out.println("Server: begin printing...");
for (int i = 0 ; i < (count) ; ++i) {
System.out.println(((header) + msg));
}
System.out.println("Server: print done.");
}
public String getHeader() {
return header;
}
public void setHeader(final String header) {
this.header = header;
}
public int getCount() {
return count;
}
public void setCount(final int count) {
this.count = count;
}
}
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld OSGi
*
* Copyright (c) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
*
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<groupId>org.ow2.frascati.examples</groupId>
<artifactId>helloworld-osgi-parent</artifactId>
<packaging>pom</packaging>
<name>OW2 FraSCAti Examples: HelloWorld OSGi</name>
<modules>
<module>bundles</module>
<module>sca</module>
</modules>
</project>
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld OSGi
*
* Copyright (c) 2010 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle