001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009:
010: package de.uka.ilkd.key.casetool.together;
011:
012: import java.io.File;
013: import java.util.Enumeration;
014: import java.util.Iterator;
015:
016: import com.togethersoft.openapi.ide.project.IdeProject;
017: import com.togethersoft.openapi.ide.project.IdeProjectManagerAccess;
018: import com.togethersoft.openapi.rwi.*;
019: import com.togethersoft.openapi.sci.SciModel;
020: import com.togethersoft.openapi.sci.SciModelAccess;
021:
022: import de.uka.ilkd.key.casetool.HashMapOfClassifier;
023: import de.uka.ilkd.key.casetool.UMLOCLAssociation;
024: import de.uka.ilkd.key.casetool.UMLOCLClassifier;
025: import de.uka.ilkd.key.casetool.UMLOCLJavaModel;
026: import de.uka.ilkd.key.java.Services;
027:
028: public class UMLOCLTogetherModel extends UMLOCLJavaModel {
029: //debug flag
030: private static final boolean DEBUG = false;
031: private static String pathSep = File.separator;
032: private static final String TOGETHER_UNIQUE_NAME_PREFIX = "<oiref:java#Class#";
033: private static final String TOGETHER_UNIQUE_NAME_POSTFIX = ":oiref>";
034:
035: public UMLOCLTogetherModel() {
036: super (getTogetherProjectDir());
037: }
038:
039: public UMLOCLTogetherModel(Services services) {
040: super (services, getTogetherProjectDir());
041: }
042:
043: public static String getTogetherProjectDir() {
044: IdeProject prj = IdeProjectManagerAccess.getProjectManager()
045: .getActiveProject();
046: if (prj != null) {
047: String tprFile = prj.getFileName();
048: return tprFile.substring(0, tprFile.lastIndexOf(pathSep));
049: } else
050: return "";
051: }
052:
053: public HashMapOfClassifier getUMLOCLClassifiers() {
054:
055: super .getUMLOCLClassifiers();
056: // find associations
057: RwiModel rwiModel = RwiModelAccess.getModel();
058: Enumeration rwiRoots = rwiModel.rootPackages(RwiProperty.MODEL);
059: while (rwiRoots.hasMoreElements()) {
060: RwiPackage rwiPackage = (RwiPackage) rwiRoots.nextElement();
061: processAssociations(rwiPackage);
062: }
063:
064: if (DEBUG)
065: System.out.println("------------- found the following "
066: + "associations ------------------");
067:
068: Iterator cit = classifiers.values().iterator();
069: UMLOCLClassifier c;
070: while (cit.hasNext()) {
071: c = (UMLOCLClassifier) cit.next();
072: Iterator it = c.getAssociations().values().iterator();
073: UMLOCLAssociation assoc;
074: while (it.hasNext()) {
075: assoc = (UMLOCLAssociation) it.next();
076: if (DEBUG)
077: System.out.println("assoc from: "
078: + assoc.getSource().getName() + " to: "
079: + assoc.getTarget().getName());
080: }
081: }
082: return classifiers;
083: }
084:
085: protected void processAssociations(RwiPackage rwiPackage) {
086: RwiModel rwiModel = RwiModelAccess.getModel();
087:
088: Enumeration rwiNodesEnum = rwiPackage.nodes();
089: RwiNode rwiNode;
090: TogetherModelClass cls;
091: while (rwiNodesEnum.hasMoreElements()) {
092: rwiNode = (RwiNode) rwiNodesEnum.nextElement();
093: cls = new TogetherModelClass(rwiNode, rwiModel, null);
094: cls.getAssociations(classifiers);
095: }
096: Enumeration subpackages = rwiPackage.subpackages();
097: while (subpackages.hasMoreElements()) {
098: RwiPackage subpackage = (RwiPackage) subpackages
099: .nextElement();
100: processAssociations(subpackage);
101: }
102: }
103:
104: /** Given the full name (i.e. including package prefix, e.g. "java.lang.Object")
105: * of a classifier contained in the current model, this method returns the
106: * corresponding TogetherReprModelClass.
107: * @param fullName the name, including package prefix, of a classifier
108: * in the current UML model.
109: * @return the corresponding TogetherReprModelClass
110: */
111: public TogetherModelClass getTogetherReprModelClass(String fullName) {
112: String uniqueName = TOGETHER_UNIQUE_NAME_PREFIX + fullName
113: + TOGETHER_UNIQUE_NAME_POSTFIX;
114: RwiModel rwiModel = RwiModelAccess.getModel();
115: RwiElement elem = rwiModel.findElement(uniqueName);
116: TogetherModelClass togetherClass = null;
117: if (elem != null && elem instanceof RwiNode) {
118: RwiNode rwiNode = (RwiNode) elem;
119: RwiDiagram diagram = rwiNode.getContainingPackage()
120: .getPhysicalDiagram();
121: togetherClass = new TogetherModelClass(rwiNode, rwiModel,
122: diagram);
123: }
124: return togetherClass;
125: }
126: }
|