Search in sources :

Example 1 with Specification

use of org.opengis.annotation.Specification in project sis by apache.

the class ReferencingUtilities method toPropertyName.

/**
 * Returns the XML property name of the given interface.
 *
 * For {@link CoordinateSystem} base type, the returned value shall be one of
 * {@code affineCS}, {@code cartesianCS}, {@code cylindricalCS}, {@code ellipsoidalCS}, {@code linearCS},
 * {@code parametricCS}, {@code polarCS}, {@code sphericalCS}, {@code timeCS} or {@code verticalCS}.
 *
 * @param  base  the abstract base interface.
 * @param  type  the interface or classes for which to get the XML property name.
 * @return the XML property name for the given class or interface, or {@code null} if none.
 *
 * @see WKTUtilities#toType(Class, Class)
 */
public static StringBuilder toPropertyName(final Class<?> base, final Class<?> type) {
    final UML uml = type.getAnnotation(UML.class);
    if (uml != null) {
        final Specification spec = uml.specification();
        if (spec == Specification.ISO_19111) {
            final String name = uml.identifier();
            final int length = name.length();
            final StringBuilder buffer = new StringBuilder(length).append(name, name.indexOf('_') + 1, length);
            if (buffer.length() != 0) {
                buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0)));
                return buffer;
            }
        }
    }
    for (final Class<?> c : type.getInterfaces()) {
        if (base.isAssignableFrom(c)) {
            final StringBuilder name = toPropertyName(base, c);
            if (name != null) {
                return name;
            }
        }
    }
    return null;
}
Also used : UML(org.opengis.annotation.UML) Specification(org.opengis.annotation.Specification)

Aggregations

Specification (org.opengis.annotation.Specification)1 UML (org.opengis.annotation.UML)1