org.eclipse.osgi_3.7.2.v20120110-1415

e Object parse_substring()
        throws InvalidSyntaxException
      {
        StringBuffer sb = new StringBuffer(filterChars.length - pos);
        
        List<String> operands = new ArrayList(10);
        for (;;)
        {
          char c = filterChars[pos];
          switch (c)
          {
          case ')': 
            if (sb.length() <= 0) {
              break label222;
            }
            operands.add(sb.toString());
            
            break;
          case '(': 
            throw new InvalidSyntaxException("Invalid value: " + 
              filterstring.substring(pos), filterstring);
          case '*': 
            if (sb.length() > 0) {
              operands.add(sb.toString());
            }
            sb.setLength(0);
            
            operands.add(null);
            pos += 1;
            
            break;
          case '\\': 
            pos += 1;
            c = filterChars[pos];
          default: 
            sb.append(c);
            pos += 1;
          }
        }
        label222:
        int size = operands.size();
        if (size == 0) {
          return "";
        }
        if (size == 1)
        {
          Object single = operands.get(0);
          if (single != null) {
            return single;
          }
        }
        return operands.toArray(new String[size]);
      }
      
      private void skipWhiteSpace()
      {
        for (int length = filterChars.length; (pos < length) && (
              Character.isWhitespace(filterChars[pos]));) {
          pos += 1;
        }
      }
    }
  }
  
  private static final class CaseInsensitiveMap
    extends AbstractMap<String, Object>
    implements Map<String, Object>
  {
    private final Dictionary<String, ?> dictionary;
    private final String[] keys;
    
    CaseInsensitiveMap(Dictionary<String, ?> dictionary)
    {
      if (dictionary == null)
      {
        this.dictionary = null;
        keys = new String[0];
        return;
      }
      this.dictionary = dictionary;
      List<String> keyList = new ArrayList(dictionary.size());
      for (Enumeration<?> e = dictionary.keys(); e.hasMoreElements();)
      {
        Object k = e.nextElement();
        if ((k instanceof String))
        {
          String key = (String)k;
          for (Iterator localIterator = keyList.iterator(); localIterator.hasNext();)
          {
            String i = (String)localIterator.next();
            if (key.equalsIgnoreCase(i)) {
              throw new IllegalArgumentException();
            }
          }
          keyList.add(key);
        }
      }
      keys = ((String[])keyList.toArray(new String[keyList.size()]));
    }
    
    public Object get(Object o)
    {
      String k = (String)o;
      String[] arrayOfString;
      int j = (arrayOfString = keys).length;
      for (int i = 0; i < j; i++)
      {
        String key = arrayOfString[i];
        if (key.equalsIgnoreCase(k)) {
          return dictionary.get(key);
        }
      }
      return null;
    }
    
    public Set<Map.Entry<String, Object>> entrySet()
    {
      throw new UnsupportedOperationException();
    }
  }
  
  private static final class ServiceReferenceMap
    extends AbstractMap<String, Object>
    implements Map<String, Object>
  {
    private final ServiceReference<?> reference;
    
    ServiceReferenceMap(ServiceReference<?> reference)
    {
      this.reference = reference;
    }
    
    public Object get(Object key)
    {
      if (reference == null) {
        return null;
      }
      return reference.getProperty((String)key);
    }
    
    public Set<Map.Entry<String, Object>> entrySet()
    {
      throw new UnsupportedOperationException();
    }
  }
  
  private static final class SetAccessibleAction
    implements PrivilegedAction<Object>
  {
    private final AccessibleObject accessible;
    
    SetAccessibleAction(AccessibleObject accessible)
    {
      this.accessible = accessible;
    }
    
    public Object run()
    {
      accessible.setAccessible(true);
      return null;
    }
  }
  
  private static final class DNChainMatching
  {
    private static final String MINUS_WILDCARD = "-";
    private static final String STAR_WILDCARD = "*";
    
    private static boolean rdnmatch(List<?> rdn, List<?> rdnPattern)
    {
      if (rdn.size() != rdnPattern.size()) {
        return false;
      }
      for (int i = 0; i < rdn.size(); i++)
      {
        String rdnNameValue = (String)rdn.get(i);
        String patNameValue = (String)rdnPattern.get(i);
        int rdnNameEnd = rdnNameValue.indexOf('=');
        int patNameEnd = patNameValue.indexOf('=');
        if ((rdnNameEnd != patNameEnd) || 
          (!rdnNameValue.regionMatches(0, patNameValue, 0, 
          rdnNameEnd))) {
          return false;
        }
        String patValue = patNameValue.substring(patNameEnd);
        String rdnValue = rdnNameValue.substring(rdnNameEnd);
        if ((!rdnValue.equals(patValue)) && (!patValue.equals("=*")) && 
          (!patValue.equals("=#16012a"))) {
          return false;
        }
      }
      return true;
    }
    
    private static boolean dnmatch(List<?> dn, List<?> dnPattern)
    {
      int dnStart = 0;
      int patStart = 0;
      int patLen = dnPattern.size();
      if (patLen == 0) {
        return false;
      }
      if (dnPattern.get(0).equals("*"))
      {
        patStart = 1;
        patLen--;
      }
      if (dn.size() < patLen) {
        return false;
      }
      if (dn.size() > patLen)
      {
        if (!dnPattern.get(0).equals("*")) {
          return false;
        }
        dnStart = dn.size() - patLen;
      }
      for (int i = 0; i < patLen; i++) {
        if (!rdnmatch((List)dn.get(i + dnStart), 
        
          (List)dnPattern.get(i + patStart))) {
          return false;
        }
      }
      return true;
    }
    
    private static List<Object> parseDNchainPattern(String dnChain)
    {
      if (dnChain == null) {
        throw new IllegalArgumentException(
          "The DN chain must not be null.");
      }
      List<Object> parsed = new ArrayList();
      int startIndex = 0;
      startIndex = skipSpaces(dnChain, startIndex);
      label124:
      while (startIndex < dnChain.length())
      {
        int endIndex = startIndex;
        boolean inQuote = false;
        while (endIndex < dnChain.length())
        {
          char c = dnChain.charAt(endIndex);
          switch (c)
          {
          case '"': 
            inQuote = !inQuote;
            break;
          case '\\': 
            endIndex++;
            break;
          case ';': 
            if (!inQuote) {
              break label124;
            }
          }
          endIndex++;
        }
        if (endIndex > dnChain.length()) {
          throw new IllegalArgumentException("unterminated escape");
        }
        parsed.add(dnChain.substring(startIndex, endIndex));
        startIndex = endIndex + 1;
        startIndex = skipSpaces(dnChain, startIndex);
      }
      for (int i = 0; i < parsed.size(); i++)
      {
        String dn = (String)parsed.get(i);
        if ((!dn.equals("*")) && (!dn.equals("-")))
        {
          List<Object> rdns = new ArrayList();
          if (dn.charAt(0) == '*')
          {
            if (dn.charAt(1) != ',') {
              throw new IllegalArgumentException(
                "invalid wildcard prefix");
            }
            rdns.add("*");
            dn = new X500Principal(dn.substring(2))
              .getName("CANONICAL");
          }
          else
          {
            dn = new X500Principal(dn).getName("CANONICAL");
          }
          parseDN(dn, rdns);
          parsed.set(i, rdns);
        }
      }
      if (parsed.size() == 0) {
        throw new IllegalArgumentException("empty DN chain");
      }
      return parsed;
    }
    
    private static List<Object> parseDNchain(List<String> chain)
    {
      if (chain == null) {
        throw new IllegalArgumentException("DN chain must not be null.");
      }
      List<Object> result = new ArrayList(chain.size());
      for (Iterator localIterator = chain.iterator(); localIterator.hasNext();)
      {
        String dn = (String)localIterator.next();
        dn = new X500Principal(dn).getName("CANONICAL");
        
        List<Object> rdns = new ArrayList();
        parseDN(dn, rdns);
        result.add(rdns);
      }
      if (result.size() == 0) {
        throw new IllegalArgumentException("empty DN chain");
      }
      return result;
    }
    
    private static int skipSpaces(String dnChain, int startIndex)
    {
      while ((startIndex < dnChain.length()) && 
        (dnChain.charAt(startIndex) == ' ')) {
        startIndex++;
      }
      return startIndex;
    }
    
    private static void parseDN(String dn, List<Object> rdn)
    {
      int startIndex = 0;
      char c = '\000';
      List<String> nameValues = new ArrayList();
      while (startIndex < dn.length())
      {
        for (int endIndex = startIndex; endIndex < dn.length(); endIndex++)
        {
          c = dn.charAt(endIndex);
          if ((c == ',') || (c == '+')) {
            break;
          }
          if (c == '\\') {
            endIndex++;
          }
        }
        if (endIndex > dn.length()) {
          throw new IllegalArgumentException("unterminated escape " + 
            dn);
        }
        nameValues.add(dn.substring(startIndex, endIndex));
        if (c != '+')
        {
          rdn.add(nameValues);
          if (endIndex != dn.length()) {
            nameValues = new ArrayList();
          } else {
            nameValues = null;
          }
        }
        startIndex = endIndex + 1;
      }
      if (nameValues != null) {
        throw new IllegalArgumentException("improperly terminated DN " + 
          dn);
      }
    }
    
    private static int skipWildCards(List<Object> dnChainPattern, int dnChainPatternIndex)
    {
      for (int i = dnChainPatternIndex; i < dnChainPattern.size(); i++)
      {
        Object dnPattern = dnChainPattern.get(i);
        if ((dnPattern instanceof String))
        {
          if ((!dnPattern.equals("*")) && 
            (!dnPattern.equals("-"))) {
            throw new IllegalArgumentException(
              "expected wildcard in DN pattern");
          }
        }
        else
        {
          if ((dnPattern instanceof List)) {
            break;
          }
          throw new IllegalArgumentException(
            "expected String or List in DN Pattern");
        }
      }
      return i;
    }
    
    private static boolean dnChainMatch(List<Object> dnChain, int dnChainIndex, List<Object> dnChainPattern, int dnChainPatternIndex)
      throws IllegalArgumentException
    {
      if (dnChainIndex >= dnChain.size()) {
        return false;
      }
      if (dnChainPatternIndex >= dnChainPattern.size()) {
        return false;
      }
      Object dnPattern = dnChainPattern.get(dnChainPatternIndex);
      if ((dnPattern instanceof String))
      {
        if ((!dnPattern.equals("*")) && 
          (!dnPattern.equals("-"))) {
          throw new IllegalArgumentException(
            "expected wildcard in DN pattern");
        }
        if (dnPattern.equals("-")) {
          dnChainPatternIndex = skipWildCards(dnChainPattern, 
            dnChainPatternIndex);
        } else {
          dnChainPatternIndex++;
        }
        if (dnChainPatternIndex >= dnChainPattern.size()) {
          return dnPattern.equals("-");
        }
        if (dnPattern.equals("*"))
        {
          if (!dnChainMatch(dnChain, dnChainIndex, dnChainPattern, 
            dnChainPatternIndex)) {
            if (!dnChainMatch(dnChain, dnChainIndex + 1, 
              dnChainPattern, dnChainPatternIndex)) {
              return false;
            }
          }
          return 
          
            true;
        }
        for (int i = dnChainIndex; i < dnChain.size(); i++) {
          if (dnChainMatch(dnChain, i, dnChainPattern, 
            dnChainPatternIndex)) {
            return true;
          }
        }
      }
      else
      {
        if ((dnPattern instanceof List))
        {
          do
          {
            if (!dnmatch((List)dnChain.get(dnChainIndex), 
              (List)dnPattern)) {
              return false;
            }
            dnChainIndex++;
            dnChainPatternIndex++;
            if (dnChainIndex >= dnChain.size()) {
              if (dnChainPatternIndex >= dnChainPattern.size()) {
                return true;
              }
            }
            if (dnChainIndex >= dnChain.size())
            {
              dnChainPatternIndex = skipWildCards(dnChainPattern, 
                dnChainPatternIndex);
              
              return dnChainPatternIndex >= dnChainPattern.size();
            }
            if (dnChainPatternIndex >= dnChainPattern.size()) {
              return false;
            }
            dnPattern = dnChainPattern.get(dnChainPatternIndex);
            if ((dnPattern instanceof String))
            {
              if ((!dnPattern.equals("*")) && 
                (!dnPattern.equals("-"))) {
                throw new IllegalArgumentException(
                  "expected wildcard in DN pattern");
              }
              return dnChainMatch(dnChain, dnChainIndex, 
                dnChainPattern, dnChainPatternIndex);
            }
          } while ((dnPattern instanceof List));
          throw new IllegalArgumentException(
            "expected String or List in DN Pattern");
        }
        throw new IllegalArgumentException(
          "expected String or List in DN Pattern");
      }
      return false;
    }
    
    static boolean match(String pattern, List<String> dnChain)
    {
      try
      {
        parsedDNChain = parseDNchain(dnChain);
      }
      catch (RuntimeException e)
      {
        List<Object> parsedDNChain;
        IllegalArgumentException iae = new IllegalArgumentException(
          "Invalid DN chain: " + toString(dnChain));
        iae.initCause(e);
        throw iae;
      }
      List<Object> parsedDNChain;
      try
      {
        parsedDNPattern = parseDNchainPattern(pattern);
      }
      catch (RuntimeException e)
      {
        List<Object> parsedDNPattern;
        IllegalArgumentException iae = new IllegalArgumentException(
          "Invalid match pattern: " + pattern);
        iae.initCause(e);
        throw iae;
      }
      List<Object> parsedDNPattern;
      return dnChainMatch(parsedDNChain, 0, parsedDNPattern, 0);
    }
    
    private static String toString(List<?> dnChain)
    {
      if (dnChain == null) {
        return null;
      }
      StringBuffer sb = new StringBuffer();
      for (Iterator<?> iChain = dnChain.iterator(); iChain.hasNext();)
      {
        sb.append(iChain.next());
        if (iChain.hasNext()) {
          sb.append("; ");
        }
      }
      return sb.toString();
    }
  }
}

