delegatingscript.java

来自「cqME :java framework for TCK test.」· Java 代码 · 共 138 行

JAVA
138
字号
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * 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 version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.j2me.javatest;import com.sun.javatest.Script;import com.sun.javatest.Status;import com.sun.javatest.TestDescription;import com.sun.javatest.TestEnvironment;import com.sun.tck.javatest.TCKScript;/** * A special purpose script that helps breaking deep Script hierarchies and * allows replacing inheritance with delegation. * <p> * For example, scripts to execute distributed tests in CLDC and CDC * environments are almost identical but use separate parent Scripts to * delegate an execution of non-distributed tests. Since separate parents are * used, it makes it impossible to refactor shared functionality into single * base class and inherit this shared functionality by both scripts, and that * introduces lots of code duplication and complicates the maintenance since * bug fixes need to be added to both scripts. * <p> * The solution is to introduce a subclass of this class and implement the * shared functionality there and make both CLDC and CDC-specific script * classes extend this common base but differently specify their delegate * scripts. So, basically, CLDC and CDC scripts will start sharing common * parent (and common functionality) but still have different delegate scripts * that perform different actions. */public class DelegatingScript extends TCKScript {    private Script delegateScript;    /**     * Creates an instance of DelegatingScript and sets the script     * to be used for delegation.     */    protected DelegatingScript(Script delegateScript) {        this.delegateScript = delegateScript;    }    /**     * Initializes test description.     * <p>     * This implementation forwards the call to both, parent     * and the delegate scripts.     *     * @param td     *            the test description for the test to be run.     */    public void initTestDescription(TestDescription td) {        super.initTestDescription(td);        delegateScript.initTestDescription(td);    }    /**     * Initializes any custom args for the script.     * <p>     * This implementation forwards the call to both, parent     * and the delegate scripts.     *     * @param args     *            custom args for the script.     */    public void initArgs(String[] args) {        super.initArgs(args);        delegateScript.initArgs(args);    }    /**     * Initializes the list of test cases to be excluded from the test.     * <p>     * This implementation forwards the call to both, the parent and the     * delegate scripts.     *     * @param excludedTestCases     *            a list of test cases within the test that should not be run     */    public void initExcludedTestCases(String[] excludedTestCases) {        super.initExcludedTestCases(excludedTestCases);        delegateScript.initExcludedTestCases(excludedTestCases);    }    /**     * Executes the script in a special manner. The JavaTest harness starts     * the test execution by invoking this method and this call is forwarded     * only to the parent script. The parent method then invokes     * {@link #run(String[], TestDescription, TestEnvironment)}, in     * accordance with its contract.     */    public void run() {        initDelegate(delegateScript, scriptArgs);        super.run();    }    /**     * Executes the script in a special manner. This call is forwarded only to     * the delegate script. This is the place where inheritance is replaced     * with delegation.     *     * @param args     *            Any script-specific options specified in the script property.     * @param td     *            The test description for the test to be performed.     * @param env     *            The test environment giving the details of how to run the     *            test.     * @return The result of running the script.     */    public Status run(String[] args, TestDescription td, TestEnvironment env) {        return delegateScript.run(args, td, env);    }}

⌨️ 快捷键说明

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