Commit 1e228ee8 authored by Lionel Seinturier's avatar Lionel Seinturier
Browse files

Adding support for the <include> tag when parsing .composite files.

parent cef96270
......@@ -49,6 +49,7 @@ import org.eclipse.stp.sca.ComponentService;
import org.eclipse.stp.sca.Composite;
import org.eclipse.stp.sca.DocumentRoot;
import org.eclipse.stp.sca.Implementation;
import org.eclipse.stp.sca.Include;
import org.eclipse.stp.sca.Interface;
import org.eclipse.stp.sca.JavaImplementation;
import org.eclipse.stp.sca.JavaInterface;
......@@ -273,31 +274,49 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
private ComponentDesc toComponentDesc( Composite composite )
throws IOException {
String name = composite.getName();
EList<Component> subs = composite.getComponent();
/*
* Composite type.
* Includes.
*
* The <include> tag is used in frascati-assembly-factory.
*/
EList<Include> includes = composite.getInclude();
if( includes.size() != 0 ) {
if( includes.size() > 1 ) {
String name = composite.getName();
String msg = "Only 1 <include> tag supported in "+name;
throw new IOException(msg);
}
Include include = includes.get(0);
QName qname = include.getName();
String namespaceURI = qname.getNamespaceURI();
String localpart = qname.getLocalPart();
String adl = namespaceURI.replace('/','.')+'.'+localpart;
ComponentDesc cdesc = parse(adl,null);
return cdesc;
}
/*
* Naming convention for component-based membranes. The thing is that
* the grammar of the SCA ADL does not allow specifying a controller
* descriptor (or could we find a way to specify it with an existing
* concept?) just like Fractal ADL enables it. We then assume that all
* parsed ADL with a name which starts with
* parsed ADL with a name that starts with
* org.ow2.frascati.tinfi.membrane (MEMBRANE_PKG_NAME constant)
* correspond to a component-based membrane.
*/
String id = "C"+(compidx++);
ComponentType ct = ecore2fractal(composite);
String name = composite.getName();
String controllerDesc =
name.startsWith(MEMBRANE_PKG_NAME) ? "mComposite" : "scaComposite";
ComponentDesc cdesc =
new ComponentDesc(id,name,name,ct,controllerDesc,null);
/*
* Subcomponents.
*/
EList<Component> subs = composite.getComponent();
Map<String,ComponentDesc> subcdescs =
new HashMap<String,ComponentDesc>();
String subControllerDesc =
......
......@@ -26,9 +26,12 @@ package org.ow2.frascati.tinfi.emf;
import java.io.IOException;
import java.util.List;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.api.ADLParserSupportItf;
import org.objectweb.fractal.juliac.conf.JuliacConfig;
import org.objectweb.fractal.juliac.desc.AttributeDesc;
import org.objectweb.fractal.juliac.desc.ComponentDesc;
......@@ -42,14 +45,26 @@ import org.objectweb.fractal.juliac.desc.ComponentDesc;
*/
public class EMFParserSupportImplTestCase {
private Juliac jc;
private ADLParserSupportItf emfps;
@Before
public void setUp() throws IOException {
jc = new Juliac();
jc.setJuliacConfig(new JuliacConfig(jc));
emfps = new EMFParserSupportImpl();
emfps.init(jc);
}
@After
public void tearDown() throws IOException {
emfps.close(jc);
jc.close();
}
@Test
public void testPropertyClass() throws IOException {
Juliac jc = new Juliac();
jc.setJuliacConfig(new JuliacConfig(jc));
EMFParserSupportImpl emfps = new EMFParserSupportImpl();
emfps.init(jc);
ComponentDesc cdesc = emfps.parse("Property",null);
List<ComponentDesc> subs = cdesc.getSubComponents();
ComponentDesc sub = subs.get(0);
......@@ -59,8 +74,20 @@ public class EMFParserSupportImplTestCase {
Assert.assertEquals(Class.class.getName(),type);
Assert.assertEquals(Runnable.class.getName(),value);
}
emfps.close(jc);
jc.close();
@Test
public void testInclude() throws IOException {
ComponentDesc cdesc =
emfps.parse("org.ow2.frascati.bootstrap.FraSCAti",null);
List<ComponentDesc> subs = cdesc.getSubComponents();
ComponentDesc sub = subs.get(0);
AttributeDesc adesc = sub.getAttribute("classprop");
String type = adesc.getType();
String value = adesc.getValue();
Assert.assertEquals(Class.class.getName(),type);
Assert.assertEquals(Runnable.class.getName(),value);
}
}
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:java="http://frascati.ow2.org/xmlns/java"
name="org.ow2.frascati.FraSCAti">
<component name="server">
<property name="stringprop">Hello World!</property>
<property name="classprop" type="java:java.lang.Class">java.lang.Runnable</property>
<implementation.java class="java.lang.Object" />
</component>
</composite>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:frascati="org/ow2/frascati"
name="org.ow2.frascati.bootstrap.FraSCAti">
<include name="frascati:FraSCAti"/>
</composite>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment