use of org.apache.sis.internal.referencing.DeprecatedCode in project sis by apache.
the class EPSGDataAccess method createProperties.
/**
* Returns the name and aliases for the {@link IdentifiedObject} to construct.
*
* @param table the table on which a query has been executed.
* @param name the name for the {@link IdentifiedObject} to construct.
* @param code the EPSG code of the object to construct.
* @param remarks remarks as a {@link String} or {@link InternationalString}, or {@code null} if none.
* @param deprecated {@code true} if the object to create is deprecated.
* @return the name together with a set of properties.
*/
@SuppressWarnings("ReturnOfCollectionOrArrayField")
private Map<String, Object> createProperties(final String table, String name, final Integer code, CharSequence remarks, final boolean deprecated) throws SQLException, FactoryDataException {
/*
* Search for aliases. Note that searching for the object code is not sufficient. We also need to check if the
* record is really from the table we are looking for since different tables may have objects with the same ID.
*
* Some aliases are identical to the name except that some letters are replaced by their accented letters.
* For example "Reseau Geodesique Francais" → "Réseau Géodésique Français". If we find such alias, replace
* the name by the alias so we have proper display in user interface. Notes:
*
* - WKT formatting will still be compliant with ISO 19162 because the WKT formatter replaces accented
* letters by ASCII ones.
* - We do not perform this replacement directly in our EPSG database because ASCII letters are more
* convenient for implementing accent-insensitive searches.
*/
final List<GenericName> aliases = new ArrayList<>();
try (ResultSet result = executeQuery("Alias", "SELECT OBJECT_TABLE_NAME, NAMING_SYSTEM_NAME, ALIAS" + " FROM [Alias] INNER JOIN [Naming System]" + " ON [Alias].NAMING_SYSTEM_CODE =" + " [Naming System].NAMING_SYSTEM_CODE" + " WHERE OBJECT_CODE = ?", code)) {
while (result.next()) {
if (tableMatches(table, result.getString(1))) {
final String naming = getOptionalString(result, 2);
final String alias = getString(code, result, 3);
NameSpace ns = null;
if (naming != null) {
ns = namingSystems.get(naming);
if (ns == null) {
ns = owner.nameFactory.createNameSpace(owner.nameFactory.createLocalName(null, naming), null);
namingSystems.put(naming, ns);
}
}
if (CharSequences.toASCII(alias).toString().equals(name)) {
name = alias;
} else {
aliases.add(owner.nameFactory.createLocalName(ns, alias));
}
}
}
}
/*
* At this point we can fill the properties map.
*/
properties.clear();
GenericName gn = null;
final Locale locale = getLocale();
final Citation authority = owner.getAuthority();
final InternationalString edition = authority.getEdition();
final String version = (edition != null) ? edition.toString() : null;
if (name != null) {
gn = owner.nameFactory.createGenericName(namespace, Constants.EPSG, name);
properties.put("name", gn);
properties.put(NamedIdentifier.CODE_KEY, name);
properties.put(NamedIdentifier.VERSION_KEY, version);
properties.put(NamedIdentifier.AUTHORITY_KEY, authority);
properties.put(AbstractIdentifiedObject.LOCALE_KEY, locale);
final NamedIdentifier id = new NamedIdentifier(properties);
properties.clear();
properties.put(IdentifiedObject.NAME_KEY, id);
}
if (!aliases.isEmpty()) {
properties.put(IdentifiedObject.ALIAS_KEY, aliases.toArray(new GenericName[aliases.size()]));
}
if (code != null) {
final String codeString = code.toString();
final ImmutableIdentifier identifier;
if (deprecated) {
final String replacedBy = getSupersession(table, code, locale);
identifier = new DeprecatedCode(authority, Constants.EPSG, codeString, version, Character.isDigit(replacedBy.charAt(0)) ? replacedBy : null, Vocabulary.formatInternational(Vocabulary.Keys.SupersededBy_1, replacedBy));
properties.put(AbstractIdentifiedObject.DEPRECATED_KEY, Boolean.TRUE);
} else {
identifier = new ImmutableIdentifier(authority, Constants.EPSG, codeString, version, (gn != null) ? gn.toInternationalString() : null);
}
properties.put(IdentifiedObject.IDENTIFIERS_KEY, identifier);
}
properties.put(IdentifiedObject.REMARKS_KEY, remarks);
properties.put(AbstractIdentifiedObject.LOCALE_KEY, locale);
properties.put(ReferencingServices.MT_FACTORY, owner.mtFactory);
return properties;
}
Aggregations