| /******************************************************************************* |
| * 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.IEntity; |
| import org.eclipse.viatra2.core.IModelElement; |
| import org.eclipse.viatra2.core.IModelManager; |
| import org.eclipse.viatra2.core.IModelSpace; |
| import org.eclipse.viatra2.core.IRelation; |
| import org.eclipse.viatra2.errors.VPMCoreException; |
|
|
| /**
|
| * @author babo
|
| *
|
| */
|
| public class RelationDefinition extends ElementDefinition {
|
|
|
| IRelation element = null;
|
| public IModelElement getElement()
|
| {
|
| if (element==null)
|
| {
|
| //System.out.println("GETELEMENT: "+this.toString());
|
| elemGen(VTMLMetaModelHelper.getInstance().getMSpace());
|
| }
|
| return element;
|
| }
|
| /* (non-Javadoc)
|
| * @see java.lang.Object#toString()
|
| */
|
| public String toString() {
|
| // TODO Auto-generated method stub
|
| return "relation name : "+name+" type : "+type+" src : "+source+" trg: "+target+" namespace: "+namespace;
|
| }
|
| String name;
|
| String namespace;
|
| String defns;
|
| String type;
|
| String source;
|
| String target;
|
|
|
| IModelElement tar;
|
| IModelElement src;
|
| IModelElement typ;
|
| IEntity ns;
|
|
|
| public boolean isNativ = false;
|
|
|
| public RelationDefinition(IRelation r)
|
| {
|
| defns="";
|
| name = r.getName();
|
| namespace = r.getNamespace().getFullyQualifiedName();
|
| source = r.getFrom().getFullyQualifiedName();
|
| target = r.getTo().getFullyQualifiedName();
|
| element = r;
|
| type = null;
|
| isNativ = true;
|
| }
|
|
|
| public RelationDefinition(int l, String ns, String n, String t, String s, String tar)
|
| {
|
| name = n;
|
| if (name.indexOf(".")>0) name = name.substring(name.lastIndexOf(".")+1);
|
| namespace = ns;
|
| defns = ns;
|
| type = t;
|
| source = s;
|
| target = tar;
|
| setLine(l);
|
| isNativ=false;
|
| }
|
|
|
| RelationDefinition _type = null;
|
| ElementDefinition _source = null;
|
| ElementDefinition _target = null;
|
| /* (non-Javadoc)
|
| * @see org.eclipse.viatra2.imports.vtcl.ASTNode#checkDefintion(org.eclipse.viatra2.imports.vtcl.ASTBuilder, org.eclipse.viatra2.core.IModelSpace)
|
| */
|
| public boolean checkDefintion(ASTBuilder ab, IModelSpace m) {
|
| String tmp = null;
|
| if (!isNativ)
|
| {
|
|
|
| _type = ab.getRelationWithLookup(defns,type);
|
| if ((_type==null) && (!type.equals("relation")))
|
| {
|
| ab.log.error("type "+type+" for relation "+name+" not found. Error in line "+getLine());
|
| return false;
|
| }
|
|
|
| _source = ab.getElementWithLookup(defns,source);
|
|
|
| if (_source==null)
|
| {
|
| ab.log.error("Source "+source+" for relation "+name+" not found. Error in line "+getLine());
|
| return false;
|
| } else source = tmp;
|
|
|
| _target = ab.getElementWithLookup(defns,target);
|
|
|
| if (_target==null)
|
| {
|
| ab.log.error("Target "+target+" for relation "+name+" not found. Error in line "+getLine());
|
| return false;
|
| } else target = tmp;
|
| if (_target==this || _source==this)
|
| {
|
| ab.log.error("Relation cannot start or end in itself. Error in line "+getLine());
|
| return false;
|
| }
|
| }
|
| for (RelationDefinition r : relations)
|
| {
|
| boolean btm = r.checkDefintion(ab,m);
|
| if (!btm) return false;
|
| }
|
| return true;
|
|
|
| }
|
|
|
|
|
| /* (non-Javadoc)
|
| * @see org.eclipse.viatra2.imports.vtcl.ASTNode#resolveReferences(org.eclipse.viatra2.imports.vtcl.ASTBuilder)
|
| */
|
| public void resolveReferences(ASTBuilder ab) throws VPMCoreException{
|
|
|
|
|
|
|
|
|
| }
|
|
|
| public String getFQN()
|
| {
|
| return namespace+"."+name;
|
| //if (namespace.length()==0) return name; else return namespace+"."+name;
|
| }
|
| /* (non-Javadoc)
|
| * @see org.eclipse.viatra2.imports.vtcl.ASTNode#updateModelspace(org.eclipse.viatra2.imports.vtcl.ASTBuilder, org.eclipse.viatra2.core.IModelSpace)
|
| */
|
| public void updateModelspace(ASTBuilder ab, IModelSpace m) throws VPMCoreException{
|
| elemGen(m);
|
| for (RelationDefinition r : relations)
|
| {
|
| r.updateModelspace(ab,m);
|
| }
|
|
|
| }
|
|
|
| String tmpName;
|
| IRelation me;
|
| IEntity tmp;
|
| boolean amIFun=false;
|
| IModelManager mm;
|
| public void generateElements(ASTBuilder ab, IModelSpace m,IEntity temp) throws VPMCoreException
|
| {
|
|
|
| }
|
|
|
| public void elemGen(IModelSpace m)
|
| {
|
| if (element==null)
|
| {
|
| try
|
| {
|
| mm = m.getModelManager();
|
| // System.out.println("<DEBUG>"+name+" "+isNativ+" "+_source+" "+_target);
|
| element = mm.newRelation(name,_source.getElement(),_target.getElement());
|
| if (_type!=null) mm.newInstanceOf(_type.getElement(),element);
|
| }
|
| catch (Exception e)
|
| {
|
| e.printStackTrace();
|
| }
|
| }
|
| }
|
| /**
|
| * @return Returns the name.
|
| */
|
| public String getName() {
|
| if (isNativ)
|
| return element.getName();
|
| else
|
| return name;
|
| }
|
| /**
|
| * @param name The name to set.
|
| */
|
| public void setName(String name) {
|
| this.name = name;
|
| }
|
| /**
|
| * @return Returns the namespace.
|
| */
|
| public String getNamespace() {
|
| if (isNativ)
|
| if (element.getFrom().getNamespace()!=null)
|
| return element.getFrom().getNamespace().getFullyQualifiedName();
|
| else return "";
|
| else
|
| return namespace;
|
| }
|
| /**
|
| * @param namespace The namespace to set.
|
| */
|
| public void setNamespace(String namespace) {
|
| this.namespace = namespace;
|
| }
|
| /**
|
| * @return Returns the source.
|
| */
|
| public String getSource() {
|
| if (isNativ)
|
| return element.getFrom().getName();
|
| else
|
| return source;
|
| }
|
| /**
|
| * @param source The source to set.
|
| */
|
| public void setSource(String source) {
|
| this.source = source;
|
| }
|
| /**
|
| * @return Returns the target.
|
| */
|
| public String getTarget() {
|
| return target;
|
| }
|
| /**
|
| * @param target The target to set.
|
| */
|
| public void setTarget(String target) {
|
| this.target = target;
|
| }
|
| /**
|
| * @return Returns the type.
|
| */
|
| public String getType() {
|
| return type;
|
| }
|
| /**
|
| * @param type The type to set.
|
| */
|
| public void setType(String type) {
|
| this.type = type;
|
| }
|
| }
|