Example usage for java.lang Class getName

List of usage examples for java.lang Class getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String .

Usage

From source file:Main.java

/**
 * <p>Given a <code>List</code> of <code>Class</code> objects, this method converts
 * them into class names.</p>//from  w  w  w.j  a va2  s .  c  om
 *
 * <p>A new <code>List</code> is returned. <code>null</code> objects will be copied into
 * the returned list as <code>null</code>.</p>
 *
 * @param classes  the classes to change
 * @return a <code>List</code> of class names corresponding to the Class objects,
 *  <code>null</code> if null input
 * @throws ClassCastException if <code>classes</code> contains a non-<code>Class</code> entry
 */
public static List convertClassesToClassNames(List classes) {
    if (classes == null) {
        return null;
    }
    List classNames = new ArrayList(classes.size());
    for (Iterator it = classes.iterator(); it.hasNext();) {
        Class cls = (Class) it.next();
        if (cls == null) {
            classNames.add(null);
        } else {
            classNames.add(cls.getName());
        }
    }
    return classNames;
}

From source file:nl.talsmasoftware.enumerables.support.json.jackson2.Compatibility.java

private static Method method(Class<?> type, String method) throws NoSuchMethodException {
    final String key = type.getName() + "." + method;
    Object resolved = RESOLVED_METHODS.get(key);
    if (resolved == null) {
        try {//from w  w w  . ja va  2s  . com
            RESOLVED_METHODS.putIfAbsent(key, type.getMethod(method));
        } catch (NoSuchMethodException nsme) {
            RESOLVED_METHODS.putIfAbsent(key, nsme);
        }
        resolved = RESOLVED_METHODS.get(key);
    }
    if (resolved instanceof NoSuchMethodException) {
        throw (NoSuchMethodException) resolved;
    }
    return (Method) resolved;
}

From source file:org.LexGrid.LexBIG.caCore.utils.LexEVSCaCoreUtils.java

/**
 * Returns true if the given invocation is for a LexBig object.
 *
 * @param clazz the clazz// ww  w  . j av a 2s .co  m
 *
 * @return true, if checks if is lex big class
 */
public static boolean isLexBigClass(Class clazz) {
    String className = clazz.getName().toLowerCase();
    return className.startsWith("org.lexgrid") || className.startsWith("org.lexevs");
}

From source file:br.gov.frameworkdemoiselle.util.contrib.Reflections.java

/**
 * Build a array of super classes fields
 * /*from ww w.  j av  a 2s . c  o m*/
 * @return Array of Super Classes Fields
 */
public static Field[] getSuperClassesFields(Class<?> entryClass) {
    Field[] fieldArray = null;
    fieldArray = (Field[]) ArrayUtils.addAll(fieldArray, entryClass.getDeclaredFields());
    Class<?> superClazz = entryClass.getSuperclass();
    while (superClazz != null && !"java.lang.Object".equals(superClazz.getName())) {
        fieldArray = (Field[]) ArrayUtils.addAll(fieldArray, superClazz.getDeclaredFields());
        superClazz = superClazz.getSuperclass();
    }
    return fieldArray;
}

From source file:SwingResourceManager.java

/**
 * Returns an image stored in the file at the specified path relative to the specified class
 * @param clazz Class The class relative to which to find the image
 * @param path String The path to the image file
 * @return Image The image stored in the file at the specified path
 */// w  w w.  j av a 2  s.  com
public static Image getImage(Class<?> clazz, String path) {
    String key = clazz.getName() + '|' + path;
    Image image = m_ClassImageMap.get(key);
    if (image == null) {
        if ((path.length() > 0) && (path.charAt(0) == '/')) {
            String newPath = path.substring(1, path.length());
            image = getImage(new BufferedInputStream(clazz.getClassLoader().getResourceAsStream(newPath)));
        } else {
            image = getImage(clazz.getResourceAsStream(path));
        }
        m_ClassImageMap.put(key, image);
    }
    return image;
}

From source file:nl.talsmasoftware.enumerables.support.json.jackson2.EnumerableSerializer.java

private static List<BeanPropertyDefinition> serializationPropertiesFor(Class<?> simpleType,
        SerializationConfig config) {/*from   w  ww. ja v a2 s  .  co m*/
    final String cacheKey = simpleType.getName();
    List<BeanPropertyDefinition> properties = CACHE.get(cacheKey);
    if (properties == null) {
        properties = new BasicClassIntrospector()
                .forSerialization(config, SimpleType.construct(simpleType), null).findProperties();
        CACHE.putIfAbsent(cacheKey, properties);
    }
    return properties;
}

