IdentifiedObjectFinder changes for revisions 26211:26250

Changes in this commit have been reverted: we do not provide a getProxy() method, and we do not log (at this time) object creation failures.

Command line:

svn diff --extensions "--unified --ignore-space-change --ignore-all-space --ignore-eol-style" -r26211:26250 https://svn.osgeo.org/geotools/trunk/modules/library/referencing/src/main/java/org/geotools/referencing/factory/IdentifiedObjectFinder.java
Revision 26211Revision 26250
// J2SE dependencies
import java.util.Set;
import java.util.Iterator;

// OpenGIS dependencies
import org.opengis.util.GenericName;
// J2SE dependencies
import java.util.Set;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;

// OpenGIS dependencies
import org.opengis.util.GenericName;
 * @author Martin Desruisseaux
 */
public class IdentifiedObjectFinder {
    /**
     * The proxy for object creation.
     */
    final AuthorityFactoryProxy proxy;

    /**
     * {@code true} for performing full scans, or {@code false} otherwise.
 * @author Martin Desruisseaux
 */
public class IdentifiedObjectFinder {
    public static final Logger LOGGER = Logger.getLogger("org.geotools.referencing.factory.finder");

    /**
     * The proxy for object creation.
     */
    private AuthorityFactoryProxy proxy;

    /**
     * {@code true} for performing full scans, or {@code false} otherwise.
 */
private boolean fullScan = true;

/**
 * Creates a finder using the same proxy than the specified finder.
 */
IdentifiedObjectFinder(final IdentifiedObjectFinder finder) {
    this.proxy = finder.proxy;
}

/**
 */
private boolean fullScan = true;

/** Default constructor, subclass should provide an override for getProxy */
protected IdentifiedObjectFinder() {
}

/**
 * Creates a finder using the same proxy than the specified finder.
 */
IdentifiedObjectFinder(final IdentifiedObjectFinder finder) {
    this.setProxy(finder.getProxy());
}

/**
protected IdentifiedObjectFinder(final AuthorityFactory factory,
                                 final Class/*<? extends IdentifiedObject>*/ type)
{
    proxy = AuthorityFactoryProxy.getInstance(factory, type);
}

/*
protected IdentifiedObjectFinder(final AuthorityFactory factory,
                                 final Class/*<? extends IdentifiedObject>*/ type)
{
    setProxy(AuthorityFactoryProxy.getInstance(factory, type));
}

/*
 */

/**
 * If {@code true}, an exhaustive full scan against all registered objects
 * will be performed (may be slow). Otherwise only a fast lookup based on
 * embedded identifiers and names will be performed. The default value is
 */

/**
 * @return the proxy
 */
protected AuthorityFactoryProxy getProxy() {
    return proxy;
}

/**
 * If {@code true}, an exhaustive full scan against all registered objects
 * will be performed (may be slow). Otherwise only a fast lookup based on
 * embedded identifiers and names will be performed. The default value is
}

/**
 * Returns the identifier for the specified object.
 */
final String getIdentifier(final IdentifiedObject object) {
    Citation authority = proxy.getAuthorityFactory().getAuthority();
    if (ReferencingFactory.ALL.equals(authority)) {
        /*
         * "All" is a pseudo-authority declared by AllAuthoritiesFactory. This is not a real
}

/**
 * The Authority for this Finder; used during get Identifier.
 * @return Citation for the authority being represented.
 */
protected Citation getAuthority(){
    return getProxy().getAuthorityFactory().getAuthority();
}
/**
 * Returns the identifier for the specified object.
 */
final String getIdentifier(final IdentifiedObject object) {
    Citation authority = getAuthority();
    if (ReferencingFactory.ALL.equals(authority)) {
        /*
         * "All" is a pseudo-authority declared by AllAuthoritiesFactory. This is not a real
 * @throws FactoryException if an error occured while creating an object.
 */
final IdentifiedObject createFromIdentifiers(final IdentifiedObject object) throws FactoryException {
    final Citation authority = proxy.getAuthorityFactory().getAuthority();
    final boolean isAll = ReferencingFactory.ALL.equals(authority);
    for (final Iterator it=object.getIdentifiers().iterator(); it.hasNext();) {
        final Identifier id = (Identifier) it.next();
 * @throws FactoryException if an error occured while creating an object.
 */
final IdentifiedObject createFromIdentifiers(final IdentifiedObject object) throws FactoryException {
    final Citation authority = getProxy().getAuthorityFactory().getAuthority();
    final boolean isAll = ReferencingFactory.ALL.equals(authority);
    for (final Iterator it=object.getIdentifiers().iterator(); it.hasNext();) {
        final Identifier id = (Identifier) it.next();
}
IdentifiedObject candidate;
try {
    candidate = proxy.create(id.getCode());
} catch (NoSuchAuthorityCodeException e) {
    // The identifier was not recognized. No problem, let's go on.
    continue;
}
IdentifiedObject candidate;
try {
    candidate = getProxy().create(id.getCode());
} catch (NoSuchAuthorityCodeException e) {
    // The identifier was not recognized. No problem, let's go on.
    continue;
final IdentifiedObject createFromNames(final IdentifiedObject object) throws FactoryException {
    IdentifiedObject candidate;
    try {
        candidate = proxy.create(object.getName().getCode());
        candidate = deriveEquivalent(candidate, object);
        if (candidate != null) {
            return candidate;
final IdentifiedObject createFromNames(final IdentifiedObject object) throws FactoryException {
    IdentifiedObject candidate;
    try {
        candidate = getProxy().create(object.getName().getCode());
        candidate = deriveEquivalent(candidate, object);
        if (candidate != null) {
            return candidate;
for (final Iterator it=object.getAlias().iterator(); it.hasNext();) {
    final GenericName id = (GenericName) it.next();
    try {
        candidate = proxy.create(id.toString());
    } catch (FactoryException e) {
        // The name was not recognized. No problem, let's go on.
        continue;
for (final Iterator it=object.getAlias().iterator(); it.hasNext();) {
    final GenericName id = (GenericName) it.next();
    try {
        candidate = getProxy().create(id.toString());
    } catch (FactoryException e) {
        // The name was not recognized. No problem, let's go on.
        continue;
final String code = (String) it.next();
IdentifiedObject candidate;
try {
    candidate = proxy.create(code);
} catch (FactoryException e) {
    // Some object cannot be created properly.
    continue;
}
candidate = deriveEquivalent(candidate, object);
if (candidate != null) {
    return candidate;
final String code = (String) it.next();
IdentifiedObject candidate;
try {
    candidate = getProxy().create(code);
}
catch (FactoryException e) {
    LOGGER.log( Level.FINEST, "Could not create '"+code+"':"+e );
    // Some object cannot be created properly.
    continue;
}
catch (Exception problemCode ){
    LOGGER.log( Level.FINEST, "Could not create '"+code+"':"+problemCode, problemCode );
    continue;
}

candidate = deriveEquivalent(candidate, object);
if (candidate != null) {
    return candidate;
 * @throws FactoryException if an error occured while fetching the set of code candidates.
 */
protected Set/*<String>*/ getCodeCandidates(final IdentifiedObject object) throws FactoryException {
    return proxy.getAuthorityCodes();
}

/*
 * @throws FactoryException if an error occured while fetching the set of code candidates.
 */
protected Set/*<String>*/ getCodeCandidates(final IdentifiedObject object) throws FactoryException {
    return getProxy().getAuthorityCodes();
}

/*
 */
//@Override
public String toString() {
    return proxy.toString(IdentifiedObjectFinder.class);
}
 */
//@Override
public String toString() {
    return getProxy().toString(IdentifiedObjectFinder.class);
}
/**
 * A finder which delegate part of its work to an other finder. This adapter forwards
 * some method calls to the underlying finder. This class should not be public, because
 * not all method are overriden. The choice is tuned for {@link BufferedAuthorityFactory}
/**
 * @param proxy the proxy to set
 */
public void setProxy( AuthorityFactoryProxy proxy ) {
    this.proxy = proxy;
}




/**
 * A finder which delegate part of its work to an other finder. This adapter forwards
 * some method calls to the underlying finder. This class should not be public, because
 * not all method are overriden. The choice is tuned for {@link BufferedAuthorityFactory}