| /******************************************************************************* |
| * Copyright (c) 2004-2008 Andras Schmidt, Andras Balogh, Istvan Rath 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 Schmidt, Andras Balogh, Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.core.simple; |
| |
| import org.eclipse.viatra2.core.EMultiplicityKind; |
| import org.eclipse.viatra2.core.IModelElement; |
| import org.eclipse.viatra2.core.IRelation; |
| |
| /** |
| * @author Andras Schmidt, Istvan Rath |
| * |
| */ |
| public class SimpleRelation extends SimpleModelElement implements IRelation { |
| /** |
| * The source element of this relation |
| */ |
| protected SimpleModelElement from = null; |
| |
| /** |
| * The target element of this relation |
| */ |
| protected SimpleModelElement to = null; |
| |
| /** |
| * The multiplicity of this relation. It has sense in meta-models only |
| */ |
| protected EMultiplicityKind multiplicity = EMultiplicityKind.MANY_TO_MANY; |
| |
| protected IRelation inverse = null; |
| |
| /** |
| * The isAggregation property of the relation |
| */ |
| protected boolean isAggregation = false; |
| |
| /** |
| * The isAnyfrom property of the relation |
| */ |
| protected boolean isAnyFrom = false; |
| |
| /** |
| * The isAnyto property of the relation |
| */ |
| protected boolean isAnyTo = false; |
| |
| /** |
| * Instatiatates a relation. |
| */ |
| public SimpleRelation(long ID, SimpleModelSpace ms) { |
| super(ID, ms); |
| } |
| |
| /** |
| * Gets the source of this relation. |
| * |
| * @return An Entity |
| */ |
| public IModelElement getFrom() { |
| try { |
| modelSpace.lock.readLock().lock(); |
| return from; |
| } finally { |
| modelSpace.lock.readLock().unlock(); |
| } |
| } |
| |
| /** |
| * Gets the destination of this relation. |
| * |
| * @return an Entity |
| */ |
| public IModelElement getTo() { |
| try { |
| modelSpace.lock.readLock().lock(); |
| return to; |
| } finally { |
| modelSpace.lock.readLock().unlock(); |
| } |
| } |
| |
| /** |
| * Returns one of the element's fully qualified name |
| * |
| * @return name |
| */ |
| public String getFullyQualifiedName() { |
| try { |
| modelSpace.lock.readLock().lock(); |
| if (from == null) |
| return null; |
| String name = getName(); |
| name = from.getFullyQualifiedName() + "." + name; |
| return name; |
| } finally { |
| modelSpace.lock.readLock().unlock(); |
| } |
| } |
| |
| public IModelElement getNamespace() { |
| try { |
| modelSpace.lock.readLock().lock(); |
| return from; |
| } finally { |
| modelSpace.lock.readLock().unlock(); |
| } |
| } |
| |
| public EMultiplicityKind getMultiplicity() { |
| try { |
| modelSpace.lock.readLock().lock(); |
| return multiplicity; |
| } finally { |
| modelSpace.lock.readLock().unlock(); |
| } |
| } |
| |
| public IRelation getInverse() { |
| try { |
| modelSpace.lock.readLock().lock(); |
| return inverse; |
| } finally { |
| modelSpace.lock.readLock().unlock(); |
| } |
| } |
| |
| public boolean getIsAggregation() { |
| try { |
| modelSpace.lock.readLock().lock(); |
| return isAggregation; |
| } finally { |
| modelSpace.lock.readLock().unlock(); |
| } |
| } |
| |
| public boolean getIsAnyFrom() { |
| return isAnyFrom; |
| } |
| |
| public boolean getIsAnyTo() { |
| return isAnyTo; |
| } |
| |
| public boolean isEntity() { |
| return false; |
| } |
| |
| public boolean isRelation() { |
| return true; |
| } |
| |
| } |