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:cc.aileron.dao.db.sql.G2DaoSqlMapImpl.java

/**
 * @param targetClass// w w  w. j  a va2  s . c o m
 * @return dir
 */
private String getDir(final Class<?> targetClass) {
    final String name = targetClass.getCanonicalName();
    if (name == null) {
        return null;
    }
    final StringBuffer buffer = new StringBuffer();
    final Matcher matcher = pattern.matcher(name);
    while (matcher.find()) {
        matcher.appendReplacement(buffer, "/" + matcher.group(1).toLowerCase());
    }
    return matcher.appendTail(buffer).toString();
}

From source file:ru.trett.cis.DAO.CommonDAOImpl.java

@Override
@SuppressWarnings("unchecked")
public <T extends BaseEntity> List<T> list(Class<T> tClass) {
    return sessionFactory.getCurrentSession().createQuery(String.format("from %s", tClass.getCanonicalName()))
            .list();/* ww  w .j  av a  2s .  co  m*/
}

From source file:de.lgohlke.sonar.maven.lint.LintSensorTest.java

@Test
public void testConfiguredAllRulesInAnnotation() {

    class StringComparator implements Comparator<String> {
        @Override/*w w w.j  av  a  2 s .  c  om*/
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    }

    Reflections reflections = new Reflections("de.lgohlke.sonar.maven.lint.rules");
    Set<Class<? extends MavenRule>> rulesImplemented = reflections.getSubTypesOf(MavenRule.class);

    Rules rules = LintSensor.class.getAnnotation(Rules.class);

    TreeSet<String> configuredRules = new TreeSet<String>(new StringComparator());
    for (Class clazz : rules.values()) {
        configuredRules.add(clazz.getCanonicalName());
    }
    TreeSet<String> implementedRules = new TreeSet<String>(new StringComparator());
    for (Class clazz : rulesImplemented) {
        implementedRules.add(clazz.getCanonicalName());
    }

    assertThat(configuredRules).isEqualTo(implementedRules);
}

From source file:com.vmware.photon.controller.common.xenon.ServiceHostUtils.java

/**
 * Logs the contents of all factories on a host.
 *
 * @param host//from   www  .ja  v a 2s.  c o m
 * @throws Throwable
 */
public static <H extends ServiceHost & XenonHostInfoProvider> void dumpHost(H host, String referrer)
        throws Throwable {
    logger.info(String.format("host: %s - %s", host.getId(), host.getPort()));
    for (Class factory : host.getFactoryServices()) {
        try {
            Operation op = Operation
                    .createGet(UriUtils.buildExpandLinksQueryUri(UriUtils.buildUri(host, factory)));
            Operation result = sendRequestAndWait(host, op, referrer);
            logger.info(String.format("%s: %s: %s", host.getPort(), factory.getSimpleName(),
                    Utils.toJson(false, false, result.getBodyRaw())));
        } catch (Throwable ex) {
            logger.info(String.format("Could not get service: %s", factory.getCanonicalName()));
        }
    }
}

From source file:com.garethahealy.camelmapstruct.converter.MapStructTypeConverter.java

private String getFromCacheOrFindMethodName(Class<?> type, Object value) throws IllegalAccessException {
    Class<?> from = value.getClass();
    Class<?> to = type;//from w ww  .ja va  2 s  .c  o  m
    String key = String.format("%s->%s", from.getCanonicalName(), to.getCanonicalName());

    LOG.trace("Cached method key: {}", key);
    LOG.debug("Looking for mapping method for {} -> {}", from.getCanonicalName(), to.getCanonicalName());

    String methodName;
    if (cache.containsKey(key)) {
        methodName = cache.get(key);

        LOG.debug("Found method in cache: {}", methodName);
    } else {
        methodName = findMethodName(from, to);

        LOG.debug("Adding method into cache: {}", methodName);

        cache.put(key, methodName);
    }

    return methodName;
}

From source file:ca.uhn.fhir.context.ModelScanner.java

@SuppressWarnings("unchecked")
static IValueSetEnumBinder<Enum<?>> getBoundCodeBinder(Field theNext) {
    Class<?> bound = getGenericCollectionTypeOfCodedField(theNext);
    if (bound == null) {
        throw new ConfigurationException("Field '" + theNext + "' has no parameter for "
                + BoundCodeDt.class.getSimpleName() + " to determine enum type");
    }//from   ww w .j  ava 2 s  .com

    String fieldName = "VALUESET_BINDER";
    try {
        Field bindingField = bound.getField(fieldName);
        return (IValueSetEnumBinder<Enum<?>>) bindingField.get(null);
    } catch (Exception e) {
        throw new ConfigurationException("Field '" + theNext + "' has type parameter "
                + bound.getCanonicalName()
                + " but this class has no valueset binding field (must have a field called " + fieldName + ")",
                e);
    }
}

From source file:org.vaadin.spring.servlet.SpringAwareUIProvider.java

@Override
protected void detectUIs() {
    logger.info("Checking the application context for Vaadin UIs");
    final String[] uiBeanNames = getWebApplicationContext().getBeanNamesForAnnotation(VaadinUI.class);
    for (String uiBeanName : uiBeanNames) {
        Class<?> beanType = getWebApplicationContext().getType(uiBeanName);
        if (UI.class.isAssignableFrom(beanType)) {
            logger.info("Found Vaadin UI [{}]", beanType.getCanonicalName());
            final String path = getWebApplicationContext().findAnnotationOnBean(uiBeanName, VaadinUI.class)
                    .path();/*from   w w w  .  ja  va2 s  . co  m*/
            Class<? extends UI> existingBeanType = getUIByPath(path);
            if (existingBeanType != null) {
                throw new IllegalStateException(String.format("[%s] is already mapped to the path [%s]",
                        existingBeanType.getCanonicalName(), path));
            }
            logger.debug("Mapping Vaadin UI [{}] to path [{}]", beanType.getCanonicalName(), path);
            mapPathToUI(path, (Class<? extends UI>) beanType);
        }
    }
}

From source file:org.vaadin.spring.touchkit.servlet.SpringAwareTouchKitUIProvider.java

@Override
protected void detectUIs() {
    logger.info("Checking the application context for TouchKit UIs");
    final String[] uiBeanNames = getWebApplicationContext().getBeanNamesForAnnotation(TouchKitUI.class);
    for (String uiBeanName : uiBeanNames) {
        Class<?> beanType = getWebApplicationContext().getType(uiBeanName);
        if (UI.class.isAssignableFrom(beanType)) {
            logger.info("Found TouchKit UI [{}]", beanType.getCanonicalName());
            final String path = getWebApplicationContext().findAnnotationOnBean(uiBeanName, TouchKitUI.class)
                    .path();/*w  w  w  .j  av a2 s.com*/
            Class<? extends UI> existingBeanType = getUIByPath(path);
            if (existingBeanType != null) {
                throw new IllegalStateException(String.format("[%s] is already mapped to the path [%s]",
                        existingBeanType.getCanonicalName(), path));
            }
            logger.debug("Mapping TouchKit UI [{}] to path [{}]", beanType.getCanonicalName(), path);
            mapPathToUI(path, (Class<? extends UI>) beanType);
        }
    }
}

From source file:org.openmrs.module.formentry.advice.DuplicateFormAdvisor.java

public boolean matches(Method method, Class targetClass) {
    if (method.getName().equals("duplicateForm"))
        log.error("duplicateForm method matched on class " + targetClass.getCanonicalName() + ", hash code "
                + this.hashCode());
    return method.getName().equals("duplicateForm");
}

From source file:edu.uoc.pelp.engine.aem.BasicCodeAnalyzer.java

/**
 * Obtain an instance that implements a proper Code Analyzer for the programming
 * language used in the given project./*from  www .j a  va  2 s .c  o m*/
 * @param project Code project to be analyzed
 * @return Implementation of a code analyzer object compatible with the given project.
 * @throws LanguageAEMPelpException There no exists any implementation for the given programming language.
 */
public static BasicCodeAnalyzer getInstance(CodeProject project) throws LanguageAEMPelpException {
    BasicCodeAnalyzer instance = null;

    // If the project has an assigned language, create an instance of the class for this language
    if (project.getLanguage() != null) {
        if (!_specificImplementations.containsKey(project.getLanguage())) {
            throw new LanguageAEMPelpException(
                    "Analyzer for language <" + project.getLanguage() + "> is not available.");
        }
        try {
            // Create the instance for this project
            instance = (BasicCodeAnalyzer) _specificImplementations.get(project.getLanguage()).newInstance();
        } catch (Exception ex) {
            throw new LanguageAEMPelpException(
                    "Cannot create an object for the language <" + project.getLanguage() + ">");
        }
    } else {
        // Create an instance for each available implementation and check the project
        for (Class c : _specificImplementations.values()) {
            try {
                // Create a new instance
                instance = (BasicCodeAnalyzer) c.newInstance();

                // Check the files of this project
                if (instance.isValidProject(project)) {
                    break;
                }

                // Invalid project, remove the instance
                instance = null;
            } catch (Exception ex) {
                throw new LanguageAEMPelpException(
                        "Cannot create an object of the class <" + c.getCanonicalName() + ">");
            }
        }
    }

    return instance;
}