1 |
/* AlgorithmParameterGenerator.java --- Algorithm Parameter Generator |
/* AlgorithmParameterGenerator.java --- Algorithm Parameter Generator |
2 |
Copyright (C) 1999, 2003, Free Software Foundation, Inc. |
Copyright (C) 1999, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
80 |
*/ |
*/ |
81 |
public class AlgorithmParameterGenerator |
public class AlgorithmParameterGenerator |
82 |
{ |
{ |
83 |
|
/** Service name for algorithm parameter generators. */ |
84 |
|
private static final String ALGORITHM_PARAMETER_GENERATOR = |
85 |
|
"AlgorithmParameterGenerator"; |
86 |
|
|
87 |
private AlgorithmParameterGeneratorSpi paramGenSpi; |
private AlgorithmParameterGeneratorSpi paramGenSpi; |
88 |
private Provider provider; |
private Provider provider; |
89 |
private String algorithm; |
private String algorithm; |
136 |
for (int i = 0; i < p.length; i++) |
for (int i = 0; i < p.length; i++) |
137 |
try |
try |
138 |
{ |
{ |
139 |
getInstance(algorithm, p[i]); |
return getInstance(algorithm, p[i]); |
140 |
} |
} |
141 |
catch (NoSuchAlgorithmException ignored) {} |
catch (NoSuchAlgorithmException ignored) {} |
142 |
|
|
163 |
String provider) |
String provider) |
164 |
throws NoSuchAlgorithmException, NoSuchProviderException |
throws NoSuchAlgorithmException, NoSuchProviderException |
165 |
{ |
{ |
166 |
|
if (provider == null || provider.length() == 0) |
167 |
|
throw new IllegalArgumentException("Illegal provider"); |
168 |
|
|
169 |
Provider p = Security.getProvider(provider); |
Provider p = Security.getProvider(provider); |
170 |
if (p == null) |
if (p == null) |
171 |
throw new NoSuchProviderException(); |
throw new NoSuchProviderException(); |
193 |
throws NoSuchAlgorithmException |
throws NoSuchAlgorithmException |
194 |
{ |
{ |
195 |
if (provider == null) |
if (provider == null) |
196 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException("Illegal provider"); |
|
|
|
|
// try the name as is |
|
|
String className = provider.getProperty( |
|
|
"AlgorithmParameterGenerator." + algorithm); |
|
|
if (className == null) // try all uppercase |
|
|
{ |
|
|
String upper = algorithm.toUpperCase(); |
|
|
className = provider.getProperty("AlgorithmParameterGenerator." + upper); |
|
|
if (className == null) // try if it's an alias |
|
|
{ |
|
|
String alias = provider.getProperty( |
|
|
"Alg.Alias.AlgorithmParameterGenerator." + algorithm); |
|
|
if (alias == null) // try all-uppercase alias name |
|
|
{ |
|
|
alias = provider.getProperty( |
|
|
"Alg.Alias.AlgorithmParameterGenerator." + upper); |
|
|
if (alias == null) // spit the dummy |
|
|
throw new NoSuchAlgorithmException(algorithm); |
|
|
} |
|
|
className = provider.getProperty( |
|
|
"AlgorithmParameterGenerator." + alias); |
|
|
if (className == null) |
|
|
throw new NoSuchAlgorithmException(algorithm); |
|
|
} |
|
|
} |
|
|
return getInstance(className, algorithm, provider); |
|
|
} |
|
|
|
|
|
private static AlgorithmParameterGenerator getInstance(String classname, |
|
|
String algorithm, |
|
|
Provider provider) |
|
|
throws NoSuchAlgorithmException |
|
|
{ |
|
197 |
|
|
198 |
try |
try |
199 |
{ |
{ |
200 |
return new AlgorithmParameterGenerator( |
return new AlgorithmParameterGenerator( |
201 |
(AlgorithmParameterGeneratorSpi) Class.forName(classname).newInstance(), |
(AlgorithmParameterGeneratorSpi) Engine.getInstance( |
202 |
provider, |
ALGORITHM_PARAMETER_GENERATOR, algorithm, provider), |
203 |
algorithm); |
provider, algorithm); |
204 |
} |
} |
205 |
catch (ClassNotFoundException cnfe) |
catch (ClassCastException cce) |
|
{ |
|
|
throw new NoSuchAlgorithmException("Class not found"); |
|
|
} |
|
|
catch (InstantiationException ie) |
|
|
{ |
|
|
throw new NoSuchAlgorithmException("Class instantiation failed"); |
|
|
} |
|
|
catch (IllegalAccessException iae) |
|
206 |
{ |
{ |
207 |
throw new NoSuchAlgorithmException("Illegal Access"); |
throw new NoSuchAlgorithmException(algorithm); |
208 |
} |
} |
209 |
} |
} |
210 |
|
|