Search in sources :

Example 31 with Citation

use of org.opengis.metadata.citation.Citation in project sis by apache.

the class SimpleIdentifiedObject method toString.

/**
 * Returns a pseudo-WKT representation for debugging purpose.
 */
@Override
public String toString() {
    final String code, codespace;
    final Citation authority;
    final ReferenceIdentifier name = this.name;
    if (name != null) {
        code = name.getCode();
        codespace = name.getCodeSpace();
        authority = name.getAuthority();
    } else {
        code = null;
        codespace = null;
        authority = null;
    }
    final StringBuilder buffer = new StringBuilder("IdentifiedObject[\"");
    if (codespace != null) {
        buffer.append(codespace).append(DefaultNameSpace.DEFAULT_SEPARATOR);
    }
    buffer.append(code).append('"');
    final String identifier = Citations.getIdentifier(authority, true);
    if (identifier != null) {
        // "Id" should be consistent with WKTKeywords.Id.
        buffer.append(", Id[\"").append(identifier).append("\"]");
    }
    return buffer.append(']').toString();
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) InternationalString(org.opengis.util.InternationalString) Citation(org.opengis.metadata.citation.Citation)

Example 32 with Citation

use of org.opengis.metadata.citation.Citation in project sis by apache.

the class Parameters method getName.

/**
 * Returns the name or alias of the given parameter for the authority code space expected by this group.
 * If no name or alias for this group's authority can be found, then the primary name will be returned.
 *
 * @param  source  the parameter for which the name is wanted.
 * @return the name of the given parameter. May be {@code null} if there is no name at all,
 *         but such nameless descriptors are not legal.
 */
private String getName(final GeneralParameterDescriptor source) {
    final ParameterDescriptorGroup descriptor = getDescriptor();
    if (descriptor != null) {
        // Paranoiac check (should never be null)
        final Identifier group = descriptor.getName();
        if (group != null) {
            // Paranoiac check (should never be null)
            final Citation authority = group.getAuthority();
            final String name = IdentifiedObjects.getName(source, authority);
            if (name != null || authority == null) {
                return name;
            }
        }
    }
    return IdentifiedObjects.getName(source, null);
}
Also used : Identifier(org.opengis.metadata.Identifier) Citation(org.opengis.metadata.citation.Citation)

Example 33 with Citation

use of org.opengis.metadata.citation.Citation in project sis by apache.

the class ConcurrentAuthorityFactory method getAuthority.

/**
 * Returns the database or specification that defines the codes recognized by this factory.
 * The default implementation performs the following steps:
 * <ul>
 *   <li>Returns the cached value if it exists.</li>
 *   <li>Otherwise:
 *     <ol>
 *       <li>get an instance of the Data Access Object,</li>
 *       <li>delegate to its {@link GeodeticAuthorityFactory#getAuthority()} method,</li>
 *       <li>release the Data Access Object,</li>
 *       <li>cache the result.</li>
 *     </ol>
 *   </li>
 * </ul>
 *
 * If this method can not get a Data Access Object (for example because no database connection is available),
 * then this method returns {@code null}.
 *
 * @return the organization responsible for definition of the database, or {@code null} if unavailable.
 */
@Override
public Citation getAuthority() {
    Citation c = authority;
    if (c == null || c == UNAVAILABLE)
        try {
            final DAO factory = getDataAccess();
            try {
                /*
                 * Cache only in case of success. If we failed, we
                 * will try again next time this method is invoked.
                 */
                authority = c = factory.getAuthority();
            } finally {
                release("getAuthority", Citation.class, null);
            }
        } catch (FactoryException e) {
            authority = UNAVAILABLE;
            /*
             * Use the warning level only on the first failure, then the fine level on all subsequent failures.
             * Do not log the stack trace if we failed because of UnavailableFactoryException since it may be
             * normal (the EPSG geodetic dataset is optional, even if strongly recommended).
             */
            final LogRecord record = new LogRecord(c == null ? Level.WARNING : Level.FINE, e.getLocalizedMessage());
            if (!(e instanceof UnavailableFactoryException)) {
                record.setThrown(e);
            }
            record.setLoggerName(Loggers.CRS_FACTORY);
            Logging.log(ConcurrentAuthorityFactory.class, "getAuthority", record);
            c = null;
        }
    return c;
}
Also used : FactoryException(org.opengis.util.FactoryException) LogRecord(java.util.logging.LogRecord) SimpleCitation(org.apache.sis.internal.simple.SimpleCitation) Citation(org.opengis.metadata.citation.Citation)

