org.eclipse.osgi_3.7.2.v20120110-1415

lue());
        }
        break;
      case '=': 
        if (filterChars[(pos + 1)] == '*')
        {
          int oldpos = pos;
          pos += 2;
          skipWhiteSpace();
          if (filterChars[pos] == ')') {
            return new FilterImpl(5, attr, null);
          }
          pos = oldpos;
        }
        pos += 1;
        Object string = parse_substring();
        if ((string instanceof String)) {
          return new FilterImpl(1, attr, string);
        }
        return new FilterImpl(6, attr, string);
      }
      throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_INVALID_OPERATOR, filterstring.substring(pos)), filterstring);
    }
    
    private String parse_attr()
      throws InvalidSyntaxException
    {
      skipWhiteSpace();
      
      int begin = pos;
      int end = pos;
      
      char c = filterChars[pos];
      while ((c != '~') && (c != '<') && (c != '>') && (c != '=') && (c != '(') && (c != ')'))
      {
        pos += 1;
        if (!Character.isWhitespace(c)) {
          end = pos;
        }
        c = filterChars[pos];
      }
      int length = end - begin;
      if (length == 0) {
        throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_ATTR, filterstring.substring(pos)), filterstring);
      }
      return new String(filterChars, begin, length);
    }
    
    private String parse_value()
      throws InvalidSyntaxException
    {
      StringBuffer sb = new StringBuffer(filterChars.length - pos);
      for (;;)
      {
        char c = filterChars[pos];
        switch (c)
        {
        case ')': 
          break;
        case '(': 
          throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_INVALID_VALUE, filterstring.substring(pos)), filterstring);
        case '\\': 
          pos += 1;
          c = filterChars[pos];
        default: 
          sb.append(c);
          pos += 1;
        }
      }
      if (sb.length() == 0) {
        throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_MISSING_VALUE, filterstring.substring(pos)), filterstring);
      }
      return sb.toString();
    }
    
    private 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 label213;
          }
          operands.add(sb.toString());
          
          break;
        case '(': 
          throw new InvalidSyntaxException(NLS.bind(Msg.FILTER_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;
        }
      }
      label213:
      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 class ServiceReferenceDictionary
    extends Dictionary<String, Object>
  {
    private final ServiceReference<?> reference;
    
    ServiceReferenceDictionary(ServiceReference<?> reference)
    {
      this.reference = reference;
    }
    
    public Object get(Object key)
    {
      if (reference == null) {
        return null;
      }
      return reference.getProperty((String)key);
    }
    
    public boolean isEmpty()
    {
      throw new UnsupportedOperationException();
    }
    
    public Enumeration<String> keys()
    {
      throw new UnsupportedOperationException();
    }
    
    public Enumeration<Object> elements()
    {
      throw new UnsupportedOperationException();
    }
    
    public Object put(String key, Object value)
    {
      throw new UnsupportedOperationException();
    }
    
    public Object remove(Object key)
    {
      throw new UnsupportedOperationException();
    }
    
    public int size()
    {
      throw new UnsupportedOperationException();
    }
  }
  
  private static class SetAccessibleAction
    implements PrivilegedAction<Object>
  {
    private final AccessibleObject accessible;
    
    SetAccessibleAction(AccessibleObject accessible)
    {
      this.accessible = accessible;
    }
    
    public Object run()
    {
      accessible.setAccessible(true);
      return null;
    }
  }
}

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

import java.io.InputStream;
import java.net.URLConnection;
import java.security.AccessControlContext;
import java.security.PrivilegedExceptionAction;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.osgi.framework.BundleException;

class Framework$1
  implements PrivilegedExceptionAction<AbstractBundle>
{
  final Framework this$0;
  
  Framework$1(Framework paramFramework, InputStream paramInputStream, String paramString, AccessControlContext paramAccessControlContext) {}
  
  public AbstractBundle run()
    throws BundleException
  {
    URLConnection source = val$in != null ? new BundleSource(val$in) : this$0.adaptor.mapLocationToURLConnection(val$location);
    
    return this$0.installWorkerPrivileged(val$location, source, val$callerContext);
  }
}

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

import java.security.PrivilegedExceptionAction;

