Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
frascati
frascati
Commits
a77c1d20
Commit
a77c1d20
authored
Jun 20, 2016
by
seinturi
Browse files
Abstract implementation for the ADL parser service.
Additionnal helper methods.
parent
bb4b0323
Changes
1
Hide whitespace changes
Inline
Side-by-side
tinfi/module/adlparser-scaadl/src/main/java/org/ow2/frascati/tinfi/emf/EMFParserSupportImpl.java
View file @
a77c1d20
...
...
@@ -30,7 +30,6 @@ import java.net.URI;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.xml.namespace.QName
;
...
...
@@ -61,19 +60,16 @@ import org.eclipse.stp.sca.Service;
import
org.eclipse.stp.sca.Wire
;
import
org.eclipse.stp.sca.util.ScaResourceFactoryImpl
;
import
org.objectweb.fractal.api.NoSuchInterfaceException
;
import
org.objectweb.fractal.api.Type
;
import
org.objectweb.fractal.api.factory.InstantiationException
;
import
org.objectweb.fractal.api.type.ComponentType
;
import
org.objectweb.fractal.api.type.InterfaceType
;
import
org.objectweb.fractal.api.type.TypeFactory
;
import
org.objectweb.fractal.julia.type.BasicComponentType
;
import
org.objectweb.fractal.julia.type.BasicInterfaceType
;
import
org.objectweb.fractal.juliac.Juliac
;
import
org.objectweb.fractal.juliac.api.ADLParserSupportItf
;
import
org.objectweb.fractal.juliac.api.FCSourceCodeGeneratorItf
;
import
org.objectweb.fractal.juliac.api.TypeGeneratorItf
;
import
org.objectweb.fractal.juliac.commons.lang.StringHelper
;
import
org.objectweb.fractal.juliac.conf.JuliacConfig
;
import
org.objectweb.fractal.juliac.desc.AbstractADLSupportImpl
;
import
org.objectweb.fractal.juliac.desc.AttributeDesc
;
import
org.objectweb.fractal.juliac.desc.BindingDesc
;
import
org.objectweb.fractal.juliac.desc.BindingType
;
...
...
@@ -87,29 +83,8 @@ import org.objectweb.fractal.juliac.desc.ComponentDesc;
* @author Philippe Merle <Philippe.Merle@inria.fr>
* @since 1.1
*/
public
class
EMFParserSupportImpl
implem
en
t
s
A
DLParserSupportItf
{
public
class
EMFParserSupportImpl
ext
en
d
s
A
bstractADLSupportImpl
<
Composite
>
{
// --------------------------------------------------------------------
// Implementation of the JuliacModuleItf interface
// --------------------------------------------------------------------
final
public
static
Class
<
ADLParserSupportItf
>
SERVICE_TYPE
=
ADLParserSupportItf
.
class
;
protected
Juliac
jc
;
public
void
init
(
Juliac
jc
)
{
this
.
jc
=
jc
;
JuliacConfig
jconf
=
jc
.
getJuliacConfig
();
jconf
.
register
(
SERVICE_TYPE
,
this
);
}
public
void
close
(
Juliac
jc
)
{
JuliacConfig
jconf
=
jc
.
getJuliacConfig
();
jconf
.
unregister
(
SERVICE_TYPE
,
this
);
}
// --------------------------------------------------------------------
// Implementation of the ADLParserSupportItf interface
// --------------------------------------------------------------------
...
...
@@ -125,13 +100,6 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
// Declared protected to enable usage in frascati-tinfi-osgi-scaadl
protected
int
compidx
=
0
;
/**
* Test whether this ADL parser accepts the specified ADL descriptor.
*
* @param adl the fully-qualified name of the ADL descriptor
* @return <code>true</code> if this ADL parser accepts the specified
* ADL descriptor
*/
public
boolean
acceptADLDesc
(
String
adl
)
{
/*
* Do not use File#separatorChar (even on Windows) as it leads to is
...
...
@@ -145,61 +113,24 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
return
exist
;
}
/**
* Parse the specified ADL descriptor and return a model of it.
*
* @param adl the fully-qualified name of the ADL descriptor
* @param context contextual information
* @return the model of the specified ADL
*/
public
ComponentDesc
parse
(
String
adl
,
Map
<
Object
,
Object
>
context
)
throws
IOException
{
Composite
composite
=
innerparse
(
adl
,
context
);
ComponentDesc
ret
=
toComponentDesc
(
composite
);
return
ret
;
}
/**
* Generate the source code of a factory class for the specified ADL
* descriptor.
*
* @param adl the fully-qualified name of the ADL descriptor
* @param targetname the fully-qualified name of the factory class
*/
public
void
generate
(
String
adl
,
String
targetname
)
// ----------------------------------------------------------------------
// Methods for handling Composite
// ----------------------------------------------------------------------
protected
Composite
load
(
String
adl
,
Map
<
Object
,
Object
>
context
)
throws
IOException
{
/*
* Generate the factory for the assembly.
* Generate factories for each component included in the assembly.
*/
ComponentDesc
cdesc
=
parse
(
adl
,
null
);
generate
(
cdesc
,
targetname
);
generateIOE
(
cdesc
);
Composite
composite
=
innerparse
(
adl
,
context
);
return
composite
;
}
/**
* Generate the source code of a factory class for the specified model of
* the ADL.
*
* @param cdesc the model of the ADL descriptor
* @param targetname the fully-qualified name of the factory class
* @since 2.5
*/
public
void
generate
(
ComponentDesc
cdesc
,
String
targetname
)
throws
IOException
{
@Override
protected
TypeGeneratorItf
getComponentDescFactoryClassGenerator
(
ComponentDesc
cdesc
,
String
targetname
)
{
TypeGeneratorItf
cg
=
new
ComponentDescFactoryClassGenerator
(
jc
,
cdesc
,
targetname
);
jc
.
generateSourceCode
(
cg
);
return
new
ComponentDescFactoryClassGenerator
(
jc
,
cdesc
,
targetname
);
}
// ----------------------------------------------------------------------
// Methods for transforming Composite to ComponentDesc
// ----------------------------------------------------------------------
/**
* Parse the specified ADL descriptor and return a model of it.
*
...
...
@@ -269,7 +200,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
/**
* Transform the specified {@link Composite} to {@link ComponentDesc}.
*/
pr
ivate
ComponentDesc
toComponentDesc
(
Composite
composite
)
pr
otected
ComponentDesc
toComponentDesc
(
Composite
composite
)
throws
IOException
{
/*
...
...
@@ -360,7 +291,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
* Component name and type.
*/
String
name
=
sub
.
getName
();
ComponentType
subct
=
ecore2fractal
(
sub
);
ComponentType
subct
=
ecore2fractal
(
sub
);
Implementation
implementation
=
sub
.
getImplementation
();
ComponentDesc
cdesc
=
null
;
...
...
@@ -720,7 +651,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
Interface
itf
=
service
.
getInterface
();
InterfaceType
it
=
ecore2fractal
(
name
,
itf
,
ONE_TO_ONE
,
TypeFactory
.
SERVER
);
return
it
;
return
it
;
}
/**
...
...
@@ -736,7 +667,7 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
Multiplicity
multiplicity
=
reference
.
getMultiplicity
();
String
mult
=
multiplicity
.
getLiteral
();
InterfaceType
it
=
ecore2fractal
(
name
,
itf
,
mult
,
TypeFactory
.
CLIENT
);
return
it
;
return
it
;
}
/**
...
...
@@ -827,27 +758,4 @@ public class EMFParserSupportImpl implements ADLParserSupportItf {
resourceSet
.
getPackageRegistry
();
reg
.
put
(
ScaPackage
.
eNS_URI
,
ScaPackage
.
eINSTANCE
);
}
/**
* Traverse the component hierarchy and generate the factory for each
* visited component.
*/
private
void
generateIOE
(
ComponentDesc
cdesc
)
throws
IOException
{
Type
type
=
cdesc
.
getCT
();
Object
controllerDesc
=
cdesc
.
getCtrlDesc
();
Object
contentDesc
=
cdesc
.
getContentClassName
();
FCSourceCodeGeneratorItf
<?>
fcscg
=
jc
.
getFCSourceCodeGenerator
(
controllerDesc
);
fcscg
.
generate
(
type
,
controllerDesc
,
contentDesc
);
/*
* Recurse for subcomponents.
*/
List
<
ComponentDesc
>
subs
=
cdesc
.
getSubComponents
();
for
(
ComponentDesc
sub
:
subs
)
{
generateIOE
(
sub
);
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment