blob: 51cca04be8c4a41ac6b6aa6dc2aadd34fdcd54bc [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.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.ConstantSearchGraphNode;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
/**
* @author Akos Horvath
*
*/
//In normal cases this type of relation creating operation would not be nstanciated
public class CreateRelationConstant2Constant extends CreateConstant2Constant {
ConstantSearchGraphNode sourceNode, targetNode;
public CreateRelationConstant2Constant(ConstantSearchGraphNode s,
ConstantSearchGraphNode t, int variableI,IModelManager manager){
super(manager,variableI);
sourceNode = s;
targetNode = t;
source = manager.getElementByName(s.getElement());
target= manager.getElementByName(t.getElement());
}
@Override
protected boolean create(MatchingFrame frame)throws GTOperationException {
if (source == null) {
String[] context = {sourceNode.getName(),getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
,context
,sourceNode.getTraceabilityElement().getRepresentativeEMFElement());
}
if (target == null) {
String[] context = {targetNode.getName(),getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
,context
,targetNode.getTraceabilityElement().getRepresentativeEMFElement());
}
try {
frame.setValue(variableIndex, manager.newRelation(source,target));
} catch (VPMCoreException e) {
String[] context = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),e.getMessage()};
throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_RELATION
,context
,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());
}
return true;
}
public String toString() {
return getClass().getSimpleName() + " : " +
source.getName() + " -- Relation:"+ variableIndex+" -> " + target.getName();
}
@Override
public AnnotatedElement getErrorfulElement(MatchingFrame frame){
return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
}
}