blob: 101669e84d207f86ee52de015a9d93777fc363b2 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Andras Balogh 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:
* Andras Balogh - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.imports.vtml;
import org.eclipse.viatra2.core.EMultiplicityKind;
import org.eclipse.viatra2.core.IModelSpace;
import org.eclipse.viatra2.core.IRelation;
import org.eclipse.viatra2.errors.VPMCoreException;
public class MultiplicityDefinition extends RelationshipDefinition{
String multiplicity = "";
public MultiplicityDefinition(int l, String ns, String n, String s)
{
super(l,ns,n,null);
multiplicity = s;
}
@Override
public boolean checkDefintion(ASTBuilder ab, IModelSpace m) {
// TODO Auto-generated method stub
boolean tmp = super.checkDefintion(ab, m);
if (tmp)
{
if (_mstr instanceof EntityDefinition)
{
ab.log.error("Multiplicity can only be specified for relations. Error in line "+getLine());
return false;
}
}
return tmp;
}
@Override
public void resolveReferences(ASTBuilder ab) throws VPMCoreException {
EMultiplicityKind mk = EMultiplicityKind.MANY_TO_MANY;
if (multiplicity.equals("one_to_one")) mk = EMultiplicityKind.ONE_TO_ONE;
if (multiplicity.equals("one_to_many")) mk = EMultiplicityKind.ONE_TO_MANY;
if (multiplicity.equals("many_to_one")) mk = EMultiplicityKind.MANY_TO_ONE;
ab.mm.setRelationMultiplicity((IRelation)_mstr.getElement(),mk);
}
}