Commit d0fca6f5 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

af3.component complete

refs 190
parent 00eefd92
......@@ -9,4 +9,19 @@ Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.fortiss.af3.component.AF3ComponentActivator
Require-Bundle: org.fortiss.af3.project
Require-Bundle: org.fortiss.af3.expression;bundle-version="1.0.0";visibility:=reexport
Export-Package: org.fortiss.af3.component,
org.fortiss.af3.component.generator.c,
org.fortiss.af3.component.generator.model.base,
org.fortiss.af3.component.generator.model.c,
org.fortiss.af3.component.model,
org.fortiss.af3.component.model.behavior.code,
org.fortiss.af3.component.model.behavior.code.impl,
org.fortiss.af3.component.model.behavior.code.util,
org.fortiss.af3.component.model.behavior.common,
org.fortiss.af3.component.model.behavior.common.impl,
org.fortiss.af3.component.model.behavior.common.util,
org.fortiss.af3.component.model.impl,
org.fortiss.af3.component.model.util,
org.fortiss.af3.component.simulator,
org.fortiss.af3.component.utils
......@@ -3,8 +3,8 @@
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="model"
nsURI="http://www.fortiss.org/af3/base/project" nsPrefix="org-fortiss-af3-base-project">
<eClassifiers xsi:type="ecore:EClass" name="ComponentArchitecture" eSuperTypes="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//IProjectRootElement ../../org.fortiss.tooling.base/model/base.ecore#//element/IHierarchicElement"/>
<eClassifiers xsi:type="ecore:EClass" name="Component" eSuperTypes="../../org.fortiss.tooling.base/model/base.ecore#//base/HierarchicElementBase">
<eClassifiers xsi:type="ecore:EClass" name="ComponentArchitecture" eSuperTypes="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//IProjectRootElement platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//element/IHierarchicElement"/>
<eClassifiers xsi:type="ecore:EClass" name="Component" eSuperTypes="platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//base/HierarchicElementBase">
<eOperations name="getOutputPorts" upperBound="-1" eType="#//OutputPort">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf(&#xA;&#x9;&#x9;&#x9;&#x9;OutputPort.class, getConnectorsList());"/>
......@@ -21,7 +21,7 @@
</eAnnotations>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Channel" eSuperTypes="../../org.fortiss.tooling.base/model/base.ecore#//base/ConnectionSegmentBase">
<eClassifiers xsi:type="ecore:EClass" name="Channel" eSuperTypes="platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//base/ConnectionSegmentBase">
<eOperations name="getSource" eType="#//Port">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return (Port) super.getSource();"/>
......@@ -33,7 +33,7 @@
</eAnnotations>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Port" abstract="true" eSuperTypes="../../org.fortiss.tooling.base/model/base.ecore#//base/ConnectorBase">
<eClassifiers xsi:type="ecore:EClass" name="Port" abstract="true" eSuperTypes="platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//base/ConnectorBase">
<eOperations name="getPortSpecification" eType="#//PortSpecification">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf(&#xA;&#x9;&#x9;&#x9;&#x9;PortSpecification.class, getSpecificationsList()).get(0);"/>
......@@ -55,12 +55,12 @@
</eAnnotations>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="InputPort" eSuperTypes="#//Port ../../org.fortiss.tooling.base/model/base.ecore#//base/EntryConnectorBase"/>
<eClassifiers xsi:type="ecore:EClass" name="OutputPort" eSuperTypes="#//Port ../../org.fortiss.tooling.base/model/base.ecore#//base/ExitConnectorBase"/>
<eClassifiers xsi:type="ecore:EClass" name="CausalityComponentSpecification" eSuperTypes="../../org.fortiss.tooling.base/model/base.ecore#//element/IHiddenSpecification">
<eClassifiers xsi:type="ecore:EClass" name="InputPort" eSuperTypes="#//Port platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//base/EntryConnectorBase"/>
<eClassifiers xsi:type="ecore:EClass" name="OutputPort" eSuperTypes="#//Port platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//base/ExitConnectorBase"/>
<eClassifiers xsi:type="ecore:EClass" name="CausalityComponentSpecification" eSuperTypes="platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//element/IHiddenSpecification">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="stronglyCausal" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="PortSpecification" eSuperTypes="../../org.fortiss.tooling.base/model/base.ecore#//element/IHiddenSpecification">
<eClassifiers xsi:type="ecore:EClass" name="PortSpecification" eSuperTypes="platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//element/IHiddenSpecification">
<eStructuralFeatures xsi:type="ecore:EReference" name="type" eType="ecore:EClass platform:/plugin/org.fortiss.af3.project/model/project.ecore#//typesystem/IType"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="initialValue" eType="ecore:EClass platform:/plugin/org.fortiss.af3.project/model/project.ecore#//typesystem/ITerm"
......@@ -92,10 +92,10 @@
</eSubpackages>
<eSubpackages name="code" nsURI="http://www.fortiss.org/af3/component/behavior/code"
nsPrefix="org-fortiss-af3-component-behavior-code">
<eClassifiers xsi:type="ecore:EClass" name="CodeSpecification" eSuperTypes="../../org.fortiss.tooling.base/model/base.ecore#//element/IModelElementSpecification">
<eClassifiers xsi:type="ecore:EClass" name="CodeSpecification" eSuperTypes="platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//element/IModelElementSpecification">
<eOperations name="getComponent" eType="#//Component">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return (org.fortiss.af3.micro.model.architecture.component.Component) eContainer();"/>
<details key="body" value="return (org.fortiss.af3.component.model.Component) eContainer();"/>
</eAnnotations>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EReference" name="body" eType="ecore:EClass ../../org.fortiss.af3.expression/model/expression.ecore#//terms/imperative/StatementSequence"
......
......@@ -8,7 +8,7 @@
editorPluginClass="org.fortiss.af3.component.model.presentation.ModelEditorPlugin"
testsDirectory="/org.fortiss.af3.component.tests/test-src" importerID="org.eclipse.emf.importer.ecore"
containmentProxies="true" arrayAccessors="true" complianceLevel="5.0" copyrightFields="false"
language="" usedGenPackages="platform:/plugin/org.fortiss.tooling.base/model/base.genmodel#//model platform:/plugin/org.fortiss.af3.project/model/project.genmodel#//model platform:/plugin/org.fortiss.tooling.kernel/model/kernel.genmodel#//model">
language="" usedGenPackages="platform:/plugin/org.fortiss.tooling.base/model/base.genmodel#//model ../../org.fortiss.af3.expression/model/expression.genmodel#//model platform:/plugin/org.fortiss.af3.project/model/project.genmodel#//model platform:/plugin/org.fortiss.tooling.kernel/model/kernel.genmodel#//model">
<foreignModel>component.ecore</foreignModel>
<genPackages prefix="AF3Component" basePackage="org.fortiss.af3.component" disposableProviderFactory="true"
ecorePackage="component.ecore#/">
......@@ -38,8 +38,10 @@
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//PortSpecification/initialValue"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute component.ecore#//PortSpecification/stateSignal"/>
</genClasses>
<nestedGenPackages prefix="Behavior" disposableProviderFactory="true" ecorePackage="component.ecore#//behavior">
<nestedGenPackages prefix="Common" disposableProviderFactory="true" ecorePackage="component.ecore#//behavior/common">
<nestedGenPackages prefix="Behavior" basePackage="org.fortiss.af3.component.model"
disposableProviderFactory="true" ecorePackage="component.ecore#//behavior">
<nestedGenPackages prefix="Common" basePackage="org.fortiss.af3.component.model.behavior"
disposableProviderFactory="true" ecorePackage="component.ecore#//behavior/common">
<genClasses ecoreClass="component.ecore#//behavior/common/DataStateVariable">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//behavior/common/DataStateVariable/variable"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//behavior/common/DataStateVariable/initialValue"/>
......@@ -53,7 +55,8 @@
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//behavior/common/Action/value"/>
</genClasses>
</nestedGenPackages>
<nestedGenPackages prefix="Code" disposableProviderFactory="true" ecorePackage="component.ecore#//behavior/code">
<nestedGenPackages prefix="Code" basePackage="org.fortiss.af3.component.model.behavior"
disposableProviderFactory="true" ecorePackage="component.ecore#//behavior/code">
<genClasses ecoreClass="component.ecore#//behavior/code/CodeSpecification">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//behavior/code/CodeSpecification/body"/>
<genOperations ecoreOperation="component.ecore#//behavior/code/CodeSpecification/getComponent"/>
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| 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.fortiss.af3.component.generator.c;
import java.util.Collections;
import org.fortiss.af3.component.generator.model.base.SourcePackage;
import org.fortiss.af3.component.generator.model.c.Function;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.behavior.code.CodeSpecification;
import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm;
import org.fortiss.af3.expression.model.types.impl.TBoolStaticImpl;
import org.fortiss.af3.project.model.typesystem.ITerm;
/**
* {@link CSourceComponent} for {@link CodeSpecification}.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class CSourceCodeSpecification extends
CSourceComponent<CodeSpecification> {
/** Constructor. */
public CSourceCodeSpecification(CodeSpecification specification) {
super((Component) specification.eContainer(), specification);
initialize();
}
/** Creates the performStep function. */
@Override
@SuppressWarnings("unchecked")
protected Function createPerformStepFunction() {
ITerm replaced = Replacement.applyReplacement(specification.getBody(),
portVariableReplacement);
return Function.createExternFunction(TBoolStaticImpl.create(),
getPerformStepFunctionName(), Collections.EMPTY_LIST,
Collections.EMPTY_LIST, (IStatementTerm) replaced);
}
/** {@inheritDoc} */
@Override
public SourcePackage getSourcePackage() {
SourcePackage sp = new SourcePackage(getIdentifier());
sp.addSourceUnit(getHeaderFile());
sp.addSourceUnit(createImplementationFile());
return sp;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| 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.fortiss.af3.component.generator.c;
import org.conqat.lib.commons.reflect.ReflectionUtils;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.behavior.code.CodeSpecification;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
/**
* Transformation for a {@link Component} with a {@link CodeSpecification} into
* an {@link CSourceCodeSpecification};
*
* @author hoelzlf
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class CSourceCodeSpecificationTransformation extends
CSourceComponentTransformationBase {
/** {@inheritDoc} */
@Override
public boolean canHandleChainTransformation(Class<?> sourceClass,
ITransformationContext context) {
return Component.class.isAssignableFrom(sourceClass);
}
/** {@inheritDoc} */
@Override
public boolean canTransform(Object source, ITransformationContext context) {
return source instanceof Component
&& ReflectionUtils.pickInstanceOf(CodeSpecification.class,
((Component) source).getSpecificationsList()) != null;
}
/** {@inheritDoc} */
@Override
public Object transform(Object source, ITransformationContext context) {
return new CSourceCodeSpecification(ReflectionUtils.pickInstanceOf(
CodeSpecification.class,
((Component) source).getSpecificationsList()));
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| 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.fortiss.af3.component.generator.c;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.conqat.lib.commons.reflect.ReflectionUtils;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.fortiss.af3.component.generator.model.base.SourcePackage;
import org.fortiss.af3.component.generator.model.base.SourceUnitBase;
import org.fortiss.af3.component.generator.model.c.Function;
import org.fortiss.af3.component.generator.model.c.HeaderFile;
import org.fortiss.af3.component.generator.model.c.ImplementationFile;
import org.fortiss.af3.component.generator.model.c.Include;
import org.fortiss.af3.component.generator.model.c.Modifier;
import org.fortiss.af3.component.generator.model.c.Variable;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.component.model.Port;
import org.fortiss.af3.component.model.PortSpecification;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.expression.model.terms.Var;
import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm;
import org.fortiss.af3.expression.model.terms.imperative.impl.AssignmentStaticImpl;
import org.fortiss.af3.expression.model.terms.imperative.impl.ReturnStaticImpl;
import org.fortiss.af3.expression.model.terms.impl.BoolConstStaticImpl;
import org.fortiss.af3.expression.model.terms.impl.VarStaticImpl;
import org.fortiss.af3.expression.model.types.impl.TBoolStaticImpl;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.utils.IdentifierUtils;
/**
* Transformation result and executable of the C code generator.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public abstract class CSourceComponent<S extends IModelElementSpecification> {
/** Stores the underlying component element. */
protected final Component modelElement;
/** Stores the specification of the component element to be simulated. */
protected final S specification;
/** Stores the initialize function. */
protected Function initialize;
/** Stores the performStep function. */
protected Function performStep;
/** Stores the list of variables. */
protected List<Variable> variables = new ArrayList<Variable>();
/** Stores the header file. */
private HeaderFile headerFile;
/** Port variable replacement map. */
protected Map<String, String> portVariableReplacement = new HashMap<String, String>();
/** Constructor. */
public CSourceComponent(Component component, S specification) {
this.modelElement = component;
this.specification = specification;
}
/**
* Initializes the source component. Sub-classes must call this method
* before using {@link #variables}, {@link #performStep} and
* {@link #initialize}.
*/
protected final void initialize() {
addVariables();
this.initialize = createInitializeFunction();
this.performStep = createPerformStepFunction();
}
/** Returns the SourcePackage. */
public abstract SourcePackage getSourcePackage();
/** Creates the performStep function. */
protected abstract Function createPerformStepFunction();
/** Creates the code for initializing the port variables. */
protected final List<IStatementTerm> createPortInitializationCode() {
List<IStatementTerm> body = new LinkedList<IStatementTerm>();
for (IConnector p : modelElement.getConnectorsList()) {
if (p instanceof OutputPort) {
PortSpecification spec = ReflectionUtils.pickInstanceOf(
PortSpecification.class, p.getSpecificationsList());
Var pVar = VarStaticImpl.create(getPortIdentifier((Port) p));
body.add(AssignmentStaticImpl
.create(pVar, (IExpressionTerm) EcoreUtil.copy(spec
.getInitialValue())));
}
}
return body;
}
/** Creates the initialize function. */
@SuppressWarnings("unchecked")
protected Function createInitializeFunction() {
List<IStatementTerm> body = createPortInitializationCode();
body.add(ReturnStaticImpl.create(BoolConstStaticImpl.create(true)));
return Function.createExternFunction(TBoolStaticImpl.create(),
getInitializeFunctionName(), Collections.EMPTY_LIST,
Collections.EMPTY_LIST, body);
}
/** Creates the port variables. */
private void addVariables() {
for (IConnector p : modelElement.getConnectorsList()) {
Port port = (Port) p;
PortSpecification spec = ReflectionUtils.pickInstanceOf(
PortSpecification.class, p.getSpecificationsList());
String portVarName = getPortIdentifier(port);
variables.add(new Variable(Modifier.EXTERN, spec.getType(),
portVarName));
portVariableReplacement.put(port.getName(), portVarName);
}
}
/** Returns the identifier for the model element extended with the ID. */
protected final String getIdentifier() {
return getIdentifier(modelElement);
}
/** Returns the identifier of the given element extended with the ID. */
protected final String getIdentifier(INamedElement element) {
return IdentifierUtils.getUniqueIdentifier(element);
}
/** Returns the identifier for the given port. */
protected final String getPortIdentifier(Port port) {
String prefix = port instanceof InputPort ? "INPORT_" : "OUTPORT_";
return prefix + getIdentifier(port);
}
/** Returns the name of the initialize function. */
protected final String getInitializeFunctionName() {
return "init_" + getIdentifier();
}
/** Returns the name of the performStep function. */
protected final String getPerformStepFunctionName() {
return "perform_step_" + getIdentifier();
}
/** Returns the header file for the model element. */
protected final HeaderFile getHeaderFile() {
if (headerFile == null) {
headerFile = createHeaderFile();
}
return headerFile;
}
/** Creates the header file for the model element. */
protected HeaderFile createHeaderFile() {
HeaderFile hFile = new HeaderFile(getIdentifier());
for (Include inc : getHeaderIncludes()) {
hFile.addImport(inc);
}
for (Variable v : variables) {
hFile.addDeclaration(v.getDeclaration());
}
hFile.addDeclaration(initialize.getDeclaration());
hFile.addDeclaration(performStep.getDeclaration());
return hFile;
}
/** Creates the implementation file for the model element. */
protected SourceUnitBase createImplementationFile() {
ImplementationFile iFile = new ImplementationFile(getIdentifier());
iFile.addImport(new Include(getHeaderFile()));
for (Variable v : variables) {
iFile.addDefinition(v.getDefinition());
}
iFile.addDefinition(initialize.getDefinition());
iFile.addDefinition(performStep.getDefinition());
return iFile;
}
/** Returns the includes of the header file. */
protected List<Include> getHeaderIncludes() {
return new LinkedList<Include>();
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| 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.fortiss.af3.component.generator.c;
import org.fortiss.af3.component.model.Component;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.kernel.extension.ITransformationProvider;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.extension.exception.ChainTransformationFailedException;
import org.fortiss.tooling.kernel.extension.exception.TransformationFailedException;
import org.fortiss.tooling.kernel.utils.TransformationUtils;
/**
* Base implementation for transformation of {@link Component}s into
* {@link CSourceComponent}s
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
// TODO: most of this class is a clone of ExecutableComponentTransformationBase
public abstract class CSourceComponentTransformationBase implements
ITransformationProvider {
/** {@inheritDoc} */
@SuppressWarnings("rawtypes")
@Override
public final Class<CSourceComponent> getTargetClass() {
return CSourceComponent.class;
}
/**
* Creates a C source for the given specification and the given target class
* using the context.
*/
@SuppressWarnings("unchecked")
protected final CSourceComponent<? extends IModelElementSpecification> createExecutableForSpecification(
IModelElementSpecification specification, Class<?> targetClass,
ITransformationContext context)
throws ChainTransformationFailedException {
return (CSourceComponent<? extends IModelElementSpecification>) TransformationUtils
.createTransformedObjectFor(specification, targetClass, context);
}
/**
* Creates a C source for the given component and context. First all
* specifications of the component are searched for a suitable
* transformation. If no such transformation is found the component itself
* is used as the transformation source.
* <P>
* Sub-classes may override this behavior.
*/
@SuppressWarnings("unchecked")
protected CSourceComponent<? extends IModelElementSpecification> createExecutableForComponent(
Component component, ITransformationContext context)
throws TransformationFailedException {
TransformationFailedException lastException = null;
// // try component specifications first
// for (IModelElementSpecification spec : component
// .getSpecificationsList()) {
// try {
// CSourceComponent<? extends IModelElementSpecification> exec =
// createExecutableForSpecification(
// spec, getTargetClass(), context);
// if (exec != null) {
// // found a transformation for the specification, which
// // succeeded
// return exec;
// }
// } catch (ChainTransformationFailedException cex) {
// lastException = cex;
// }
// }
// try component itself
try {
CSourceComponent<? extends IModelElementSpecification> exec = TransformationUtils
.createTransformedObjectFor(component, getTargetClass(),
context);
if (exec != null) {
// found a transformation for the component, which succeeded
return exec;
}
} catch (ChainTransformationFailedException cex) {
// if (lastException == null) {
// component transformation failed
lastException = cex;
// }
}
if (lastException != null) {
// there is a possible transformation, either of specification or
// component, which failed
throw lastException;
}
return null;
}
}