Search in sources :

Example 1 with AlgorithmAlreadyRegisteredException

use of com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException in project jdk8u_jdk by JetBrains.

the class ClassLoaderTest method main.

public static void main(String[] args) throws Exception {
    File file = new File(BASE);
    URL[] urls = new URL[1];
    urls[0] = file.toURI().toURL();
    URLClassLoader ucl = new URLClassLoader(urls);
    Class<?> c = ucl.loadClass("MyTransform");
    Constructor<?> cons = c.getConstructor(new Class[] {});
    Object o = cons.newInstance();
    // it again and catching an AlgorithmAlreadyRegisteredExc
    try {
        Transform.register(MyTransform.URI, "MyTransform");
        throw new Exception("ClassLoaderTest failed");
    } catch (AlgorithmAlreadyRegisteredException e) {
    // test passed
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) File(java.io.File) AlgorithmAlreadyRegisteredException(com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException) URL(java.net.URL) AlgorithmAlreadyRegisteredException(com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException)

Example 2 with AlgorithmAlreadyRegisteredException

use of com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException in project jdk8u_jdk by JetBrains.

the class SignatureAlgorithm method register.

/**
     * Registers implementing class of the SignatureAlgorithm with algorithmURI
     *
     * @param algorithmURI algorithmURI URI representation of <code>SignatureAlgorithm</code>.
     * @param implementingClass <code>implementingClass</code> the implementing class of
     * {@link SignatureAlgorithmSpi}
     * @throws AlgorithmAlreadyRegisteredException if specified algorithmURI is already registered
     * @throws XMLSignatureException
     * @throws SecurityException if a security manager is installed and the
     *    caller does not have permission to register the signature algorithm
     */
@SuppressWarnings("unchecked")
public static void register(String algorithmURI, String implementingClass) throws AlgorithmAlreadyRegisteredException, ClassNotFoundException, XMLSignatureException {
    JavaUtils.checkRegisterPermission();
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Try to register " + algorithmURI + " " + implementingClass);
    }
    // are we already registered?
    Class<? extends SignatureAlgorithmSpi> registeredClass = algorithmHash.get(algorithmURI);
    if (registeredClass != null) {
        Object[] exArgs = { algorithmURI, registeredClass };
        throw new AlgorithmAlreadyRegisteredException("algorithm.alreadyRegistered", exArgs);
    }
    try {
        Class<? extends SignatureAlgorithmSpi> clazz = (Class<? extends SignatureAlgorithmSpi>) ClassLoaderUtils.loadClass(implementingClass, SignatureAlgorithm.class);
        algorithmHash.put(algorithmURI, clazz);
    } catch (NullPointerException ex) {
        Object[] exArgs = { algorithmURI, ex.getMessage() };
        throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs, ex);
    }
}
Also used : AlgorithmAlreadyRegisteredException(com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)

Aggregations

AlgorithmAlreadyRegisteredException (com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException)2 XMLSignatureException (com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)1 File (java.io.File)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1