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

public static ArrayList<Class<?>> buildClassHierarchy(Class<?> cls) {
    ArrayList<Class<?>> hierarhy = new ArrayList<Class<?>>();
    boolean enteredDroidParts = false;
    do {//  w  w w  .  j  a  v a 2  s .co  m
        hierarhy.add(0, cls);
        boolean inDroidParts = cls.getName().startsWith("org.droidparts");
        if (enteredDroidParts && !inDroidParts) {
            break;
        } else {
            enteredDroidParts = inDroidParts;
            cls = cls.getSuperclass();
        }
    } while (cls != null);
    return hierarhy;
}

From source file:com.evolveum.midpoint.util.logging.LoggingUtils.java

public static String dumpStackTrace(Class... classesToSkip) {
    StackTraceElement[] fullStack = Thread.currentThread().getStackTrace();
    String immediateClass = null;
    String immediateMethod = null;
    boolean firstFrameLogged = false;
    StringBuilder sb = new StringBuilder();
    OUTER: for (StackTraceElement stackElement : fullStack) {
        if (!firstFrameLogged) {
            if (stackElement.getClassName().equals(Thread.class.getName())) {
                // skip call to thread.getStackTrace();
                continue;
            }//from  ww w.  j av  a 2  s .  co  m
            if (classesToSkip != null) {
                for (Class classToSkip : classesToSkip) {
                    if (stackElement.getClassName().equals(classToSkip.getName())) {
                        continue OUTER;
                    }
                }
            }
        }
        firstFrameLogged = true;

        sb.append(stackElement.toString());
        sb.append("\n");
    }
    return sb.toString();
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.DomainObjectJSONSerializer.java

public static JSONObject getDomainObject(DomainObject obj) throws SecurityException, NoSuchMethodException,
        IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    final JSONObject jsonObject = new JSONObject();
    final Class<? extends DomainObject> clazz = obj.getClass();
    final String objClassName = clazz.getName();

    jsonObject.put("externalId", obj.getExternalId());
    jsonObject.put("className", objClassName);
    final DomainClass domainClass = getDomainClass(objClassName);
    if (domainClass == null) {
        return jsonObject;
    }//from ww w.ja  v a2 s. c o  m
    for (Slot slot : getAllSlots(domainClass)) {
        final String slotName = slot.getName();
        final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName));
        final Object result = method.invoke(obj);
        jsonObject.put(slotName, result == null ? null : result.toString());
    }

    for (Role roleSlot : getAllRoleSlots(domainClass)) {
        final String slotName = roleSlot.getName();
        if (roleSlot.getMultiplicityUpper() == 1) {
            final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName));
            final AbstractDomainObject singleRelationObj = (AbstractDomainObject) method.invoke(obj);
            final JSONArray oneRelation = new JSONArray();
            if (singleRelationObj != null) {
                oneRelation.add(singleRelationObj.getExternalId());
            }
            jsonObject.put(slotName, oneRelation);
        } else {
            final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName) + "Set");
            final Set<? extends AbstractDomainObject> result = (Set<? extends AbstractDomainObject>) method
                    .invoke(obj);
            jsonObject.put(slotName, serializeRelation(result));
        }

    }

    return jsonObject;
}

From source file:net.iponweb.hadoop.streaming.parquet.ParquetAsTextOutputFormat.java

public static void setWriteSupportClass(Configuration configuration, Class<?> writeSupportClass) {
    configuration.set(ParquetOutputFormat.WRITE_SUPPORT_CLASS, writeSupportClass.getName());
}

From source file:org.codehaus.groovy.grails.plugins.searchable.compass.mapping.CompassMappingUtils.java

/**
 * Get the Compass alias for the given Class
 *
 * @param clazz the class/* w  w w . ja  v  a  2s  . co m*/
 * @return the Compass alias
 */
public static String getDefaultAlias(Class clazz) {
    Assert.notNull(clazz, "clazz cannot be null");
    String alias = clazz.getName();
    if (alias.indexOf(".") != -1) {
        alias = alias.substring(alias.lastIndexOf(".") + 1, alias.length());
    }
    return "ALIAS" + alias + "ALIAS";
}

From source file:blue.lapis.pore.converter.wrapper.WrapperConverterTest.java

@Parameterized.Parameters(name = "{0}")
public static Set<Object[]> getObjects() throws Exception {
    ImmutableSet.Builder<Object[]> objects = ImmutableSet.builder();
    ListMultimap<Class<?>, Class<?>> registry = createRegistry();
    for (Class<?> type : registry.keySet()) {
        objects.add(new Object[] { StringUtils.removeStart(type.getName(), IMPL_PREFIX), type,
                registry.get(type) });//from  www  . j a  va 2  s.  c  o  m
    }
    return objects.build();
}

From source file:com.netflix.nicobar.core.module.ScriptModuleUtils.java

/**
 * Find a class in the module that matches the given className
 *
 * @param module the script module to search
 * @param className the class name in dotted form.
 * @return the found class, or null./* w w w  .  jav  a  2s  . com*/
 */
@Nullable
public static Class<?> findClass(ScriptModule module, String className) {
    Set<Class<?>> classes = module.getLoadedClasses();
    Class<?> targetClass = null;
    for (Class<?> clazz : classes) {
        if (clazz.getName().equals(className)) {
            targetClass = clazz;
            break;
        }
    }

    return targetClass;
}

From source file:Main.java

public static List<Field> listAnnotatedFields(Class<?> cls) {
    ArrayList<Class<?>> clsTree = new ArrayList<Class<?>>();
    boolean enteredDroidParts = false;
    do {//from   w  w  w . j  a v  a  2 s.com
        clsTree.add(0, cls);
        boolean inDroidParts = cls.getName().startsWith("org.droidparts");
        if (enteredDroidParts && !inDroidParts) {
            break;
        } else {
            enteredDroidParts = inDroidParts;
            cls = cls.getSuperclass();
        }
    } while (cls != null);
    ArrayList<Field> fields = new ArrayList<Field>();
    for (Class<?> c : clsTree) {
        for (Field f : c.getDeclaredFields()) {
            if (f.getAnnotations().length > 0) {
                fields.add(f);
            }
        }
    }
    return fields;
}

From source file:com.delphix.appliance.logger.Logger.java

public static Logger getLogger(Class<?> clazz) {
    return getLogger(clazz.getName());
}

From source file:models.Attach.java

/**
 * ?id?/*  w ww  .ja v a2 s .c  om*/
 * @param <T>
 * @return
 */
public static <T> T queryById(Long id, Class<T> entityClass) {
    List<T> attachList = JPA.em().createQuery("from " + entityClass.getName() + " where id = :id", entityClass)
            .setParameter("id", id).getResultList();
    if (CollectionUtils.isNotEmpty(attachList)) {
        return attachList.get(0);
    }
    return null;
}