Example usage for java.lang Class getCanonicalName

List of usage examples for java.lang Class getCanonicalName

Introduction

In this page you can find the example usage for java.lang Class getCanonicalName.

Prototype

public String getCanonicalName() 

Source Link

Document

Returns the canonical name of the underlying class as defined by the Java Language Specification.

Usage

From source file:org.wte4j.impl.format.FormatterRegistry.java

private static String createSpringExpression(Class<? extends Formatter> formatterClass, List<String> args) {
    StringBuilder springExpression = new StringBuilder("new ");
    springExpression.append(formatterClass.getCanonicalName());
    springExpression.append("(");
    appendArgs(springExpression, args);//from   ww  w.  ja v  a2s  .  c om
    springExpression.append(")");
    return springExpression.toString();
}

From source file:Main.java

public static String getMethodFullName(String name, Class<?>[] parameterTypes) {
    StringBuilder buf = new StringBuilder();
    buf.append(name);/*from w ww. j  a v a  2 s  . c om*/
    buf.append("(");
    if (parameterTypes != null && parameterTypes.length > 0) {
        boolean first = true;
        for (Class<?> type : parameterTypes) {
            if (type != null) {
                if (first) {
                    first = false;
                } else {
                    buf.append(",");
                }
                buf.append(type.getCanonicalName());
            }
        }
    }
    buf.append(")");
    return buf.toString();
}

From source file:Main.java

/**
 * build method by name and parameters, like: method(type1,type2)
 *//*w ww . j ava2  s.  c  om*/
public static String getMethodFullName(String name, Class<?>[] parameterTypes) {
    StringBuilder builder = new StringBuilder();
    builder.append(name);
    builder.append("(");
    if (parameterTypes != null && parameterTypes.length > 0) {
        boolean first = true;
        for (Class<?> type : parameterTypes) {
            if (type != null) {
                if (first) {
                    first = false;
                } else {
                    builder.append(",");
                }
                builder.append(type.getCanonicalName());
            }
        }
    }
    builder.append(")");
    return builder.toString();
}

From source file:Main.java

private static String getParametersString(Class<?>... clazzes) {
    StringBuilder sb = new StringBuilder("(");
    boolean first = true;
    for (Class<?> clazz : clazzes) {
        if (first)
            first = false;//  w  w w .ja  v a2  s  .c om
        else
            sb.append(",");

        if (clazz != null)
            sb.append(clazz.getCanonicalName());
        else
            sb.append("null");
    }
    sb.append(")");
    return sb.toString();
}

From source file:com.adaptris.core.marshaller.xstream.XStreamUtils.java

/**
* Given a Field of a Class this method will return a Set of a number of
* possible fully qualified reference names for the field. This would be
* based on the class hierarchy eg currentClass:field, parentClass:field,
* grandparentClass:field etc./* w w w. j a v a 2s  .c  o m*/
* 
* @param clazz - Parent Class of the given field
* @param field - Given field to process
* @param separator - class-field separator
* @return - Set<String> of possible paths for the field
*/
public static Collection<String> createParentFields(Class<?> clazz, String field, String separator) {
    Set<String> result = new HashSet<String>();
    result.add(clazz.getCanonicalName() + separator + field);
    Class<?> c = clazz;
    while (c.getSuperclass() != null) {
        c = c.getSuperclass();
        result.add(c.getCanonicalName() + separator + field);
    }
    return result;
}

From source file:com.l2jfree.util.Introspection.java

/**
 * Returns the complete status of the given object in a multi-line string. <BR>
 * <BR>//from  w  w  w  .j a v a2 s  . c o m
 * The beginning and the end of the string are separated with '=' lines. First, the object's own
 * class is reported in a canonical form and all non-static object's own class fields are
 * reported in name = value pairs. The value is reported using {@link String#valueOf(Object)}
 * except if {@code o == Object}, when 'this' is reported instead. Then, the same is done for
 * each superclass in the class hierarchy. Superclass info is separated by a line of '-'s before
 * the line with the canonical name. <BR>
 * <BR>
 * An example output could be:<BR>
 * <CODE>
 * =================================================<BR>
 * Object's class: com.l2jfree.model.SomeClass<BR>
 * number = 15<BR>
 * object = this<BR>
 * -------------------------------------------------<BR>
 * Superclass: com.l2jfree.model.IntrospectiveObject<BR>
 * -------------------------------------------------<BR>
 * Superclass: java.lang.Object<BR>
 * =================================================<BR>
 * </CODE>
 * 
 * @param o an object
 * @return a textual representation of the given object
 */
public static String toMultiLineString(Object o) {
    String eol = System.getProperty("line.separator");
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < DEFAULT_WIDTH; i++)
        sb.append('=');
    sb.append(eol);

    Class<?> c = o.getClass();
    sb.append("Object's class: ");
    sb.append(c.getCanonicalName());
    sb.append(eol);

    writeFields(c, o, sb, eol, true);

    while ((c = c.getSuperclass()) != null) {
        for (int i = 0; i < DEFAULT_WIDTH; i++)
            sb.append('-');
        sb.append(eol);

        sb.append("Superclass: ");
        sb.append(c.getCanonicalName());
        sb.append(eol);

        writeFields(c, o, sb, eol, true);
    }

    for (int i = 0; i < DEFAULT_WIDTH; i++)
        sb.append('=');
    return sb.toString();
}

From source file:de.Keyle.MyPet.util.BukkitUtil.java

