blob: 4d0c1a6d390217b615c15bdb0e46e4b2701b79bc [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.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.VariableSearchGraphNode;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
/**
* @author Akos Horvath
*
*/
public class CreateEntityWithVariableContainment extends CreateEntity{
VariableSearchGraphNode container;
/**
* @param variableIndex
* @param manager
*/
public CreateEntityWithVariableContainment(int variableI, IModelManager manager, VariableSearchGraphNode con) {
super(variableI, manager);
this.container = con;
}
protected boolean create(MatchingFrame frame) throws GTOperationException{
IEntity tempContainer =null;
try{
tempContainer = (IEntity)frame.getValue(container.getId());
} catch(ClassCastException e){
String[] context = {container.getName(), getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.NOT_AN_ENTITY
,context
,container.getTraceabilityElement().getRepresentativeEMFElement());
}
if(tempContainer == null)
{
String[] context = {container.getName(),getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
,context
,container.getTraceabilityElement().getRepresentativeEMFElement());
}
try {
frame.setValue(variableIndex, manager.newEntity(tempContainer));
} catch (VPMCoreException e) {
String context[] = {frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getName(),e.getMessage()};
throw new GTOperationException(GTErrorStrings.INTERNAL_CREATE_ENTITY
,context
,frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement());
}
return true;
}
public String toString() {
return getClass().getSimpleName() + " : " +
variableIndex+" in "+container;
}
@Override
public AnnotatedElement getErrorfulElement(MatchingFrame frame){
return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
}
}