| /******************************************************************************* |
| * 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 MoveBoundunderConstant extends MoveElement {
|
|
|
| // private boolean hasBeenExecuted;
|
| IEntity container;
|
| SearchGraphEdge relatedSearchGraphEdge;
|
|
|
| public MoveBoundunderConstant(IModelManager manager, IEntity cont |
| , int variable, SearchGraphEdge edge) {
|
| super(manager,variable);
|
| container = cont;
|
| relatedSearchGraphEdge = edge;
|
| }
|
|
|
| public boolean update(MatchingFrame frame) throws GTOperationException {
|
| IEntity variableElement = null;
|
| 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 (container == 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, container);
|
| return true;
|
| }catch (VPMCoreException e) {
|
| String[] context = {container.getFullyQualifiedName() |
| , 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.getName();
|
| } |
| |
| @Override |
| public AnnotatedElement getErrorfulElement(MatchingFrame frame){ |
| return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement(); |
| }
|
| }
|