| /******************************************************************************* |
| * 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.patternmatcher.internal.operation;
|
|
|
| import org.eclipse.viatra2.core.IModelElement; |
| import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherRuntimeException; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.MatchingFrame; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.PatternMatcherErrorStrings; |
| import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.algorithms.ISearchGraph; |
| 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 IsEntityorRelationCheckOperation extends CheckOperation {
|
|
|
| private Integer source;
|
| private SearchGraphEdge relatedSearchGraphEdge;
|
| private String type;
|
|
|
| /**
|
| *
|
| */
|
| public IsEntityorRelationCheckOperation(Integer source,
|
| SearchGraphEdge edge,
|
| String type) {
|
| this.source = source;
|
| this.relatedSearchGraphEdge = edge;
|
| this.type = type;
|
| }
|
|
|
| @Override
|
| protected boolean check(MatchingFrame frame)
|
| throws PatternMatcherRuntimeException {
|
| IModelElement sourceElement = null;
|
| try{
|
| sourceElement = (IModelElement) frame.getValue(source);
|
| }catch (ClassCastException e) {
|
| String[] context = {relatedSearchGraphEdge.getSourceNode().getName(), getClass().getSimpleName()}; |
| throw new PatternMatcherRuntimeException(GTErrorStrings.NOT_A_MODELELEMENT |
| ,context |
| ,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement()); |
| } |
|
|
| if (sourceElement == null) {
|
| String[] context = {relatedSearchGraphEdge.getSourceNode().getName(),getClass().getSimpleName()}; |
| throw new PatternMatcherRuntimeException(PatternMatcherErrorStrings.INTERNAL_EMPTY_VALUE |
| ,context |
| ,relatedSearchGraphEdge.getSourceNode().getTraceabilityElement().getRepresentativeEMFElement()); |
| }
|
|
|
| if(ISearchGraph.VPM_ENTITY_FQN.equals(type))
|
| return sourceElement.isEntity();
|
|
|
| if(ISearchGraph.VPM_RELATION_FQN.equals(type))
|
| return sourceElement.isRelation();
|
|
|
| return false;
|
| }
|
|
|
| public String toString(){
|
| return getClass().getSimpleName() + " : " +
|
| type+"-- " + relatedSearchGraphEdge.getVPMEdgeType().name() + "- CHECK -> " + source;
|
| } |
| |
| public AnnotatedElement getErrorfulElement(MatchingFrame frame) { |
| return relatedSearchGraphEdge.getTraceabilityElement().getRepresentativeEMFElement(); |
| }
|
|
|
| }
|