Exemplo n.º 1
1
  protected PsmMethodAction(Class c, String m, Class[] argArray) {
    // This prevents IllegalAccessExceptions when attempting to
    // invoke methods on a class that is in another package and not
    // defined 'public'.
    if (!Modifier.isPublic(c.getModifiers())) {
      throw new IllegalPsmMethodActionException("Action class must be public.");
    }

    try {
      method = c.getMethod(m, argArray);
    } catch (NoSuchMethodException ex) {
      throw new IllegalPsmMethodActionException(ex.toString() + ": method " + m);
    }

    // Check each exception this method declares thrown.  If it declares
    // exceptions, and any of them are not runtime exceptions, abort.
    Class[] exceptionTypes = method.getExceptionTypes();
    for (int i = 0; i < exceptionTypes.length; i++) {
      Class exceptionClass = exceptionTypes[i];
      if (!RuntimeException.class.isAssignableFrom(exceptionClass)) {
        throw new IllegalPsmMethodActionException(
            "Method must not declare non-Runtime " + "exceptions.");
      }
    }

    // Ensure that the method returns PsmEvent
    if (PsmEvent.class != method.getReturnType()) {
      throw new IllegalPsmMethodActionException("Method return type must be PsmEvent");
    }

    // Ensure that both the method is both public and static.
    if (!Modifier.isStatic(method.getModifiers()) || !Modifier.isPublic(method.getModifiers())) {
      throw new IllegalPsmMethodActionException("Method " + m + " must be static and public.");
    }
  }
 /**
  * Builds a new page stream transform using the given PDF operator processors (represented by
  * their class) to process the given PDF operators (represented by their operator string), and
  * imposing a default of {@link SimpleOperatorProcessor} for all others.
  *
  * @param pdfOperatorString1 A PDF operator string.
  * @param pdfOperatorProcessor1 A PDF operator processor class for <code>pdfOperatorString1</code>
  *     .
  * @param pdfOperatorString2 A PDF operator string.
  * @param pdfOperatorProcessor2 A PDF operator processor class for <code>pdfOperatorString2</code>
  *     .
  * @throws IOException if any processing error occurs.
  * @see #PageStreamTransform(Properties)
  * @see PropUtil#fromArgs(String, String, String, String)
  * @deprecated Use {@link #PageStreamTransform(OperatorProcessorFactory, String, Class, String,
  *     Class)}.
  */
 public PageStreamTransform(
     String pdfOperatorString1,
     Class pdfOperatorProcessor1,
     String pdfOperatorString2,
     Class pdfOperatorProcessor2)
     throws IOException {
   this(
       PropUtil.fromArgs(
           pdfOperatorString1, pdfOperatorProcessor1.getName(),
           pdfOperatorString2, pdfOperatorProcessor2.getName()));
 }
 /**
  * Builds a new page stream transform using the given PDF operator processors (represented by
  * their class) to process the given PDF operators (represented by their operator string), and
  * imposing a default of {@link SimpleOperatorProcessor} for all others.
  *
  * @param factory A {@link PdfOperatorProcessor} factory.
  * @param pdfOperatorString1 A PDF operator string.
  * @param pdfOperatorProcessor1 A PDF operator processor class for <code>pdfOperatorString1</code>
  *     .
  * @param pdfOperatorString2 A PDF operator string.
  * @param pdfOperatorProcessor2 A PDF operator processor class for <code>pdfOperatorString2</code>
  *     .
  * @param pdfOperatorString3 A PDF operator string.
  * @param pdfOperatorProcessor3 A PDF operator processor class for <code>pdfOperatorString3</code>
  *     .
  * @throws IOException if any processing error occurs.
  * @see #PageStreamTransform(OperatorProcessorFactory, Properties)
  * @see PropUtil#fromArgs(String, String, String, String, String, String)
  */
 public PageStreamTransform(
     OperatorProcessorFactory factory,
     String pdfOperatorString1,
     Class pdfOperatorProcessor1,
     String pdfOperatorString2,
     Class pdfOperatorProcessor2,
     String pdfOperatorString3,
     Class pdfOperatorProcessor3)
     throws IOException {
   this(
       factory,
       PropUtil.fromArgs(
           pdfOperatorString1, pdfOperatorProcessor1.getName(),
           pdfOperatorString2, pdfOperatorProcessor2.getName(),
           pdfOperatorString3, pdfOperatorProcessor3.getName()));
 }
 /**
  * Returns an instance of the type of MBF indicated by "version" intended to verify a proof of
  * effort.
  *
  * @param nonceVal a byte array containing the nonce
  * @param eVal the effort sizer (# of low-order zeros in destination)
  * @param lVal the effort sizer (length of each path)
  * @param nVal the proof density
  * @param sVal an array of ints containing the proof
  * @param maxPathVal maximum number of steps to verify
  * @throws NoSuchAlgorithmException no such implementation
  * @throws InstantiationException XXX
  * @throws IllegalAccessException XXX
  * @throws MemoryBoundFunctionException could not initialize instance
  */
 public MemoryBoundFunction makeVerifier(
     byte[] nonceVal, int eVal, int lVal, int nVal, int[] sVal, long maxPathVal)
     throws NoSuchAlgorithmException, InstantiationException, IllegalAccessException,
         MemoryBoundFunctionException {
   MemoryBoundFunction ret = null;
   if (classToUse == null) throw new NoSuchAlgorithmException();
   ret = (MemoryBoundFunction) classToUse.newInstance();
   ret.initialize(nonceVal, eVal, lVal, nVal, sVal, maxPathVal, A0, T);
   return (ret);
 }
 /**
  * Public constructor for an object that creates MemoryBoundFunction objects of the requested
  * implementation.
  *
  * @param impl A String specifying the implementation to use.
  * @param A0array The A0 basis array
  * @param Tarray The T basis array
  * @throws NoSuchAlgorithmException if no such implementation
  */
 public MemoryBoundFunctionFactory(String impl, byte[] A0array, byte[] Tarray)
     throws NoSuchAlgorithmException, ClassNotFoundException, MemoryBoundFunctionException {
   classToUse = null;
   implToUse = null;
   for (int i = 0; i < implNames.length; i++) {
     if (implNames[i].equals(impl)) implToUse = impls[i];
   }
   if (implToUse != null) {
     // Found it
     if (A0array == null || Tarray == null) {
       throw new MemoryBoundFunctionException("Array is null");
     }
     classToUse = Class.forName(implToUse);
     logger.info("factory for " + impl + " size " + A0array.length + " / " + Tarray.length);
     A0 = A0array;
     T = Tarray;
   } else {
     throw new NoSuchAlgorithmException(impl);
   }
 }
 /**
  * Builds a new page stream transform using the given PDF operator processor (represented by its
  * class) to process the given PDF operator (represented by its operator string), and imposing a
  * default of {@link SimpleOperatorProcessor} for all others.
  *
  * @param factory A {@link PdfOperatorProcessor} factory.
  * @param pdfOperatorString A PDF operator string.
  * @param pdfOperatorProcessor A PDF operator processor class for <code>pdfOperatorString</code>..
  * @throws IOException if any processing error occurs.
  * @see #PageStreamTransform(OperatorProcessorFactory, Properties)
  * @see PropUtil#fromArgs(String, String)
  */
 public PageStreamTransform(
     OperatorProcessorFactory factory, String pdfOperatorString, Class pdfOperatorProcessor)
     throws IOException {
   this(factory, PropUtil.fromArgs(pdfOperatorString, pdfOperatorProcessor.getName()));
 }
Exemplo n.º 7
0
  protected void initResultMap() throws PluginException.InvalidDefinition {
    HttpResultMap hResultMap = new HttpResultMap();
    // XXX Currently this only allows a CacheResultHandler class to
    // initialize the result map.  Instead, don't use a CacheResultMap
    // directly, use either the plugin's CacheResultHandler, if specified,
    // or a default one that wraps the CacheResultMap

    String handler_class = null;
    handler_class = definitionMap.getString(KEY_EXCEPTION_HANDLER, null);
    if (handler_class != null) {
      try {
        resultHandler = (CacheResultHandler) newAuxClass(handler_class, CacheResultHandler.class);
        resultHandler.init(hResultMap);
      } catch (Exception ex) {
        throw new PluginException.InvalidDefinition(
            mapName + " has invalid Exception handler: " + handler_class, ex);
      } catch (LinkageError le) {
        throw new PluginException.InvalidDefinition(
            mapName + " has invalid Exception handler: " + handler_class, le);
      }
    } else {
      // Expect a list of mappings from either result code or exception
      // name to CacheException name
      Collection<String> mappings = definitionMap.getCollection(KEY_EXCEPTION_LIST, null);
      if (mappings != null) {
        // add each entry
        for (String entry : mappings) {
          if (log.isDebug2()) {
            log.debug2("initMap(" + entry + ")");
          }
          String first;
          String ceName;
          try {
            List<String> pair = StringUtil.breakAt(entry, '=', 2, true, true);
            first = pair.get(0);
            ceName = pair.get(1);
          } catch (Exception ex) {
            throw new PluginException.InvalidDefinition(
                "Invalid syntax: " + entry + "in " + mapName);
          }
          Object val;

          // Value should be either a CacheException or CacheResultHandler
          // class name.
          PluginFetchEventResponse resp =
              (PluginFetchEventResponse) newAuxClass(ceName, PluginFetchEventResponse.class, null);
          if (resp instanceof CacheException) {
            val = resp.getClass();
          } else if (resp instanceof CacheResultHandler) {
            val = WrapperUtil.wrap((CacheResultHandler) resp, CacheResultHandler.class);
          } else {
            throw new PluginException.InvalidDefinition(
                "Second arg not a "
                    + "CacheException or "
                    + "CacheResultHandler class: "
                    + entry
                    + ", in "
                    + mapName);
          }
          try {
            int code = Integer.parseInt(first);
            // If parseable as an integer, it's a result code.
            hResultMap.storeMapEntry(code, val);
          } catch (NumberFormatException e) {
            try {
              Class eClass = Class.forName(first);
              // If a class name, it should be an exception class
              if (Exception.class.isAssignableFrom(eClass)) {
                hResultMap.storeMapEntry(eClass, val);
              } else {
                throw new PluginException.InvalidDefinition(
                    "First arg not an " + "Exception class: " + entry + ", in " + mapName);
              }
            } catch (Exception ex) {
              throw new PluginException.InvalidDefinition(
                  "First arg not a " + "number or class: " + entry + ", in " + mapName);
            } catch (LinkageError le) {
              throw new PluginException.InvalidDefinition("Can't load " + first, le);
            }
          }
        }
      }
    }
    resultMap = hResultMap;
  }