org.eclipse.osgi_3.8.2.v20130124-134944

ation:
 * 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 transient String[] objectClass;
  transient Filter filter;
  private volatile transient Map<String, Object> properties;
  private transient boolean wildcard;
  private transient String prefix;
  
  public ServicePermission(String name, String actions)
  {
    this(name, parseActions(actions));
    if ((filter != null) && ((action_mask & 0x3) != 1)) {
      throw new IllegalArgumentException("invalid action string for filter expression");
    }
  }
  
  public ServicePermission(ServiceReference<?> reference, String actions)
  {
    super(createName(reference));
    setTransients(null, parseActions(actions));
    service = reference;
    objectClass = ((String[])reference.getProperty("objectClass"));
    if ((action_mask & 0x3) != 1) {
      throw new IllegalArgumentException("invalid action string");
    }
  }
  
  private static String createName(ServiceReference<?> reference)
  {
    if (reference == null) {
      throw new IllegalArgumentException("reference must not be null");
    }
    StringBuffer sb = new StringBuffer("(service.id=");
    sb.append(reference.getProperty("service.id"));
    sb.append(")");
    return sb.toString();
  }
  
  ServicePermission(String name, int mask)
  {
    super(name);
    setTransients(parseFilter(name), mask);
    service = null;
    objectClass = null;
  }
  
  private void setTransients(Filter f, int mask)
  {
    if ((mask == 0) || ((mask & 0x3) != mask)) {
      throw new IllegalArgumentException("invalid action string");
    }
    action_mask = mask;
    filter = f;
    if (f == null)
    {
      String name = getName();
      int l = name.length();
      
      wildcard = ((name.charAt(l - 1) == '*') && ((l == 1) || (name.charAt(l - 2) == '.')));
      if ((wildcard) && (l > 1)) {
        prefix = name.substring(0, l - 1);
      }
    }
  }
  
  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 >= 2) && ((a[(i - 2)] == 'g') || (a[(i - 2)] == 'G')) && 
        ((a[(i - 1)] == 'e') || (a[(i - 1)] == 'E')) && (
        (a[i] == 't') || (a[i] == 'T')))
      {
        int matchlen = 3;
        mask |= 0x1;
      }
      else if ((i >= 7) && ((a[(i - 7)] == 'r') || (a[(i - 7)] == 'R')) && 
        ((a[(i - 6)] == 'e') || (a[(i - 6)] == 'E')) && 
        ((a[(i - 5)] == 'g') || (a[(i - 5)] == 'G')) && 
        ((a[(i - 4)] == 'i') || (a[(i - 4)] == 'I')) && 
        ((a[(i - 3)] == 's') || (a[(i - 3)] == 'S')) && 
        ((a[(i - 2)] == 't') || (a[(i - 2)] == 'T')) && 
        ((a[(i - 1)] == 'e') || (a[(i - 1)] == 'E')) && (
        (a[i] == 'r') || (a[i] == 'R')))
      {
        int matchlen = 8;
        mask |= 0x2;
      }
      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 ServicePermission)) {
      return false;
    }
    ServicePermission requested = (ServicePermission)p;
    if (service != null) {
      return false;
    }
    if (filter != null) {
      return false;
    }
    return implies0(requested, 0);
  }
  
  boolean implies0(ServicePermission requested, int effective)
  {
    effective |= action_mask;
    int desired = action_mask;
    if ((effective & desired) != desired) {
      return false;
    }
    if ((wildcard) && (prefix == null)) {
      return true;
    }
    Filter f = filter;
    if (f != null) {
      return f.matches(requested.getProperties());
    }
    String[] requestedNames = objectClass;
    if (requestedNames == null) {
      return super.implies(requested);
    }
    if (wildcard)
    {
      int pl = prefix.length();
      int i = 0;
      for (int l = requestedNames.length; i < l; i++)
      {
        String requestedName = requestedNames[i];
        if ((requestedName.length() > pl) && (requestedName.startsWith(prefix))) {
          return true;
        }
      }
    }
    else
    {
      String name = getName();
      int i = 0;
      for (int l = requestedNames.length; i < l; i++) {
        if (requestedNames[i].equals(name)) {
          return true;
        }
      }
    }
    return false;
  }
  
  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("get");
        comma = true;
      }
      if ((mask & 0x2) == 2)
      {
        if (comma) {
          sb.append(',');
        }
        sb.append("register");
      }
      actions = (result = sb.toString());
    }
    return result;
  }
  
  public PermissionCollection newPermissionCollection()
  {
    return new ServicePermissionCollection();
  }
  
  public boolean equals(Object obj)
  {
    if (obj == this) {
      return true;
    }
    if (!(obj instanceof ServicePermission)) {
      return false;
    }
    ServicePermission sp = (ServicePermission)obj;
    
    return (action_mask == action_mask) && (getName().equals(sp.getName())) && ((service == service) || ((service != null) && (service.compareTo(service) == 0)));
  }
  
  public int hashCode()
  {
    int h = 527 + getName().hashCode();
    h = 31 * h + getActions().hashCode();
    if (service != null) {
      h = 31 * h + service.hashCode();
    }
    return h;
  }
  
  private synchronized void writeObject(ObjectOutputStream s)
    throws IOException
  {
    if (service != null) {
      throw new NotSerializableException("cannot serialize");
    }
    if (actions == null) {
      getActions();
    }
    s.defaultWriteObject();
  }
  
  private synchronized void readObject(ObjectInputStream s)
    throws IOException, ClassNotFoundException
  {
    s.defaultReadObject();
    setTransients(parseFilter(getName()), parseActions(actions));
  }
  
  private Map<String, Object> getProperties()
  {
    Map<String, Object> result = properties;
    if (result != null) {
      return result;
    }
    if (service == null)
    {
      result = new HashMap(1);
      result.put("objectClass", new String[] { getName() });
      return properties = result;
    }
    final Map<String, Object> props = new HashMap(4);
    final Bundle bundle = service.getBundle();
    if (bundle != null) {
      AccessController.doPrivileged(new PrivilegedAction()
      {
        public Object run()
        {
          props.put("id", new Long(bundle.getBundleId()));
          props.put("location", bundle.getLocation());
          String name = bundle.getSymbolicName();
          if (name != null) {
            props.put("name", name);
          }
          SignerProperty signer = new SignerProperty(bundle);
          if (signer.isBundleSigned()) {
            props.put("signer", signer);
          }
          return null;
        }
      });
    }
    return properties = new Properties(props, service);
  }
  
  private static final class Properties
    extends AbstractMap<String, Object>
  {
    private final Map<String, Object> properties;
    private final ServiceReference<?> service;
    private volatile transient Set<Map.Entry<String, Object>> entries;
    
    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
 * 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 ServicePermissionCollection
  extends PermissionCollection
{
  static final long serialVersionUID = 662615640374640621L;
  private transient Map<String, ServicePermission> permissions;
  private boolean all_allowed;
  private Map<String, ServicePermission> filterPermissions;
  
  public ServicePermissionCollection()
  {
    permissions = new HashMap();
    all_allowed = false;
  }
  
  public void add(Permission permission)
  {
    if (!(permission instanceof ServicePermission)) {
      throw new IllegalArgumentException("invalid permission: " + permission);
    }
    if (isReadOnly()) {
      throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
    }
    ServicePermission sp = (ServicePermission)permission;
    if (service != null) {
      throw new IllegalArgumentException("cannot add to collection: " + sp);
    }
    String name = sp.getName();
    Filter f = filter;
    synchronized (this)
    {
      Map<String, ServicePermission> pc;
      if (f != null)
      {
        Map<String, ServicePermission> pc = filterPermissions;
        if (pc == null) {
          filterPermissions = (pc = new HashMap());
        }
      }
      else
      {
        pc = permissions;
      }
      ServicePermission existing = (ServicePermission)pc.get(name);
      if (existing != null)
      {
        int oldMask = action_mask;
        int newMask = action_mask;
        if (oldMask != newMask) {
          pc.put(name, new ServicePermission(name, oldMask | newMask));
        }
      }
      else
      {
        pc.put(name, sp);
      }
      if ((!all_allowed) && 
        (name.equals("*"))) {
        all_allowed = true;
      }
    }
  }
  
  public boolean implies(Permission permission)
  {
    if (!(permission instanceof ServicePermission)) {
      return false;
    }
    ServicePermission requested = (ServicePermission)permission;
    if (filter != null) {
      return false;
    }
    int effective = 0;
    Collection<ServicePermission> perms;
    synchronized (this)
    {
      desired = action_mask;
      if (all_allowed)
      {
        ServicePermission sp = (ServicePermission)permissions.get("*");
        if (sp != null)
        {
          effective |= action_mask;
          if ((effective & desired) == desired) {
            return true;
          }
        }
      }
      String[] requestedNames = objectClass;
      if (requestedNames == null)
      {
        effective |= effective(requested.getName(), desired, effective);
        if ((effective & desired) == desired) {
          return true;
        }
      }
      else
      {
        int i = 0;
        for (int l = requestedNames.length; i < l; i++) {
          if ((effective(requestedNames[i], desired, effective) & desired) == desired) {
            return true;
          }
        }
      }
      Map<String, ServicePermission> pc = filterPermissions;
      if (pc == null) {
        return false;
      }
      perms = pc.values();
    }
    Collection<ServicePermission> perms;
    for (int desired = perms.iterator(); desired.hasNext();)
    {
      ServicePermission perm = (ServicePermission)desired.next();
      if (perm.implies0(requested, effective)) {
        return true;
      }
    }
    return false;
  }
  
  private int effective(String requestedName, int desired, int effective)
  {
    Map<String, ServicePermission> pc = permissions;
    ServicePermission sp = (ServicePermission)pc.get(requestedName);
    if (sp != null)
    {
      effective |= action_mask;
      if ((effective & desired) == desired) {
        return effective;
      }
    }
    int offset = requestedName.length() - 1;
    int last;
    while ((last = requestedName.lastIndexOf(".", offset)) != -1)
    {
      int last;
      requestedName = requestedName.substring(0, last + 1) + "*";
      sp = (ServicePermission)pc.get(requestedName);
      if (sp != null)
      {
        effective |= action_mask;
        if ((effective & desired) == desired) {
          return effective;
        }
      }
      offset = last - 1;
    }
    return effective;
  }
  
  public sy
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 85 86 87

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-2019. Infinite Loop Ltd