custompermissionsinterview.java.svn-base
来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 478 行 · 第 1/2 页
SVN-BASE
478 行
/* * $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.util.ArrayList;import java.util.Arrays;import java.util.Iterator;import java.util.List;import java.util.MissingResourceException;import java.util.Set;import java.util.logging.Logger;import javax.help.Map.ID;import com.sun.interview.ChoiceArrayQuestion;import com.sun.interview.ChoiceQuestion;import com.sun.interview.ErrorQuestion;import com.sun.interview.FinalQuestion;import com.sun.interview.Interview;import com.sun.interview.NullQuestion;import com.sun.interview.Question;import com.sun.tck.midp.policy.PermissionSet;import java.util.ResourceBundle;/** * Dynamic custom permissions interview that is configurable by properties. * * <p>The interview may contain many <code>ChoiceArray</code> questions, one * question per each specification (e.g. midp permissions, mmapi permissions, * etc.). * * <p>Configuration properties format is as follows: * <pre> # ordered list of all sub-questions to be shown in the interview specs = midp mmapi wma ######### midp spec ######## # summary for midp permissions question midp.smry = stuff # text for midp permissions question midp.text = text # list of all midp permissions midp.permissions = javax.microedition.io.Connector.https #short names that appear in the GUI javax.microedition.io.Connector.https = shortName ##### end of midp spec ######## ######### mmapi spec ######## mmapi.permissions = javax.microedition.media.control.RecordControl mmapi.smry = custom MMAPI perms mmapi.text = custom MMAPI text javax.microedition.media.control.RecordControl = MMAPI RecordControl # this permission will always be granted javax.microedition.media.control.RecordControl.alwaysGranted = true ##### end of mmapi spec ######## ######### wma spec ######## wma.permissions=javax.wma.Connector \ javax.wma.Receiver javax.wma.Connector = WMA Connector javax.wma.Receiver = WMA Receiver # this permission will always be denied javax.wma.Receiver.alwaysDenied = true ##### end of wma spec ######## </pre> * <p> Besides the specifications list, permissions list and * permissions' short names, it is possible to specify whether the permission * is always granted or always denied via: * <pre> * PERMISSION_1.alwaysGranted = true * PERMISSION_2.alwaysDenied = true * </pre> * Currently, always granted and always denied permissions are not * shown to the user, but {@link #getPermissionSet()} returns a proper * permission set that takes them into account. */public class CustomPermissionsInterview extends Interview { /** * Creates an <code>Interview</code> with the specified parent and then * configures it with properties from resource bundle. * * <p>If properties location is <code>null</code>, an empty interview * will be created. * * @param parent * parent interview. * @param permsBundle * resource bundle with properties. * @throws Interview.Fault * if there are problems during interview creation. */ public CustomPermissionsInterview(Interview parent, ResourceBundle permsBundle) throws Interview.Fault { super(parent, "customPermissions"); setHelpSet("help/vm"); setResourceBundle("trusted"); // empty interview by default setFirstQuestion(qEnd); questions = new MyChoiceQuestion[] {}; if (permsBundle == null) { log.config("Created empty PermissionsInterview, " + "since permsBundle is null"); return; } Permissions perms = new Permissions(permsBundle); String[] specs = perms.getSpecs(); if (specs == null || specs.length == 0) { return; } questions = new MyChoiceQuestion[specs.length]; // create single Help ID for all questions Question dummy = new ErrorQuestion(this, "customPerms"); ID id = dummy.getHelpID(); // create an array of all ChoiceArray questions for (int i = 0; i < specs.length; i++) { String spec = specs[i]; MyChoiceQuestion q = new MyChoiceQuestion(this, spec, id, perms); questions[i] = q; } if (questions.length > 1) { // add intro question if there are more than 1 permission groups setFirstQuestion(qIntro); } else { setFirstQuestion(questions[0]); } // chain each question to the next one for (int i = 0; i < questions.length - 1; i++) { questions[i].setNext(questions[i + 1]); } questions[questions.length - 1].setNext(qEnd); } /** * Returns true if interview is empty. * The interview is empty when there are no specs in permissions * file or all of them with empty permissions list. * @return true if interview is empty */ public boolean isEmpty() { return questions.length == 0; } /** * Returns a {@link com.sun.tck.midp.policy.PermissionSet} object, * corresponding to the answers of this interview. * * <p>Returns empty <code>PermissionSet</code> if the questions of * this interview are not on Interview path. * * @return the PermissionSet object. */ public PermissionSet getPermissionSet() { PermissionSet ps = new PermissionSet(); // make sure that this interview is indeed on path if (pathContains(getFirstQuestion())) { if (!pathContains(qQuickPermissions) || qQuickPermissions.isCustom()) { for (int i = 0; i < questions.length; i++) { MyChoiceQuestion q = questions[i]; boolean okStatus = ps.merge(q.getPermissionSet()); assert okStatus : "Contradicting permissions " + "in CustomPermissionsInterview(#0)!"; } } else { for (int i = 0; i < questions.length; i++) { MyChoiceQuestion q = questions[i]; boolean okStatus = ps.merge(q.getMaxPermissionSet()); assert okStatus : "Contradicting permissions " + "in CustomPermissionsInterview(#5)!"; } } } return ps; } /** * Returns a string representation of the object. * * @return a string representation of the object. */ public String toString() { String result = "[" + getClass().getName(); Question[] path = getPath(); if (path == null) { result += "NULL PATH"; } else { for (int i = 0; i < path.length; i++) { if (path[i] != null) { result += "[" + path[i].getTag() + "] "; } else { result += "[NULL QUESTION]"; } } } return result + "]"; } private MyChoiceQuestion[] questions;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?