/* Location:
 * Qualified Name:     org.osgi.framework.FrameworkUtil
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

public class InvalidSyntaxException
  extends Exception
{
  static final long serialVersionUID = -4295194420816491875L;
  private final String filter;
  
  public InvalidSyntaxException(String msg, String filter)
  {
    super(msg);
    this.filter = filter;
  }
  
  public InvalidSyntaxException(String msg, String filter, Throwable cause)
  {
    super(msg, cause);
    this.filter = filter;
  }
  
  public String getFilter()
  {
    return filter;
  }
  
  public Throwable getCause()
  {
    return super.getCause();
  }
  
  public Throwable initCause(Throwable cause)
  {
    return super.initCause(cause);
  }
}

/* Location:
 * Qualified Name:     org.osgi.framework.InvalidSyntaxException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

import java.security.PrivilegedAction;
import java.util.Map;

class PackagePermission$1
  implements PrivilegedAction<Object>
{
  final PackagePermission this$0;
  
  PackagePermission$1(PackagePermission paramPackagePermission, Map paramMap) {}
  
  public Object run()
  {
    val$map.put("id", new Long(this$0.bundle.getBundleId()));
    val$map.put("location", this$0.bundle.getLocation());
    String name = this$0.bundle.getSymbolicName();
    if (name != null) {
      val$map.put("name", name);
    }
    SignerProperty signer = new SignerProperty(this$0.bundle);
    if (signer.isBundleSigned()) {
      val$map.put("signer", signer);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.osgi.framework.PackagePermission.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

import java.io.IOException;
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.AccessController;
import java.security.BasicPermission;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;

public final class PackagePermission
  extends BasicPermission
{
  static final long serialVersionUID = -5107705877071099135L;
  /**
   * @deprecated
   */
  public static final String EXPORT = "export";
  public static final String EXPORTONLY = "exportonly";
  public static final String IMPORT = "import";
  private static final int ACTION_EXPORT = 1;
  private static final int ACTION_IMPORT = 2;
  private static final int ACTION_ALL = 3;
  static final int ACTION_NONE = 0;
  transient int action_mask;
  private volatile String actions = null;
  final transient Bundle bundle;
  transient Filter filter;
  private volatile transient Map<String, Object> properties;
  
  public PackagePermission(String name, String actions)
  {
    this(name, parseActions(actions));
    if ((filter != null) && 
      ((action_mask & 0x3) != 2)) {
      throw new IllegalArgumentException(
        "invalid action string for filter expression");
    }
  }
  
  public PackagePermission(String name, Bundle exportingBundle, String actions)
  {
    super(name);
    setTransients(name, parseActions(actions));
    bundle = exportingBundle;
    if (exportingBundle == null) {
      throw new IllegalArgumentException("bundle must not be null");
    }
    if (filter != null) {
      throw new IllegalArgumentException("invalid name");
    }
    if ((action_mask & 0x3) != 2) {
      throw new IllegalArgumentException("invalid action string");
    }
  }
  
  PackagePermission(String name, int mask)
  {
    super(name);
    setTransients(name, mask);
    bundle = null;
  }
  
  private void setTransients(String name, int mask)
  {
    if ((mask == 0) || ((mask & 0x3) != mask)) {
      throw new IllegalArgumentException("invalid action string");
    }
    action_mask = mask;
    filter = parseFilter(name);
  }
  
  private static int parseActions(String actions)
  {
    boolean seencomma = false;
    
    int mask = 0;
    if (actions == null) {
      return mask;
    }
    char[] a = actions.toCharArray();
    
    int i = a.length - 1;
    if (i < 0) {}
    while (i != -1)
    {
      return mask;
      char c;
      while ((i != -1) && (
        ((c = a[i]) == ' ') || (c == '\r') || (c == '\n') || 
        (c == '\f') || (c == '\t')))
      {
        char c;
        i--;
      }
      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')))
      {
        int matchlen = 6;
        mask |= 0x2;
      }
      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')))
      {
        int matchlen = 6;
        mask |= 0x3;
      }
      else if ((i >= 9) && ((a[(i - 9)] == 'e') || (a[(i - 9)] == 'E')) && 
        ((a[(i - 8)] == 'x') || (a[(i - 8)] == 'X')) && 
        ((a[(i - 7)] == 'p') || (a[(i - 7)] == 'P')) && 
        ((a[(i - 6)] == 'o') || (a[(i - 6)] == 'O')) && 
        ((a[(i - 5)] == 'r') || (a[(i - 5)] == 'R')) && 
        ((a[(i - 4)] == 't') || (a[(i - 4)] == 'T')) && 
        ((a[(i - 3)] == 'o') || (a[(i - 3)] == 'O')) && 
        ((a[(i - 2)] == 'n') || (a[(i - 2)] == 'N')) && 
        ((a[(i - 1)] == 'l') || (a[(i - 1)] == 'L')) && (
        (a[i] == 'y') || (a[i] == 'Y')))
      {
        int matchlen = 10;
        mask |= 0x1;
      }
      else
      {
        throw new IllegalArgumentException(
          "invalid permission: " + actions);
      }
      int matchlen;
      seencomma = false;
      while ((i >= matchlen) && (!seencomma))
      {
        switch (a[(i - matchlen)])
        {
        case ',': 
          seencomma = true;
        case '\t': 
        case '\n': 
        case '\f': 
        case '\r': 
        case ' ': 
          break;
        default: 
          throw new IllegalArgumentException(
            "invalid permission: " + actions);
        }
        i--;
      }
      i -= matchlen;
    }
    if (seencomma) {
      throw new IllegalArgumentException("invalid permission: " + actions);
    }
    return mask;
  }
  
  private static Filter parseFilter(String filterString)
  {
    filterString = filterString.trim();
    if (filterString.charAt(0) != '(') {
      return null;
    }
    try
    {
      return FrameworkUtil.createFilter(filterString);
    }
    catch (InvalidSyntaxException e)
    {
      IllegalArgumentException iae = new IllegalArgumentException(
        "invalid filter");
      iae.initCause(e);
      throw iae;
    }
  }
  
  public boolean implies(Permission p)
  {
    if (!(p instanceof PackagePermission)) {
      return false;
    }
    PackagePermission requested = (PackagePermission)p;
    if (bundle != null) {
      return false;
    }
    if (filter != null) {
      return false;
    }
    return implies0(requested, 0);
  }
  
  boolean implies0(PackagePermission requested, int effective)
  {
    effective |= action_mask;
    int desired = action_mask;
    if ((effective & desired) != desired) {
      return false;
    }
    Filter f = filter;
    if (f == null) {
      return super.implies(requested);
    }
    return f.matches(requested.getProperties());
  }
  
  public String getActions()
  {
    String result = actions;
    if (result == null)
    {
      StringBuffer sb = new StringBuffer();
      boolean comma = false;
      
      int mask = action_mask;
      if ((mask & 0x1) == 1)
      {
        sb.append("exportonly");
        comma = true;
      }
      if ((mask & 0x2) == 2)
      {
        if (comma) {
          sb.append(',');
        }
        sb.append("import");
      }
      actions = (result = sb.toString());
    }
    return result;
  }
  
  public PermissionCollection newPermissionCollection()
  {
    return new PackagePermissionCollection();
  }
  
  public boolean equals(Object obj)
  {
    if (obj == this) {
      return true;
    }
    if (!(obj instanceof PackagePermission)) {
      return false;
    }
    PackagePermission pp = (PackagePermission)obj;
    
    return (action_mask == action_mask) && (getName().equals(pp.getName())) && ((bundle == bundle) || ((bundle != null) && (bundle.equals(bundle))));
  }
  
  public int hashCode()
  {
    int h = 527 + getName().hashCode();
    h = 31 * h + getActions().hashCode();
    if (bundle != null) {
      h = 31 * h + bundle.hashCode();
    }
    return h;
  }
  
  private synchronized void writeObject(ObjectOutputStream s)
    throws IOException
  {
    if (bundle != null) {
      throw new NotSerializableException("cannot serialize");
    }
    if (actions == null) {
      getActions();
    }
    s.defaultWriteObject();
  }
  
  private synchronized void readObject(ObjectInputStream s)
    throws IOException, ClassNotFoundException
  {
    s.defaultReadObject();
    setTransients(getName(), parseActions(actions));
  }
  
  private Map<String, Object> getProperties()
  {
    Map<String, Object> result = properties;
    if (result != null) {
      return result;
    }
    final Map<String, Object> map = new HashMap(5);
    map.put("package.name", getName());
    if (bundle != null) {
      AccessController.doPrivileged(new PrivilegedAction()
      {
        public Object run()
        {
          map.put("id", new Long(bundle.getBundleId()));
          map.put("location", bundle.getLocation());
          String name = bundle.getSymbolicName();
          if (name != null) {
            map.put("name", name);
          }
          SignerProperty signer = new SignerProperty(bundle);
          if (signer.isBundleSigned()) {
            map.put("signer", signer);
          }
          return null;
        }
      });
    }
    return properties = map;
  }
}