class Framework$2
  implements PrivilegedExceptionAction<Object>
{
  final Framework this$0;
  
  Framework$2(Framework paramFramework, AbstractBundle paramAbstractBundle, boolean paramBoolean) {}
  
  public Object run()
    throws Exception
  {
    this$0.checkAdminPermission(val$bundle, "lifecycle");
    if (val$extension) {
      this$0.checkAdminPermission(val$bundle, "extensionLifecycle");
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Framework.2
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.security.PrivilegedAction;
import java.util.Collection;

class Framework$3
  implements PrivilegedAction<Object>
{
  final Framework this$0;
  
  Framework$3(Framework paramFramework, BundleContextImpl paramBundleContextImpl, Collection paramCollection) {}
  
  public Object run()
  {
    this$0.notifyFindHooksPriviledged(val$context, val$shrinkable);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Framework.3
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.util.Collection;
import org.eclipse.osgi.internal.serviceregistry.HookContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.bundle.FindHook;

class Framework$4
  implements HookContext
{
  final Framework this$0;
  
  Framework$4(Framework paramFramework, BundleContextImpl paramBundleContextImpl, Collection paramCollection) {}
  
  public void call(Object hook, ServiceRegistration<?> hookRegistration)
    throws Exception
  {
    if ((hook instanceof FindHook)) {
      ((FindHook)hook).find(val$context, val$allBundles);
    }
  }
  
  public String getHookClassName()
  {
    return Framework.findHookName;
  }
  
  public String getHookMethodName()
  {
    return "find";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Framework.4
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.security.PrivilegedAction;
import java.util.List;

class Framework$5
  implements PrivilegedAction<AbstractBundle>
{
  final Framework this$0;
  
  Framework$5(Framework paramFramework, String paramString) {}
  
  public AbstractBundle run()
  {
    List<AbstractBundle> allBundles = this$0.bundles.getBundles();
    int size = allBundles.size();
    for (int i = 0; i < size; i++)
    {
      AbstractBundle bundle = (AbstractBundle)allBundles.get(i);
      if (val$finalLocation.equals(bundle.getLocation())) {
        return bundle;
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Framework.5
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.security.PrivilegedAction;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;

class Framework$6
  implements PrivilegedAction<Object>
{
  final Framework this$0;
  
  Framework$6(Framework paramFramework, FrameworkEvent paramFrameworkEvent, FrameworkListener[] paramArrayOfFrameworkListener) {}
  
  public Object run()
  {
    this$0.publishFrameworkEventPrivileged(val$event, val$listeners);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Framework.6
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.security.PrivilegedAction;
import org.osgi.framework.BundleEvent;

class Framework$7
  implements PrivilegedAction<Object>
{
  final Framework this$0;
  
  Framework$7(Framework paramFramework, BundleEvent paramBundleEvent) {}
  
  public Object run()
  {
    this$0.publishBundleEventPrivileged(val$event);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Framework.7
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.util.Collection;
import org.eclipse.osgi.internal.serviceregistry.HookContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.bundle.EventHook;

class Framework$8
  implements HookContext
{
  final Framework this$0;
  
  Framework$8(Framework paramFramework, BundleEvent paramBundleEvent, Collection paramCollection) {}
  
  public void call(Object hook, ServiceRegistration<?> hookRegistration)
    throws Exception
  {
    if ((hook instanceof EventHook)) {
      ((EventHook)hook).event(val$event, val$result);
    }
  }
  
  public String getHookClassName()
  {
    return Framework.eventHookName;
  }
  
  public String getHookMethodName()
  {
    return "event";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Framework.8
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import org.eclipse.osgi.framework.adaptor.StatusException;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;

class Framework$DuplicateBundleException
  extends BundleException
  implements StatusException
{
  private static final long serialVersionUID = 135669822846323624L;
  private final Bundle duplicate;
  final Framework this$0;
  
  public Framework$DuplicateBundleException(Framework paramFramework, String msg, Bundle duplicate)
  {
    super(msg, 9);
    this.duplicate = duplicate;
  }
  
  public Object getStatus()
  {
    return duplicate;
  }
  
  public int getStatusCode()
  {
    return 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Framework.DuplicateBundleException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.io.File;
import java.security.PrivilegedAction;
import org.eclipse.osgi.framework.adaptor.BundleData;

class Framework$GetDataFileAction
  implements PrivilegedAction<File>
{
  private AbstractBundle bundle;
  private String filename;
  
  public Framework$GetDataFileAction(AbstractBundle bundle, String filename)
  {
    this.bundle = bundle;
    this.filename = filename;
  }
  
  public File run()
  {
    return bundle.getBundleData().getDataFile(filename);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Framework.GetDataFileAction
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.framework.internal.core;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandlerFactory;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.internal.adaptor.ContextFinder;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.baseadaptor.HookRegistry;
import org.eclipse.osgi.framework.adaptor.BundleData;
import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook;
import org.eclipse.osgi.framework.adaptor.EventPublisher;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.eclipse.osgi.framework.adaptor.StatusException;
import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap;
import org.eclipse.osgi.framework.eventmgr.EventDispatcher;
import org.eclipse.osgi.framework.eventmgr.EventManager;
import org.eclipse.osgi.framework.eventmgr.ListenerQueue;
import org.eclipse.osgi.framework.internal.protocol.StreamHandlerFactory;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.internal.loader.BundleLoader;
import org.eclipse.osgi.internal.loader.PackageSource;
import org.eclipse.osgi.internal.loader.SystemBundleLoader;
import org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager;
import org.eclipse.osgi.internal.permadmin.SecurityAdmin;
import org.eclipse.osgi.internal.profile.Profile;
import org.eclipse.osgi.internal.serviceregistry.HookContext;
import org.eclipse.osgi.internal.serviceregistry.ServiceRegistry;
import org.eclipse.osgi.internal.serviceregistry.ShrinkableCollection;
import org.eclipse.osgi.signedcontent.SignedContentFactory;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleListener;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.SynchronousBundleListener;
import org.osgi.framework.Version;
import org.osgi.framework.hooks.bundle.EventHook;
import org.osgi.framework.hooks.bundle.FindHook;
import org.osgi.util.tracker.ServiceTracker;

public class Framework
  implements EventPublisher, Runnable
{
  private static final String PROP_CONTEXTCLASSLOADER_PARENT = "osgi.contextClassLoaderParent";
  private static final String CONTEXTCLASSLOADER_PARENT_APP = "app";
  private static final String CONTEXTCLASSLOADER_PARENT_EXT = "ext";
  private static final String CONTEXTCLASSLOADER_PARENT_BOOT = "boot";
  private static final String CONTEXTCLASSLOADER_PARENT_FWK = "fwk";
  public static final String PROP_FRAMEWORK_THREAD = "osgi.framework.activeThreadType";
  public static final String THREAD_NORMAL = "normal";
  public static final String PROP_EQUINOX_SECURITY = "eclipse.security";
  public static final String SECURITY_OSGI = "osgi";
  private static String J2SE = "J2SE-";
  private static String JAVASE = "JavaSE-";
  private static String PROFILE_EXT = ".profile";
  protected FrameworkAdaptor adaptor;
  protected Properties properties;
  protected boolean active;
  private FrameworkEvent[] shutdownEvent;
  protected BundleRepository bundles;
  protected PackageAdminImpl packageAdmin;
  protected SecurityAdmin securityAdmin;
  protected StartLevelManager startLevelManager;
  private ServiceRegistry serviceRegistry;
  private final Map<BundleContextImpl, CopyOnWriteIdentityMap<BundleListener, BundleListener>> allBundleListeners = new HashMap();
  protected static final int BUNDLEEVENT = 1;
  private final Map<BundleContextImpl, CopyOnWriteIdentityMap<SynchronousBundleListener, SynchronousBundleListener>> allSyncBundleListeners = new HashMap();
  protected static final int BUNDLEEVENTSYNC = 2;
  private final Map<BundleContextImpl, CopyOnWriteIdentityMap<FrameworkListener, FrameworkListener>> allFrameworkListeners = new HashMap();
  protected static final int FRAMEWORKEVENT = 4;
  protected static final int BATCHEVENT_BEGIN = -2147483647;
  protected static final int BATCHEVENT_END = Integer.MIN_VALUE;
  static final String eventHookName = EventHook.class.getName();
  static final String findHookName = FindHook.class.getName();
  protected EventManager eventManager;
  private Map<String, Thread> installLock;
  protected InternalSystemBundle systemBundle;
  private String[] bootDelegation;
  private String[] bootDelegationStems;
  private boolean bootDelegateAll = false;
  public final boolean contextBootDelegation = "true".equals(FrameworkProperties.getProperty("osgi.context.bootdelegation", "true"));
  public final boolean compatibiltyBootDelegation = "true".equals(FrameworkProperties.getProperty(Constants.OSGI_COMPATIBILITY_BOOTDELEGATION, "true"));
  private final boolean allowDuplicateBSNVersion = "multiple".equals(FrameworkProperties.getProperty("org.osgi.framework.bsnversion"));
  private final boolean allowRefreshDuplicateBSN = Boolean.TRUE.toString().equals(FrameworkProperties.getProperty("equinox.refresh.duplicate.bsn", "true"));
  ClassLoaderDelegateHook[] delegateHooks;
  private volatile boolean forcedRestart = false;
  protected static AliasMapper aliasMapper = new AliasMapper();
  SecureAction secureAction = (SecureAction)AccessController.doPrivileged(SecureAction.createSecureAction());
  private final Map<Long, Map<String, AdminPermission>> adminPermissions = new HashMap();
  private StreamHandlerFactory streamHandlerFactory;
  private org.eclipse.osgi.framework.internal.protocol.ContentHandlerFactory contentHandlerFactory;
  private volatile ServiceTracker<SignedContentFactory, SignedContentFactory> signedContentFactory;
  private volatile ContextFinder contextFinder;
  
  static
  {
    Class<?> c = GetDataFileAction.class;
    c.getName();
  }
  
  static class GetDataFileAction
    implements PrivilegedAction<File>
  {
    private AbstractBundle bundle;
    private String filename;
    
    public GetDataFileAction(AbstractBundle bundle, String filename)
    {
      this.bundle = bundle;
      this.filename = filename;
    }
    
    public File run()
    {
      return bundle.getBundleData().getDataFile(filename);
    }
  }
  
  public Framework(FrameworkAdaptor adaptor)
  {
    initialize(adaptor);
  }
  
  protected void initialize(FrameworkAdaptor initAdaptor)
  {
    if (Profile.STARTUP) {
      Profile.logEnter("Framework.initialze()", null);
    }
    long start = System.currentTimeMillis();
    adaptor = initAdaptor;
    delegateHooks = ((initAdaptor instanceof BaseAdaptor) ? ((BaseAdaptor)initAdaptor).getHookRegistry().getClassLoaderDelegateHooks() : null);
    active = false;
    installSecurityManager();
    if (Debug.DEBUG_SECURITY)
    {
      Debug.println("SecurityManager: " + System.getSecurityManager());
      Debug.println("ProtectionDomain of Framework.class: \n" + getClass().getProtectionDomain());
    }
    setNLSFrameworkLog();
    
    initializeContextFinder();
    
    initAdaptor.initialize(this);
    if (Profile.STARTUP) {
      Profile.logTime("Framework.initialze()", "adapter initialized");
    }
    try
    {
      initAdaptor.initializeStorage();
    }
    catch (IOException e)
    {
      throw new RuntimeException(e.getMessage(), e);
    }
    if (Profile.STARTUP) {
      Profile.logTime("Framework.initialze()", "adapter storage initialized");
    }
    initializeProperties(initAdaptor.getProperties());
    
    packageAdmin = new PackageAdminImpl(this);
    try
    {
      securityAdmin = new SecurityAdmin(null, this, initAdaptor.getPermissionStorage());
    }
    catch (IOException e)
    {
      e.printStackTrace();
      throw new RuntimeException(e.getMessage(), e);
    }
    if (Profile.STARTUP) {
      Profile.logTime("Framework.initialze()", "done init props & new PermissionAdminImpl");
    }
    startLevelManager = new StartLevelManager(this);
    
    eventManager = new EventManager("Framework Event Dispatcher");
    if (Profile.STARTUP) {
      Profile.logTime("Framework.initialze()", "done new EventManager");
    }
    serviceRegistry = new ServiceRegistry(this);
    
    installLock = new HashMap(10);
    
    createSystemBundle();
    loadVMProfile();
    setBootDelegation();
    if (Profile.STARTUP) {
      Profile.logTime("Framework.initialze()", "done createSystemBundle");
    }
    installURLStreamHandlerFactory(systemBundle.context, initAdaptor);
    
    installContentHandlerFactory(systemBundle.context, initAdaptor);
    if (Profile.STARTUP) {
      Profile.logTime("Framework.initialze()", "done new URLStream/Content HandlerFactory");
    }
    BundleData[] bundleDatas = initAdaptor.getInstalledBundles();
    bundles = new BundleRepository(bundleDatas == null ? 10 : bundleDatas.length + 1);
    
    bundles.add(systemBundle);
    if (bundleDatas != null) {
      for (int i = 0; i < bundleDatas.length; i++) {
        try
        {
          AbstractBundle bundle = AbstractBundle.createBundle(bundleDatas[i], this, true);
          bundles.add(bundle);
        }
        catch (BundleException be)
        {
          publishFrameworkEvent(2, systemBundle, be);
        }
      }
    }
    if (Debug.DEBUG_GENERAL) {
      System.out.println("Initialize the framework: " + (System.currentTimeMillis() - start));
    }
    if (Profile.STARTUP) {
      Profile.logExit("Framework.initialize()");
    }
  }
  
  public FrameworkAdaptor getAdaptor()
  {
    return adaptor;
  }
  
  public ClassLoaderDelegateHook[] getDelegateHooks()
  {
    return delegateHooks;
  }
  
  public ServiceRegistry getServiceRegistry()
  {
    return serviceRegistry;
  }
  
  private void setNLSFrameworkLog()
  {
    try
    {
      Field frameworkLogField = NLS.class.getDeclaredField("frameworkLog");
      frameworkLogField.setAccessible(true);
      frameworkLogField.set(null, adaptor.getFrameworkLog());
    }
    catch (Exception e)
    {
      adaptor.getFrameworkLog().log(new FrameworkLogEntry("org.eclipse.osgi", 4, 0, e.getMessage(), 0, e, null));
    }
  }
  
  private void createSystemBundle()
  {
    try
    {
      systemBundle = new InternalSystemBundle(this);
      systemBundle.getBundleData().setBundle(systemBundle);
    }
    catch (BundleException e)
    {
      e.printStackTrace();
      throw new RuntimeException(NLS.bind(Msg.OSGI_SYSTEMBUNDLE_CREATE_EXCEPTION, e.getMessage()), e);
    }
  }
  
  protected void initializeProperties(Properties adaptorProperties)
  {
    properties = FrameworkProperties.getProperties();
    Enumeration<?> enumKeys = adaptorProperties.propertyNames();
    while (enumKeys.hasMoreElements())
    {
      String key = (String)enumKeys.nextElement();
      if (properties.getProperty(key) == null) {
        properties.put(key, adaptorProperties.getProperty(key));
      }
    }
    properties.put("org.osgi.framework.vendor", "Eclipse");
    properties.put("org.osgi.framework.version", "1.3");
    String value = properties.getProperty("org.osgi.framework.processor");
    if (value == null)
    {
      value = properties.getProperty("os.arch");
      if (value != null) {
        properties.put("org.osgi.framework.processor", aliasMapper.aliasProcessor(value));
      }
    }
    value = properties.getProperty("org.osgi.framework.os.name");
    if (value == null)
    {
      value = properties.getProperty("os.name");
      try
      {
        String canonicalValue = (String)aliasMapper.aliasOSName(value);
        if (canonicalValue != null) {
          value = canonicalValue;
        }
      }
      catch (ClassCastException localClassCastException) {}
      if (value != null) {
        properties.put("org.osgi.framework.os.name", value);
      }
    }
    value = properties.getProperty("org.osgi.framework.os.version");
    if (value == null)
    {
      value = properties.getProperty("os.version");
      if (value != null)
      {
        int space = value.indexOf(' ');
        if (space > 0) {
          value = value.substring(0, space);
        }
        int major = 0;int minor = 0;int micro = 0;
        String qualifier = "";
        try
        {
          StringTokenizer st = new StringTokenizer(value, ".", true);
          major = parseVersionInt(st.nextToken());
          if (st.hasMoreTokens())
          {
            st.nextToken();
            minor = parseVersionInt(st.nextToken());
            if (st.hasMoreTokens())
            {
              st.nextToken();
              micro = parseVersionInt(st.nextToken());
              if (st.hasMoreTokens())
              {
                st.nextToken();
                qualifier = st.nextToken();
              }
            }
          }
        }
        catch (NoSuchElementException localNoSuchElementException) {}
        try
        {
          value = new Version(major, minor, micro, qualifier).toString();
        }
        catch (IllegalArgumentException localIllegalArgumentException)
        {
          value = new Version(major, minor, micro).toString();
        }
        properties.put("org.osgi.framework.os.version", value);
      }
    }
    value = properties.getProperty("org.osgi.framework.language");
    if (value == null) {
      properties.put("org.osgi.framework.language", Locale.getDefault().getLanguage());
    }
    properties.put("org.osgi.supports.framework.fragment", "true");
    properties.put("org.osgi.supports.framework.requirebundle", "true");
    properties.put("org.osgi.framework.uuid", new UniversalUniqueIdentifier().toString());
  }
  
  private int parseVersionInt(String value)
  {
    try
    {
      return Integer.parseInt(value);
    }
    catch (NumberFormatException localNumberFormatException)
    {
      StringBuffer sb = new StringBuffer(value.length());
      char[] chars = value.toCharArray();
      for (int i = 0; i < chars.length; i++)
      {
        if (!Character.isDigit(chars[i])) {
          break;
        }
        sb.append(chars[i]);
      }
      if (sb.length() > 0) {
        return Integer.parseInt(sb.toString());
      }
    }
    return 0;
  }
  
  private void setBootDelegation()
  {
    String bootDelegationProp = properties.getProperty("org.osgi.framework.bootdelegation");
    if (bootDelegationProp == null) {
      return;
    }
    if (bootDelegationProp.trim().length() == 0) {
      return;
    }
    String[] bootPackages = ManifestElement.getArrayFromList(bootDelegationProp);
    List<String> exactMatch = new ArrayList(bootPackages.length);
    List<String> stemMatch = new ArrayList(bootPackages.length);
    for (int i = 0; i < bootPackages.length; i++)
    {
      if (bootPackages[i].equals("*"))
      {
        bootDelegateAll = true;
        return;
      }
      if (bootPackages[i].endsWith("*"))
      {
        if ((bootPackages[i].length() > 2) && (bootPackages[i].endsWith(".*"))) {
          stemMatch.add(bootPackages[i].substring(0, bootPackages[i].length() - 1));
        }
      }
      else {
        exactMatch.add(bootPackages[i]);
      }
    }
    if (!exactMatch.isEmpty()) {
      bootDelegation = ((String[])exactMatch.toArray(new String[exactMatch.size()]));
    }
    if (!stemMatch.isEmpty()) {
      bootDelegationStems = ((String[])stemMatch.toArray(new String[stemMatch.size()]));
    }
  }
  
  private void loadVMProfile()
  {
    Properties profileProps = findVMProfile();
    String systemExports = properties.getProperty("org.osgi.framework.system.packages");
    if (systemExports == null)
    {
      systemExports = profileProps.getProperty("org.osgi.framework.system.packages");
      if (systemExports != null) {
        properties.put("org.osgi.framework.system.packages", systemExports);
      }
    }
    String type = properties.getProperty("osgi.java.profile.bootdelegation");
    String profileBootDelegation = profileProps.getProperty("org.osgi.framework.bootdelegation");
    if ("override".equals(type))
    {
      if (profileBootDelegation == null) {
        properties.remove("org.osgi.framework.bootdelegation");
      } else {
        properties.put("org.osgi.framework.bootdelegation", profileBootDelegation);
      }
    }
    else if ("none".equals(type)) {
      properties.remove("org.osgi.framework.bootdelegation");
    }
    if (properties.getProperty("org.osgi.framework.executionenvironment") == null)
    {
      String ee = profileProps.getProperty("org.osgi.framework.executionenvironment", profileProps.getProperty("osgi.java.profile.name"));
      if (ee != null) {
        properties.put("org.osgi.framework.executionenvironment", ee);
      }
    }
    if (properties.getProperty("org.osgi.framework.system.capabilities") == null)
    {
      String systemCapabilities = profileProps.getProperty("org.osgi.framework.system.capabilities");
      if (systemCapabilities != null) {
        properties.put("org.osgi.framework.system.capabilities", systemCapabilities);
      }
    }
  }
  
  private Properties findVMProfile()
  {
    Properties result = new Properties();
    
    String j2meConfig = properties.getProperty("microedition.configuration");
    String j2meProfiles = properties.getProperty("microedition.profiles");
    String vmProfile = null;
    String javaEdition = null;
    Version javaVersion = null;
    if ((j2meConfig != null) && (j2meConfig.length() > 0) && (j2meProfiles != null) && (j2meProfiles.length() > 0))
    {
      String[] j2meProfileList = ManifestElement.getArrayFromList(j2meProfiles, " ");
      if ((j2meProfileList != null) && (j2meProfileList.length > 0)) {
        vmProfile = j2meConfig + '_' + j2meProfileList[(j2meProfileList.length - 1)];
      }
    }
    else
    {
      String javaSpecVersion = properties.getProperty("java.specification.version");
      if (javaSpecVersion != null)
      {
        StringTokenizer st = new StringTokenizer(javaSpecVersion, " _-");
        javaSpecVersion = st.nextToken();
        String javaSpecName = properties.getProperty("java.specification.name");
        if ((javaSpecName != null) && ((javaSpecName.indexOf("Foundation Specification") >= 0) || (javaSpecName.indexOf("Foundation Profile Specification") >= 0)))
        {
          vmProfile = "CDC-" + javaSpecVersion + "_Foundation-" + javaSpecVersion;
        }
        else
        {
          v16 = new Version("1.6");
          javaEdition = J2SE;
          try
          {
            javaVersion = new Version(javaSpecVersion);
            if (v16.compareTo(javaVersion) <= 0) {
              javaEdition = JAVASE;
            }
          }
          catch (IllegalArgumentException localIllegalArgumentException) {}
          vmProfile = javaEdition + javaSpecVersion;
        }
      }
    }
    URL url = null;
    
    String propJavaProfile = FrameworkProperties.getProperty("osgi.java.profile");
    if (propJavaProfile != null) {
      try
      {
        url = new URL(propJavaProfile);
      }
      catch (MalformedURLException localMalformedURLException)
      {
        url = findInSystemBundle(propJavaProfile);
      }
    }
    if ((url == null) && (vmProfile != null))
    {
      String javaProfile = vmProfile + PROFILE_EXT;
      url = findInSystemBundle(javaProfile);
      if (url == null) {
        url = getNextBestProfile(javaEdition, javaVersion);
      }
    }
    if (url == null) {
      url = findInSystemBundle("OSGi_Minimum-1.2.profile");
    }
    if (url != null)
    {
      InputStream in = null;
      try
      {
        in = url.openStream();
        result.load(new BufferedInputStream(in));
      }
      catch (IOException localIOException1)
      {
        if (in != null) {
          try
          {
            in.close();
          }
          catch (IOException localIOException2) {}
        }
      }
      finally
      {
        if (in != null) {
          try
          {
            in.close();
          }
          catch (IOException localIOException3) {}
        }
      }
    }
    if (result.getProperty("osgi.java.profile.name") == null) {
      if (vmProfile != null) {
        result.put("osgi.java.profile.name", vmProfile.replace('_', '/'));
      } else {
        result.put("osgi.java.profile.name", "OSGi/Minimum-1.2");
      }
    }
    return result;
  }
  
  private URL getNextBestProfile(String javaEdition, Version javaVersion)
  {
    if ((javaVersion == null) || ((javaEdition != J2SE) && (javaEdition != JAVASE))) {
      return null;
    }
    URL bestProfile = findNextBestProfile(javaEdition, javaVersion);
    if ((bestProfile == null) && (javaEdition == JAVASE)) {
      bestProfile = findNextBestProfile(J2SE, javaVersion);
    }
    return bestProfile;
  }
  
  private URL findNextBestProfile(String javaEdition, Version javaVersion)
  {
    URL result = null;
    int minor = javaVersion.getMinor();
    do
    {
      result = findInSystemBundle(javaEdition + javaVersion.getMajor() + "." + minor + PROFILE_EXT);
      minor--;
    } while ((result == null) && (minor > 0));
    return result;
  }
  
  private URL findInSystemBundle(String entry)
  {
    URL result = systemBundle.getEntry0(entry);
    if (result == null)
    {
      ClassLoader loader = getClass().getClassLoader();
      result = loader == null ? ClassLoader.getSystemResource(entry) : loader.getResource(entry);
    }
    return result;
  }
  
  protected boolean isActive()
  {
    return active;
  }
  
  public synchronized void close()
  {
    if (adaptor == null) {
      return;
    }
    if (active) {
      shutdown(64);
    }
    synchronized (bundles)
    {
      List<AbstractBundle> allBundles = bundles.getBundles();
      int size = allBundles.size();
      for (int i = 0; i < size; i++)
      {
        AbstractBundle bundle = (AbstractBundle)allBundles.get(i);
        bundle.close();
      }
      bundles.removeAllBundles();
    }
    serviceRegistry = null;
    allBundleListeners.clear();
    allSyncBundleListeners.clear();
    allFrameworkListeners.clear();
    if (eventManager != null)
    {
      eventManager.close();
      eventManager = null;
    }
    secureAction = null;
    packageAdmin = null;
    adaptor = null;
    uninstallURLStreamHandlerFactory();
    uninstallContentHandlerFactory();
    if ((System.getSecurityManager() instanceof EquinoxSecurityManager)) {
      System.setSecurityManager(null);
    }
  }
  
  public synchronized void launch()
  {
    if (active) {
      return;
    }
    active = true;
    shutdownEvent = new FrameworkEvent[1];
    if ("normal".equals(FrameworkProperties.getProperty("osgi.framework.activeThreadType", "normal")))
    {
      Thread fwkThread = new Thread(this, "Framework Active Thread");
      fwkThread.setDaemon(false);
      fwkThread.start();
    }
    if (Debug.DEBUG_GENERAL) {
      Debug.println("Trying to launch framework");
    }
    systemBundle.resume();
    signedContentFactory = new ServiceTracker(systemBundle.getBundleContext(), SignedContentFactory.class.getName(), null);
    signedContentFactory.open();
  }
  
  public synchronized void shutdown(int eventType)
  {
    if (!active) {
      return;
    }
    shutdownEvent[0] = new FrameworkEvent(eventType, systemBundle, null);
    
    systemBundle.state = 16;
    publishBundleEvent(256, systemBundle);
    try
    {
      adaptor.frameworkStopping(systemBundle.getContext());
    }
    catch (Throwable t)
    {
      publishFrameworkEvent(2, systemBundle, t);
    }
    if (Debug.DEBUG_GENERAL) {
      Debug.println("Trying to shutdown Framework");
    }
    systemBundle.suspend();
    try
    {
      adaptor.compactStorage();
    }
    catch (IOException e)
    {
      publishFrameworkEvent(2, systemBundle, e);
    }
    if (signedContentFactory != null) {
      signedContentFactory.close();
    }
    active = false;
    notifyAll();
  }
  
  AbstractBundle createAndVerifyBundle(BundleData bundledata, boolean setBundle)
    throws BundleException
  {
    if ((!allowDuplicateBSNVersion) && (bundledata.getSymbolicName() != null))
    {
      AbstractBundle installedBundle = getBundleBySymbolicName(bundledata.getSymbolicName(), bundledata.getVersion());
      if ((installedBundle != null) && (installedBundle.getBundleId() != bundledata.getBundleID()))
      {
        String msg = NLS.bind(Msg.BUNDLE_INSTALL_SAME_UNIQUEID, new Object[] { installedBundle.getSymbolicName(), installedBundle.getVersion().toString(), installedBundle.getLocation() });
        throw new DuplicateBundleException(msg, installedBundle);
      }
    }
    return AbstractBundle.createBundle(bundledata, this, setBundle);
  }
  
  private class DuplicateBundleException
    extends BundleException
    implements StatusException
  {
    private static final long serialVersionUID = 135669822846323624L;
    private final Bundle duplicate;
    
    public DuplicateBundleException(String msg, Bundle duplicate)
    {
      super(9);
      this.duplicate = duplicate;
    }
    
    public Object getStatus()
    {
      return duplicate;
    }
    
    public int getStatusCode()
    {
      return 1;
    }
  }
  
  public String getProperty(String key)
  {
    return properties.getProperty(key);
  }
  
  protected String getProperty(String key, String def)
  {
    return properties.getProperty(key, def);
  }
  
  protected Object setProperty(String key, String value)
  {
    return properties.put(key, value);
  }
  
  AbstractBundle installBundle(final String location, final InputStream in, BundleContext origin)
    throws BundleException
  {
    if (Debug.DEBUG_GENERAL) {
      Debug.println("install from inputstream: " + location + ", " + in);
    }
    final AccessControlContext callerContext = AccessController.getContext();
    installWorker(location, new PrivilegedExceptionAction()
    {
      public AbstractBundle run()
        throws BundleException
      {
        URLConnection source = in != null ? new BundleSource(in) : adaptor.mapLocationToURLConnection(location);
        
        return installWorkerPrivileged(location, source, callerContext);
      }
    }, origin);
  }
  
  protected AbstractBundle installWorker(String location,
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-2019. Infinite Loop Ltd