Example 34 with Citation

use of org.opengis.metadata.citation.Citation in project sis by apache.

the class GeodeticAuthorityFactory method cast.

/**
 * Casts the given object to the given type, or throws an exception if the object can not be casted.
 * This convenience method is provided for implementation of {@code createXXX} methods.
 *
 * @param  type    the type to return (e.g. {@code CoordinateReferenceSystem.class}).
 * @param  object  the object to cast.
 * @param  code    the authority code, used only for formatting an error message.
 * @return the object casted to the given type.
 * @throws NoSuchAuthorityCodeException if the given object is not an instance of the given type.
 */
@SuppressWarnings("unchecked")
private <T> T cast(final Class<T> type, final IdentifiedObject object, final String code) throws NoSuchAuthorityCodeException {
    if (type.isInstance(object)) {
        return (T) object;
    }
    /*
         * Get the actual type of the object. Returns the GeoAPI type if possible,
         * or fallback on the implementation class otherwise.
         */
    final Class<?> actual;
    if (object instanceof AbstractIdentifiedObject) {
        actual = ((AbstractIdentifiedObject) object).getInterface();
    } else {
        actual = object.getClass();
    }
    /*
         * Get the authority from the object if possible, in order to avoid a call
         * to the potentially costly (for EPSGDataAccess) getAuthority() method.
         */
    final Identifier id = object.getName();
    final Citation authority = (id != null) ? id.getAuthority() : getAuthority();
    throw new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.UnexpectedTypeForReference_3, code, type, actual), Citations.getIdentifier(authority, false), trimNamespace(code), code);
}
Also used : AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject) Identifier(org.opengis.metadata.Identifier) Citation(org.opengis.metadata.citation.Citation)

Example 35 with Citation

use of org.opengis.metadata.citation.Citation in project sis by apache.

the class AbstractDatum method formatTo.

/**
 * Formats the inner part of the <cite>Well Known Text</cite> (WKT) representation for this datum.
 * See {@link AbstractIdentifiedObject#formatTo(Formatter)} for more information.
 *
 * @param  formatter  the formatter where to format the inner content of this WKT element.
 * @return the {@linkplain org.apache.sis.io.wkt.KeywordCase#CAMEL_CASE CamelCase} keyword
 *         for the WKT element, or {@code null} if unknown.
 */
@Override
protected String formatTo(final Formatter formatter) {
    final Citation authority = formatter.getNameAuthority();
    String name = IdentifiedObjects.getName(this, authority);
    if (name == null) {
        name = IdentifiedObjects.getName(this, null);
        if (name == null) {
            // Should never happen, but be safe.
            return super.formatTo(formatter);
        }
        if ("ESRI".equalsIgnoreCase(Citations.getCodeSpace(authority)) && !name.startsWith(ESRI_PREFIX)) {
            name = ESRI_PREFIX + name;
        }
    }
    formatter.append(name, ElementKind.DATUM);
    return null;
}
Also used : Citation(org.opengis.metadata.citation.Citation) InternationalString(org.opengis.util.InternationalString)

Aggregations

Citation (org.opengis.metadata.citation.Citation)43 Test (org.junit.Test)17 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)12 InternationalString (org.opengis.util.InternationalString)11 Identifier (org.opengis.metadata.Identifier)10 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)7 Series (org.opengis.metadata.citation.Series)6 DependsOnMethod (org.apache.sis.test.DependsOnMethod)5 ArrayList (java.util.ArrayList)4 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)4 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)4 ResponsibleParty (org.opengis.metadata.citation.ResponsibleParty)3 CI_Citation (org.apache.sis.internal.jaxb.metadata.CI_Citation)2 FormattableObject (org.apache.sis.io.wkt.FormattableObject)2 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)2 DefaultInternationalString (org.apache.sis.util.iso.DefaultInternationalString)2 OnlineResource (org.opengis.metadata.citation.OnlineResource)2 NoSuchAuthorityCodeException (org.opengis.referencing.NoSuchAuthorityCodeException)2 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)1 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)1