Commit ecc4ccff authored by dfournier's avatar dfournier
Browse files

Added HelloWorld example using complex property

parent 25dfff80
<?xml version="1.0"?>
<!--
* SCOrWare Assembly Factory.
*
* Copyright (c) 2007-2008 INRIA
*
* 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
-->
<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.scorware.assembly.examples</groupId>
<artifactId>parent</artifactId>
<version>0.4-SNAPSHOT</version>
</parent>
<groupId>org.scorware.assembly.examples</groupId>
<artifactId>helloworld-property</artifactId>
<packaging>jar</packaging>
<name>SCOrWare FraSCAti Assembly Factory Examples: HelloWorld with Property</name>
<properties>
<example.main.composite>helloworld-complex-property</example.main.composite>
<example.main.class>example.hw.ClientProperty</example.main.class>
</properties>
<pluginRepositories>
<pluginRepository>
<id>java.net</id>
<name>java.net Maven Repository</name>
<url>https://maven-repository.dev.java.net/nonav/repository</url>
<layout>legacy</layout>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.scorware.assembly</groupId>
<artifactId>frascati-af-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Used to create java files from XSD -->
<!-- note that your schema must use the attributes: -->
<!-- attributeFormDefault="qualified" -->
<!-- and -->
<!-- elementFormDefault="qualified" -->
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
<artifactId>maven-jaxb-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<extension>true</extension>
</configuration>
</plugin>
<!-- FraSCAti plugin take -->
<plugin>
<groupId>org.scorware.assembly</groupId>
<artifactId>frascati-factory-tools</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>generate-factory</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<factory>GenerateFactory</factory>
<srcs>
<src>src/main/java</src>
<src>src/main/resources</src>
<src>target/generated-sources/xjc</src>
</srcs>
<composite>${example.main.composite}</composite>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
</configuration>
</plugin>
</plugins>
</build>
</project>
############################################################
# Default Logging Configuration File
#
# You can use a different file by specifying a filename
# with the java.util.logging.config.file system property.
# For example java -Djava.util.logging.config.file=myfile
############################################################
############################################################
# Global properties
############################################################
# "handlers" specifies a comma separated list of log Handler
# classes. These handlers will be installed during VM startup.
# Note that these classes must be on the system classpath.
# By default we only configure a ConsoleHandler, which will only
# show messages at the INFO and above levels.
handlers= java.util.logging.ConsoleHandler
# To also add the FileHandler, use the following line instead.
#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
# Default global logging level.
# This specifies which kinds of events are logged across
# all loggers. For any given facility this global level
# can be overriden by a facility specific level
# Note that the ConsoleHandler also has a separate level
# setting to limit messages printed to the console.
.level = ALL
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
# default file output is in user's home directory.
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
# Limit the message that are printed on the console to INFO and above.
java.util.logging.ConsoleHandler.level = OFF
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
# For example, set the com.xyz.foo logger to only log SEVERE
# messages: com.xyz.foo.level = SEVERE
spoonlet.level = OFF
spoonlet.fractal.level = OFF
spoonlet.fractaladl.level = OFF
/***
* SCOrWare FraSCAti Assembly Factory Examples: HelloWorld with complex property
* Copyright (C) 2008 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: Damien.Fournier@inria.fr
*
* Author: Damien Fournier
*/
package example.hw;
import org.objectweb.fractal.api.Component;
import org.scorware.assembly.AssemblyFactory;
import org.scorware.tinfi.TinfiDomain;
public class Client {
public static void main(String args []) {
Component scaDomain;
try {
System.out.println("\n\n\nStarting The Helloworld Example \n");
scaDomain = new AssemblyFactory().getComposite("helloworld");
java.lang.Runnable hello = TinfiDomain.getService(scaDomain,
java.lang.Runnable.class, "r");
// performs some calls
hello.run();
//closing sca domain
TinfiDomain.close(scaDomain);
System.out.println("\n\n\n");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/***
* SCOrWare FraSCAti Assembly Factory Examples: HelloWorld with complex property
* Copyright (C) 2008 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: Damien.Fournier@inria.fr
*
* Author: Damien Fournier
*/
package example.hw;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
public class ClientImpl implements Runnable {
public ClientImpl() {
System.err.println("CLIENT created");
}
@Init
public void init() {
System.err.println("CLIENT initialized");
}
public void run() {
s.print("hello world");
}
@Reference
public Service s;
}
\ No newline at end of file
/***
* SCOrWare FraSCAti Assembly Factory Examples: HelloWorld with complex property
* Copyright (C) 2008 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: Damien.Fournier@inria.fr
*
* Author: Damien Fournier
*/
package example.hw;
import org.objectweb.fractal.api.Component;
import org.scorware.assembly.Factory;
import org.scorware.tinfi.TinfiDomain;
public class ClientProperty {
public static void main(String args []) {
Component scaDomain;
try {
System.out.println("\n\n\nStarting The Helloworld Example \n");
scaDomain = new Factory().getComposite("helloworld-complex-property.composite");
java.lang.Runnable hello = TinfiDomain.getService(scaDomain,
java.lang.Runnable.class, "r");
// performs some calls
hello.run();
//closing sca domain
TinfiDomain.close(scaDomain);
System.out.println("\n\n\n");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/***
* SCOrWare FraSCAti Assembly Factory Examples: HelloWorld with complex property
* Copyright (C) 2008 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: Damien.Fournier@inria.fr
*
* Author: Damien Fournier
*/
package example.hw;
import org.osoa.sca.annotations.Property;
@org.osoa.sca.annotations.Service(interfaces = { example.hw.Service.class })
public class ServerImpl implements Service {
public Message header = null;
private int count = 1;
public ServerImpl() {
System.err.println("SERVER created");
}
public void print(final String msg) {
new Exception() {
private static final long serialVersionUID = 2182742162070453637L;
public String toString() {
return "Server: print method called";
}
}.printStackTrace();
System.err.println("Server: begin printing...");
for (int i = 0; i < (count); ++i) {
System.err.println(((header.getPre()) + " " + msg + " " + (header.getPost())));
}
System.err.println("Server: print done.");
}
@Property
public void setHeader(Message header) {
this.header = header;
}
@Property
public void setCount(final int count) {
this.count = count;
}
}
\ No newline at end of file
/***
* SCOrWare FraSCAti Assembly Factory Examples: HelloWorld with complex property
* Copyright (C) 2008 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: Damien.Fournier@inria.fr
*
* Author: Damien Fournier
*
* Contributor: Philippe Merle
*/
package example.hw;
public interface Service {
void print(String msg);
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- Assembly Factory Examples : HelloWorld -->
<!-- Copyright (C) 2008 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: Damien.Fournier@inria.fr -->
<!-- -->
<!-- Author: Damien Fournier -->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:hw="http://example/hw" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="helloworldProperty" targetNamespace="http://helloworld">
<service name="r" promote="client/r">
<interface.java interface="java.lang.Runnable" />
</service>
<component name="client">
<implementation.java class="example.hw.ClientImpl" />
<service name="r">
<interface.java interface="java.lang.Runnable" />
</service>
<reference name="s" target="server/s">
<interface.java interface="example.hw.Service" />
</reference>
</component>
<component name="server">
<implementation.java class="example.hw.ServerImpl" />
<service name="s">
<interface.java interface="example.hw.Service" />
</service>
<property name="header" type="hw:Message">
<hw:Message>
<hw:pre>This is the</hw:pre>
<hw:post>test</hw:post>
</hw:Message>
</property>
</component>
</composite>
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:data="http://example/hw"
targetNamespace="http://example/hw" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc"
attributeFormDefault="qualified" elementFormDefault="qualified">
<annotation>
<appinfo>
<jaxb:globalBindings>
<xjc:simple />
</jaxb:globalBindings>
</appinfo>
</annotation>
<element name="Message" type="data:MessageType" />
<complexType name="MessageType">
<sequence>
<element name="pre" type="string" />
<element name="post" type="string" />
</sequence>
</complexType>
</schema>
package example.hw;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.scorware.assembly.Factory;
import org.scorware.tinfi.TinfiDomain;
import org.objectweb.fractal.api.Component;
public class HelloWorldPropertyTestCase {
private Component scaDomain;
private java.lang.Runnable service;
@Before
public void setUp() throws Exception {
scaDomain = new Factory().getComposite("helloworld-complex-property.composite");
service = TinfiDomain.getService(scaDomain,
java.lang.Runnable.class, "r");
}
@Test
public void testInit() {
assertNotNull(scaDomain);
assertNotNull(service);
}
@Test
public void testCall() {
service.run();
}
@After
public void tearDown() throws Exception {
TinfiDomain.close(scaDomain);
}
}