/**
   * Activatable constructor. This constructor:
   *
   * <UL>
   *   <LI>Retrieves an <code>ActivateDesc</code> from the provided <code>data</code> parameter.
   *   <LI>creates a {@link ServiceClassLoader} using the import and export codebases obtained from
   *       the provided <code>ActivateDesc</code>,
   *   <LI>checks the import codebase(s) for the required <code>SharedActivationPolicyPermission
   *       </code>
   *   <LI>associates the newly created {@link ServiceClassLoader} and the corresponding policy file
   *       obtained from the <code>ActivateDesc</code> with the <code>AggregatePolicyProvider</code>
   *   <LI>loads the "wrapped" activatable object's class and calls its activation constructor with
   *       the context classloader set to the newly created {@link ServiceClassLoader}.
   *   <LI>resets the context class loader to the original context classloader
   * </UL>
   *
   * The first instance of this class will also replace the VM's existing <code>Policy</code>
   * object, if any, with a <code>AggregatePolicyProvider</code>.
   *
   * @param id The <code>ActivationID</code> of this object
   * @param data The activation data for this object
   * @throws Exception of any errors occur
   * @see ServiceClassLoader
   * @see com.sun.jini.start.AggregatePolicyProvider
   * @see com.sun.jini.start.SharedActivationPolicyPermission
   * @see java.security.Policy
   */
  public ActivateWrapper(ActivationID id, MarshalledObject data) throws Exception {
    logger.entering(ActivateWrapper.class.getName(), "ActivateWrapper", new Object[] {id, data});
    ActivateDesc desc = (ActivateDesc) data.get();
    logger.log(Level.FINEST, "ActivateDesc: {0}", desc);

    CommonClassLoader commonCL = CommonClassLoader.getInstance();
    commonCL.addCommonJARs(desc.commonJARs);
    if (logger.isLoggable(Level.FINEST))
      logger.log(Level.FINEST, "Created CommonClassLoader: {0}", commonCL);

    ServiceClassLoader cl;
    try {

      cl =
          new ServiceClassLoader(
              ServiceClassLoader.getURIs(desc.importLocation),
              new ClassAnnotator(desc.exportLocation),
              commonCL);
      if (logger.isLoggable(Level.FINEST))
        logger.log(Level.FINEST, "Created ServiceClassLoader: {0}", cl);
    } catch (Exception e) {
      logger.throwing(ActivateWrapper.class.getName(), "ActivateWrapper", e);
      throw e;
    }
    checkPolicyPermission(desc.policy, desc.importLocation);
    synchronized (ActivateWrapper.class) {
      // supplant global policy 1st time through
      if (globalPolicy == null) {
        initialGlobalPolicy = Policy.getPolicy();
        globalPolicy = new AggregatePolicyProvider(initialGlobalPolicy);
        Policy.setPolicy(globalPolicy);
        logger.log(Level.FINEST, "Global policy set: {0}", globalPolicy);
      }
      DynamicPolicyProvider service_policy =
          new DynamicPolicyProvider(new PolicyFileProvider(desc.policy));
      LoaderSplitPolicyProvider split_service_policy =
          new LoaderSplitPolicyProvider(
              cl, service_policy, new DynamicPolicyProvider(initialGlobalPolicy));
      split_service_policy.grant(
          this.getClass(), null, /* Principal[] */ new Permission[] {new AllPermission()});
      globalPolicy.setPolicy(cl, split_service_policy);
      logger.log(Level.FINEST, "Added policy to set: {0}", desc.policy);
    }
    Thread t = Thread.currentThread();
    ClassLoader ccl = t.getContextClassLoader();
    logger.log(Level.FINEST, "Saved current context class loader: {0}", ccl);
    t.setContextClassLoader(cl);
    logger.log(Level.FINEST, "Set new context class loader: {0}", cl);
    try {
      boolean initialize = false;
      Class ac = Class.forName(desc.className, initialize, cl);
      logger.log(Level.FINEST, "Obtained implementation class: {0}", ac);
      Constructor constructor = ac.getDeclaredConstructor(actTypes);
      logger.log(Level.FINEST, "Obtained implementation constructor: {0}", constructor);
      constructor.setAccessible(true);
      impl = constructor.newInstance(id, desc.data);
      logger.log(Level.FINEST, "Obtained implementation instance: {0}", impl);
    } finally {
      t.setContextClassLoader(ccl);
      logger.log(Level.FINEST, "Context class loader reset to: {0}", ccl);
    }
    logger.exiting(ActivateWrapper.class.getName(), "ActivateWrapper");
  }
Exemple #2
0
 private ProtectionDomain getUrlDomain(URL url) {
   CodeSource cs;
   cs = new CodeSource(url, (java.security.cert.Certificate[]) null);
   PermissionCollection pc = Policy.getPolicy().getPermissions(cs);
   return new ProtectionDomain(cs, pc);
 }