blob: 617bda72c1040c11b01a1a5d85a29f5e9fbedb26 [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.IModelElement;
import org.eclipse.viatra2.core.IModelManager;
import org.eclipse.viatra2.core.IRelation;
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;
public class SetRelationSource extends SetRelation {
SearchGraphEdge relatedSearchGraphEdge;
int source;
public SetRelationSource(int rel, int source
,IModelManager manager, SearchGraphEdge edge) {
super(manager,rel);
this.source= source;
relatedSearchGraphEdge = edge;
}
public boolean update(MatchingFrame frame)throws GTOperationException {
IModelElement sourceElement = null;
IRelation relationElement = null;
try {
sourceElement = (IModelElement) frame.getValue(source);
} catch (ClassCastException e) {
String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT
,context
,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
}
try {
relationElement = (IRelation) frame.getValue(relation);
} catch (ClassCastException e) {
String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.NOT_A_RELATION
,context
,relatedSearchGraphEdge.getTargetNode().getTraceabilityElement().getRepresentativeEMFElement());
}
if (sourceElement == null) {
String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
,context
,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement());
}
try {
if(!relationElement.getFrom().equals(sourceElement))
manager.setRelationFrom(relationElement,sourceElement);
return true;
}catch (VPMCoreException e) {
String[] context = {relatedSearchGraphEdge.getTargetNode().getName(), relatedSearchGraphEdge.getTargetNode().getName(), e.getMessage()};
throw new GTOperationException(GTErrorStrings.INTERNAL_SET_RELATION_SOURCE
,context
,relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement());
}
}
@Override
public String toString() {
return "Relation: "+ relation+"-- set Source --> " + source;
}
@Override
public AnnotatedElement getErrorfulElement(MatchingFrame frame){
return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement();
}
}