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

📄 msystem.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.sys;import java.io.*;import java.util.ArrayList;import java.util.EmptyStackException;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.swing.event.EventListenerList;import org.tzi.use.gen.tool.GGenerator;import org.tzi.use.uml.mm.MClass;import org.tzi.use.uml.mm.MModel;import org.tzi.use.uml.mm.MOperation;import org.tzi.use.uml.mm.MPrePostCondition;import org.tzi.use.uml.ocl.expr.Evaluator;import org.tzi.use.uml.ocl.expr.Expression;import org.tzi.use.uml.ocl.value.BooleanValue;import org.tzi.use.uml.ocl.value.Value;import org.tzi.use.uml.ocl.value.VarBindings;import org.tzi.use.util.Log;import org.tzi.use.util.UniqueNameGenerator;import org.tzi.use.util.cmd.*;/** * A system maintains a system state and provides functionality for * doing state transitions. * * @version     $ProjectVersion: 2-3-0-release.1 $ * @author      Mark Richters  */public final class MSystem {    private MModel fModel;  // The model of this system.     private MSystemState fCurrentState; // The current system state.     private Map fObjects;   // (String -> MObject) The set of all objects    private UniqueNameGenerator fUniqueNameGenerator; // creation of object names    private CommandProcessor fCommandProcessor; // executing state change commands    protected EventListenerList fListenerList = new EventListenerList();    private List fOperationCallStack; // stack of active operations    private VarBindings fVarBindings; // top-level variable bindings    private GGenerator fGenerator;    // snapshot generator    public MSystem(MModel model) {        fModel = model;        init();    }    private void init() {        fObjects = new HashMap();        fUniqueNameGenerator = new UniqueNameGenerator();        fCommandProcessor = new CommandProcessor();        fCurrentState = new MSystemState(fUniqueNameGenerator.generate("state#"), this);        fOperationCallStack = new ArrayList();        fVarBindings = new VarBindings();        fGenerator = new GGenerator(this);    }    /**     * Returns the current system state.     */    public MSystemState state() {        return fCurrentState;    }    /**     * Returns the system's model.     */    public MModel model() {        return fModel;    }    /**     * Returns the system's instance generator.     */    public GGenerator generator() {        return fGenerator;    }    public void addChangeListener(StateChangeListener l) {        fListenerList.add(StateChangeListener.class, l);    }        public void removeChangeListener(StateChangeListener l) {        fListenerList.remove(StateChangeListener.class, l);    }    /**     * Creates and adds a new object to the system. The name of the     * object may be null in which case a unique name is automatically     * generated.     *     * @return the created object.       */    MObject createObject(MClass cls, String name) throws MSystemException {        if (cls.isAbstract() )            throw new MSystemException("The abstract class `" + cls.name() +                                        "' cannot be instantiated.");            // create new object and initial state        if (name == null ) {            name = uniqueObjectNameForClass(cls.name());        } else if (fObjects.containsKey(name) )            throw new MSystemException("An object with name `" + name +                                        "' already exists.");                MObject obj = new MObjectImpl(cls, name);        addObject(obj);        return obj;    }    void addObject(MObject obj) {        fObjects.put(obj.name(), obj);    }    void deleteObject(MObject obj) {        fObjects.remove(obj.name());    }    /**     * Returns a unique name that can be used for a new object of the     * given class.       */    public String uniqueObjectNameForClass(String clsName) {        return fUniqueNameGenerator.generate(clsName);    }    /**     * Executes a state manipulation command.     */    public void executeCmd(MCmd cmd) throws MSystemException {        Log.trace(this, "executing command: " + cmd);        try {            fCommandProcessor.execute(cmd);            fireStateChanged(cmd, false);        } catch (CommandFailedException ex) {            throw new MSystemException(ex.getMessage());        }    }    /**     * Undoes the last state manipulation command.     */    public void undoCmd() throws MSystemException {        Log.trace(this, "undoing last command");        try {            MCmd cmd = (MCmd) fCommandProcessor.undoLast();            fireStateChanged(cmd, true);        } catch (CannotUndoException ex) {            throw new MSystemException(ex.getMessage());        }    }    /**      * Returns the name of the next command that can be undone.     *     * @return null, if there is no command for undo.     */    public String nextUndoableCmdName() {        Command cmd = fCommandProcessor.nextUndoableCmd();        String name = null;        if (cmd != null )            name = cmd.name();        return name;    }    /**     * Writes a sequence of commands that can be read and executed by     * the USE shell to reproduce the same effects of all command     * executed so far.       */    public void writeUSEcmds(PrintWriter out)         throws IOException     {        Iterator cmdIter = fCommandProcessor.commands().iterator();        while (cmdIter.hasNext() ) {            MCmd cmd = (MCmd) cmdIter.next();            Log.trace(this, cmd.getUSEcmd());            out.println(cmd.getUSEcmd());        }    }    /**     * Returns the number of commands executed so far.     */    public int numExecutedCmds() {        return fCommandProcessor.commands().size();    }    /**     * Returns the list of commands executed so far.     *     * @return List(MCmd)     */    public List commands() {        return fCommandProcessor.commands();    }    /**     * Resets the system to its initial state.     */    public void reset() {        init();    }    /**     * Simulate entry of an operation. The preconditions of the     * operation are checked with the current state. If all

⌨️ 快捷键说明

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