jarquestion.java
来自「cqME :java framework for TCK test.」· Java 代码 · 共 125 行
JAVA
125 行
/* * $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.interview;import java.io.File;import java.util.Map;import com.sun.interview.ExtensionFileFilter;import com.sun.interview.FileQuestion;import com.sun.interview.Interview;import com.sun.interview.Question;import com.sun.javatest.TestSuite;class JarQuestion extends com.sun.interview.FileQuestion { Question next; String id; CldcBaseCommInterview i; public JarQuestion(CldcBaseCommInterview i, Interview j, String id, Question next) { super(j, id); this.i = i; this.next = next; this.id = id; setFilter(new ExtensionFileFilter("jar", "Jar Files")); } public JarQuestion(CldcBaseCommInterview i, String id, Question next) { this(i, i, id, next); } protected Question getNext() { if (value == null || value.getPath().equals("")) { wasMissingJar = false; return null; } else if (!value.exists()) { wasMissingJar = true; return null; } else if (!value.isFile()) { return null; } else { return next; } } public void export (Map data) { data.put(id, "\"" + value.getAbsolutePath() + "\""); } // override this to set the base dir // can't be done at construction time because TS is not available public File getValue() { File tsLib = i.getTckLibDir(); // could optimize this to only happen once if (tsLib != null && tsLib.canRead()) setBaseDirectory(tsLib); return super.getValue(); } public void setValue(File newVal) { boolean wasEq = equal(newVal, value); boolean pathUpdated = false; File adjustedValue = newVal; if (newVal == null || newVal.getPath().length() == 0) { super.setValue(newVal); return; } else if (!newVal.isAbsolute()) adjustedValue = new File(getBaseDirectory(), newVal.getPath()); // Workaround for the following problem: // If the user types a non-existent path, the validation fails // and the interview blocks. If the user then goes and creates // the file/path, the FileQuestion doesn't revalidate the value, // and the interview cannot continue. // use wasEq to avoid double updatePath - // superclass will do action if the value has actually changed if (wasMissingJar && wasEq && adjustedValue != null) { if (adjustedValue.exists()) { pathUpdated = true; wasMissingJar= false; } } super.setValue(adjustedValue); if (pathUpdated) { interview.updatePath(this); interview.setEdited(true); } } private boolean wasMissingJar;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?