blob: 2c4ba55c87e39c4d23a65b07079b3c4746990ea6 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Akos Horvath, Gergely Varro - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation;
import org.eclipse.viatra2.core.IEntity;
import org.eclipse.viatra2.core.IModelManager;
import org.eclipse.viatra2.errors.VPMCoreException;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTOperationException;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.searchgraph.SearchGraphEdge;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
/**
* @author Akos Horvath
*
*/
public class MoveBoundunderBound extends MoveElement{
int container;
SearchGraphEdge relatedSearchGraphEdge;
public MoveBoundunderBound(IModelManager manager, int cont
, int variable, SearchGraphEdge edge) {
super(manager,variable);
container = cont;
relatedSearchGraphEdge = edge;
}
public boolean update(MatchingFrame frame) throws GTOperationException {
IEntity containerElement = null;
IEntity variableElement = null;
try {
containerElement = (IEntity) frame.getValue(container);
} catch (ClassCastException e) {
String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.NOT_AN_ENTITY
,context
,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
}
try {
variableElement = (IEntity) frame.getValue(variableIndex);
} catch (ClassCastException e) {
String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.NOT_AN_ENTITY
,context
,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
}
if (containerElement == null) {
String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
,context
,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
}
if (variableElement == null) {
String[] context = {relatedSearchGraphEdge.getTargetNode().getName(),getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
,context
,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
}
try {
manager.moveEntityTo(variableElement,containerElement);
// hasBeenExecuted = true;
return true;
}
catch (VPMCoreException e) {
String[] context = {frame.getPattern().getSearchGraph().getSearchNode(container).getName()
, frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName()
, e.getMessage()};
throw new GTOperationException(GTErrorStrings.INTERNAL_MOVE_MODELELEMENT
,context
,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
}
}
public String toString() {
return getClass().getSimpleName() + " : " +
variableIndex + " -- move under -> " + container;
}
/**
* @return the container
*/
public int getContainer() {
return container;
}
@Override
public AnnotatedElement getErrorfulElement(MatchingFrame frame){
return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
}
}