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:com.sqewd.open.dal.core.persistence.DataManager.java

/**
 * Get the persistence handler defined for the specified entity type. If no
 * persistence handler found for the current class, search thru the super
 * classes to see if a handler is defined for any?
 * /*  w ww.j a  v  a 2  s  .  c  om*/
 * @param type
 *            - Class of the Entity.
 * @return
 * @throws Exception
 */
public AbstractPersister getPersister(final Class<?> type) throws Exception {
    String key = type.getCanonicalName();
    if (persistmap.containsKey(key))
        return persistmap.get(key);
    Class<?> ttype = type;
    key = type.getPackage().getName();
    if (persistmap.containsKey(key))
        return persistmap.get(key);
    while (true) {
        ttype = ttype.getSuperclass();
        if (ttype.getCanonicalName().compareTo(Object.class.getCanonicalName()) == 0) {
            break;
        }
        key = ttype.getCanonicalName();
        if (persistmap.containsKey(key))
            return persistmap.get(key);
    }
    throw new Exception("No persistence handler found for class [" + type.getCanonicalName() + "]");
}

From source file:com.ryantenney.metrics.spring.MetricAnnotationBeanPostProcessor.java

@Override
protected void withField(Object bean, String beanName, Class<?> targetClass, Field field) {
    final Metric annotation = field.getAnnotation(Metric.class);
    final String metricName = Util.forMetricField(targetClass, field, annotation);

    final Class<?> type = field.getType();
    if (!com.codahale.metrics.Metric.class.isAssignableFrom(type)) {
        throw new IllegalArgumentException("Field " + targetClass.getCanonicalName() + "." + field.getName()
                + " must be a subtype of " + com.codahale.metrics.Metric.class.getCanonicalName());
    }/*from   w  w w.java 2s .  c o m*/

    ReflectionUtils.makeAccessible(field);

    // Get the value of the field annotated with @Metric
    com.codahale.metrics.Metric metric = (com.codahale.metrics.Metric) ReflectionUtils.getField(field, bean);

    if (metric == null) {
        // If null, create a metric of the appropriate type and inject it
        metric = getMetric(metrics, type, metricName);
        ReflectionUtils.setField(field, bean, metric);
        LOG.debug("Injected metric {} for field {}.{}", metricName, targetClass.getCanonicalName(),
                field.getName());
    } else {
        // If non-null, register that instance of the metric
        try {
            // Attempt to register that instance of the metric
            metrics.register(metricName, metric);
            LOG.debug("Registered metric {} for field {}.{}", metricName, targetClass.getCanonicalName(),
                    field.getName());
        } catch (IllegalArgumentException ex1) {
            // A metric is already registered under that name
            // (Cannot determine the cause without parsing the Exception's message)
            try {
                metric = getMetric(metrics, type, metricName);
                ReflectionUtils.setField(field, bean, metric);
                LOG.debug("Injected metric {} for field {}.{}", metricName, targetClass.getCanonicalName(),
                        field.getName());
            } catch (IllegalArgumentException ex2) {
                // A metric of a different type is already registered under that name
                throw new IllegalArgumentException("Error injecting metric for field "
                        + targetClass.getCanonicalName() + "." + field.getName(), ex2);
            }
        }
    }
}

From source file:com.agileapes.couteau.maven.sample.task.CompileCodeTask.java

@Override
public void execute(final SampleExecutor executor) throws MojoFailureException {
    final DefaultDynamicClassCompiler compiler = new DefaultDynamicClassCompiler(
            executor.getProjectClassLoader());
    try {/*w w w .  j  a  v a  2  s  .  c om*/
        compiler.setOption(SimpleJavaSourceCompiler.Option.CLASSPATH, getClassPath(executor));
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoFailureException("Classpath resolution failed", e);
    }
    with(repository.getClassNames()).each(new Processor<String>() {
        @Override
        public void process(String className) {
            final Class<?> compiledClass;
            try {
                compiledClass = compiler.compile(className,
                        new StringReader(repository.getSourceCode(className)));
            } catch (CompileException e) {
                throw new Error("Compilation error", e);
            }
            System.out.println("Compiled: " + compiledClass.getCanonicalName());
            ((ConfigurableClassLoader) executor.getProjectClassLoader()).addClass(compiledClass);
        }
    });
}

From source file:gr.abiss.calipso.tiers.processor.ModelDrivenBeanGeneratingRegistryPostProcessor.java

protected void findModels(String basePackage) throws Exception {
    Set<BeanDefinition> entityBeanDefs = EntityUtil.findAnnotatedClasses(basePackage);
    for (BeanDefinition beanDef : entityBeanDefs) {
        Class<?> entity = ClassUtils.getClass(beanDef.getBeanClassName());
        LOGGER.info("Found resource model class {}", entity.getCanonicalName());
        entityModelContextsMap.put(entity, ModelContext.from(entity));
    }//  ww w  .j  a  va 2s  .com
}

From source file:com.pentaho.big.data.bundles.impl.shim.common.ShimBridgingClassloaderTest.java

