DefaultMathTransformFactory changes for revisions 11127:11128

This change do not apply to Apache SIS since FactoryFinder is replaced by java.util.ServiceLoader.

Command line:

svn diff --extensions "--unified --ignore-space-change --ignore-all-space --ignore-eol-style" -r11127:11128 https://svn.osgeo.org/geotools/trunk/modules/library/referencing/src/main/java/org/geotools/referencing/operation/DefaultMathTransformFactory.java
Revision 11127Revision 11128
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import javax.imageio.spi.ServiceRegistry;

// OpenGIS dependencies
import org.opengis.metadata.citation.Citation;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchIdentifierException;
import org.opengis.referencing.operation.Conversion;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.Operation;
import org.opengis.referencing.operation.OperationMethod;
import org.opengis.referencing.operation.Projection;

// Geotools dependencies
import org.geotools.parameter.ParameterWriter;
import org.geotools.referencing.IdentifiedObject;
import org.geotools.referencing.Identifier;
import org.geotools.referencing.operation.transform.AbstractMathTransform;
import org.geotools.referencing.operation.transform.ConcatenatedTransform;
import org.geotools.referencing.operation.transform.PassThroughTransform;
import org.geotools.referencing.operation.transform.ProjectiveTransform;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

import javax.imageio.spi.ServiceRegistry;

import org.geotools.parameter.ParameterWriter;
import org.geotools.referencing.IdentifiedObject;
import org.geotools.referencing.Identifier;
import org.geotools.referencing.operation.transform.ConcatenatedTransform;
import org.geotools.referencing.operation.transform.PassThroughTransform;
import org.geotools.referencing.operation.transform.ProjectiveTransform;
import org.geotools.resources.LazySet;
import org.geotools.resources.cts.ResourceKeys;
import org.geotools.resources.cts.Resources;
import org.geotools.util.DerivedSet;
import org.geotools.util.WeakHashSet;


/**
import org.geotools.resources.LazySet;
import org.geotools.resources.cts.ResourceKeys;
import org.geotools.resources.cts.Resources;
import org.geotools.util.ClassFinder;
import org.geotools.util.DerivedSet;
import org.geotools.util.WeakHashSet;
import org.opengis.metadata.citation.Citation;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchIdentifierException;
import org.opengis.referencing.operation.Conversion;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.Operation;
import org.opengis.referencing.operation.OperationMethod;
import org.opengis.referencing.operation.Projection;


/**
 */
private final WeakHashSet pool = new WeakHashSet();

/**
 * The service registry for finding {@link MathTransformProvider} implementations.
 */
private final ServiceRegistry registry;

/**
 * Construct a default {@link MathTransform math transform} factory.
 */
private final WeakHashSet pool = new WeakHashSet();

private ServiceRegistry registry;

/**
 * Construct a default {@link MathTransform math transform} factory.
 * @see #createParameterizedTransform
 */
public Set/*<OperationMethod>*/ getAvailableMethods(final Class type) {
    Set methods = new LazySet(getProviders(MathTransformProvider.class));
    if (type != null) {
        methods = new FilteredSet(methods, type);
    }
 * @see #createParameterizedTransform
 */
public Set/*<OperationMethod>*/ getAvailableMethods(final Class type) {
    Set methods = new LazySet(ClassFinder.getProviders(registry, MathTransformProvider.class));
    if (type != null) {
        methods = new FilteredSet(methods, type);
    }
}

/**
 * Returns the providers for the specified category. This method will scan for plugin the
 * first time it will be invoked.
 */
private synchronized Iterator getProviders(final Class category) {
    Iterator iterator = registry.getServiceProviders(category, false);
    if (!iterator.hasNext()) {
        /*
         * No plugin. This method is probably invoked the first time for the specified
         * category, otherwise we should have found at least the Geotools implementation.
         */
        scanForPlugins();
        iterator = registry.getServiceProviders(category, false);
    }
    return iterator;
}

/**
 * Returns the math transform provider for the specified operation method.
 * This provider can be used in order to query parameter for a method name
 * (e.g. <code>getProvider("Transverse_Mercator").getParameters()</code>),
}

/**
 * Returns the math transform provider for the specified operation method.
 * This provider can be used in order to query parameter for a method name
 * (e.g. <code>getProvider("Transverse_Mercator").getParameters()</code>),
if (provider!=null && provider.nameMatches(method)) {
    return provider;
}
final Iterator providers = getProviders(MathTransformProvider.class);
while (providers.hasNext()) {
    provider = (MathTransformProvider) providers.next();
    if (provider.nameMatches(method)) {
if (provider!=null && provider.nameMatches(method)) {
    return provider;
}
final Iterator providers = ClassFinder.getProviders(registry, MathTransformProvider.class);
while (providers.hasNext()) {
    provider = (MathTransformProvider) providers.next();
    if (provider.nameMatches(method)) {
}

/**
 * Scans for provider plug-ins on the application class path. This method is needed because the
 * application class path can theoretically change, or additional plug-ins may become available.
 * Rather than re-scanning the classpath on every invocation of the API, the class path is
 * scanned automatically only on the first invocation. Clients can call this method to prompt
 * a re-scan. Thus this method need only be invoked by sophisticated applications which
 * dynamically make new plug-ins available at runtime.
 *
 * @todo Provides the same logging mechanism than in {@link org.geotools.referencing.FactoryFinder}
 *       once it will be implemented in the later.
 */
public synchronized void scanForPlugins() {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    for (final Iterator categories=registry.getCategories(); categories.hasNext();) {
        final Class category = (Class) categories.next();
        final Iterator providers = ServiceRegistry.lookupProviders(category, loader);
        while (providers.hasNext()) {
            registry.registerServiceProvider(providers.next(), category);
        }
    }
    last = null;
}

/**
 * Dump to the standard output stream a list of available operation method.
 * This method can be invoked from the command line. It provides a mean to
 * verify which transforms were found in the classpath. The syntax is:
}

/**
 * Dump to the standard output stream a list of available operation method.
 * This method can be invoked from the command line. It provides a mean to
 * verify which transforms were found in the classpath. The syntax is: