blob: 1113b8d0dfb41b2ca98204baba5623e036b6a8d7 [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.ConstantSearchGraphNode;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.core.AnnotatedElement;
/**
* @author Akos Horvath
*
*/
public class CreateEntityWithConstantContainer extends CreateEntity {
IEntity container;
ConstantSearchGraphNode containerSearchGraphNode;
/**
* @param variableIndex
* @param manager
* @param containerSearchGraphNode
*/
public CreateEntityWithConstantContainer(int variableI, IModelManager manager, IEntity con, ConstantSearchGraphNode containerSearchGraphNode) {
super(variableI, manager);
this.container = con;
this.containerSearchGraphNode = containerSearchGraphNode;
}
protected boolean create(MatchingFrame frame) throws GTOperationException{
if(container == null)
{
String[] context = {containerSearchGraphNode.getName(),getClass().getSimpleName()};
throw new GTOperationException(GTErrorStrings.INTERNAL_EMPTY_VALUE
,context
,containerSearchGraphNode.getTraceabilityElement().getRepresentativeEMFElement());
}
try {
frame.setValue(variableIndex, manager.newEntity(container));
} 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.getName();
}
@Override
public AnnotatedElement getErrorfulElement(MatchingFrame frame){
return frame.getPattern().getSearchGraph().getSearchNode(variableIndex).getTraceabilityElement().getRepresentativeEMFElement();
}
}