/* Location:
 * Qualified Name:     org.osgi.framework.PackagePermission
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectInputStream.GetField;
import java.io.ObjectOutputStream;
import java.io.ObjectOutputStream.PutField;
import java.io.ObjectStreamField;
import java.security.Permission;
import java.security.PermissionCollection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

final class PackagePermissionCollection
  extends PermissionCollection
{
  static final long serialVersionUID = -3350758995234427603L;
  private transient Map<String, PackagePermission> permissions;
  private boolean all_allowed;
  private Map<String, PackagePermission> filterPermissions;
  
  public PackagePermissionCollection()
  {
    permissions = new HashMap();
    all_allowed = false;
  }
  
  public void add(Permission permission)
  {
    if (!(permission instanceof PackagePermission)) {
      throw new IllegalArgumentException("invalid permission: " + 
        permission);
    }
    if (isReadOnly()) {
      throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
    }
    PackagePermission pp = (PackagePermission)permission;
    if (bundle != null) {
      throw new IllegalArgumentException("cannot add to collection: " + 
        pp);
    }
    String name = pp.getName();
    Filter f = filter;
    synchronized (this)
    {
      Map<String, PackagePermission> pc;
      if (f != null)
      {
        Map<String, PackagePermission> pc = filterPermissions;
        if (pc == null) {
          filterPermissions = (pc = new HashMap());
        }
      }
      else
      {
        pc = permissions;
      }
      PackagePermission existing = (PackagePermission)pc.get(name);
      if (existing != null)
      {
        int oldMask = action_mask;
        int newMask = action_mask;
        if (oldMask != newMask) {
          pc.put(name, new PackagePermission(name, oldMask | 
            newMask));
        }
      }
      else
      {
        pc.put(name, pp);
      }
      if ((!all_allowed) && 
        (name.equals("*"))) {
        all_allowed = true;
      }
    }
  }
  
  public boolean implies(Permission permission)
  {
    if (!(permission instanceof PackagePermission)) {
      return false;
    }
    PackagePermission requested = (PackagePermission)permission;
    if (filter != null) {
      return false;
    }
    String requestedName = requested.getName();
    int desired = action_mask;
    int effective = 0;
    Collection<PackagePermission> perms;
    synchronized (this)
    {
      pc = permissions;
      if (all_allowed)
      {
        PackagePermission pp = (PackagePermission)pc.get("*");
        if (pp != null)
        {
          effective |= action_mask;
          if ((effective & desired) == desired) {
            return true;
          }
        }
      }
      PackagePermission pp = (PackagePermission)pc.get(requestedName);
      if (pp != null)
      {
        effective |= action_mask;
        if ((effective & desired) == desired) {
          return true;
        }
      }
      int offset = requestedName.length() - 1;
      int last;
      while ((last = requestedName.lastIndexOf(".", offset)) != -1)
      {
        int last;
        requestedName = requestedName.substring(0, last + 1) + "*";
        pp = (PackagePermission)pc.get(requestedName);
        if (pp != null)
        {
          effective |= action_mask;
          if ((effective & desired) == desired) {
            return true;
          }
        }
        offset = last - 1;
      }
      pc = filterPermissions;
      if (pc == null) {
        return false;
      }
      perms = pc.values();
    }
    Collection<PackagePermission> perms;
    for (Map<String, PackagePermission> pc = perms.iterator(); pc.hasNext();)
    {
      PackagePermission perm = (PackagePermission)pc.next();
      if (perm.implies0(requested, effective)) {
        return true;
      }
    }
    return false;
  }
  
  public synchronized Enumeration<Permission> elements()
  {
    List<Permission> all = new ArrayList(permissions.values());
    Map<String, PackagePermission> pc = filterPermissions;
    if (pc != null) {
      all.addAll(pc.values());
    }
    return Collections.enumeration(all);
  }
  
  private static final ObjectStreamField[] serialPersistentFields = {
    new ObjectStreamField("permissions", Hashtable.class), 
    new ObjectStreamField("all_allowed", Boolean.TYPE), 
    new ObjectStreamField("filterPermissions", HashMap.class) };
  
  private synchronized void writeObject(ObjectOutputStream out)
    throws IOException
  {
    Hashtable<String, PackagePermission> hashtable = new Hashtable(
      permissions);
    ObjectOutputStream.PutField pfields = out.putFields();
    pfields.put("permissions", hashtable);
    pfields.put("all_allowed", all_allowed);
    pfields.put("filterPermissions", filterPermissions);
    out.writeFields();
  }
  
  private synchronized void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
  {
    ObjectInputStream.GetField gfields = in.readFields();
    Hashtable<String, PackagePermission> hashtable = (Hashtable)gfields
      .get("permissions", null);
    permissions = new HashMap(hashtable);
    all_allowed = gfields.get("all_allowed", false);
    HashMap<String, PackagePermission> fp = (HashMap)gfields
      .get("filterPermissions", null);
    filterPermissions = fp;
  }
}

/* Location:
 * Qualified Name:     org.osgi.framework.PackagePermissionCollection
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

import java.util.EventObject;

public class ServiceEvent
  extends EventObject
{
  static final long serialVersionUID = 8792901483909409299L;
  private final ServiceReference<?> reference;
  private final int type;
  public static final int REGISTERED = 1;
  public static final int MODIFIED = 2;
  public static final int UNREGISTERING = 4;
  public static final int MODIFIED_ENDMATCH = 8;
  
  public ServiceEvent(int type, ServiceReference<?> reference)
  {
    super(reference);
    this.reference = reference;
    this.type = type;
  }
  
  public ServiceReference<?> getServiceReference()
  {
    return reference;
  }
  
  public int getType()
  {
    return type;
  }
}

/* Location:
 * Qualified Name:     org.osgi.framework.ServiceEvent
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

public class ServiceException
  extends RuntimeException
{
  static final long serialVersionUID = 3038963223712959631L;
  private final int type;
  public static final int UNSPECIFIED = 0;
  public static final int UNREGISTERED = 1;
  public static final int FACTORY_ERROR = 2;
  public static final int FACTORY_EXCEPTION = 3;
  public static final int SUBCLASSED = 4;
  public static final int REMOTE = 5;
  public static final int FACTORY_RECURSION = 6;
  
  public ServiceException(String msg, Throwable cause)
  {
    this(msg, 0, cause);
  }
  
  public ServiceException(String msg)
  {
    this(msg, 0);
  }
  
  public ServiceException(String msg, int type, Throwable cause)
  {
    super(msg, cause);
    this.type = type;
  }
  
  public ServiceException(String msg, int type)
  {
    super(msg);
    this.type = type;
  }
  
  public int getType()
  {
    return type;
  }
}

/* Location:
 * Qualified Name:     org.osgi.framework.ServiceException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

public abstract interface ServiceFactory<S>
{
  public abstract S getService(Bundle paramBundle, ServiceRegistration<S> paramServiceRegistration);
  
  public abstract void ungetService(Bundle paramBundle, ServiceRegistration<S> paramServiceRegistration, S paramS);
}

/* Location:
 * Qualified Name:     org.osgi.framework.ServiceFactory
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

import java.util.EventListener;

public abstract interface ServiceListener
  extends EventListener
{
  public abstract void serviceChanged(ServiceEvent paramServiceEvent);
}

/* Location:
 * Qualified Name:     org.osgi.framework.ServiceListener
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

import java.security.PrivilegedAction;
import java.util.Map;

class ServicePermission$1
  implements PrivilegedAction<Object>
{
  final ServicePermission this$0;
  
  ServicePermission$1(ServicePermission paramServicePermission, Map paramMap, Bundle paramBundle) {}
  
  public Object run()
  {
    val$props.put("id", new Long(val$bundle.getBundleId()));
    val$props.put("location", val$bundle.getLocation());
    String name = val$bundle.getSymbolicName();
    if (name != null) {
      val$props.put("name", name);
    }
    SignerProperty signer = new SignerProperty(val$bundle);
    if (signer.isBundleSigned()) {
      val$props.put("signer", signer);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.osgi.framework.ServicePermission.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

import java.util.Map.Entry;

final class ServicePermission$Properties$Entry
  implements Map.Entry<String, Object>
{
  private final String k;
  private final Object v;
  
  ServicePermission$Properties$Entry(String key, Object value)
  {
    k = key;
    v = value;
  }
  
  public String getKey()
  {
    return k;
  }
  
  public Object getValue()
  {
    return v;
  }
  
  public Object setValue(Object value)
  {
    throw new UnsupportedOperationException();
  }
  
  public String toString()
  {
    return k + "=" + v;
  }
  
  public int hashCode()
  {
    return (k == null ? 0 : k.hashCode()) ^ 
      (v == null ? 0 : v.hashCode());
  }
  
  public boolean equals(Object obj)
  {
    if (obj == this) {
      return true;
    }
    if (!(obj instanceof Map.Entry)) {
      return false;
    }
    Map.Entry<?, ?> e = (Map.Entry)obj;
    Object key = e.getKey();
    if ((k == key) || ((k != null) && (k.equals(key))))
    {
      Object value = e.getValue();
      if ((v == value) || ((v != null) && (v.equals(value)))) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.osgi.framework.ServicePermission.Properties.Entry
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

import java.util.AbstractMap;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

final class ServicePermission$Properties
  extends AbstractMap<String, Object>
{
  private final Map<String, Object> properties;
  private final ServiceReference<?> service;
  private volatile transient Set<Map.Entry<String, Object>> entries;
  
  ServicePermission$Properties(Map<String, Object> properties, ServiceReference<?> service)
  {
    this.properties = properties;
    this.service = service;
    entries = null;
  }
  
  public Object get(Object k)
  {
    if (!(k instanceof String)) {
      return null;
    }
    String key = (String)k;
    if (key.charAt(0) == '@') {
      return service.getProperty(key.substring(1));
    }
    Object value = properties.get(key);
    if (value != null) {
      return value;
    }
    return service.getProperty(key);
  }
  
  public Set<Map.Entry<String, Object>> entrySet()
  {
    if (entries != null) {
      return entries;
    }
    Set<Map.Entry<String, Object>> all = new HashSet(
      properties.entrySet());
    String[] arrayOfString;
    int j = (arrayOfString = service.getPropertyKeys()).length;
    for (int i = 0; i < j; i++)
    {
      String key = arrayOfString[i];
      for (Iterator localIterator = properties.keySet().iterator(); localIterator.hasNext();)
      {
        String k = (String)localIterator.next();
        if (key.equalsIgnoreCase(k)) {
          break;
        }
      }
      all.add(new Entry(key, service.getProperty(key)));
    }
    return entries = Collections.unmodifiableSet(all);
  }
  
  private static final class Entry
    implements Map.Entry<String, Object>
  {
    private final String k;
    private final Object v;
    
    Entry(String key, Object value)
    {
      k = key;
      v = value;
    }
    
    public String getKey()
    {
      return k;
    }
    
    public Object getValue()
    {
      return v;
    }
    
    public Object setValue(Object value)
    {
      throw new UnsupportedOperationException();
    }
    
    public String toString()
    {
      return k + "=" + v;
    }
    
    public int hashCode()
    {
      return (k == null ? 0 : k.hashCode()) ^ 
        (v == null ? 0 : v.hashCode());
    }
    
    public boolean equals(Object obj)
    {
      if (obj == this) {
        return true;
      }
      if (!(obj instanceof Map.Entry)) {
        return false;
      }
      Map.Entry<?, ?> e = (Map.Entry)obj;
      Object key = e.getKey();
      if ((k == key) || ((k != null) && (k.equals(key))))
      {
        Object value = e.getValue();
        if ((v == value) || ((v != null) && (v.equals(value)))) {
          return true;
        }
      }
      return false;
    }
  }
}

/* Location:
 * Qualified Name:     org.osgi.framework.ServicePermission.Properties
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.osgi.framework;

import java.io.IOException;
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.AccessController;
import java.security.BasicPermission;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.PrivilegedAction;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public final class ServicePermission
  extends BasicPermission
{
  static final long serialVersionUID = -7662148639076511574L;
  public static final String GET = "get";
  public static final String REGISTER = "register";
  private static final int ACTION_GET = 1;
  private static final int ACTION_REGISTER = 2;
  private static final int ACTION_ALL = 3;
  static final int ACTION_NONE = 0;
  transient int action_mask;
  private volatile String actions = null;
  final transient ServiceReference<?> service;
  final 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd