/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Collection of utility methods to facilitate implementing getInstance()
*
* @author Andreas Sterbenz
* @since 1.5
*/
public class GetInstance {
private GetInstance() {
// empty
}
/**
* Static inner class representing a newly created instance.
*/
public static final class Instance {
// public final fields, access directly without accessors
}
// Return Provider and implementation as an array as used in the
// old Security.getImpl() methods.
}
}
throws NoSuchAlgorithmException {
if (s == null) {
throw new NoSuchAlgorithmException
}
return s;
}
throw new IllegalArgumentException("missing provider");
}
if (p == null) {
}
if (s == null) {
throw new NoSuchAlgorithmException("no such algorithm: "
}
return s;
}
throw new IllegalArgumentException("missing provider");
}
if (s == null) {
throw new NoSuchAlgorithmException("no such algorithm: "
}
return s;
}
/**
* Return a List of all the available Services that implement
* (type, algorithm). Note that the list is initialized lazily
* and Provider loading and lookup is only trigered when
* necessary.
*/
}
/**
* This method exists for compatibility with JCE only. It will be removed
* once JCE has been changed to use the replacement method.
* @deprecated use getServices(List<ServiceId>) instead
*/
}
/**
* Return a List of all the available Services that implement any of
* the specified algorithms. See getServices(String, String) for detals.
*/
}
/*
* For all the getInstance() methods below:
* @param type the type of engine (e.g. MessageDigest)
* @param clazz the Spi class that the implementation must subclass
* (e.g. MessageDigestSpi.class) or null if no superclass check
* is required
* @param algorithm the name of the algorithm (or alias), e.g. MD5
* @param provider the provider (String or Provider object)
* @param param the parameter to pass to the Spi constructor
* (for CertStores)
*
* There are overloaded methods for all the permutations.
*/
// in the almost all cases, the first service will work
// avoid taking long path if so
if (firstService == null) {
throw new NoSuchAlgorithmException
}
try {
} catch (NoSuchAlgorithmException e) {
failure = e;
}
// if we cannot get the service from the prefered provider,
// fail over to the next
if (s == firstService) {
// do not retry initial failed service
continue;
}
try {
return getInstance(s, clazz);
} catch (NoSuchAlgorithmException e) {
failure = e;
}
}
throw failure;
}
try {
} catch (NoSuchAlgorithmException e) {
failure = e;
}
}
throw failure;
} else {
throw new NoSuchAlgorithmException
}
}
}
}
throws NoSuchAlgorithmException {
}
throws NoSuchAlgorithmException {
}
/*
* The two getInstance() methods below take a service. They are
* intended for classes that cannot use the standard methods, e.g.
* because they implement delayed provider selection like the
* Signature class.
*/
throws NoSuchAlgorithmException {
}
}
/**
* Check is subClass is a subclass of superClass. If not,
* throw a NoSuchAlgorithmException.
*/
if (superClass == null) {
return;
}
throw new NoSuchAlgorithmException
}
}
}