Exemplo n.º 1
0
 /**
  * Print a debug message to the console. Pre-pend the message with the current date and the name
  * of the current thread.
  */
 public static void debug(String message) {
   StringBuffer buffer = new StringBuffer();
   buffer.append(new Date(System.currentTimeMillis()));
   buffer.append(" - ["); // $NON-NLS-1$
   buffer.append(Thread.currentThread().getName());
   buffer.append("] "); // $NON-NLS-1$
   buffer.append(message);
   System.out.println(buffer.toString());
 }
Exemplo n.º 2
0
 /**
  * Returns the absolute path name of a native library.
  *
  * @param name the library name
  * @return the absolute path of the native library or null if not found
  */
 public String findLibrary(final String name) {
   if (System.getSecurityManager() == null) return findLocalLibrary(name);
   return (String)
       AccessController.doPrivileged(
           new PrivilegedAction() {
             public Object run() {
               return findLocalLibrary(name);
             }
           });
 }
Exemplo n.º 3
0
 private static ClassLoader getClassLoader(final Class clazz) {
   if (System.getSecurityManager() == null) return clazz.getClassLoader();
   return (ClassLoader)
       AccessController.doPrivileged(
           new PrivilegedAction() {
             public Object run() {
               return clazz.getClassLoader();
             }
           });
 }
Exemplo n.º 4
0
  private ClassLoader getParentPrivileged(final BundleClassLoader bcl) {
    if (System.getSecurityManager() == null) return bcl.getParent();

    return (ClassLoader)
        AccessController.doPrivileged(
            new PrivilegedAction() {
              public Object run() {
                return bcl.getParent();
              }
            });
  }
Exemplo n.º 5
0
  private BundleClassLoader createBCLPrevileged(
      final BundleProtectionDomain pd, final String[] cp) {
    // Create the classloader as previleged code if security manager is present.
    if (System.getSecurityManager() == null) return createBCL(pd, cp);

    return (BundleClassLoader)
        AccessController.doPrivileged(
            new PrivilegedAction() {
              public Object run() {
                return createBCL(pd, cp);
              }
            });
  }
  protected Object[] findCallees(IPluginModelBase model) {
    BundleDescription desc = model.getBundleDescription();
    if (desc == null) return new Object[0];
    fFragmentDescription = null;
    HostSpecification spec = desc.getHost();
    if (spec != null) {
      fFragmentDescription = desc;
      Object[] fragmentDependencies = getDependencies(desc);
      BaseDescription host = spec.getSupplier();
      if (host instanceof BundleDescription) {
        BundleDescription hostDesc = (BundleDescription) host;
        // check to see if the host is already included as a dependency.  If so, we don't need to
        // include the host manually.
        for (int i = 0; i < fragmentDependencies.length; i++) {
          BundleDescription dependency = null;
          if (fragmentDependencies[i] instanceof BundleSpecification)
            dependency = ((BundleSpecification) fragmentDependencies[i]).getBundle();
          else if (fragmentDependencies[i] instanceof ImportPackageSpecification) {
            ExportPackageDescription epd =
                (ExportPackageDescription)
                    ((ImportPackageSpecification) fragmentDependencies[i]).getSupplier();
            if (epd != null) dependency = epd.getSupplier();
          }
          if (dependency != null && dependency.equals(hostDesc)) return fragmentDependencies;
        }

        // host not included as dependency, include it manually.
        Object[] result = new Object[fragmentDependencies.length + 1];
        result[0] = hostDesc;
        System.arraycopy(fragmentDependencies, 0, result, 1, fragmentDependencies.length);
        return result;
      }
      return fragmentDependencies;
    }
    return getDependencies(desc);
  }
