| /******************************************************************************* |
| * 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.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
|
| *
|
| */
|
| public class CreateRelationConstant2Bound extends CreateConstant2Bound {
|
| |
| ConstantSearchGraphNode sourceNode; |
|
|
| public CreateRelationConstant2Bound(ConstantSearchGraphNode s, int t |
| ,int variableI,IModelManager manager){
|
| super(manager,variableI);
|
| sourceNode = s; |
| source = manager.getElementByName(s.getElement());
|
| target= t; |
| }
|
|
|
| /* (non-Javadoc)
|
| * @see org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.operation.CreateElement#create(org.eclipse.viatra2.gtasm.patternmatcher.internal.MatchingFrame)
|
| */
|
| @Override
|
| protected boolean create(MatchingFrame frame) throws GTOperationException {
|
| IModelElement targetElement = null;
|
| try { |
| targetElement = (IModelElement) frame.getValue(target); |
| } catch (ClassCastException e) { |
| String[] context = {frame.getPattern().getSearchGraph().getSearchNode(target).getName(), getClass().getSimpleName()}; |
| throw new GTOperationException(GTErrorStrings.NOT_A_MODELELEMENT |
| ,context |
| ,frame.getPattern().getSearchGraph().getSearchNode(target).getTraceabilityElement().getRepresentativeEMFElement()); |
| } |
| if (source == null) { |
| String[] context = {sourceNode.getName(),getClass().getSimpleName()}; |
| throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE |
| ,context |
| ,sourceNode.getTraceabilityElement().getRepresentativeEMFElement()); |
| |
| } |
| if (targetElement == null) { |
| String[] context = {frame.getPattern().getSearchGraph().getSearchNode(target).getName(),getClass().getSimpleName()}; |
| throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE |
| ,context |
| ,frame.getPattern().getSearchGraph().getSearchNode(target).getTraceabilityElement().getRepresentativeEMFElement()); |
| }
|
|
|
| try {
|
| frame.setValue(variableIndex, manager.newRelation(source,targetElement));
|
| }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;
|
| } |
| |
| @Override |
| public AnnotatedElement getErrorfulElement(MatchingFrame frame){ |
| return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement(); |
| }
|
|
|
| }
|