org.eclipse.osgi_3.8.2.v20130124-134944

 Object run()
  {
    this$0.notifyCollisionHooksPriviledged(val$operationType, val$target, val$shrinkable);
    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.util.Collection;
import org.eclipse.osgi.internal.serviceregistry.HookContext;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.bundle.CollisionHook;

class Framework$6
  implements HookContext
{
  final Framework this$0;
  
  Framework$6(Framework paramFramework, int paramInt, Bundle paramBundle, Collection paramCollection) {}
  
  public void call(Object hook, ServiceRegistration<?> hookRegistration)
    throws Exception
  {
    if ((hook instanceof CollisionHook)) {
      ((CollisionHook)hook).filterCollisions(val$operationType, val$target, val$collisionCandidates);
    }
  }
  
  public String getHookClassName()
  {
    return Framework.collisionHookName;
  }
  
  public String getHookMethodName()
  {
    return "filterCollisions";
  }
}

/* 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 java.util.List;

class Framework$7
  implements PrivilegedAction<AbstractBundle>
{
  final Framework this$0;
  
  Framework$7(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.7
 * 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$8
  implements PrivilegedAction<Object>
{
  final Framework this$0;
  
  Framework$8(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.8
 * 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$9
  implements PrivilegedAction<Object>
{
  final Framework this$0;
  
  Framework$9(Framework paramFramework, BundleEvent paramBundleEvent) {}
  
  public Object run()
  {
    this$0.publishBundleEventPrivileged(val$event);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.framework.internal.core.Framework.9
 * 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 transient 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.CollisionHook;
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 volatile FrameworkAdaptor adaptor;
  protected Properties properties;
  protected volatile boolean active;
  private FrameworkEvent[] shutdownEvent;
  protected BundleRepository bundles;
  protected volatile PackageAdminImpl packageAdmin;
  protected SecurityAdmin securityAdmin;
  protected StartLevelManager startLevelManager;
  private volatile ServiceRegistry serviceRegistry;
  private final int BSN_VERSION;
  private static final int BSN_VERSION_SINGLE = 1;
  private static final int BSN_VERSION_MULTIPLE = 2;
  private static final int BSN_VERSION_MANAGED = 3;
  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();
  static final String collisionHookName = CollisionHook.class.getName();
  protected volatile 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 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();
  static final 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)
  {
    if (Profile.STARTUP) {
      Profile.logEnter("Framework.initialze()", null);
    }
    String bsnVersion = FrameworkProperties.getProperty("org.osgi.framework.bsnversion");
    if ("single".equals(bsnVersion)) {
      BSN_VERSION = 1;
    } else if ("multiple".equals(bsnVersion)) {
      BSN_VERSION = 2;
    } else {
      BSN_VERSION = 3;
    }
    long start = System.currentTimeMillis();
    this.adaptor = adaptor;
    delegateHooks = ((adaptor instanceof BaseAdaptor) ? ((BaseAdaptor)adaptor).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();
    
    adaptor.initialize(this);
    if (Profile.STARTUP) {
      Profile.logTime("Framework.initialze()", "adapter initialized");
    }
    try
    {
      adaptor.initializeStorage();
    }
    catch (IOException e)
    {
      throw new RuntimeException(e.getMessage(), e);
    }
    if (Profile.STARTUP) {
      Profile.logTime("Framework.initialze()", "adapter storage initialized");
    }
    initializeProperties(adaptor.getProperties());
    
    packageAdmin = new PackageAdminImpl(this);
    try
    {
      securityAdmin = new SecurityAdmin(null, this, adaptor.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, adaptor);
    
    installContentHandlerFactory(systemBundle.context, adaptor);
    if (Profile.STARTUP) {
      Profile.logTime("Framework.initialze()", "done new URLStream/Content HandlerFactory");
    }
    BundleData[] bundleDatas = adaptor.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;
    }
    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(int operationType, Bundle target, BundleData bundledata, boolean setBundle)
    throws BundleException
  {
    if ((BSN_VERSION != 2) && (bundledata.getSymbolicName() != null))
    {
      List<AbstractBundle> installedBundles = getBundleBySymbolicName(bundledata.getSymbolicName(), bundledata.getVersion());
      if (operationType == 2) {
        installedBundles.remove(target);
      }
      if ((BSN_VERSION == 3) && (!installedBundles.isEmpty())) {
        notifyCollisionHooks(operationType, target, installedBundles);
      }
      if (!installedBundles.isEmpty())
      {
        Bundle installedBundle = (Bundle)installedBundles.iterator().next();
        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 transient 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, final BundleContextImpl 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);
      }
    }, origin);
  }
  
  protected AbstractBundle installWorker(String location, PrivilegedExceptionAction<AbstractBundle> action, BundleContext origin)
    throws BundleException
  {
    Thread current;
    synchronized (installLock)
    {
      for (;;)
      {
        bundle = getBundleByLocation(location);
        if (bundle != null)
        {
          Bundle visible = origin.getBundle(bundle.getBundleId());
          if (visible == null)
          {
            BundleData data = bundle.getBundleData();
            String msg = NLS.bind(Msg.BUNDLE_INSTALL_SAME_UNIQUEID, new Object[] { data.getSymbolicName(), data.getVersion().toString(), data.getLocation() });
            throw new BundleException(msg, 12);
          }
          return bundle;
        }
        current = Thread.currentThread();
        
        Thread reservation = (Thread)installLock.put(location, current);
        if (reservation != null)
        {
          if (current.equals(reservation)) {
            throw new BundleException(Msg.BUNDLE_INSTALL_RECURSION_EXCEPTION, 7);
          }
          try
          {
            installLock.wait();
          }
          catch (InterruptedException e)
          {
            Thread.currentThread().interrupt();
            throw new BundleException("Thread has been interrupted while waiting for the location lock.", e);
          }
        }
      }
    }
    try
    {
      AbstractBundle bundle = (AbstractBundle)AccessController.doPrivileged(action);
      publishBundleEvent(new BundleEvent(1, bundle, origin.getBundle()));
      return bundle;
    }
    catch (PrivilegedActionException e)
    {
      if ((e.getException() instanceof RuntimeException)) {
        throw ((RuntimeException)e.getException());
      }
      throw ((BundleException)e.getException());
    }
    finally
    {
      synchronized (installLock)
      {
        installLock.remove(location);
        
        installLock.notifyAll();
      }
    }
  }
  
  /* Error */
  protected AbstractBundle installWorkerPrivileged(String location, URLConnection source, AccessControlContext callerContext, BundleContextImpl origin)
    throws BundleException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 1564	org/eclipse/osgi/framework/internal/core/Framework:adaptor	Lorg/eclipse/osgi/framework/adaptor/FrameworkAdaptor;
    //   4: aload_1
    //   5: aload_2
    //   6: invokeinterface 1892 3 0
    //   11: astore 5
    //   13: aload 5
    //   15: invokeinterface 1881 1 0
    //   20: astore 7
    //   22: aload_0
    //   23: iconst_1
    //   24: aload 4
    //   26: invokevirtual 1720	org/eclipse/osgi/framework/internal/core/BundleContextImpl:getBundle	()Lorg/osgi/framework/Bundle;
    //   29: aload 7
    //   31: iconst_1
    //   32: invokevirtual 1771	org/eclipse/osgi/framework/internal/core/Framework:createAndVerifyBundle	(ILorg/osgi/framework/Bundle;Lorg/eclipse/osgi/framework/adaptor/BundleData;Z)Lorg/eclipse/osgi/framework/internal/core/AbstractBundle;
    //   35: astore 6
    //   37: aload_0
    //   38: getfield 1564	org/eclipse/osgi/framework/internal/core/Framework:adaptor	Lorg/eclipse/osgi/framework/adaptor/FrameworkAdaptor;
    //   41: invokeinterface 1887 1 0
    //   46: astore 8
    //   48: aload 8
    //   50: ifnull +13 -> 63
    //   53: aload 8
    //   55: aload 6
    //   57: iconst_1
    //   58: invokeinterface 1882 3 0
    //   63: aload 6
    //   65: invokevirtual 1707	org/eclipse/osgi/framework/internal/core/AbstractBundle:load	()V
    //   68: invokestatic 1644	java/lang/System:getSecurityManager	()Ljava/lang/SecurityManager;
    //   71: ifnull +94 -> 165
    //   74: aload 7
    //   76: invokeinterface 1874 1 0
    //   81: bipush 22
    //   83: iand
    //   84: ifeq +7 -> 91
    //   87: iconst_1
    //   88: goto +4 -> 92
    //   91: iconst_0
    //   92: istore 9
    //   94: iload 9
    //   96: ifeq +41 -> 137
    //   99: aload 6
    //   101: new 842	java/security/AllPermission
    //   104: dup
    //   105: invokespecial 1669	java/security/AllPermission:<init>	()V
    //   108: invokevirtual 1713	org/eclipse/osgi/framework/internal/core/AbstractBundle:hasPermission	(Ljava/lang/Object;)Z
    //   111: ifne +26 -> 137
    //   114: new 914	org/osgi/framework/BundleException
    //   117: dup
    //   118: getstatic 1580	org/eclipse/osgi/framework/internal/core/Msg:BUNDLE_EXTENSION_PERMISSION	Ljava/lang/String;
    //   121: bipush 6
    //   123: new 826	java/lang/SecurityException
    //   126: dup
    //   127: getstatic 1580	org/eclipse/osgi/framework/internal/core/Msg:BUNDLE_EXTENSION_PERMISSION	Ljava/lang/String;
    //   130: invokespecial 1620	java/lang/SecurityException:<init>	(Ljava/lang/String;)V
    //   133: invokespecial 1838	org/osgi/framework/BundleException:<init>	(Ljava/lang/String;ILjava/lang/Throwable;)V
    //   136: athrow
    //   137: new 878	org/eclipse/osgi/framework/internal/core/Framework$2
    //   140: dup
    //   141: aload_0
    //   142: aload 6
    //   144: iload 9
    //   146: invokespecial 1778	org/eclipse/osgi/framework/internal/core/Framework$2:<init>	(Lorg/eclipse/osgi/framework/internal/core/Framework;Lorg/eclipse/osgi/framework/internal/core/AbstractBundle;Z)V
    //   149: aload_3
    //   150: invokestatic 1668	java/security/AccessController:doPrivileged	(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
    //   153: pop
    //   154: goto +11 -> 165
    //   157: astore 10
    //   159: aload 10
    //   161: invokevirtual 1670	java/security/PrivilegedActionException:getException	()Ljava/lang/Exception;
    //   164: athrow
    //   165: aload_0
    //   166: getfield 1567	org/eclipse/osgi/framework/internal/core/Framework:bundles	Lorg/eclipse/osgi/framework/internal/core/BundleRepository;
    //   169: aload 6
    //   171: invokevirtual 1725	org/eclipse/osgi/framework/internal/core/BundleRepository:add	(Lorg/eclipse/osgi/framework/internal/core/AbstractBundle;)V
    //   174: aload 5
    //   176: iconst_0
    //   177: invokeinterface 1880 2 0
    //   182: goto +67 -> 249
    //   185: astore 9
    //   187: aload_0
    //   188: getfield 1567	org/eclipse/osgi/framework/internal/core/Framework:bundles	Lorg/eclipse/osgi/framework/internal/core/BundleRepository;
    //   191: aload 6
    //   193: invokevirtual 1726	org/eclipse/osgi/framework/internal/core/BundleRepository:remove	(Lorg/eclipse/osgi/framework/internal/core/AbstractBundle;)Z
    //   196: pop
    //   197: aload_0
    //   198: getfield 1567	org/eclipse/osgi/framework/internal/core/Framework:bundles	Lorg/eclipse/osgi/framework/internal/core/BundleRepository;
    //   201: dup
    //   202: astore 10
    //   204: monitorenter
    //   205: aload 6
    //   207: invokevirtual 1711	org/eclipse/osgi/framework/internal/core/AbstractBundle:unload	()Z
    //   210: pop
    //   211: aload 10
    //   213: monitorexit
    //   214: goto +7 -> 221
    //   217: aload 10
    //   219: monitorexit
    //   220: athrow
    //   221: aload 6
    //   223: invokevirtual 1706	org/eclipse/osgi/framework/internal/core/AbstractBundle:close	()V
    //   226: aload 9
    //   228: athrow
    //   229: astore 11
    //   231: aload 8
    //   233: ifnull +13 -> 246
    //   236: aload 8
    //   238: aload 6
    //   240: iconst_2
    //   241: invokeinterface 1
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-2017. Infinite Loop Ltd