@Test
public void testFindClassSuccess() throws ClassNotFoundException, IOException, KettleFileException {
    String canonicalName = ShimBridgingClassloader.class.getCanonicalName();
    FileObject myFile = KettleVFS.getFileObject("ram://testFindClassSuccess");
    try (FileObject fileObject = myFile) {
        try (OutputStream outputStream = fileObject.getContent().getOutputStream(false)) {
            IOUtils.copy(// w  w  w  .j  ava2  s .c o  m
                    getClass().getClassLoader().getResourceAsStream(canonicalName.replace(".", "/") + ".class"),
                    outputStream);
        }
        String packageName = ShimBridgingClassloader.class.getPackage().getName();
        when(bundleWiring.findEntries("/" + packageName.replace(".", "/"),
                ShimBridgingClassloader.class.getSimpleName() + ".class", 0))
                        .thenReturn(Arrays.asList(fileObject.getURL()));
        when(parentClassLoader.loadClass(anyString(), anyBoolean())).thenAnswer(new Answer<Class<?>>() {
            @Override
            public Class<?> answer(InvocationOnMock invocation) throws Throwable {
                Object[] arguments = invocation.getArguments();
                return new ShimBridgingClassloader.PublicLoadResolveClassLoader(getClass().getClassLoader())
                        .loadClass((String) arguments[0], (boolean) arguments[1]);
            }
        });
        Class<?> shimBridgingClassloaderClass = shimBridgingClassloader.findClass(canonicalName);
        assertEquals(canonicalName, shimBridgingClassloaderClass.getCanonicalName());
        assertEquals(shimBridgingClassloader, shimBridgingClassloaderClass.getClassLoader());
        assertEquals(packageName, shimBridgingClassloaderClass.getPackage().getName());
    } finally {
        myFile.delete();
    }
}

From source file:eu.eubrazilcc.lvl.core.xml.PubMedXmlBinder.java

@Override
@SuppressWarnings("unchecked")
protected <T> JAXBElement<T> createType(final T obj) {
    Object element = null;/*from  w  w  w .ja  va  2 s  .c o m*/
    Class<? extends Object> clazz = obj.getClass();
    if (clazz.equals(PubmedArticleSet.class)) {
        element = PUBMED_XML_FACTORY.createPubmedArticleSet();
    } else if (clazz.equals(PubmedArticle.class)) {
        element = PUBMED_XML_FACTORY.createPubmedArticle();
    } else {
        throw new IllegalArgumentException("Unsupported type: " + clazz.getCanonicalName());
    }
    return (JAXBElement<T>) element;
}

From source file:io.fabric8.spring.boot.AbstractServiceRegistar.java

private BeanDefinitionHolder createServiceDefinition(Service service, String alias, String protocol,
        String port, Class type) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder
            .genericBeanDefinition(KubernetesServiceFactoryBean.class);

    builder.addPropertyValue("name", alias);
    builder.addPropertyValue("service", service);
    builder.addPropertyValue("port", port);
    builder.addPropertyValue("type", type.getCanonicalName());
    builder.setAutowireMode(Autowire.BY_TYPE.value());
    //Add protocol qualifier
    builder.getBeanDefinition()// www  .  j  a  va2 s.  com
            .addQualifier(new AutowireCandidateQualifier(ServiceName.class, KubernetesHelper.getName(service)));
    builder.getBeanDefinition().addQualifier(new AutowireCandidateQualifier(Protocol.class, protocol));
    builder.getBeanDefinition()
            .addQualifier(new AutowireCandidateQualifier(PortName.class, port != null ? port : ""));
    return new BeanDefinitionHolder(builder.getBeanDefinition(), alias);
}

From source file:io.stallion.dataAccess.DataAccessRegistry.java

@Deprecated
public ModelController getControllerForModel(Class<? extends Model> model) {
    return getControllerForModelName(model.getCanonicalName());
}

From source file:io.fabric8.spring.boot.AbstractServiceRegistar.java

private <S, T> BeanDefinitionHolder createConverterBean(Class type, String methodName, Class<S> sourceType,
        Class<T> targetType) {

    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FactoryConverter.class);

    String beanName = type.getName() + "." + methodName;
    builder.addPropertyValue("name", methodName);
    builder.addPropertyValue("type", type.getCanonicalName());
    builder.addPropertyValue("sourceType", sourceType.getCanonicalName());
    builder.addPropertyValue("targetType", targetType.getCanonicalName());

    builder.setAutowireMode(Autowire.BY_TYPE.value());
    return new BeanDefinitionHolder(builder.getBeanDefinition(), beanName);
}

From source file:org.apache.cxf.fediz.service.idp.service.jpa.ProtocolSupportValidator.java

@Override
public boolean isValid(String object, ConstraintValidatorContext constraintContext) {

    ConstraintValidatorContextImpl x = (ConstraintValidatorContextImpl) constraintContext;
    Class<?> owner = x.getValidationContext().getCurrentOwner();

    List<String> protocols = null;
    if (owner.equals(TrustedIdpEntity.class)) {
        protocols = trustedIdpProtocolHandlers.getProtocols();
    } else if (owner.equals(ApplicationEntity.class)) {
        protocols = applicationProtocolHandlers.getProtocols();
    } else {/*from   w  w w  .  ja  v a  2 s  .c  o  m*/
        LOG.warn("Invalid owner {}. Ignoring validation.", owner.getCanonicalName());
        return true;
    }

    for (String protocol : protocols) {
        if (protocol.equals(object)) {
            return true;
        }
    }
    return false;
}