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:com.nextep.designer.synch.ui.SynchUIPlugin.java

@SuppressWarnings("unchecked")
public static <T> T getService(Class<T> serviceInterface) {
    final BundleContext context = getDefault().getBundle().getBundleContext();
    final ServiceReference ref = context.getServiceReference(serviceInterface.getName());
    if (ref != null) {
        Object o = context.getService(ref);
        if (o != null && serviceInterface.isAssignableFrom(o.getClass())) {
            return (T) o;
        }// w ww  .  ja va2 s  .c  o  m
    }
    throw new ErrorException("Unable to locate requested service " + serviceInterface.getName());
}

From source file:models.Attach.java

public static <T> void deleteByIds(List<Long> attachIdList, Class<T> entityClass) {
    if (CollectionUtils.isNotEmpty(attachIdList)) {
        JPA.em().createQuery("update " + entityClass.getName() + " set isDelete=true where id in (:ids)")
                .setParameter("ids", attachIdList).executeUpdate();
    }//from ww  w  . j  a  v  a2s.  c  om
}

From source file:net.peakplatform.sonar.plugins.spring.rules.SpringRulesRepository.java

/**
 * Instantiate checks as defined in the RulesProfile.
 * //from   ww  w . ja  v  a  2  s.c om
 * @param profile
 */
public static List<BeanCheck> createChecks(final RulesProfile profile) {
    LOGGER.debug("Loading checks for profile " + profile.getName());

    List<BeanCheck> checks = new ArrayList<BeanCheck>();
    LOGGER.debug("SpringSensor analyse profile.getActiveRules().size(): " + profile.getActiveRules().size());

    for (ActiveRule activeRule : profile.getActiveRules()) {
        LOGGER.debug("SpringRulesRepository createChecks activeRule: " + activeRule.toString());
        if (REPOSITORY_KEY.equals(activeRule.getRepositoryKey())) {
            Class<BeanCheck> checkClass = getCheckClass(activeRule);
            LOGGER.debug("SpringRulesRepository createChecks checkClass.getName(): " + checkClass.getName());
            if (checkClass != null) {
                checks.add(createCheck(checkClass, activeRule));
            }
        }
    }

    return checks;
}

From source file:org.focusns.common.validation.ValidationHelper.java

/**
 * ??/*from   ww  w. jav  a2s. c o  m*/
 * 
 * @param constraintDescriptor
 * @return
 */
private static List<String> getConstraintParams(ConstraintDescriptor<?> constraintDescriptor) {
    Annotation constraintInstance = constraintDescriptor.getAnnotation();
    Class<?> constraintClass = constraintDescriptor.getAnnotation().annotationType();
    //
    List<String> params = new ArrayList<String>();
    //
    Method valueMethod = ClassUtils.getMethodIfAvailable(constraintClass, "value", (Class<?>[]) null);
    if (valueMethod != null) {
        String value = String.valueOf(ReflectionUtils.invokeMethod(valueMethod, constraintInstance));
        params.add("value:" + value);
    }
    Map<String, Object> annotationAttrs = AnnotationUtils.getAnnotationAttributes(constraintInstance);
    for (String key : annotationAttrs.keySet()) {
        if ("message".equals(key) || "payload".equals(key)) {
            continue;
        }
        //
        String value = "";
        if ("groups".equals(key)) {
            List<String> groupNames = new ArrayList<String>();
            Class[] groupClasses = (Class[]) annotationAttrs.get(key);
            for (Class groupClass : groupClasses) {
                groupNames.add(groupClass.getName());
            }
            value = StringUtils.collectionToDelimitedString(groupNames, "|");
        } else {
            value = String.valueOf(annotationAttrs.get(key));
        }
        //
        if (StringUtils.hasText(value)) {
            params.add(key + ":" + "'" + value + "'");
        }
    }
    //
    return params;
}

From source file:org.lightadmin.core.util.NumberUtils.java

