Skip to content
Snippets Groups Projects
Commit a66c0ac7 authored by Simon Spinner's avatar Simon Spinner
Browse files

Initial version of commands framework.

parent 64b74514
No related branches found
No related tags found
No related merge requests found
Showing
with 571 additions and 314 deletions
package tools.descartes.prisma.core;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
......@@ -33,6 +35,10 @@ public class ApplicationModel {
this.name = name;
}
public String getApplicationName() {
return name;
}
public String getResourceLandscapePath() {
return name + "/" + name + ".resourcelandscape";
}
......@@ -53,15 +59,16 @@ public class ApplicationModel {
return name + "/" + name + ".usageprofile";
}
public void update(List<ModelCommand<?>> commands) {
public void update(List<ModelCommand<?,?>> commands) {
boolean successful = false;
int retries = TRANSACTION_RETRIES;
do {
CDOTransaction transaction = connection.startTransaction();
CommandContext context = new CommandContext(this, transaction);
for (ModelCommand<?> currentCommand : commands) {
currentCommand.apply(context);
for (ModelCommand<?,?> currentCommand : commands) {
currentCommand.setContext(context);
}
try {
transaction.commit();
successful = true;
......@@ -79,35 +86,51 @@ public class ApplicationModel {
public void create() {
try {
CDOTransaction transaction = connection.startTransaction();
CDOResourceFolder appFolder = transaction.createResourceFolder(name);
transaction.getOrCreateResourceFolder(name);
CDOResource resourceLandscapeResource = appFolder.addResource(name + ".resourcelandscape");
DistributedDataCenter dataCenter = ResourcelandscapeFactory.eINSTANCE.createDistributedDataCenter();
dataCenter.setName(name);
resourceLandscapeResource.getContents().add(dataCenter);
CDOResource resourceLandscapeResource = transaction.getOrCreateResource(getResourceLandscapePath());
DistributedDataCenter dataCenter;
if (resourceLandscapeResource.getContents().isEmpty()) {
dataCenter = ResourcelandscapeFactory.eINSTANCE.createDistributedDataCenter();
dataCenter.setName(name);
resourceLandscapeResource.getContents().add(dataCenter);
} else {
dataCenter = (DistributedDataCenter)resourceLandscapeResource.getContents().get(0);
}
CDOResource repositoryResource = appFolder.addResource(name + ".repository");
Repository repository = RepositoryFactory.eINSTANCE.createRepository();
repository.setName(name);
repositoryResource.getContents().add(repository);
CDOResource repositoryResource = transaction.getOrCreateResource(getRepositoryPath());
if (repositoryResource.getContents().isEmpty()) {
Repository repository = RepositoryFactory.eINSTANCE.createRepository();
repository.setName(name);
repositoryResource.getContents().add(repository);
}
CDOResource systemResource = appFolder.addResource(name + ".system");
System system = SystemFactory.eINSTANCE.createSystem();
system.setName(name);
systemResource.getContents().add(system);
CDOResource systemResource = transaction.getOrCreateResource(getSystemPath());
System system;
if (systemResource.getContents().isEmpty()) {
system = SystemFactory.eINSTANCE.createSystem();
system.setName(name);
systemResource.getContents().add(system);
} else {
system = (System)systemResource.getContents().get(0);
}
CDOResource deploymentResource = appFolder.addResource(name + ".deployment");
Deployment deployment = DeploymentFactory.eINSTANCE.createDeployment();
deployment.setName(name);
deployment.setSystem(system);
deployment.setTargetResourceLandscape(dataCenter);
deploymentResource.getContents().add(deployment);
CDOResource deploymentResource = transaction.getOrCreateResource(getDeploymentPath());
if (deploymentResource.getContents().isEmpty()) {
Deployment deployment = DeploymentFactory.eINSTANCE.createDeployment();
deployment.setName(name);
deployment.setSystem(system);
deployment.setTargetResourceLandscape(dataCenter);
deploymentResource.getContents().add(deployment);
}
CDOResource usageProfileResource = appFolder.addResource(name + ".usageprofile");
UsageProfile usage = UsageProfileFactory.eINSTANCE.createUsageProfile();
usage.setName(name);
usage.setSystem(system);
usageProfileResource.getContents().add(usage);
CDOResource usageProfileResource = transaction.getOrCreateResource(getUsageProfilePath());
if (usageProfileResource.getContents().isEmpty()) {
UsageProfile usage = UsageProfileFactory.eINSTANCE.createUsageProfile();
usage.setName(name);
usage.setSystem(system);
usageProfileResource.getContents().add(usage);
}
transaction.commit();
} catch(Exception ex) {
......
package tools.descartes.prisma.core.commands;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.AbstractAction;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ComponentInternalBehavior;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ServicebehaviorPackage;
public abstract class AbstractActionCommand<E extends AbstractAction> extends ModelCommand<ComponentInternalBehavior, E> {
private int position = -1;
protected AbstractActionCommand(Class<E> actionType) {
super(ServicebehaviorPackage.Literals.COMPONENT_INTERNAL_BEHAVIOR__ACTIONS, actionType);
}
@Override
protected void insert(ComponentInternalBehavior parent, E action) {
if (position < 0 || position >= parent.getActions().size()) {
parent.getActions().add(action);
} else {
parent.getActions().add(position, action);
}
}
@Override
protected E find(ComponentInternalBehavior parent) {
Class<E> actionType = getElementType();
if (position < 0) {
// the position is unspecified. Search for any object of the required type
for (AbstractAction a : parent.getActions()) {
if (a.getClass().isAssignableFrom(actionType)) {
E obj = actionType.cast(a);
if (matches(obj)) {
return obj;
}
}
}
} else if (position < parent.getActions().size()){
AbstractAction a = parent.getActions().get(position);
if (a.getClass().isAssignableFrom(actionType)) {
E obj = actionType.cast(a);
if (matches(obj)) {
return obj;
}
}
}
return null;
}
public void at(int position) {
this.position = position;
}
}
package tools.descartes.prisma.core.commands;
import java.util.Collection;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.AssemblyConnector;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.AssemblyContext;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceProvidingRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceRequiringRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryFactory;
import edu.kit.ipd.descartes.mm.applicationlevel.system.System;
public class AddAssemblyConnectorCommand extends ModelCommand<AssemblyConnector> {
private final AddAssemblyContextCommand addSourceContext;
private final AddInterfaceRequiringRoleCommand addRequiringRole;
private final AddAssemblyContextCommand addTargetContext;
private final AddInterfaceProvidingRoleCommand addProvidingRole;
public AddAssemblyConnectorCommand(AddAssemblyContextCommand sourceContext, AddInterfaceRequiringRoleCommand requiringRole,
AddAssemblyContextCommand targetContext, AddInterfaceProvidingRoleCommand providingRole) {
this.addSourceContext = sourceContext;
this.addRequiringRole = requiringRole;
this.addTargetContext = targetContext;
this.addProvidingRole = providingRole;
}
@Override
public AssemblyConnector apply(CommandContext ctx) {
AssemblyContext sourceContext = addSourceContext.apply(ctx);
InterfaceRequiringRole requiringRole = addRequiringRole.apply(ctx);
AssemblyContext targetContext = addTargetContext.apply(ctx);
InterfaceProvidingRole providingRole = addProvidingRole.apply(ctx);
System system = ctx.getSystem();
AssemblyConnector connector = find(system.getAssemblyConnectors(), sourceContext, requiringRole, targetContext, providingRole);
if (connector == null) {
connector = RepositoryFactory.eINSTANCE.createAssemblyConnector();
connector.setName(sourceContext.getName() + " -> " + targetContext.getName());
connector.setRequiringAssemblyContext(sourceContext);
connector.setProvidingAssemblyContext(targetContext);
connector.setInterfaceRequiringRole(requiringRole);
connector.setInterfaceProvidingRole(providingRole);
system.getAssemblyConnectors().add(connector);
}
return connector;
}
private AssemblyConnector find(Collection<AssemblyConnector> connectors, AssemblyContext sourceContext,
InterfaceRequiringRole requiringRole, AssemblyContext targetContext, InterfaceProvidingRole providingRole) {
for (AssemblyConnector con : connectors) {
if (con.getRequiringAssemblyContext().equals(sourceContext)) {
if (con.getInterfaceRequiringRole().equals(requiringRole)) {
if (con.getProvidingAssemblyContext().equals(targetContext)) {
if (con.getInterfaceProvidingRole().equals(providingRole)) {
return con;
}
}
}
}
}
return null;
}
}
package tools.descartes.prisma.core.commands;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Repository;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryComponent;
public abstract class AddComponentCommand<E extends RepositoryComponent> extends ModelCommand<RepositoryComponent> {
private final String componentName;
public AddComponentCommand(String componentName) {
this.componentName = componentName;
}
@Override
public E apply(CommandContext ctx) {
Repository repository = ctx.getRepository();
RepositoryComponent component = find(repository.getComponents(), componentName);
if (component == null) {
component = createRepositoryComponent();
component.setId("Component_" + getId(componentName));
component.setName(componentName);
repository.getComponents().add(component);
}
return (E)component;
}
protected abstract E createRepositoryComponent();
public String getComponentName() {
return componentName;
}
}
package tools.descartes.prisma.core.commands;
public class AddExternalCallCommand {
}
package tools.descartes.prisma.core.commands;
import java.util.Collection;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.BasicComponent;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceProvidingRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Signature;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.FineGrainedBehavior;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ServicebehaviorFactory;
public class AddFineGrainedBehaviorCommand extends ModelCommand<FineGrainedBehavior> {
private final AddBasicComponentCommand addComponent;
private final AddInterfaceProvidingRoleCommand addProvidingRole;
private final AddSignatureCommand addSignature;
public AddFineGrainedBehaviorCommand(AddBasicComponentCommand addComponent, AddInterfaceProvidingRoleCommand addProvidingRole, AddSignatureCommand addSignature) {
this.addComponent = addComponent;
this.addProvidingRole = addProvidingRole;
this.addSignature = addSignature;
}
@Override
public FineGrainedBehavior apply(CommandContext ctx) {
BasicComponent component = addComponent.apply(ctx);
InterfaceProvidingRole providingRole = addProvidingRole.apply(ctx);
Signature signature = addSignature.apply(ctx);
FineGrainedBehavior behavior = find(component.getFineGrainedBehavior(), providingRole, signature);
if (behavior == null) {
behavior = ServicebehaviorFactory.eINSTANCE.createFineGrainedBehavior();
behavior.setInterfaceProvidingRole(providingRole);
behavior.setDescribedSignature(signature);
behavior.setBehavior(ServicebehaviorFactory.eINSTANCE.createComponentInternalBehavior());
}
return behavior;
}
private FineGrainedBehavior find(Collection<FineGrainedBehavior> behaviors, InterfaceProvidingRole providingRole, Signature signature) {
for (FineGrainedBehavior cur : behaviors) {
if (cur.getInterfaceProvidingRole().equals(providingRole)) {
if (cur.getDescribedSignature().equals(signature)) {
return cur;
}
}
}
return null;
}
}
package tools.descartes.prisma.core.commands;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Interface;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Repository;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryFactory;
public class AddInterfaceCommand extends ModelCommand<Interface> {
private final String interfaceName;
public AddInterfaceCommand(String interfaceName) {
this.interfaceName = interfaceName;
}
@Override
public Interface apply(CommandContext ctx) {
Repository repository = ctx.getRepository();
Interface curInterface = find(repository.getInterfaces(), interfaceName);
if (curInterface == null) {
curInterface = RepositoryFactory.eINSTANCE.createInterface();
curInterface.setId("Interface_" + getId(interfaceName));
curInterface.setName(interfaceName);
repository.getInterfaces().add(curInterface);
}
return curInterface;
}
}
package tools.descartes.prisma.core.commands;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Interface;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceProvidingRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryComponent;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryFactory;
public class AddInterfaceProvidingRoleCommand extends ModelCommand<InterfaceProvidingRole> {
private final String portName;
private final AddComponentCommand addComponent;
private final AddInterfaceCommand addInterface;
public AddInterfaceProvidingRoleCommand(String portName, AddComponentCommand addComponent, AddInterfaceCommand addInterface) {
this.portName = portName;
this.addComponent = addComponent;
this.addInterface = addInterface;
}
@Override
public InterfaceProvidingRole apply(CommandContext ctx) {
Interface interf = addInterface.apply(ctx);
RepositoryComponent component = addComponent.apply(ctx);
String name = component.getName() + "#Prov:" + interf.getName();
if (!portName.isEmpty()) {
name = name + ":" + portName;
}
InterfaceProvidingRole providingRole = find(component.getInterfaceProvidingRoles(), name);
if (providingRole == null) {
providingRole = RepositoryFactory.eINSTANCE.createInterfaceProvidingRole();
providingRole.setName(name);
providingRole.setInterface(interf);
component.getInterfaceProvidingRoles().add(providingRole);
}
return providingRole;
}
}
package tools.descartes.prisma.core.commands;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Interface;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceRequiringRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryComponent;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryFactory;
public class AddInterfaceRequiringRoleCommand extends ModelCommand<InterfaceRequiringRole> {
private final String portName;
private final AddComponentCommand addComponent;
private final AddInterfaceCommand addInterface;
public AddInterfaceRequiringRoleCommand(AddComponentCommand addComponent, AddInterfaceCommand addInterface, String portName) {
this.portName = portName;
this.addComponent = addComponent;
this.addInterface = addInterface;
}
@Override
public InterfaceRequiringRole apply(CommandContext ctx) {
Interface interf = addInterface.apply(ctx);
RepositoryComponent component = addComponent.apply(ctx);
String name = component.getName() + "#Req:" + interf.getName();
if (!portName.isEmpty()) {
name = name + ":" + portName;
}
InterfaceRequiringRole requiringRole = find(component.getInterfaceRequiringRoles(), name);
if (requiringRole == null) {
requiringRole = RepositoryFactory.eINSTANCE.createInterfaceRequiringRole();
requiringRole.setName(name);
requiringRole.setInterface(interf);
component.getInterfaceRequiringRoles().add(requiringRole);
}
return requiringRole;
}
}
package tools.descartes.prisma.core.commands;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.AssemblyConnector;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.AssemblyContext;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.ComposedStructure;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceProvidingRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceRequiringRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryFactory;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryPackage;
public class AssemblyConnectorCommand extends ModelCommand<ComposedStructure, AssemblyConnector> {
private final AssemblyContextCommand addSourceContext;
private final InterfaceRequiringRoleCommand addRequiringRole;
private final AssemblyContextCommand addTargetContext;
private final InterfaceProvidingRoleCommand addProvidingRole;
public AssemblyConnectorCommand(AssemblyContextCommand sourceContext, InterfaceRequiringRoleCommand requiringRole,
AssemblyContextCommand targetContext, InterfaceProvidingRoleCommand providingRole) {
super(RepositoryPackage.Literals.COMPOSED_STRUCTURE__ASSEMBLY_CONNECTORS, AssemblyConnector.class);
this.addSourceContext = sourceContext;
this.addRequiringRole = requiringRole;
this.addTargetContext = targetContext;
this.addProvidingRole = providingRole;
}
@Override
public boolean matches(AssemblyConnector connector) {
return addSourceContext.matches(connector.getRequiringAssemblyContext())
&& addRequiringRole.matches(connector.getInterfaceRequiringRole())
&& addTargetContext.matches(connector.getProvidingAssemblyContext())
&& addProvidingRole.matches(connector.getInterfaceProvidingRole());
}
@Override
protected AssemblyConnector create(ComposedStructure parent) {
AssemblyContext sourceContext = addSourceContext.get(parent);
InterfaceRequiringRole requiringRole = addRequiringRole.get(sourceContext.getEncapsulatedComponent());
AssemblyContext targetContext = addTargetContext.get(parent);
InterfaceProvidingRole providingRole = addProvidingRole.get(sourceContext.getEncapsulatedComponent());
AssemblyConnector connector = RepositoryFactory.eINSTANCE.createAssemblyConnector();
connector.setName(sourceContext.getName() + " -> " + targetContext.getName());
connector.setRequiringAssemblyContext(sourceContext);
connector.setProvidingAssemblyContext(targetContext);
connector.setInterfaceRequiringRole(requiringRole);
connector.setInterfaceProvidingRole(providingRole);
return connector;
}
}
package tools.descartes.prisma.core.commands;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.AssemblyContext;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.ComposedStructure;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryComponent;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryFactory;
import edu.kit.ipd.descartes.mm.applicationlevel.system.System;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryPackage;
public class AddAssemblyContextCommand extends ModelCommand<AssemblyContext> {
public class AssemblyContextCommand extends ModelCommand<ComposedStructure, AssemblyContext> {
private final String assemblyContextName;
private final AddComponentCommand component;
private final RepositoryComponentCommand<?> component;
public AddAssemblyContextCommand(String assemblyContextName, AddComponentCommand component) {
public AssemblyContextCommand(String assemblyContextName, RepositoryComponentCommand<?> component) {
super(RepositoryPackage.Literals.COMPOSED_STRUCTURE__ASSEMBLY_CONTEXTS, AssemblyContext.class);
this.assemblyContextName = assemblyContextName;
this.component = component;
}
@Override
public AssemblyContext apply(CommandContext ctx) {
RepositoryComponent encapsulated = component.apply(ctx);
System system = ctx.getSystem();
AssemblyContext assembly = find(system.getAssemblyContexts(), assemblyContextName);
if (assembly == null) {
assembly = RepositoryFactory.eINSTANCE.createAssemblyContext();
assembly.setId("AssemblyContext_" + getId(assemblyContextName));
assembly.setName(assemblyContextName);
system.getAssemblyContexts().add(assembly);
}
public boolean matches(AssemblyContext object) {
return object.getName().equals(assemblyContextName);
}
@Override
protected AssemblyContext create(ComposedStructure parent) {
RepositoryCommand repo = new RepositoryCommand();
repo.setContext(getContext());
RepositoryComponent encapsulated = component.get(repo.get(null));
AssemblyContext assembly = RepositoryFactory.eINSTANCE.createAssemblyContext();
assembly.setId("AssemblyContext_" + getId(assemblyContextName));
assembly.setName(assemblyContextName);
RepositoryComponent current = assembly.getEncapsulatedComponent();
if (current != encapsulated) {
if (current != null) {
......@@ -36,7 +37,7 @@ public class AddAssemblyContextCommand extends ModelCommand<AssemblyContext> {
//log.warn("Encapsulated component of assembly context " + assemblyContextName + " will be overwritten (current=" + current.getName() + ", new=" + encapsulated.getName() + ").");
}
assembly.setEncapsulatedComponent(encapsulated);
}
}
return assembly;
}
}
package tools.descartes.prisma.core.commands;
import java.util.LinkedList;
import java.util.List;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.BasicComponent;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryFactory;
public class AddBasicComponentCommand extends AddComponentCommand<BasicComponent> {
public class BasicComponentCommand extends RepositoryComponentCommand<BasicComponent> {
private final List<FineGrainedBehaviorCommand> fineGrainedBehaviors = new LinkedList<>();
public AddBasicComponentCommand(String componentName) {
super(componentName);
public BasicComponentCommand(String componentName) {
super(componentName, BasicComponent.class);
}
@Override
public List<ModelCommand<? super BasicComponent, ?>> getChildCommands() {
List<ModelCommand<? super BasicComponent, ?>> list = super.getChildCommands();
list.addAll(fineGrainedBehaviors);
return list;
}
@Override
protected BasicComponent createRepositoryComponent() {
return RepositoryFactory.eINSTANCE.createBasicComponent();
......
......@@ -2,7 +2,6 @@ package tools.descartes.prisma.core.commands;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.ecore.EObject;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Repository;
import edu.kit.ipd.descartes.mm.applicationlevel.system.System;
......@@ -26,44 +25,29 @@ public class CommandContext {
this.application = application;
this.transaction = transaction;
}
public String getApplicationName() {
return application.getApplicationName();
}
public DistributedDataCenter getResourceLandscape() {
if (resourcelandscape == null) {
resourcelandscape = (DistributedDataCenter)load(application.getResourceLandscapePath());
}
return resourcelandscape;
public CDOResource getResourceLandscape() {
return transaction.getOrCreateResource(application.getResourceLandscapePath());
}
public Repository getRepository() {
if (repository == null) {
repository = (Repository)load(application.getRepositoryPath());
}
return repository;
public CDOResource getRepository() {
return transaction.getOrCreateResource(application.getRepositoryPath());
}
public System getSystem() {
if (system == null) {
system = (System)load(application.getSystemPath());
}
return system;
public CDOResource getSystem() {
return transaction.getOrCreateResource(application.getSystemPath());
}
public Deployment getDeployment() {
if (deployment == null) {
deployment = (Deployment)load(application.getDeploymentPath());
}
return deployment;
public CDOResource getDeployment() {
return transaction.getOrCreateResource(application.getDeploymentPath());
}
public UsageProfile getUsageProfile() {
if (usageProfile == null) {
usageProfile = (UsageProfile)load(application.getUsageProfilePath());
}
return usageProfile;
public CDOResource getUsageProfile() {
return transaction.getOrCreateResource(application.getUsageProfilePath());
}
private EObject load(String path) {
CDOResource resource = transaction.getResource(path);
return resource.getContents().get(0);
}
}
package tools.descartes.prisma.core.commands;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ComponentInternalBehavior;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ServicebehaviorFactory;
public class ComponentInternalBehaviorCommand<P extends EObject> extends ModelCommand<P, ComponentInternalBehavior> {
private List<AbstractActionCommand<?>> actions = new LinkedList<>();
protected ComponentInternalBehaviorCommand(EStructuralFeature container) {
super(container, ComponentInternalBehavior.class);
}
@Override
public List<AbstractActionCommand<?>> getChildCommands() {
return actions;
}
@Override
public boolean matches(ComponentInternalBehavior object) {
// There should always be only on internal behavior below a parent object
return true;
}
@Override
protected ComponentInternalBehavior create(P parent) {
return ServicebehaviorFactory.eINSTANCE.createComponentInternalBehavior();
}
public void add(AbstractActionCommand<?> action) {
actions.add(action);
}
}
package tools.descartes.prisma.core.commands;
import org.eclipse.emf.ecore.EObject;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceRequiringRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryComponent;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Signature;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ComponentInternalBehavior;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ExternalCall;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ExternalCallAction;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ServicebehaviorFactory;
public class ExternalCallActionCommand extends AbstractActionCommand<ExternalCallAction> {
private InterfaceRequiringRoleCommand requiringRoleCmd;
private SignatureCommand signatureCmd;
protected ExternalCallActionCommand() {
super(ExternalCallAction.class);
}
@Override
protected ExternalCallAction create(ComponentInternalBehavior parent) {
RepositoryComponent comp = getComponent(parent);
ExternalCall extOperation = ServicebehaviorFactory.eINSTANCE.createExternalCall();
InterfaceRequiringRole extInterfaceRole = requiringRoleCmd.get(comp);
Signature signature = signatureCmd.get(extInterfaceRole.getInterface());
extOperation.setName(signature.getName());
extOperation.setInterfaceRequiringRole(extInterfaceRole);
extOperation.setSignature(signature);
ExternalCallAction callAction = ServicebehaviorFactory.eINSTANCE.createExternalCallAction();
callAction.setExternalCall(extOperation);
return callAction;
}
@Override
public boolean matches(ExternalCallAction a) {
return requiringRoleCmd.matches(a.getExternalCall().getInterfaceRequiringRole())
&& signatureCmd.matches(a.getExternalCall().getSignature());
}
private RepositoryComponent getComponent(ComponentInternalBehavior parent) {
EObject current = parent;
while(current != null) {
if (current.getClass().isAssignableFrom(RepositoryComponent.class)) {
return (RepositoryComponent)current;
}
current = parent.eContainer();
}
throw new IllegalStateException();
}
}
package tools.descartes.prisma.core.commands;
import java.util.Collections;
import java.util.List;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.BasicComponent;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceProvidingRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryPackage;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Signature;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.FineGrainedBehavior;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ServicebehaviorFactory;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ServicebehaviorPackage;
public class FineGrainedBehaviorCommand extends ModelCommand<BasicComponent, FineGrainedBehavior> {
private final ComponentInternalBehaviorCommand<FineGrainedBehavior> internalBehaviorCmd = new ComponentInternalBehaviorCommand<>(ServicebehaviorPackage.Literals.FINE_GRAINED_BEHAVIOR__BEHAVIOR);
private final InterfaceProvidingRoleCommand addProvidingRoleCmd;
private final SignatureCommand addSignatureCmd;
private FineGrainedBehaviorCommand(InterfaceProvidingRoleCommand addProvidingRole, SignatureCommand addSignature) {
super(RepositoryPackage.Literals.BASIC_COMPONENT__FINE_GRAINED_BEHAVIOR, FineGrainedBehavior.class);
this.addProvidingRoleCmd = addProvidingRole;
this.addSignatureCmd = addSignature;
}
@Override
public boolean matches(FineGrainedBehavior object) {
return addProvidingRoleCmd.matches(object.getInterfaceProvidingRole())
&& addSignatureCmd.matches(object.getDescribedSignature());
}
@Override
protected FineGrainedBehavior create(BasicComponent parent) {
InterfaceProvidingRole providingRole = addProvidingRoleCmd.get(parent);
Signature signature = addSignatureCmd.get(providingRole.getInterface());
FineGrainedBehavior behavior = ServicebehaviorFactory.eINSTANCE.createFineGrainedBehavior();
behavior.setInterfaceProvidingRole(providingRole);
behavior.setDescribedSignature(signature);
behavior.setBehavior(ServicebehaviorFactory.eINSTANCE.createComponentInternalBehavior());
return behavior;
}
@Override
public List<? extends ModelCommand<? super FineGrainedBehavior, ?>> getChildCommands() {
return Collections.singletonList(internalBehaviorCmd);
}
public static FineGrainedBehaviorCommand fineGrainedBehavior(InterfaceProvidingRoleCommand addProvidingRole, SignatureCommand addSignature) {
return new FineGrainedBehaviorCommand(addProvidingRole, addSignature);
}
public void add(AbstractActionCommand<?> action) {
internalBehaviorCmd.add(action);
}
}
package tools.descartes.prisma.core.commands;
import java.util.LinkedList;
import java.util.List;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Interface;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Repository;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryFactory;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryPackage;
public class InterfaceCommand extends ModelCommand<Repository, Interface> {
private final String interfaceName;
private final List<SignatureCommand> signatures = new LinkedList<>();
private InterfaceCommand(String interfaceName) {
super(RepositoryPackage.Literals.REPOSITORY__INTERFACES, Interface.class);
this.interfaceName = interfaceName;
}
@Override
protected Interface create(Repository repository) {
Interface curInterface = RepositoryFactory.eINSTANCE.createInterface();
curInterface.setId("Interface_" + getId(interfaceName));
curInterface.setName(interfaceName);
return curInterface;
}
@Override
public boolean matches(Interface object) {
return object.getName().equals(interfaceName);
}
@Override
public List<? extends ModelCommand<Interface, ?>> getChildCommands() {
return signatures;
}
public static InterfaceCommand _interface(String name) {
return new InterfaceCommand(name);
}
public InterfaceCommand add(SignatureCommand signature) {
signatures.add(signature);
return this;
}
}
package tools.descartes.prisma.core.commands;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Interface;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceProvidingRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceRequiringRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryComponent;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryFactory;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryPackage;
public class InterfaceProvidingRoleCommand extends ModelCommand<RepositoryComponent, InterfaceProvidingRole> {
private final String portName;
private final InterfaceCommand interfaceCmd;
private InterfaceProvidingRoleCommand(String portName, InterfaceCommand addInterface) {
super(RepositoryPackage.Literals.INTERFACE_PROVIDING_ENTITY__INTERFACE_PROVIDING_ROLES, InterfaceProvidingRole.class);
this.portName = portName;
this.interfaceCmd = addInterface;
}
@Override
public boolean matches(InterfaceProvidingRole object) {
return object.getName().equals(portName)
&& interfaceCmd.matches(object.getInterface());
}
@Override
protected InterfaceProvidingRole create(RepositoryComponent parent) {
Interface interf = interfaceCmd.get(parent.getRepository());
InterfaceProvidingRole providingRole = RepositoryFactory.eINSTANCE.createInterfaceProvidingRole();
providingRole.setName(portName);
providingRole.setInterface(interf);
return providingRole;
}
public static InterfaceProvidingRoleCommand interfaceProvidingRole(String portName, InterfaceCommand addInterface) {
return new InterfaceProvidingRoleCommand(portName, addInterface);
}
}
package tools.descartes.prisma.core.commands;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.Interface;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.InterfaceRequiringRole;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryComponent;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryFactory;
import edu.kit.ipd.descartes.mm.applicationlevel.repository.RepositoryPackage;
public class InterfaceRequiringRoleCommand extends ModelCommand<RepositoryComponent, InterfaceRequiringRole> {
private final String portName;
private final InterfaceCommand interfaceCmd;
private InterfaceRequiringRoleCommand(InterfaceCommand addInterface, String portName) {
super(RepositoryPackage.Literals.INTERFACE_REQUIRING_ENTITY__INTERFACE_REQUIRING_ROLES, InterfaceRequiringRole.class);
this.portName = portName;
this.interfaceCmd = addInterface;
}
@Override
public boolean matches(InterfaceRequiringRole object) {
return object.getName().equals(portName)
&& interfaceCmd.matches(object.getInterface());
}
@Override
protected InterfaceRequiringRole create(RepositoryComponent parent) {
Interface interf = interfaceCmd.get(parent.getRepository());
InterfaceRequiringRole requiringRole = RepositoryFactory.eINSTANCE.createInterfaceRequiringRole();
requiringRole.setName(portName);
requiringRole.setInterface(interf);
return requiringRole;
}
public static InterfaceRequiringRoleCommand interfaceRequiringRole(InterfaceCommand addInterface, String portName) {
return new InterfaceRequiringRoleCommand(addInterface, portName);
}
}
package tools.descartes.prisma.core.commands;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import edu.kit.ipd.descartes.mm.applicationlevel.parameterdependencies.ModelVariableCharacterizationType;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ComponentInternalBehavior;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.LoopAction;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.LoopIterationCount;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ServicebehaviorFactory;
import edu.kit.ipd.descartes.mm.applicationlevel.servicebehavior.ServicebehaviorPackage;
public class LoopActionCommand extends AbstractActionCommand<LoopAction> {
private final ComponentInternalBehaviorCommand<LoopAction> loopBehaviorCmd = new ComponentInternalBehaviorCommand<>(ServicebehaviorPackage.Literals.LOOP_ACTION__LOOP_BODY_BEHAVIOR);
private LoopActionCommand() {
super(LoopAction.class);
}
@Override
protected LoopAction create(ComponentInternalBehavior parent) {
LoopAction loop = ServicebehaviorFactory.eINSTANCE.createLoopAction();
LoopIterationCount invocations = ServicebehaviorFactory.eINSTANCE.createLoopIterationCount();
invocations.setCharacterization(ModelVariableCharacterizationType.EMPIRICAL);
loop.setLoopIterationCount(invocations);
ComponentInternalBehavior behavior = ServicebehaviorFactory.eINSTANCE.createComponentInternalBehavior();
loop.setLoopBodyBehavior(behavior);
return loop;
}
@Override
public boolean matches(LoopAction a) {
for (ModelCommand<ComponentInternalBehavior, ?> cmd : loopBehaviorCmd.getChildCommands()) {
if (cmd.find(a.getLoopBodyBehavior()) == null) {
return false;
}
}
return true;
}
@Override
public List<? extends ModelCommand<LoopAction, ?>> getChildCommands() {
return Collections.singletonList(loopBehaviorCmd);
}
public void add(AbstractActionCommand<?> cmd) {
loopBehaviorCmd.add(cmd);
}
public static LoopActionCommand loop() {
return new LoopActionCommand();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment