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

af3.deployment complete

refs 190
parent 758cb931
/*--------------------------------------------------------------------------+
$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.deployment.generator;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
/**
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class ComponentCodeTransformationContext extends
DeploymentTransformationContext {
/** Stores the {@link ExecutionUnit} for the component code. */
private final ExecutionUnit executionUnit;
/** Constructor. */
public ComponentCodeTransformationContext(Deployment deployment,
ExecutionUnit executionUnit, ITransformationContext original) {
super(deployment, original);
this.executionUnit = executionUnit;
}
/** Returns the execution unit. */
public ExecutionUnit getExecutionUnit() {
return executionUnit;
}
}
/*--------------------------------------------------------------------------+
$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.deployment.generator;
import java.util.HashMap;
import java.util.Map;
import org.fortiss.af3.component.generator.c.CSourceComponent;
import org.fortiss.af3.component.generator.model.base.SourcePackage;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.deployment.model.TransmissionCatalog;
import org.fortiss.af3.deployment.transform.ComponentCodeTransformationContext;
import org.fortiss.af3.deployment.transform.DeploymentTransformationContext;
import org.fortiss.af3.deployment.transform.TransceiverTransformationContext;
import org.fortiss.af3.deployment.utils.DeploymentUtils;
import org.fortiss.af3.platform.language.executable.ExecutionUnitExecutableBase;
import org.fortiss.af3.platform.language.executable.PlatformArchitectureExecutable;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.platform.model.PlatformArchitecture;
import org.fortiss.af3.platform.model.Transceiver;
import org.fortiss.af3.platform.model.TransmissionUnit;
import org.fortiss.af3.platform.utils.PlatformArchitectureUtils;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.extension.exception.ChainTransformationFailedException;
import org.fortiss.tooling.kernel.utils.TransformationUtils;
/**
* Executable generated by the deployment transformation.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class DeploymentExecutable {
/** Stores the deployment. */
private final Deployment deployment;
/** Stores the current transformation context. */
private final ITransformationContext context;
/** Stores the platform executable. */
private final PlatformArchitectureExecutable platformExecutable;
/** Stores the transmission catalog mapping of {@link TransmissionUnit}s. */
private final Map<TransmissionUnit, TransmissionCatalog> unitCatalog = new HashMap<TransmissionUnit, TransmissionCatalog>();
/** Stores the transmission catalog mapping of {@link Transceiver}s. */
private final Map<Transceiver, TransmissionCatalog> transceiverCatalog = new HashMap<Transceiver, TransmissionCatalog>();
/** Stores the source code mapping of {@link Component}s. */
private final Map<Component, CSourceComponent<?>> componentSource = new HashMap<Component, CSourceComponent<?>>();
/** Constructor. */
public DeploymentExecutable(Deployment deployment,
ITransformationContext context)
throws ChainTransformationFailedException {
this.deployment = deployment;
this.context = context;
platformExecutable = TransformationUtils.createTransformedObjectFor(
deployment.getPlatformArchitectureReference().getReference(),
PlatformArchitectureExecutable.class, context);
createTransmissionUnitCatalogs();
createTransceiverUnitCatalogs();
// create component source
for (ExecutionUnit eu : DeploymentUtils
.findDeployedExecutionUnits(deployment)) {
for (Component component : DeploymentUtils
.findDeployedComponentFor(deployment, eu)) {
createComponentCode(component, eu);
}
}
}
/** Returns the source package for the whole deployment source. */
public SourcePackage getSourcePackage() {
SourcePackage deploymentPackage = new SourcePackage(".");
for (ExecutionUnit eu : DeploymentUtils
.findDeployedExecutionUnits(deployment)) {
ExecutionUnitExecutableBase<?> exec = platformExecutable
.getExecutable(eu);
exec.createSourcePackage(this);
deploymentPackage.addSubPackage(exec.getSourcePackage());
}
return deploymentPackage;
}
/** Returns the deployment. */
public Deployment getDeployment() {
return deployment;
}
/** Returns the platform executable. */
public PlatformArchitectureExecutable getPlatformExecutable() {
return platformExecutable;
}
/** Returns the transmission catalog for the given unit. */
public TransmissionCatalog getTransmissionCatalog(TransmissionUnit tu) {
return unitCatalog.get(tu);
}
/** Returns the transmission catalog for the given transceiver. */
public TransmissionCatalog getTransmissionCatalog(Transceiver t) {
return transceiverCatalog.get(t);
}
/** Returns the source code for the given component. */
public CSourceComponent<?> getComponentSource(Component component) {
return componentSource.get(component);
}
/** Creates the {@link TransmissionCatalog} for the transceivers. */
private void createTransceiverUnitCatalogs()
throws ChainTransformationFailedException {
// TODO (FH): null check for reference
for (Transceiver tc : PlatformArchitectureUtils
.findAtomicExecutionUnitTransceivers((PlatformArchitecture) deployment
.getPlatformArchitectureReference().getReference())) {
TransmissionUnit tu = PlatformArchitectureUtils
.findConnectedTransmissionUnit(tc);
TransmissionCatalog tcat = this.getTransmissionCatalog(tu);
TransceiverTransformationContext tContext = new TransceiverTransformationContext(
deployment, tu, tcat, context);
TransmissionCatalog tres = TransformationUtils
.createTransformedObjectFor(tc, TransmissionCatalog.class,
tContext);
if (tres != null) {
transceiverCatalog.put(tc, tres);
}
}
}
/** Creates the {@link TransmissionCatalog} for the transmission units. */
private void createTransmissionUnitCatalogs()
throws ChainTransformationFailedException {
DeploymentTransformationContext deploymentContext = new DeploymentTransformationContext(
deployment, context);
// TODO (FH): null check for reference
for (TransmissionUnit tu : PlatformArchitectureUtils
.findAtomicTransmissionUnits((PlatformArchitecture) deployment
.getPlatformArchitectureReference().getReference())) {
TransmissionCatalog tc = TransformationUtils
.createTransformedObjectFor(tu, TransmissionCatalog.class,
deploymentContext);
if (tc != null) {
unitCatalog.put(tu, tc);
}
}
}
/** Creates the code executables for the deployed components. */
private void createComponentCode(Component component, ExecutionUnit unit)
throws ChainTransformationFailedException {
ComponentCodeTransformationContext cContext = new ComponentCodeTransformationContext(
deployment, unit, context);
CSourceComponent<?> sourceCode = TransformationUtils
.createTransformedObjectFor(component, CSourceComponent.class,
cContext);
if (sourceCode != null) {
componentSource.put(component, sourceCode);
}
}
}
/*--------------------------------------------------------------------------+
$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.deployment.generator;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.tooling.kernel.extension.ITransformationProvider;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.extension.exception.TransformationFailedException;
/**
* Transformation from {@link Deployment} to {@link DeploymentExecutable}.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class DeploymentTransformation implements ITransformationProvider {
/** {@inheritDoc} */
@Override
public Class<?> getTargetClass() {
return DeploymentExecutable.class;
}
/** {@inheritDoc} */
@Override
public boolean canHandleChainTransformation(Class<?> sourceClass,
ITransformationContext context) {
return Deployment.class.isAssignableFrom(sourceClass);
}
/** {@inheritDoc} */
@Override
public boolean canTransform(Object source, ITransformationContext context) {
return source instanceof Deployment;
}
/** {@inheritDoc} */
@Override
public Object transform(Object source, ITransformationContext context)
throws TransformationFailedException {
Deployment deployment = (Deployment) source;
DeploymentExecutable deploymentExecutable = new DeploymentExecutable(
deployment, context);
return deploymentExecutable;
}
}
/*--------------------------------------------------------------------------+
$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.deployment.generator;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.extension.data.ModelElementTransformationContext;
/**
* {@link ITransformationContext} referencing a deployment.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class DeploymentTransformationContext extends
ModelElementTransformationContext {
/** Constructor. */
public DeploymentTransformationContext(Deployment deployment,
ITransformationContext original) {
super(deployment, original);
}
/** Returns the deployment. */
public Deployment getDeployment() {
return (Deployment) modelElement;
}
}
/*--------------------------------------------------------------------------+
$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.deployment.generator;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.deployment.model.TransmissionCatalog;
import org.fortiss.af3.platform.model.TransmissionUnit;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
/**
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class TransceiverTransformationContext extends
DeploymentTransformationContext {
/** Stores the corresponding transmission unit catalog. */
private final TransmissionCatalog transmissionUnitCatalog;
/** Stores the transmission unit. */
private final TransmissionUnit transmissionUnit;
/** Constructor. */
public TransceiverTransformationContext(Deployment deployment,
TransmissionUnit transmissionUnit, TransmissionCatalog catalog,
ITransformationContext original) {
super(deployment, original);
this.transmissionUnit = transmissionUnit;
this.transmissionUnitCatalog = catalog;
}
/** Returns the transmission unit. */
public TransmissionUnit getTransmissionUnit() {
return transmissionUnit;
}
/** Returns the transmission catalog. */
public TransmissionCatalog getTransmissionUnitCatalog() {
return transmissionUnitCatalog;
}
}
/*--------------------------------------------------------------------------+
$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.deployment.generator;
import java.util.LinkedList;
import java.util.List;
import org.conqat.lib.commons.collections.Pair;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.platform.model.Transceiver;
/**
* This class models members of {@link TransmissionCatalog}s. Each transmission
* object stores the sender and receiver ports of the component architecture as
* well as the sending and receiving transceivers.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class Transmission {
/** Stores the source port from the component architecture. */
private final OutputPort portSource;
/** Stores the source transceiver from the platform architecture. */
private final Transceiver transceiverSource;
/** Stores the list of target port and target transceiver pairs. */
private final List<Pair<InputPort, Transceiver>> targetList;
/** Constructor. */
public Transmission(OutputPort port, Transceiver transceiver) {
this.portSource = port;
this.transceiverSource = transceiver;
this.targetList = new LinkedList<Pair<InputPort, Transceiver>>();
}
/** Adds the given target to this transmission. */
public void addTarget(InputPort port, Transceiver transceiver) {
targetList.add(new Pair<InputPort, Transceiver>(port, transceiver));
}
/** Returns the source port. */
public OutputPort getSourcePort() {
return portSource;
}
/** Returns the source transceiver. */
public Transceiver getSourceTransceiver() {
return transceiverSource;
}
}
/*--------------------------------------------------------------------------+
$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.deployment.generator;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class TransmissionCatalog {
/** Stores the transmissions contained in this catalog. */
private final List<Transmission> transmissions = new ArrayList<Transmission>();
/** Adds the given transmission to the catalog. */
public void addTransmission(Transmission transmission) {
transmissions.add(transmission);
}
}
/*--------------------------------------------------------------------------+
$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.deployment.utils;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.deployment.model.ComponentAllocation;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.platform.model.ExecutionUnit;
/**
* Utility methods for {@link Deployment}s.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class DeploymentUtils {
/**
* Returns the collection of atomic execution units with at least one
* deployed component.
*/
public static Collection<ExecutionUnit> findDeployedExecutionUnits(
Deployment deployment) {
Set<ExecutionUnit> result = new HashSet<ExecutionUnit>();
for (ComponentAllocation ca : deployment.getComponentAllocationsList()) {
result.add(ca.getExecutionUnit());
}
return result;
}
/**
* Returns the collection of components deployed to the given execution