?? packagepermission.java
字號:
/* * $Header: /cvshome/repository/org/osgi/framework/PackagePermission.java,v 1.10 2002/10/07 07:14:18 pkriens Exp $ * * Copyright (c) The Open Services Gateway Initiative (2000, 2002). * All Rights Reserved. * * Implementation of certain elements of the Open Services Gateway Initiative * (OSGI) Specification may be subject to third party intellectual property * rights, including without limitation, patent rights (such a third party may * or may not be a member of OSGi). OSGi is not responsible and shall not be * held responsible in any manner for identifying or failing to identify any or * all such third party intellectual property rights. * * This document and the information contained herein are provided on an "AS * IS" basis and OSGI DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL * NOT INFRINGE ANY RIGHTS AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL OSGI BE LIABLE FOR ANY * LOSS OF PROFITS, LOSS OF BUSINESS, LOSS OF USE OF DATA, INTERRUPTION OF * BUSINESS, OR FOR DIRECT, INDIRECT, SPECIAL OR EXEMPLARY, INCIDENTIAL, * PUNITIVE OR CONSEQUENTIAL DAMAGES OF ANY KIND IN CONNECTION WITH THIS * DOCUMENT OR THE INFORMATION CONTAINED HEREIN, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH LOSS OR DAMAGE. * * All Company, brand and product names may be trademarks that are the sole * property of their respective owners. All rights reserved. */package org.osgi.framework;import java.io.IOException;import java.security.BasicPermission;import java.security.Permission;import java.security.PermissionCollection;import java.util.Enumeration;import java.util.Hashtable;/** * A bundle's authority to import or export a package. * * <p>A package is a dot-separated string that defines a fully qualified Java * package. * <p>For example: * <pre> * <tt>org.osgi.service.http</tt> * </pre> * <p><tt>PackagePermission</tt> has two actions: <tt>EXPORT</tt> and <tt>IMPORT</tt>. * The <tt>EXPORT</tt> action implies the <tt>IMPORT</tt> action. * * @version $Revision: 1.10 $ * @author Open Services Gateway Initiative */public final class PackagePermission extends BasicPermission{ /** * The action string <tt>export</tt>. */ public final static String EXPORT = "export"; /** * The action string <tt>import</tt>. */ public final static String IMPORT = "import"; private final static int ACTION_EXPORT = 0x00000001; private final static int ACTION_IMPORT = 0x00000002; private final static int ACTION_ALL = ACTION_EXPORT | ACTION_IMPORT; private final static int ACTION_NONE = 0; private final static int ACTION_ERROR = 0x80000000; /** * The actions mask. */ private transient int action_mask = ACTION_NONE; /** * The actions in canonical form. * * @serial */ private String actions = null; /** * Defines the authority to import and/or export a package within the OSGi environment. * <p>The name is specified as a normal Java package name: a dot-separated string. Wildcards may be used. * For example: * <pre> * org.osgi.service.http * javax.servlet.* * * * </pre> * <p>Package Permissions are granted over all possible versions of a package. * * A bundle that needs to export a package must have the appropriate <tt>PackagePermission</tt> * for that package; similarly, a bundle that needs to import a package must have the appropriate * <tt>PackagePermssion</tt> for that package. * <p>Permission is granted for both classes and resources. * @param name Package name. * @param actions <tt>EXPORT</tt>, <tt>IMPORT</tt> (canonical order). */ public PackagePermission(String name, String actions) { this(name, getMask(actions)); } /** * Package private constructor used by PackagePermissionCollection. * * @param name class name * @param action mask */ PackagePermission(String name, int mask) { super(name); init(mask); } /** * Called by constructors and when deserialized. * * @param action mask */ private void init(int mask) { if ((mask == ACTION_NONE) || ((mask & ACTION_ALL) != mask)) { throw new IllegalArgumentException("invalid action string"); } action_mask = mask; } /** * Parse action string into action mask. * * @param actions Action string. * @return action mask. */ private static int getMask(String actions) { boolean seencomma = false; int mask = ACTION_NONE; if (actions == null) { return (mask); } char[] a = actions.toCharArray(); int i = a.length - 1; if (i < 0) return (mask); while (i != -1) { char c; // skip whitespace while ((i!=-1) && ((c = a[i]) == ' ' || c == '\r' || c == '\n' || c == '\f' || c == '\t')) i--; // check for the known strings int matchlen; if (i >= 5 && (a[i-5] == 'i' || a[i-5] == 'I') && (a[i-4] == 'm' || a[i-4] == 'M') && (a[i-3] == 'p' || a[i-3] == 'P') && (a[i-2] == 'o' || a[i-2] == 'O') && (a[i-1] == 'r' || a[i-1] == 'R') && (a[i] == 't' || a[i] == 'T')) { matchlen = 6; mask |= ACTION_IMPORT; } else if (i >= 5 && (a[i-5] == 'e' || a[i-5] == 'E') && (a[i-4] == 'x' || a[i-4] == 'X') && (a[i-3] == 'p' || a[i-3] == 'P') && (a[i-2] == 'o' || a[i-2] == 'O') && (a[i-1] == 'r' || a[i-1] == 'R') && (a[i] == 't' || a[i] == 'T')) { matchlen = 6; mask |= ACTION_EXPORT | ACTION_IMPORT; } else { // parse error throw new IllegalArgumentException("invalid permission: " + actions); } // make sure we didn't just match the tail of a word // like "ackbarfimport". Also, skip to the comma. seencomma = false; while (i >= matchlen && !seencomma) { switch (a[i-matchlen]) { case ',': seencomma = true; /*FALLTHROUGH*/ case ' ': case '\r': case '\n': case '\f': case '\t': break; default: throw new IllegalArgumentException("invalid permission: " + actions); } i--; } // point i at the location of the comma minus one (or -1). i -= matchlen; } if (seencomma) { throw new IllegalArgumentException("invalid permission: " + actions); } return (mask); } /** * Determines if the specified permission is implied by this object. * * <p>This method checks that the package name of the target is implied by the package name * of this object. The list of <tt>PackagePermission</tt> actions must either match or allow * for the list of the target object to imply the target <tt>PackagePermission</tt> action. * <p>The permission to export a package implies the permission to import the named package. * <pre> * x.y.*,"export" -> x.y.z,"export" is true * *,"import" -> x.y, "import" is true * *,"export" -> x.y, "import" is true * x.y,"export" -> x.y.z, "export" is false * </pre> * * @param p The target permission to interrogate. * @return <tt>true</tt> if the specified <tt>PackagePermission</tt> action is implied by * this object; <tt>false</tt> otherwise. */ public boolean implies(Permission p) { if (p instanceof PackagePermission) { PackagePermission target = (PackagePermission) p; return(((action_mask & target.action_mask)==target.action_mask) && super.implies(p)); } return(false); } /** * Returns the canonical string representation of the <tt>PackagePermission</tt> actions. * * <p>Always returns present <tt>PackagePermission</tt> actions in the following order: * <tt>EXPORT</tt>, <tt>IMPORT</tt>. * @return Canonical string representation of the <tt>PackagePermission</tt> actions. */ public String getActions() { if (actions == null) { StringBuffer sb = new StringBuffer(); boolean comma = false; if ((action_mask & ACTION_EXPORT) == ACTION_EXPORT)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -