midponcdcsecurityscript.java.svn-base
来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 150 行
SVN-BASE
150 行
/* * $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 java.util.StringTokenizer;import java.util.Vector;import com.sun.javatest.Status;import com.sun.javatest.TestDescription;import com.sun.javatest.TestEnvironment;import com.sun.tck.javatest.TCKScript;import com.sun.tck.midp.policy.PermissionSet;import com.sun.tck.midp.policy.PermissionSetFactory;/** * The Script to execute Java ME security tests on CDC. * <p> * Note: This script expects the following entries to be defined in the test * environment: <code>cldcToCdcPermissionsMapper</code>. */public class MidpOnCdcSecurityScript extends TCKScript { /** * Constructs new script for execution MIDP security tests * on CDC security model. */ public MidpOnCdcSecurityScript() { super(); } /** * Runs the script. This is the primary method to be provided by Scripts. * * @param args any script-specific options specified in the script property. * (Ignored by this implementation). * @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) { PermissionSet perms = PermissionSetFactory.fromTest(td, env); if (perms.getDenied().hasMoreElements()) { addPermMapperToEnv(td, env, perms); addPermMapperEnvToEnv(td, env); env.put("cdcSecurityCommand", CMD_CLASS_NAME); } return super.run(args, td, env); } /** * Resolves cdcSecurityPermMapper TestEnvironment param. */ private void addPermMapperToEnv(TestDescription td, TestEnvironment env, PermissionSet perms) { String mapper = td.getParameter(PERM_MAPPER_PARAM_NAME); Vector vMapper = null; if (mapper == null) { vMapper = new Vector(); vMapper.add(PERM_MAPPER_CLASS_CMD_PARAM); vMapper.add(lookupVar(env, PERM_MAPPER_CLASS_PARAM_NAME)); } else { vMapper = parseParams(mapper); vMapper.insertElementAt(PERM_MAPPER_CLASS_CMD_PARAM, 0); } vMapper.add(PERM_MAPPER_MIDP_PERMS_CMD_PARAM); vMapper.add(perms.toString()); env.put(PERM_MAPPER_PARAM_NAME, toArray(vMapper)); } /** * Resolves cdcSecurityPermMapperEnv TestEnvironment param. */ private void addPermMapperEnvToEnv(TestDescription td, TestEnvironment env) { String mapperEnv = td.getParameter(PERM_MAPPER_ENV_PARAM_NAME); if (mapperEnv != null) { Vector vMappperEnv = parseParams(mapperEnv); vMappperEnv.insertElementAt(PERM_MAPPER_ENV_CMD_PARAM, 0); vMappperEnv.add(PERM_MAPPER_ENV_END_CMD_PARAM); env.put(PERM_MAPPER_ENV_PARAM_NAME, toArray(vMappperEnv)); } } private String lookupVar(TestEnvironment env, String key) { String retVar = null; try { String[] envData = env.lookup(key); retVar = envData[0]; } catch (TestEnvironment.Fault e) { e.printStackTrace(); throw new IllegalArgumentException("Problem resolving the value of the property:" + key); } return retVar; } private Vector parseParams(String params) { Vector retVector = new Vector(); StringTokenizer strToken = new StringTokenizer(params, " \t\n\r\f,"); while (strToken.hasMoreTokens()) { retVector.add(strToken.nextToken()); } return retVector; } private String[] toArray(Vector v) { String[] ar = new String[v.size()]; ar = (String[])v.toArray(ar); return ar; } private static String PERM_MAPPER_PARAM_NAME = "cdcSecurityPermMapper"; private static String PERM_MAPPER_CLASS_PARAM_NAME = "cdcSecurityPermMapperClass"; private static String PERM_MAPPER_ENV_PARAM_NAME = "cdcSecurityPermMapperEnv"; private static String PERM_MAPPER_CLASS_CMD_PARAM = "-permMapperClass"; private static String PERM_MAPPER_MIDP_PERMS_CMD_PARAM = "-permMapperMIDPPerms"; private static String PERM_MAPPER_ENV_CMD_PARAM = "-permMapperEnv"; private static String PERM_MAPPER_ENV_END_CMD_PARAM = "-permMapperEnvEnd"; private static String CMD_CLASS_NAME = "com.sun.tck.cdc.lib.security.ExecWithMidpSecurityCommand";}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?