private static void raiseOverflowException(Number number, Class targetClass) {
    throw new IllegalArgumentException("Could not convert number [" + number + "] of type ["
            + number.getClass().getName() + "] to target class [" + targetClass.getName() + "]: overflow");
}

From source file:com.prowidesoftware.deprecation.DeprecationUtils.java

/**
 * Helper hack to set environment variables from Java code
 *///from   www .j  a  v a  2 s.co  m
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void setEnv(final String key, final String value) {
    try {
        Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
        Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
        theEnvironmentField.setAccessible(true);
        Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
        env.put(key, value);
        Field theCaseInsensitiveEnvironmentField = processEnvironmentClass
                .getDeclaredField("theCaseInsensitiveEnvironment");
        theCaseInsensitiveEnvironmentField.setAccessible(true);
        Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
        cienv.put(key, value);
    } catch (NoSuchFieldException e) {
        try {
            Class[] classes = Collections.class.getDeclaredClasses();
            Map<String, String> env = System.getenv();
            for (Class cl : classes) {
                if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
                    Field field = cl.getDeclaredField("m");
                    field.setAccessible(true);
                    Object obj = field.get(env);
                    Map<String, String> map = (Map<String, String>) obj;
                    map.clear();
                    map.put(key, value);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

From source file:cross.io.PropertyFileGenerator.java

/**
 * Creates a property file for the given class, containing those fields,
 * which are annotated by {@link cross.annotations.Configurable}.
 *
 * @param className/*from w  w  w .  j  a  va  2s. c om*/
 * @param basedir
 */
public static void createProperties(String className, File basedir) {
    Class<?> c;
    try {
        c = PropertyFileGenerator.class.getClassLoader().loadClass(className);
        LoggerFactory.getLogger(PropertyFileGenerator.class).info("Class: {}", c.getName());
        PropertiesConfiguration pc = createProperties(c);
        if (!basedir.exists()) {
            basedir.mkdirs();
        }
        try {
            pc.save(new File(basedir, c.getSimpleName() + ".properties"));
        } catch (ConfigurationException ex) {
            LoggerFactory.getLogger(PropertyFileGenerator.class).warn("{}", ex.getLocalizedMessage());
        }
    } catch (ClassNotFoundException e) {
        LoggerFactory.getLogger(PropertyFileGenerator.class).warn("{}", e.getLocalizedMessage());
    }
}

From source file:com.dragome.callbackevictor.serverside.utils.ReflectionUtils.java

public static Map<String, Object> discoverFields(final Class<?> pClazz, final Matcher pMatcher,
        final Indexer pIndexer) {

    log.debug("discovering fields on " + pClazz.getName());

    final Map<String, Object> result = new HashMap<String, Object>();

    Class<?> current = pClazz;
    do {/*from w  w  w .j a va 2  s.  co  m*/
        final Field[] fields = current.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            final String fname = fields[i].getName();
            if (pMatcher.matches(fname)) {
                pIndexer.put(result, fname, fields[i]);

                log.debug("discovered field " + fname + " -> " + fields[i]);
            }
        }
        current = current.getSuperclass();
    } while (current != null);

    return result;
}

From source file:de.micromata.genome.tpsb.GroovyExceptionInterceptor.java

protected static String methodToString(Method m) {
    StringBuilder sb = new StringBuilder();
    String returnType = m.getReturnType().getName();
    // returnType = "def";
    sb.append(returnType).append(" ").append(m.getName()).append("(");
    int pos = 0;// ww  w . j  ava2s.c  o  m
    for (Class<?> cls : m.getParameterTypes()) {
        if (pos > 0) {
            sb.append(", ");
        }
        sb.append(cls.getName()).append(" arg" + pos);
        ++pos;
    }
    sb.append(")");
    return sb.toString();
}

From source file:qianyan.mofi.utils.ReflectionUtils.java

/**
 * ?????//  w  w  w  .  j av a  2 s.  c o  m
 */
public static String getClassName(final Class<?> clazz) {
    return StringUtil.afterLastDot(clazz.getName());
}