コード例 #1
0
 private void initializeExports(ExportPackageDescription[] exports, Collection exportNames) {
   for (int i = 0; i < exports.length; i++) {
     if (proxy.forceSourceCreation(exports[i])) {
       if (!exportNames.contains(exports[i].getName())) {
         // must force filtered and reexport sources to be created early
         // to prevent lazy normal package source creation.
         // We only do this for the first export of a package name.
         proxy.createPackageSource(exports[i], true);
       }
     }
     exportNames.add(exports[i].getName());
   }
 }
コード例 #2
0
 boolean commit(List rows, long updateStamp) {
   checkAllPermission();
   synchronized (lock) {
     if (updateStamp != timeStamp) return false;
     SecurityRow[] newRows = new SecurityRow[rows.size()];
     Collection names = new ArrayList();
     for (int i = 0; i < newRows.length; i++) {
       Object rowObj = rows.get(i);
       if (!(rowObj instanceof ConditionalPermissionInfo))
         throw new IllegalStateException(
             "Invalid type \""
                 + rowObj.getClass().getName()
                 + "\" at row: "
                 + i); //$NON-NLS-1$//$NON-NLS-2$
       ConditionalPermissionInfo infoBaseRow = (ConditionalPermissionInfo) rowObj;
       String name = infoBaseRow.getName();
       if (name == null) name = generateName();
       if (names.contains(name))
         throw new IllegalStateException(
             "Duplicate name \"" + name + "\" at row: " + i); // $NON-NLS-1$//$NON-NLS-2$
       newRows[i] =
           new SecurityRow(
               this,
               name,
               infoBaseRow.getConditionInfos(),
               infoBaseRow.getPermissionInfos(),
               infoBaseRow.getAccessDecision());
     }
     condAdminTable = new SecurityTable(this, newRows);
     try {
       permissionStorage.saveConditionalPermissionInfos(condAdminTable.getEncodedRows());
     } catch (IOException e) {
       // TODO log
       e.printStackTrace();
     }
     timeStamp += 1;
     return true;
   }
 }
コード例 #3
0
 final boolean isSubstitutedExport(String name) {
   return substitutedPackages == null ? false : substitutedPackages.contains(name);
 }
コード例 #4
0
 final boolean isExportedPackage(String name) {
   return exportedPackages.contains(name);
 }
コード例 #5
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());
  }