Search in sources :

Example 1 with Version

use of services.moleculer.service.Version in project moleculer-java by moleculer-java.

the class CommonUtils method nameOf.

public static final String nameOf(Object object, boolean addQuotes) {
    Class<?> c = object.getClass();
    Version v = c.getAnnotation(Version.class);
    String version = null;
    if (v != null) {
        version = v.value();
        if (version != null) {
            version = version.trim();
            if (version.isEmpty()) {
                version = null;
            }
        }
        if (version != null) {
            try {
                Double.parseDouble(version);
                version = 'v' + version;
            } catch (Exception ignored) {
            }
        }
    }
    Name n = c.getAnnotation(Name.class);
    String name = null;
    if (n != null) {
        name = n.value();
        if (name != null) {
            name = name.trim();
        }
    }
    if (name == null || name.isEmpty()) {
        name = c.getName();
        int i = Math.max(name.lastIndexOf('.'), name.lastIndexOf('$'));
        if (i > -1) {
            name = name.substring(i + 1);
        }
        name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
    }
    if (version != null) {
        name = version + '.' + name;
    }
    if (addQuotes && name.indexOf(' ') == -1) {
        name = "\"" + name + "\"";
    }
    return name;
}
Also used : Version(services.moleculer.service.Version) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Name(services.moleculer.service.Name)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 DataFormatException (java.util.zip.DataFormatException)1 Name (services.moleculer.service.Name)1 Version (services.moleculer.service.Version)1