Java Code Examples for java.security.Provider.Service#getAttribute()

The following examples show how to use java.security.Provider.Service#getAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cipher.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static int supports(Service s, String attrName, String value) {
    if (value == null) {
        return S_YES;
    }
    String regexp = s.getAttribute(attrName);
    if (regexp == null) {
        return S_MAYBE;
    }
    return matches(regexp, value) ? S_YES : S_NO;
}
 
Example 2
Source File: TransformService.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. The specified provider
 * must be registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the string name of the provider
 * @return a new <code>TransformService</code>
 * @throws NoSuchProviderException if the specified provider is not
 *   registered in the security provider list
 * @throws NullPointerException if <code>provider</code>,
 *   <code>mechanismType</code>, or <code>algorithm</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified provider
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 3
Source File: TransformService.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM).
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate a <code>TransformService</code> implementation
 * of the desired algorithm and <code>MechanismType</code> service
 * attribute. It traverses the list of registered security
 * <code>Provider</code>s, starting with the most preferred
 * <code>Provider</code>. A new <code>TransformService</code> object
 * from the first <code>Provider</code> that supports the specified
 * algorithm and mechanism type is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>algorithm</code> or
 *   <code>mechanismType</code> is  <code>null</code>
 * @throws NoSuchAlgorithmException if no <code>Provider</code> supports a
 *   <code>TransformService</code> implementation for the specified
 *   algorithm and mechanism type
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null) {
        throw new NullPointerException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    List<Service> services = GetInstance.getServices("TransformService", algorithm);
    for (Iterator<Service> t = services.iterator(); t.hasNext(); ) {
        Service s = t.next();
        String value = s.getAttribute("MechanismType");
        if ((value == null && dom) ||
            (value != null && value.equals(mechanismType))) {
            Instance instance = GetInstance.getInstance(s, null);
            TransformService ts = (TransformService) instance.impl;
            ts.algorithm = algorithm;
            ts.mechanism = mechanismType;
            ts.provider = instance.provider;
            return ts;
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 4
Source File: TransformService.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. The specified provider
 * must be registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the string name of the provider
 * @return a new <code>TransformService</code>
 * @throws NoSuchProviderException if the specified provider is not
 *   registered in the security provider list
 * @throws NullPointerException if <code>provider</code>,
 *   <code>mechanismType</code>, or <code>algorithm</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified provider
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 5
Source File: TransformService.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. Note that the specified
 * <code>Provider</code> object does not have to be registered in the
 * provider list.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the <code>Provider</code> object
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>provider</code>,
 *   <code>algorithm</code>, or <code>mechanismType</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified <code>Provider</code> object
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, Provider provider)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    }

    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 6
Source File: TransformService.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM).
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate a <code>TransformService</code> implementation
 * of the desired algorithm and <code>MechanismType</code> service
 * attribute. It traverses the list of registered security
 * <code>Provider</code>s, starting with the most preferred
 * <code>Provider</code>. A new <code>TransformService</code> object
 * from the first <code>Provider</code> that supports the specified
 * algorithm and mechanism type is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>algorithm</code> or
 *   <code>mechanismType</code> is  <code>null</code>
 * @throws NoSuchAlgorithmException if no <code>Provider</code> supports a
 *   <code>TransformService</code> implementation for the specified
 *   algorithm and mechanism type
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null) {
        throw new NullPointerException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    List<Service> services = GetInstance.getServices("TransformService", algorithm);
    for (Iterator<Service> t = services.iterator(); t.hasNext(); ) {
        Service s = t.next();
        String value = s.getAttribute("MechanismType");
        if ((value == null && dom) ||
            (value != null && value.equals(mechanismType))) {
            Instance instance = GetInstance.getInstance(s, null);
            TransformService ts = (TransformService) instance.impl;
            ts.algorithm = algorithm;
            ts.mechanism = mechanismType;
            ts.provider = instance.provider;
            return ts;
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 7
Source File: TransformService.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. Note that the specified
 * <code>Provider</code> object does not have to be registered in the
 * provider list.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the <code>Provider</code> object
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>provider</code>,
 *   <code>algorithm</code>, or <code>mechanismType</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified <code>Provider</code> object
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, Provider provider)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    }

    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 8
Source File: TransformService.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. Note that the specified
 * <code>Provider</code> object does not have to be registered in the
 * provider list.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the <code>Provider</code> object
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>provider</code>,
 *   <code>algorithm</code>, or <code>mechanismType</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified <code>Provider</code> object
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, Provider provider)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    }

    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = provider.getService("TransformService", algorithm);
    if (s != null) {
        String value = s.getAttribute("MechanismType");
        if ((value == null && dom) ||
            (value != null && value.equals(mechanismType))) {
            Object obj = s.newInstance(null);
            if (obj instanceof TransformService) {
                TransformService ts = (TransformService) obj;
                ts.algorithm = algorithm;
                ts.mechanism = mechanismType;
                ts.provider = provider;
                return ts;
            }
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available from " + provider.getName());
}
 
Example 9
Source File: TransformService.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. The specified provider
 * must be registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the string name of the provider
 * @return a new <code>TransformService</code>
 * @throws NoSuchProviderException if the specified provider is not
 *   registered in the security provider list
 * @throws NullPointerException if <code>provider</code>,
 *   <code>mechanismType</code>, or <code>algorithm</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified provider
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 10
Source File: Cipher.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static int supports(Service s, String attrName, String value) {
    if (value == null) {
        return S_YES;
    }
    String regexp = s.getAttribute(attrName);
    if (regexp == null) {
        return S_MAYBE;
    }
    return matches(regexp, value) ? S_YES : S_NO;
}
 
Example 11
Source File: Cipher.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static int supports(Service s, String attrName, String value) {
    if (value == null) {
        return S_YES;
    }
    String regexp = s.getAttribute(attrName);
    if (regexp == null) {
        return S_MAYBE;
    }
    return matches(regexp, value) ? S_YES : S_NO;
}
 
Example 12
Source File: TransformService.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. The specified provider
 * must be registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the string name of the provider
 * @return a new <code>TransformService</code>
 * @throws NoSuchProviderException if the specified provider is not
 *   registered in the security provider list
 * @throws NullPointerException if <code>provider</code>,
 *   <code>mechanismType</code>, or <code>algorithm</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified provider
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 13
Source File: TransformService.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. The specified provider
 * must be registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the string name of the provider
 * @return a new <code>TransformService</code>
 * @throws NoSuchProviderException if the specified provider is not
 *   registered in the security provider list
 * @throws NullPointerException if <code>provider</code>,
 *   <code>mechanismType</code>, or <code>algorithm</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified provider
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 14
Source File: TransformService.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM).
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate a <code>TransformService</code> implementation
 * of the desired algorithm and <code>MechanismType</code> service
 * attribute. It traverses the list of registered security
 * <code>Provider</code>s, starting with the most preferred
 * <code>Provider</code>. A new <code>TransformService</code> object
 * from the first <code>Provider</code> that supports the specified
 * algorithm and mechanism type is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>algorithm</code> or
 *   <code>mechanismType</code> is  <code>null</code>
 * @throws NoSuchAlgorithmException if no <code>Provider</code> supports a
 *   <code>TransformService</code> implementation for the specified
 *   algorithm and mechanism type
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null) {
        throw new NullPointerException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    List<Service> services = GetInstance.getServices("TransformService", algorithm);
    for (Iterator<Service> t = services.iterator(); t.hasNext(); ) {
        Service s = t.next();
        String value = s.getAttribute("MechanismType");
        if ((value == null && dom) ||
            (value != null && value.equals(mechanismType))) {
            Instance instance = GetInstance.getInstance(s, null);
            TransformService ts = (TransformService) instance.impl;
            ts.algorithm = algorithm;
            ts.mechanism = mechanismType;
            ts.provider = instance.provider;
            return ts;
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 15
Source File: TransformService.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM).
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate a <code>TransformService</code> implementation
 * of the desired algorithm and <code>MechanismType</code> service
 * attribute. It traverses the list of registered security
 * <code>Provider</code>s, starting with the most preferred
 * <code>Provider</code>. A new <code>TransformService</code> object
 * from the first <code>Provider</code> that supports the specified
 * algorithm and mechanism type is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>algorithm</code> or
 *   <code>mechanismType</code> is  <code>null</code>
 * @throws NoSuchAlgorithmException if no <code>Provider</code> supports a
 *   <code>TransformService</code> implementation for the specified
 *   algorithm and mechanism type
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null) {
        throw new NullPointerException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    List<Service> services = GetInstance.getServices("TransformService", algorithm);
    for (Iterator<Service> t = services.iterator(); t.hasNext(); ) {
        Service s = t.next();
        String value = s.getAttribute("MechanismType");
        if ((value == null && dom) ||
            (value != null && value.equals(mechanismType))) {
            Instance instance = GetInstance.getInstance(s, null);
            TransformService ts = (TransformService) instance.impl;
            ts.algorithm = algorithm;
            ts.mechanism = mechanismType;
            ts.provider = instance.provider;
            return ts;
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 16
Source File: TransformService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. The specified provider
 * must be registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the string name of the provider
 * @return a new <code>TransformService</code>
 * @throws NoSuchProviderException if the specified provider is not
 *   registered in the security provider list
 * @throws NullPointerException if <code>provider</code>,
 *   <code>mechanismType</code>, or <code>algorithm</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified provider
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 17
Source File: TransformService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. Note that the specified
 * <code>Provider</code> object does not have to be registered in the
 * provider list.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the <code>Provider</code> object
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>provider</code>,
 *   <code>algorithm</code>, or <code>mechanismType</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified <code>Provider</code> object
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, Provider provider)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    }

    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 18
Source File: TransformService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM).
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate a <code>TransformService</code> implementation
 * of the desired algorithm and <code>MechanismType</code> service
 * attribute. It traverses the list of registered security
 * <code>Provider</code>s, starting with the most preferred
 * <code>Provider</code>. A new <code>TransformService</code> object
 * from the first <code>Provider</code> that supports the specified
 * algorithm and mechanism type is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>algorithm</code> or
 *   <code>mechanismType</code> is  <code>null</code>
 * @throws NoSuchAlgorithmException if no <code>Provider</code> supports a
 *   <code>TransformService</code> implementation for the specified
 *   algorithm and mechanism type
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null) {
        throw new NullPointerException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    List<Service> services = GetInstance.getServices("TransformService", algorithm);
    for (Iterator<Service> t = services.iterator(); t.hasNext(); ) {
        Service s = t.next();
        String value = s.getAttribute("MechanismType");
        if ((value == null && dom) ||
            (value != null && value.equals(mechanismType))) {
            Instance instance = GetInstance.getInstance(s, null);
            TransformService ts = (TransformService) instance.impl;
            ts.algorithm = algorithm;
            ts.mechanism = mechanismType;
            ts.provider = instance.provider;
            return ts;
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}
 
Example 19
Source File: Cipher.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static int supports(Service s, String attrName, String value) {
    if (value == null) {
        return S_YES;
    }
    String regexp = s.getAttribute(attrName);
    if (regexp == null) {
        return S_MAYBE;
    }
    return matches(regexp, value) ? S_YES : S_NO;
}
 
Example 20
Source File: TransformService.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. Note that the specified
 * <code>Provider</code> object does not have to be registered in the
 * provider list.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the <code>Provider</code> object
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>provider</code>,
 *   <code>algorithm</code>, or <code>mechanismType</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified <code>Provider</code> object
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, Provider provider)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    }

    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = GetInstance.getService
        ("TransformService", algorithm, provider);
    String value = s.getAttribute("MechanismType");
    if ((value == null && dom) ||
        (value != null && value.equals(mechanismType))) {
        Instance instance = GetInstance.getInstance(s, null);
        TransformService ts = (TransformService) instance.impl;
        ts.algorithm = algorithm;
        ts.mechanism = mechanismType;
        ts.provider = instance.provider;
        return ts;
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available");
}