All Downloads are FREE. Search and download functionalities are using the official Maven repository.

acscommons.io.jsonwebtoken.impl.lang.LegacyServices Maven / Gradle / Ivy

There is a newer version: 6.9.4
Show newest version
package acscommons.io.jsonwebtoken.impl.lang;

import acscommons.io.jsonwebtoken.lang.Classes;
import acscommons.io.jsonwebtoken.lang.UnknownClassException;

/**
 * A backward compatibility {@link Services} utility to help migrate away from {@link Classes#newInstance(String)}.
 * TODO: remove before v1.0
 * @deprecated use {@link Services} directly
 */
@Deprecated
public final class LegacyServices {

    /**
     * Wraps {@code Services.loadFirst} and throws a {@link UnknownClassException} instead of a
     * {@link UnavailableImplementationException} to retain the previous behavior. This method should be used when
     * to retain the previous behavior of methods that throw an unchecked UnknownClassException.
     * @param  the type of object to return
     * @param spi the class for which to find the first instance
     * @return the first instance of type {@code T} found from a call to {@link Services#loadFirst(Class)}
     */
    public static  T loadFirst(Class spi) {
        try {
            return Services.loadFirst(spi);
        } catch (UnavailableImplementationException e) {
            throw new UnknownClassException(e.getMessage(), e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy