preverifierelement.java
来自「MoMEUnit是一个单元测试的J2ME的应用程序xUnit架构实例。这是来自J」· Java 代码 · 共 258 行
JAVA
258 行
package org.momeunit.ant.taskdefs;import java.io.File;import java.util.Properties;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Task;import org.apache.tools.ant.types.Path;import org.momeunit.ant.core.Utility;import org.momeunit.ant.preverifier.Preverifier;/** * MoMEUnit nested tag intended to specify and configure <code>preverify</code> * tool used to preverify J2ME application. Contains method * {@link #getPreverifier(File, Path, ClassLoader)} for accessing configured * preverifier. Contains methods to set CLDC version used and configuration * properties. * * @author Sergio Morozov * @version 1.1.2 */public class PreverifierElement{ public static final String DEFAULT_PREVERIFIER = "sun"; private PreverifierType type = null; private String className = null; private String config = null; private File home = null; private Properties props = new Properties(); private Task task = null; /** * Instantiates PreverifierElement with owning task. * * @param task * owning task. * @since 1.1 */ public PreverifierElement(Task task) { super(); setTask(task); } /** * Instantiates PreverifierElement. * * @since 1.1 */ public PreverifierElement() { this(null); } /** * Returns CLDC version used. * * @return the CLDC version used. * @since 1.1 */ public String getConfig() { return this.config; } /** * Sets CLDC version used. * * @param config * CLDC version used. * @since 1.1 */ public void setConfig(String config) { Utility.assertNotEmpty(config, "config", "preverify"); this.config = config; } /** * Returns the owning task * * @return the owning task * @since 1.1 */ public Task getTask() { return this.task; } /** * Sets owning task. * * @param task * the owning task. * @since 1.1 */ public void setTask(Task task) { this.task = task; } /** * Returns classname of preverifier. * * @return the classname of preverifier. * @since 1.1 */ public String getPreverifierClass() { return this.className; } /** * Sets classname of preverifier. * * @param preverifierClass * classname of preverifier. * @since 1.1 */ public void setClassname(String preverifierClass) { this.className = preverifierClass; } /** * Returns type of preverifier. * * @return the type of preverifier. * @since 1.1 */ public String getType() { return this.type.getValue(); } /** * Sets type of preverifier. * * @param type * the type of preverifier. * @since 1.1 */ public void setType(String type) { Utility.assertNotEmpty(type, "type", "preverify"); this.type = new PreverifierType(type); } /** * Instantiates specified preverifier. * * @param prevClassName * classname of preverifier. * @param loader * class loader used to load preverifier class. * @return the preverifier instance. */ private Preverifier createPreverifier(String prevClassName, ClassLoader loader) { Preverifier res = null; Class prevClass = null; try { if (loader != null) prevClass = loader.loadClass(prevClassName); else prevClass = Class.forName(prevClassName); } catch (ClassNotFoundException e) { throw new BuildException("preverifier classname: " + prevClassName + " not found."); } try { res = (Preverifier) prevClass.newInstance(); } catch (InstantiationException e) { throw new BuildException("Can't instantiate preverifier of class " + prevClassName + "\nMake sure class contains public noarg constructor.", e); } catch (IllegalAccessException e) { throw new BuildException("Error accessing class " + prevClassName, e); } catch (ClassCastException e) { throw new BuildException("Preverifier " + prevClassName + " does not extend " + Preverifier.class.getName(), e); } return res; } /** * Returns configured preverifier. * * @param wtkHome * home directory of WTK. * @param classpath * classpath used to preverify classes of application. * @param loader * classloader used to load emulator class. * @return configured preverifier. * @since 1.1 */ public Preverifier getPreverifier(File wtkHome, Path classpath, ClassLoader loader) { if (this.type != null) { if (this.className != null) throw new BuildException( "Either type or classname attribute can be set on <preverify>."); this.className = this.type.getClassName(); } Preverifier res = createPreverifier(this.className != null ? this.className : new PreverifierType(DEFAULT_PREVERIFIER).getClassName(), loader); res.setTask(this.task); res.setWtkHome(this.home != null ? this.home : wtkHome); res.setClasspath(classpath); if (this.config != null) res.setConfig(this.config); res.addProperties(this.props); return res; } /** * Adds configuration property. * * @param prop * configuration property to add. * @since 1.1 */ public void addConfiguredProperty(PropertyElement prop) { String name = prop.getName(); Utility.assertNotEmpty(name, "name", "property"); String value = prop.getValue(); this.props.setProperty(name, value != null ? value : ""); } /** * Sets Preverifier home directory. * * @param home * the home preverifier directory to set. * @since 1.1 */ public void setHome(File home) { Utility.assertDirectory(home, "preverifier home "); this.home = home; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?