@SuppressWarnings("unchecked")
public static boolean unregisterMyPetEntities() {
    DebugLogger.info("Unregister MyPet entities");
    try {/*from  w w w.  j av a2 s .c  o  m*/
        Field EntityTypes_d = EntityTypes.class.getDeclaredField("d");
        Field EntityTypes_f = EntityTypes.class.getDeclaredField("f");
        EntityTypes_d.setAccessible(true);
        EntityTypes_f.setAccessible(true);

        Map<Class, String> d = (Map) EntityTypes_d.get(EntityTypes_d);
        Map<Class, Integer> f = (Map) EntityTypes_f.get(EntityTypes_f);

        Iterator dIterator = d.keySet().iterator();
        while (dIterator.hasNext()) {
            Class clazz = (Class) dIterator.next();
            if (clazz.getCanonicalName().startsWith("de.Keyle.MyPet")) {
                dIterator.remove();
            }
        }

        Iterator fIterator = f.keySet().iterator();
        while (fIterator.hasNext()) {
            Class clazz = (Class) fIterator.next();
            if (clazz.getCanonicalName().startsWith("de.Keyle.MyPet")) {
                fIterator.remove();
            }
        }

        return true;
    } catch (Exception e) {
        DebugLogger.severe("error while unregistering MyPet entities");
        DebugLogger.severe(e.getMessage());
        return false;
    }
}

From source file:de.Keyle.MyPet.util.BukkitUtil.java

@SuppressWarnings("unchecked")
public static boolean registerMyPetEntity(Class<? extends EntityMyPet> myPetEntityClass, String entityTypeName,
        int entityTypeId) {
    try {//from  w  ww  .j  av a 2s. c om
        Field EntityTypes_d = EntityTypes.class.getDeclaredField("d");
        Field EntityTypes_f = EntityTypes.class.getDeclaredField("f");
        EntityTypes_d.setAccessible(true);
        EntityTypes_f.setAccessible(true);

        Map<Class, String> d = (Map) EntityTypes_d.get(EntityTypes_d);
        Map<Class, Integer> f = (Map) EntityTypes_f.get(EntityTypes_f);

        Iterator cIterator = d.keySet().iterator();
        while (cIterator.hasNext()) {
            Class clazz = (Class) cIterator.next();
            if (clazz.getCanonicalName().equals(myPetEntityClass.getCanonicalName())) {
                cIterator.remove();
            }
        }

        Iterator eIterator = f.keySet().iterator();
        while (eIterator.hasNext()) {
            Class clazz = (Class) eIterator.next();
            if (clazz.getCanonicalName().equals(myPetEntityClass.getCanonicalName())) {
                eIterator.remove();
            }
        }

        d.put(myPetEntityClass, entityTypeName);
        f.put(myPetEntityClass, entityTypeId);

        return true;
    } catch (Exception e) {
        DebugLogger.severe("error while registering " + myPetEntityClass.getCanonicalName());
        DebugLogger.severe(e.getMessage());
        return false;
    }
}

From source file:com.alta189.bukkit.script.event.EventScanner.java

public static void writeEvents() {
    File file = new File(BScript.getInstance().getDataFolder(), "events.txt");
    if (file.exists()) {
        file.delete();/*from w  w w .  j  av  a  2  s  .co  m*/
    }

    if (file.getParentFile() != null && !file.getParentFile().exists()) {
        file.getParentFile().mkdirs();
    }
    StringBuilder builder = new StringBuilder();
    builder.append("Bukkit Event Classes").append(LINE_SEPARATOR).append("####################")
            .append(LINE_SEPARATOR).append(LINE_SEPARATOR);

    for (Map.Entry<String, Class<? extends Event>> entry : bukkitEvent.entrySet()) {
        String className = entry.getValue().getCanonicalName();
        if (className == null) {
            className = entry.getValue().getName();
        }
        builder.append("Full Name: ").append(className).append(LINE_SEPARATOR).append("Simple Name: ")
                .append(entry.getKey()).append(LINE_SEPARATOR).append(LINE_SEPARATOR);
    }

    builder.append("Plugin Event Classes").append(LINE_SEPARATOR).append("####################")
            .append(LINE_SEPARATOR).append(LINE_SEPARATOR);

    for (Map.Entry<Plugin, Set<Class<? extends Event>>> entry : pluginEvents.entrySet()) {

        builder.append("Plugin: ").append(entry.getKey().getName()).append(LINE_SEPARATOR)
                .append("---------------------").append(LINE_SEPARATOR).append(LINE_SEPARATOR);

        for (Class<? extends Event> clazz : entry.getValue()) {
            String className = clazz.getCanonicalName();
            if (className == null) {
                className = clazz.getName();
            }
            String simpleName = clazz.getSimpleName();
            builder.append("Full Name: ").append(entry.getKey().getName()).append(":").append(className)
                    .append(LINE_SEPARATOR).append("Simple Name: ").append(entry.getKey().getName()).append(":")
                    .append(simpleName);

            if (simpleNameEvents.get(simpleName) != null) {
                builder.append(LINE_SEPARATOR).append("Simplest Name: ").append(simpleName);
            }
            builder.append(LINE_SEPARATOR).append(LINE_SEPARATOR);
        }
    }
    builder.append(LINE_SEPARATOR);
    try {
        FileUtils.write(file, builder.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.taobao.datax.plugins.common.DBSource.java

/**
 * generate key to get {@link DataSource}
 * //from   ww  w  . j a  v a  2s  .  com
 * NOTE: Client must make sure all connections to the same database should
 * share the same value a suggestion: use genKey we provide below, we used
 * MD5 encryption method.
 * 
 *
* @param clazz             Class for Plugin
*
*
* @param ip                   database ip
*
* @param port               database port
*
* @param dbname         database name
*
*  @return                      an unique key
  * */
public static String genKey(Class<? extends Pluginable> clazz, String ip, String port, String dbname) {
    String str = clazz.getCanonicalName() + "_" + ip + "_" + port + "_" + dbname;
    return md5(str);
}