⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmodel.java

📁 UML设计测试工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * USE - UML based specification environment * Copyright (C) 1999-2004 Mark Richters, University of Bremen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* $ProjectHeader: use 2-3-0-release.1 Mon, 12 Sep 2005 20:18:33 +0200 green $ */package org.tzi.use.uml.mm;import java.util.ArrayList;import java.util.Collection;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.util.TreeMap;import org.tzi.use.graph.DirectedGraph;import org.tzi.use.graph.DirectedGraphBase;import org.tzi.use.uml.ocl.type.EnumType;/** * A Model is a top-level package containing all other model elements. *  * @version $ProjectVersion: 2-3-0-release.1 $ * @author Mark Richters */public class MModel extends MModelElementImpl {    private Map fEnumTypes; // (String enum -> EnumType)    private Map fClasses; // (String classname -> MClass)    private Map fAssociations; // (String assocName -> MAssociation)    private DirectedGraph fGenGraph; // (MClass/MGeneralization)    private Map fClassInvariants; // (String name -> MClassInvariant)    private Map fPrePostConditions; // (String name -> MPrePostCondition)    private String fFilename; // name of .use file    protected MModel(String name) {        super(name);        fEnumTypes = new TreeMap();        fClasses = new TreeMap();        fAssociations = new TreeMap();        fGenGraph = new DirectedGraphBase();        fClassInvariants = new TreeMap();        fPrePostConditions = new TreeMap();        fFilename = "";    }    public void setFilename(String filename) {        fFilename = filename;    }    /**     * Returns the filename of the specification from which this model was read.     * May be empty if model is not constructed from a file.     */    public String filename() {        return fFilename;    }    /**     * Adds a class. The class must have a unique name within the model.     *      * @exception MInvalidModel     *                model already contains a class with the same name.     */    public void addClass(MClass cls) throws MInvalidModelException {        if (fClasses.containsKey(cls.name()))            throw new MInvalidModelException("Model already contains a class `"                    + cls.name() + "'.");        fClasses.put(cls.name(), cls);        fGenGraph.add(cls);        cls.setModel(this);    }    /**     * Returns the specified class.     *      * @return null if class <code>name</name> does not exist.     */    public MClass getClass(String name) {        return (MClass) fClasses.get(name);    }    /**     * Returns the specified association class.     *      * @return null if class <code>name</name> does not exist.     */    public MAssociationClass getAssociationClass(String name) {        MClass cls = (MClass) fClasses.get(name);        if (cls instanceof MAssociationClass) {            return (MAssociationClass) cls;        } else {            return null;        }    }    /**     * Returns a collection containing all associationclasses in this model.     *      * @return collection of MAssociationClass objects.     */    public Collection getAssociationClassesOnly() {        Collection result = new ArrayList();        Iterator it = fClasses.values().iterator();        while (it.hasNext()) {            MClass elem = (MClass) it.next();            if (elem instanceof MAssociationClass) {                result.add(elem);            }        }        return result;    }    /**     * Returns a collection containing all classes in this model.     *      * @return collection of MClass objects.     */    public Collection classes() {        return fClasses.values();    }    /**     * Adds an association. The association must have a unique name within the     * model.     *      * @exception MInvalidModel     *                model already contains an association with the same name.     */    public void addAssociation(MAssociation assoc)            throws MInvalidModelException {        if (assoc.associationEnds().size() < 2)            throw new IllegalArgumentException("Illformed association `"                    + assoc.name() + "': number of associationEnds == "                    + assoc.associationEnds().size());        if (fAssociations.containsKey(assoc.name()))            throw new MInvalidModelException(                    "Model already contains an association named `"                            + assoc.name() + "'.");        // check for role name conflicts: for each class the set of        // navigable classes must have unique role names        Iterator it = assoc.associatedClasses().iterator();        while (it.hasNext()) {            MClass cls = (MClass) it.next();            Map aends = cls.navigableEnds();            List newRolenames = new ArrayList();            Iterator it2 = assoc.navigableEndsFrom(cls).iterator();            while (it2.hasNext()) {                String newRolename = ((MNavigableElement) it2.next())                        .nameAsRolename();                newRolenames.add( newRolename );                if (aends.containsKey(newRolename)) {                    throw new MInvalidModelException("Association end `"                            + newRolename                            + "' navigable from class `"                            + cls.name()                            + "' conflicts with same rolename in association `"                            + ((MNavigableElement) aends.get(newRolename))                                    .association().name() + "'.");                }            }                        // tests if the rolenames are already used in one of the subclasses            Iterator it3 = cls.allChildren().iterator();            while ( it3.hasNext() ) {                MClass subCls = (MClass) it3.next();                for ( int i = 0; i < newRolenames.size(); i++ ) {                    String newRolename = (String) newRolenames.get(i);                    if ( subCls.navigableEnds().containsKey( newRolename ) ) {                        throw new MInvalidModelException("Association end `"                                + newRolename                                + "' navigable from class `"                                + subCls.name()                                + "' conflicts with same rolename in association `"                                + ((MNavigableElement) subCls.navigableEnds()                                        .get( newRolename ))                                        .association().name() + "'.");                    }                }            }        }        // for each class register the association and the        // reachable association ends        it = assoc.associationEnds().iterator();        while (it.hasNext()) {            MAssociationEnd aend = (MAssociationEnd) it.next();            MClass cls = aend.cls();            // cls.addAssociation(assoc);            cls.registerNavigableEnds(assoc.navigableEndsFrom(cls));        }        fAssociations.put(assoc.name(), assoc);    }    /**     * Returns a collection containing all associations in this model.     *      * @return collection of MAssociation objects.     */    public Collection associations() {        return fAssociations.values();    }    /**     * Returns the specified association.     *      * @return null if association does not exist.     */    public MAssociation getAssociation(String name) {        return (MAssociation) fAssociations.get(name);    }    /**     * Returns the set of all associations that exist between the specified     * classes (inherited ones are not included). The arity of the returned     * associations is equal to <code>classes.size()</code>.     *      * @return Set(MAssociation)     */    public Set getAssociationsBetweenClasses(Set classes) {        Set res = new HashSet();        // search associations        Iterator assocIter = fAssociations.values().iterator();        while (assocIter.hasNext()) {            MAssociation assoc = (MAssociation) assocIter.next();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -