return null; // Not an authority that we recognize for the OGC namespace. version = getVersion(c); // Unconditionally overwrite the user-specified version. final String part; switch (p) { case 0: part = toObjectType(type); break; case 1: part = codeSpace; break; case 2: part = version; break;
/** * If the given {@code type} is found in the given {@code references}, sets that reference element to {@code null} * and returns the corresponding {@code components} element. Otherwise returns {@code null}. This is equivalent to * {@link Map#remove(Object, Object)} where {@code references} are the keys and {@code components} are the values. * We do not bother building that map because the arrays are very short (2 or 3 elements). */ private static <T> T remove(final DefinitionURI[] references, final IdentifiedObject[] components, final Class<T> type) { final String expected = NameMeaning.toObjectType(type); for (int i=0; i<references.length; i++) { final DefinitionURI ref = references[i]; if (ref != null && expected.equalsIgnoreCase(ref.type)) { references[i] = null; return type.cast(components[i]); } } return null; }
/** * Tests {@link NameMeaning#toURN(Class, String, String, String)}. * * @since 0.7 */ @Test @DependsOnMethod("testToObjectType") public void testToURN() { assertEquals("urn:ogc:def:crs:EPSG::4326", NameMeaning.toURN(GeodeticCRS.class, "EPSG", null, "4326")); assertEquals("urn:ogc:def:crs:OGC:1.3:CRS84", NameMeaning.toURN(GeographicCRS.class, "CRS", null, "84")); assertEquals("urn:ogc:def:datum:EPSG::6326", NameMeaning.toURN(GeodeticDatum.class, "EPSG", null, "6326")); assertNull ("Authority is not optional.", NameMeaning.toURN(GeographicCRS.class, null, null, "4326")); } }
/** * Creates a new identifier for the same type and authority than this identifier, but a different version * extracted from the given authority. * * @param factory the factory's authority, or {@code null} for creating an identifier without version. * @return an identifier for the version of the given authority, or {@code this} if the version is the same. */ AuthorityFactoryIdentifier versionOf(final Citation factory) { String newVersion = NameMeaning.getVersion(factory); if (newVersion != null) { newVersion = newVersion.toLowerCase(IDENTIFIER_LOCALE); } if (Objects.equals(version, newVersion)) { return this; } return new AuthorityFactoryIdentifier(type, authority, newVersion); }
/** * If the given {@code type} is found in the given {@code references}, sets that reference element to {@code null} * and returns the corresponding {@code components} element. Otherwise returns {@code null}. This is equivalent to * {@link Map#remove(Object, Object)} where {@code references} are the keys and {@code components} are the values. * We do not bother building that map because the arrays are very short (2 or 3 elements). */ private static <T> T remove(final DefinitionURI[] references, final IdentifiedObject[] components, final Class<T> type) { final String expected = NameMeaning.toObjectType(type); for (int i=0; i<references.length; i++) { final DefinitionURI ref = references[i]; if (ref != null && expected.equalsIgnoreCase(ref.type)) { references[i] = null; return type.cast(components[i]); } } return null; }
cs = org.apache.sis.internal.util.Citations.getIdentifier(identifier.getAuthority(), true); return NameMeaning.toURN(type, cs, (identifier instanceof ReferenceIdentifier) ? ((ReferenceIdentifier) identifier).getVersion() : null, identifier.getCode());
/** * Creates a new identifier for the same type and authority than this identifier, but a different version * extracted from the given authority. * * @param factory the factory's authority, or {@code null} for creating an identifier without version. * @return an identifier for the version of the given authority, or {@code this} if the version is the same. */ AuthorityFactoryIdentifier versionOf(final Citation factory) { String newVersion = NameMeaning.getVersion(factory); if (newVersion != null) { newVersion = newVersion.toLowerCase(IDENTIFIER_LOCALE); } if (Objects.equals(version, newVersion)) { return this; } return new AuthorityFactoryIdentifier(type, authority, newVersion); }
/** * Tests {@link NameMeaning#toObjectType(Class)}. */ @Test public void testToObjectType() { assertEquals("crs", NameMeaning.toObjectType(GeographicCRS .class)); assertEquals("crs", NameMeaning.toObjectType(ProjectedCRS .class)); assertEquals("crs", NameMeaning.toObjectType(VerticalCRS .class)); assertEquals("crs", NameMeaning.toObjectType(TemporalCRS .class)); assertEquals("datum", NameMeaning.toObjectType(GeodeticDatum .class)); assertEquals("datum", NameMeaning.toObjectType(VerticalDatum .class)); assertEquals("datum", NameMeaning.toObjectType(TemporalDatum .class)); assertEquals("ellipsoid", NameMeaning.toObjectType(Ellipsoid .class)); assertEquals("meridian", NameMeaning.toObjectType(PrimeMeridian .class)); assertEquals("cs", NameMeaning.toObjectType(EllipsoidalCS .class)); assertEquals("cs", NameMeaning.toObjectType(CartesianCS .class)); assertEquals("axis", NameMeaning.toObjectType(CoordinateSystemAxis.class)); assertEquals("referenceSystem", NameMeaning.toObjectType(ReferenceSystem .class)); assertEquals("coordinateOperation", NameMeaning.toObjectType(CoordinateOperation .class)); assertEquals("method", NameMeaning.toObjectType(OperationMethod .class)); assertEquals("parameter", NameMeaning.toObjectType(ParameterDescriptor .class)); assertEquals("uom", NameMeaning.toObjectType(Unit .class)); }
return null; // Not an authority that we recognize for the OGC namespace. version = getVersion(c); // Unconditionally overwrite the user-specified version. final String part; switch (p) { case 0: part = toObjectType(type); break; case 1: part = codeSpace; break; case 2: part = version; break;
cs = org.apache.sis.internal.util.Citations.getIdentifier(identifier.getAuthority(), true); return NameMeaning.toURN(type, cs, (identifier instanceof ReferenceIdentifier) ? ((ReferenceIdentifier) identifier).getVersion() : null, identifier.getCode());
/** * Returns the version number of the specified authority database, or {@code null} if * not available. * * @param authority The authority name (typically {@code "EPSG"}). * @return The version number of the authority database, or {@code null} if unknown. * @throws FactoryRegistryException if no {@link CRSAuthorityFactory} implementation * was found for the specified authority. * * @category factory * @since 2.4 */ public static Version getVersion(final String authority) throws FactoryRegistryException { final String version; try { version = NameMeaning.getVersion(org.apache.sis.referencing.CRS.getAuthorityFactory(authority).getAuthority()); } catch (FactoryException e) { throw new FactoryRegistryException(e.getLocalizedMessage(), e); } return (version != null) ? new Version(version) : null; }
if (buffer == null) { buffer = new StringBuilder(40).append(DefinitionURI.PREFIX).append(DefinitionURI.SEPARATOR) .append(NameMeaning.toObjectType(object.getClass()));
final String urn = NameMeaning.toURN(type, fallback.getCodeSpace(), fallback.getVersion(), fallback.getCode()); if (urn != null) { final Code code = new Code();
if (buffer == null) { buffer = new StringBuilder(40).append(DefinitionURI.PREFIX).append(DefinitionURI.SEPARATOR) .append(NameMeaning.toObjectType(object.getClass()));
final String urn = NameMeaning.toURN(type, fallback.getCodeSpace(), fallback.getVersion(), fallback.getCode()); if (urn != null) { final Code code = new Code();
for (final ReferenceIdentifier identifier : identifiers) { if (appendUnicodeIdentifier(id, '-', identifier.getCodeSpace(), "", true) | // Really |, not || appendUnicodeIdentifier(id, '-', NameMeaning.toObjectType(object.getClass()), "", false) | appendUnicodeIdentifier(id, '-', identifier.getCode(), "", true))
final String urn = NameMeaning.toURN(enclosing.getClass(), cs, version, code); if (urn != null) { formatter.append(new FormattableObject() {
for (final ReferenceIdentifier identifier : identifiers) { if (appendUnicodeIdentifier(id, '-', identifier.getCodeSpace(), "", true) | // Really |, not || appendUnicodeIdentifier(id, '-', NameMeaning.toObjectType(object.getClass()), "", false) | appendUnicodeIdentifier(id, '-', identifier.getCode(), "", true))
final String urn = NameMeaning.toURN(enclosing.getClass(), cs, version, code); if (urn != null) { formatter.append(new FormattableObject() {
/** * A proxy that does not execute immediately the {@code create} method on a factory, * but instead stores information for later execution. */ private static final class Deferred extends AuthorityFactoryProxy<CoordinateOperationAuthorityFactory> { Deferred() {super(CoordinateOperationAuthorityFactory.class, AuthorityFactoryIdentifier.OPERATION);} /** The authority code saved by the {@code createFromAPI(…)} method. */ String code; /** * Saves the given code in the {@link #code} field and returns the given factory unchanged. * @throws FactoryException if the given factory is not an instance of {@link CoordinateOperationAuthorityFactory}. */ @Override CoordinateOperationAuthorityFactory createFromAPI(final AuthorityFactory factory, final String code) throws FactoryException { this.code = code; return opFactory(factory); } }