From source file:com.github.dozermapper.core.loader.api.FieldsMappingOptions.java

private static String mergeTypeNames(Class<?>[] type) {
    String[] typeNames = new String[type.length];
    for (int i = 0; i < type.length; i++) {
        Class<?> t = type[i];
        typeNames[i] = t.getName();
    }//from   w  ww  . j  a  v  a2s  .co m
    return StringUtils.join(typeNames, ",");
}

From source file:Main.java

/**
 * Method called to check if we can use the passed method or constructor
 * (wrt access restriction -- public methods can be called, others
 * usually not); and if not, if there is a work-around for
 * the problem.//from  w ww . j  a  v a2s .co m
 */
public static void checkAndFixAccess(Member member) {
    // We know all members are also accessible objects...
    AccessibleObject ao = (AccessibleObject) member;

    /* 14-Jan-2009, tatu: It seems safe and potentially beneficial to
     *   always to make it accessible (latter because it will force
     *   skipping checks we have no use for...), so let's always call it.
     */
    //if (!ao.isAccessible()) {
    try {
        ao.setAccessible(true);
    } catch (SecurityException se) {
        /* 17-Apr-2009, tatu: Related to [JACKSON-101]: this can fail on
         *    platforms like EJB and Google App Engine); so let's
         *    only fail if we really needed it...
         */
        if (!ao.isAccessible()) {
            Class<?> declClass = member.getDeclaringClass();
            throw new IllegalArgumentException("Can not access " + member + " (from class "
                    + declClass.getName() + "; failed to set access: " + se.getMessage());
        }
    }
    //}
}

From source file:com.quartercode.femtoweb.impl.ActionUriResolver.java

/**
 * Returns the URI of the given {@link Action} which must be located in the given package.
 * See {@link Context#getUri(Class)} for more information.
 *
 * @param actionBasePackage The package name which will be removed from the start of the action class name.
 *        Thereby, package names like {@code com.quartercode.femtowebtest.actions} are not included in URIs.
 * @param action The action class whose URI should be returned.
 * @return The URI the given action class is mapped to.
 *//*from   ww  w.  j ava 2s. c  o m*/
public static String getUri(String actionBasePackage, Class<? extends Action> action) {

    String actionFQCN = action.getName();

    // Verify that the action class is
    // - not an inner class
    // - not called "Action"
    // - ends with action
    Validate.isTrue(!StringUtils.contains(actionFQCN, '$'),
            "Action classes are not allowed to be inner classes; '%s' is therefore invalid", actionFQCN);
    Validate.isTrue(!actionFQCN.endsWith(".Action"),
            "Actions classes which are just called 'Action' are disallowed");
    Validate.isTrue(actionFQCN.endsWith("Action"),
            "Actions classes must end with 'Action'; '%s' is therefore invalid", actionFQCN);

    // Verify that the action class is inside the base package
    Validate.isTrue(actionFQCN.startsWith(actionBasePackage),
            "Cannot retrieve URI of action class '%s' because it doesn't start with the set action base package '%s'",
            actionFQCN, actionBasePackage);

    // Retrieve the name of the action class without the base package
    String actionName = actionFQCN.substring(actionBasePackage.length() + 1);

    // Replace all "." with "/", add an "/" to the front, uncapitalize the last URI part, remove "Action" from the last URI part
    // Example: "path.to.SomeTestAction" -> "/path/to/someTest")
    String[] actionNameComponents = splitAtLastSeparator(actionName, ".");
    String uriDir = actionNameComponents[0].replace('.', '/');
    String uriName = StringUtils.uncapitalize(StringUtils.removeEnd(actionNameComponents[1], "Action"));

    return "/" + joinNonBlankItems("/", uriDir, uriName);
}

From source file:Main.java

private static void saveActivity(Activity activity, Class<? extends Activity> clazz) {
    FileOutputStream fos = null;//from w w  w.jav  a  2  s.  c o  m
    try {
        fos = activity.openFileOutput(FILENAME, Activity.MODE_PRIVATE);
        fos.write(clazz.getName().getBytes());
    } catch (Exception e) {
        Toast.makeText(activity, "saveActivity: " + e, Toast.LENGTH_LONG).show();
    } finally {
        if (null != fos)
            try {
                fos.close();
            } catch (Exception e) {
            }
    }
}