permissionsetfactory.java
来自「cqME :java framework for TCK test.」· Java 代码 · 共 117 行
JAVA
117 行
/* * $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.midp.policy;import java.util.StringTokenizer;import com.sun.javatest.TestDescription;import com.sun.javatest.TestEnvironment;import com.sun.javatest.util.I18NResourceBundle;/** * Convenient factory that produces PermissionSets. */public final class PermissionSetFactory { // This is a static utility class. private PermissionSetFactory() { super(); } /** * Returns a PermissionSet with permissions specified in the test * description, in "grant" and "deny" fields. May return an empty * PermissionSet if no permissions are specified. * <p> * Note: Values provided in "grant" and "deny" fields are resolved against * the Test Environment. * * @param td * The test. * @param env * The test environment. * @return A PermissionSet with specified permissions to be granted and * denied, as provided by the test description. * @throws IllegalArgumentException * in case of any errors. */ public static PermissionSet fromTest( TestDescription td, TestEnvironment env) { PermissionSet ps = new PermissionSet(); String granted = td.getParameter("grant"); if (granted != null) { granted = resolve(granted, env); StringTokenizer st = new StringTokenizer(granted, " \t\n\r\f,"); while (st.hasMoreTokens()) { if (!ps.grant(st.nextToken())) { throw new IllegalArgumentException( i18n.getString("tf.ContradictoryPermissions", td.getRootRelativeURL())); } } } String denied = td.getParameter("deny"); if (denied != null) { denied = resolve(denied, env); StringTokenizer st = new StringTokenizer(denied, " \t\n\r\f,"); while (st.hasMoreTokens()) { if (!ps.deny(st.nextToken())) { throw new IllegalArgumentException( i18n.getString("tf.ContradictoryPermissions", td.getRootRelativeURL())); } } } return ps; } private static String resolve(String s, TestEnvironment env) { try { String[] ss = env.resolve(s); if (ss.length == 0) { return ""; } StringBuffer buf = new StringBuffer(ss[0]); for (int i = 1; i < ss.length; i++) { buf.append(" ").append(ss[i]); } return buf.toString(); } catch (TestEnvironment.Fault e) { throw new IllegalArgumentException(i18n.getString("tf.ErrorResolving", s)); } } private static final I18NResourceBundle i18n = I18NResourceBundle.getBundleForClass(PermissionSetFactory.class);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?