use of org.opengis.parameter.ParameterNotFoundException in project sis by apache.
the class DefaultMathTransformFactory method createFromWKT.
/**
* Creates a math transform object from a
* <a href="http://www.geoapi.org/3.0/javadoc/org/opengis/referencing/doc-files/WKT.html"><cite>Well
* Known Text</cite> (WKT)</a>.
* If the given text contains non-fatal anomalies (unknown or unsupported WKT elements,
* inconsistent unit definitions, <i>etc.</i>), warnings may be reported in a
* {@linkplain java.util.logging.Logger logger} named {@code "org.apache.sis.io.wkt"}.
*
* @param text math transform encoded in Well-Known Text format.
* @return the math transform (never {@code null}).
* @throws FactoryException if the Well-Known Text can not be parsed,
* or if the math transform creation failed from some other reason.
*/
@Override
public MathTransform createFromWKT(final String text) throws FactoryException {
lastMethod.remove();
Parser p = parser.getAndSet(null);
if (p == null)
try {
Constructor<? extends Parser> c = parserConstructor;
if (c == null) {
c = Class.forName("org.apache.sis.io.wkt.MathTransformParser").asSubclass(Parser.class).getConstructor(MathTransformFactory.class);
// For allowing use in inner class or lambda expression.
final Constructor<?> cp = c;
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
cp.setAccessible(true);
return null;
});
parserConstructor = c;
}
p = c.newInstance(this);
} catch (ReflectiveOperationException e) {
throw new FactoryException(e);
}
/*
* No need to check the type of the parsed object, because MathTransformParser
* should return only instance of MathTransform.
*/
final Object object;
try {
object = p.createFromWKT(text);
} catch (FactoryException e) {
/*
* The parsing may fail because a operation parameter is not known to SIS. If this happen, replace
* the generic exception thrown be the parser (which is FactoryException) by a more specific one.
* Note that InvalidGeodeticParameterException is defined only in this sis-referencing module,
* so we could not throw it from the sis-metadata module that contain the parser.
*/
Throwable cause = e.getCause();
while (cause != null) {
if (cause instanceof ParameterNotFoundException) {
throw new InvalidGeodeticParameterException(e.getLocalizedMessage(), cause);
}
cause = cause.getCause();
}
throw e;
}
parser.set(p);
return (MathTransform) object;
}
Aggregations