if (!canExecute()) {
throw new ExecutionException(
"Invalid arguments in create link command"); //$NON-NLS-1$
}
ConnectionExpression newElement = ExpressionsFactory.eINSTANCE
.createConnectionExpression();
newElement.setConnectionOperator(OperatorsFactory.eINSTANCE
.createConnector());
eu.admire.dispel.containers.DispelFunction fnc = null;
EObject container;
if (getSource() instanceof Output && getTarget() instanceof Input) {
IdentifierReference src1 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
IdentifierReference src2 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
src1.setNext(src2);
src2.setTarget((Output) getSource());
Output out = (Output) getSource();
fnc = out.getContainingMethod();
container = out.eContainer();
if (container instanceof ProcessingElementInstance) {
ProcessingElementInstance pei = (ProcessingElementInstance) container;
Collection<LocalVariable> variables = DispelEObjectUtil
.getObjectsByType(fnc.eAllContents(),
VariablesPackage.eINSTANCE.getLocalVariable());
for (LocalVariable var : variables) {
if (var.getValue() != null && var.getValue().equals(pei)) {
src1.setTarget(var);
}
}
}
/*******************************/
IdentifierReference dst1 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
IdentifierReference dst2 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
dst1.setNext(dst2);
dst2.setTarget((Input) getTarget());
Input in = (Input) getTarget();
container = in.eContainer();
if (container instanceof ProcessingElementInstance) {
ProcessingElementInstance pei = (ProcessingElementInstance) container;
Collection<LocalVariable> variables = DispelEObjectUtil
.getObjectsByType(fnc.eAllContents(),
VariablesPackage.eINSTANCE.getLocalVariable());
for (LocalVariable var : variables) {
if (var.getValue() != null && var.getValue().equals(pei)) {
dst1.setTarget(var);
}
}
}
newElement.setChild(src1);
newElement.setValue(dst1);
}
//TODO iFO following might be buggy!
if (getSource() instanceof ConnectionInitialization
&& getTarget() instanceof Input) {
IdentifierReference dst1 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
IdentifierReference dst2 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
dst1.setNext(dst2);
dst2.setTarget((Input) getTarget());
Input in = (Input) getTarget();
fnc = in.getContainingMethod();
container = in.eContainer();
if (container instanceof ProcessingElementInstance) {
ProcessingElementInstance pei = (ProcessingElementInstance) container;
Collection<LocalVariable> variables = DispelEObjectUtil
.getObjectsByType(fnc.eAllContents(),
VariablesPackage.eINSTANCE.getLocalVariable());
for (LocalVariable var : variables) {
if (var.getValue() != null && var.getValue().equals(pei)) {
dst1.setTarget(var);
}
}
}
newElement.setChild(getSource());
newElement.setValue(dst1);
}
if (getSource() instanceof Output
&& getTarget() instanceof LocalVariable) {
IdentifierReference src1 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
IdentifierReference src2 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
src1.setNext(src2);
src2.setTarget((Output) getSource());
Output out = (Output) getSource();
fnc = out.getContainingMethod();
container = out.eContainer();
if (container instanceof ProcessingElementInstance) {
ProcessingElementInstance pei = (ProcessingElementInstance) container;
Collection<LocalVariable> variables = DispelEObjectUtil
.getObjectsByType(fnc.eAllContents(),
VariablesPackage.eINSTANCE.getLocalVariable());
for (LocalVariable var : variables) {
if (var.getValue() != null && var.getValue().equals(pei)) {
src1.setTarget(var);
}
}
}
IdentifierReference dst1 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
dst1.setTarget((LocalVariable) getTarget());
newElement.setChild(src1);
newElement.setValue(dst1);
}
if (getSource() instanceof LocalVariable
&& getTarget() instanceof Input) {
IdentifierReference dst1 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
IdentifierReference dst2 = ReferencesFactory.eINSTANCE
.createIdentifierReference();
dst1.setNext(dst2);
dst2.setTarget((Input) getTarget());
Input in = (Input) getTarget();
container = in.eContainer();
if (container instanceof ProcessingElementInstance) {
ProcessingElementInstance pei = (ProcessingElementInstance) container;
LocalVariable inVar = (LocalVariable) getSource();
fnc = inVar.getContainingMethod();
Collection<LocalVariable> variables = DispelEObjectUtil
.getObjectsByType(fnc.eAllContents(),
VariablesPackage.eINSTANCE.getLocalVariable());
for (LocalVariable var : variables) {
if (var.getValue() != null && var.getValue().equals(pei)) {
dst1.setTarget(var);
}
}
}
ConnectionInitialization src = InstantiationsFactory.eINSTANCE
.createConnectionInitialization();
IdentifierReference ir = ReferencesFactory.eINSTANCE
.createIdentifierReference();
ir.setTarget((LocalVariable) getSource());
src.setInitialValue(ir);
newElement.setChild(src);
newElement.setValue(dst1);
}
if (fnc != null && newElement.getChild() != null
&& newElement.getValue() != null) {
CreateElementRequest request = new CreateElementRequest(fnc,
DispelElementTypes.ConnectionStatement_2003);
ConnectionStatementCreateCommand command = new ConnectionStatementCreateCommand(