Exemplo n.º 7
0
  /**
   * BundleLoader runtime constructor. This object is created lazily when the first request for a
   * resource is made to this bundle.
   *
   * @param bundle Bundle object for this loader.
   * @param proxy the BundleLoaderProxy for this loader.
   * @exception org.osgi.framework.BundleException
   */
  protected BundleLoader(BundleHost bundle, BundleLoaderProxy proxy) throws BundleException {
    this.bundle = bundle;
    this.proxy = proxy;
    try {
      bundle.getBundleData().open(); /* make sure the BundleData is open */
    } catch (IOException e) {
      throw new BundleException(Msg.BUNDLE_READ_EXCEPTION, e);
    }
    BundleDescription description = proxy.getBundleDescription();
    // init the require bundles list.
    BundleDescription[] required = description.getResolvedRequires();
    if (required.length > 0) {
      // get a list of re-exported symbolic names
      HashSet reExportSet = new HashSet(required.length);
      BundleSpecification[] requiredSpecs = description.getRequiredBundles();
      if (requiredSpecs != null && requiredSpecs.length > 0)
        for (int i = 0; i < requiredSpecs.length; i++)
          if (requiredSpecs[i].isExported()) reExportSet.add(requiredSpecs[i].getName());

      requiredBundles = new BundleLoaderProxy[required.length];
      int[] reexported = new int[required.length];
      int reexportIndex = 0;
      for (int i = 0; i < required.length; i++) {
        requiredBundles[i] = getLoaderProxy(required[i]);
        if (reExportSet.contains(required[i].getSymbolicName())) reexported[reexportIndex++] = i;
      }
      if (reexportIndex > 0) {
        reexportTable = new int[reexportIndex];
        System.arraycopy(reexported, 0, reexportTable, 0, reexportIndex);
      } else {
        reexportTable = null;
      }
      requiredSources = new KeyedHashSet(10, false);
    } else {
      requiredBundles = null;
      reexportTable = null;
      requiredSources = null;
    }

    // init the provided packages set
    ExportPackageDescription[] exports = description.getSelectedExports();
    if (exports != null && exports.length > 0) {
      exportedPackages =
          Collections.synchronizedCollection(
              exports.length > 10
                  ? (Collection) new HashSet(exports.length)
                  : new ArrayList(exports.length));
      initializeExports(exports, exportedPackages);
    } else {
      exportedPackages = Collections.synchronizedCollection(new ArrayList(0));
    }

    ExportPackageDescription substituted[] = description.getSubstitutedExports();
    if (substituted.length > 0) {
      substitutedPackages =
          substituted.length > 10
              ? (Collection) new HashSet(substituted.length)
              : new ArrayList(substituted.length);
      for (int i = 0; i < substituted.length; i++)
        substitutedPackages.add(substituted[i].getName());
    } else {
      substitutedPackages = null;
    }

    // This is the fastest way to access to the description for fragments since the
    // hostdescription.getFragments() is slow
    BundleFragment[] fragmentObjects = bundle.getFragments();
    BundleDescription[] fragments =
        new BundleDescription[fragmentObjects == null ? 0 : fragmentObjects.length];
    for (int i = 0; i < fragments.length; i++)
      fragments[i] = fragmentObjects[i].getBundleDescription();
    // init the dynamic imports tables
    if (description.hasDynamicImports()) addDynamicImportPackage(description.getImportPackages());
    // ...and its fragments
    for (int i = 0; i < fragments.length; i++)
      if (fragments[i].isResolved() && fragments[i].hasDynamicImports())
        addDynamicImportPackage(fragments[i].getImportPackages());

    // Initialize the policy handler
    String buddyList = null;
    try {
      buddyList = (String) bundle.getBundleData().getManifest().get(Constants.BUDDY_LOADER);
    } catch (BundleException e) {
      // do nothing; buddyList == null
    }
    policy =
        buddyList != null
            ? new PolicyHandler(this, buddyList, bundle.getFramework().getPackageAdmin())
            : null;
    if (policy != null) policy.open(bundle.getFramework().getSystemBundleContext());
  }
 public int hashCode() {
   return System.identityHashCode(VersionConstraintImpl.this);
 }