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.github.dozermapper.core.converters.JAXBElementConverter.java

/**
 * Resolve the beanId associated to destination field name
 *
 * @return bean id//w w  w.  j ava2s .co m
 */
public String getBeanId() {
    Class<?> factoryClass = objectFactory(destObjClass, beanContainer).getClass();
    Class<?> destClass = null;
    String methodName = "create" + destObjClass.substring(destObjClass.lastIndexOf(".") + 1)
            + StringUtils.capitalize(destFieldName);

    try {
        Method method = ReflectionUtils.findAMethod(factoryClass, methodName, beanContainer);
        Class<?>[] parameterTypes = method.getParameterTypes();
        for (Class<?> parameterClass : parameterTypes) {
            destClass = parameterClass;
            break;
        }
    } catch (NoSuchMethodException e) {
        MappingUtils.throwMappingException(e);
    }

    return (destClass != null) ? destClass.getCanonicalName() : null;
}

From source file:brooklyn.util.ResourceUtils.java

/** returns the base directory or JAR from which the context is class-loaded, if possible;
 * throws exception if not found */
public String getClassLoaderDir() {
    if (contextObject == null)
        throw new IllegalArgumentException(
                "No suitable context (" + context + ") to auto-detect classloader dir");
    Class<?> cc = contextObject instanceof Class ? (Class<?>) contextObject : contextObject.getClass();
    return getClassLoaderDir(cc.getCanonicalName().replace('.', '/') + ".class");
}

From source file:de.decoit.simu.cbor.ifmap.deserializer.MetadataDeserializerManager.java

/**
 * Deserialize an object of the specified class from the specified data items.
 * The attributes and nested tags arrays may be empty but never null.
 *
 * @param <T> Type of the object to be deserialized, must be a subclass of {@link AbstractMetadata}
 * @param namespace CBOR data item representing the element namespace
 * @param cborName CBOR data item representing the element name
 * @param attributes CBOR array data item containing the element's attributes
 * @param nestedDataItem CBOR data item containing the element's nested tags or value
 * @param metadataType Type of the object to be deserialized
 * @return The deserialized object/*from www.  ja  v  a 2s .co  m*/
 * @throws CBORDeserializationException if deserialization failed
 */
public static <T extends AbstractMetadata> T deserialize(final DataItem namespace, final DataItem cborName,
        final Array attributes, final DataItem nestedDataItem, final Class<T> metadataType)
        throws CBORDeserializationException {
    if (namespace == null) {
        throw new IllegalArgumentException("Namespace must not be null");
    }

    if (cborName == null) {
        throw new IllegalArgumentException("CBOR name must not be null");
    }

    if (attributes == null) {
        throw new IllegalArgumentException("Attributes array must not be null");
    }

    if (nestedDataItem == null) {
        throw new IllegalArgumentException("Nested tags array must not be null");
    }

    if (metadataType == null) {
        throw new IllegalArgumentException("Target metadata type must not be null");
    }

    try {
        // If default deserializers were not registered yet, do so
        if (!initialized) {
            init();
        }

        // Check if a deserializer for this type was registered
        if (hasVendorDeserializer(metadataType)) {
            DictionarySimpleElement elementEntry = getTopLevelElement(namespace, cborName);

            return metadataType.cast(registeredDeserializers.get(metadataType).deserialize(attributes,
                    nestedDataItem, elementEntry));
        }

        // If no deserializer was found, fail with exception
        throw new UnsupportedOperationException("Cannot deserialize class: " + metadataType.getCanonicalName());
    } catch (CBORDeserializationException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new CBORDeserializationException("Could not cast deserialization result to target class", ex);
    }
}

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

/**
 * Run next statement and validate if expected exception is thrown.
 * //from w  ww .ja v  a 2s  . com
 * The next statement must return the this in the method.
 * 
 * The catched expected exception will be stored in the testContext with the name "expectedException"
 * 
 * @param expectEx expected exception.
 * @param callable callback
 * @param <EX> the type of the exception
 * @return t
 */
@TpsbIgnore
public <EX extends Throwable> T runWithExpectedException(final Class<EX> expectEx, CallableX<T, EX> callable) {
    try {
        callable.call();
        fail("Missing expected exception: " + expectEx.getCanonicalName());
    } catch (Throwable ex) { // NOSONAR "Illegal Catch" framework
        if (expectEx.isAssignableFrom(ex.getClass()) == false) {
            fail("expected exception: " + expectEx.getCanonicalName() + " but got: "
                    + ex.getClass().getCanonicalName() + "; " + ex.getMessage());
        }
    }
    return getBuilder();
}

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

@Override
protected void withField(final Object bean, String beanName, Class<?> targetClass, final Field field) {
    ReflectionUtils.makeAccessible(field);

    final Gauge annotation = field.getAnnotation(Gauge.class);
    final String metricName = Util.forGauge(targetClass, field, annotation);

    metrics.register(metricName, new com.codahale.metrics.Gauge<Object>() {
        @Override//from  w  w w.j a  v  a  2  s .co  m
        public Object getValue() {
            Object value = ReflectionUtils.getField(field, bean);
            if (value instanceof com.codahale.metrics.Gauge) {
                value = ((com.codahale.metrics.Gauge<?>) value).getValue();
            }
            return value;
        }
    });

    LOG.debug("Created gauge {} for field {}.{}", metricName, targetClass.getCanonicalName(), field.getName());
}

From source file:egovframework.rte.fdl.cmmn.trace.LeaveaTrace.java

/**
 * trace //w  w w  .j  a  va  2s.c o m
 * @param clazz leaveaTrace  ? ? 
 * @param messageKey    
 * @param messageParameters  ?     
 * @param locale /
 * @param log ?
 */
public void trace(Class<?> clazz, MessageSource messageSource, String messageKey, Object[] messageParameters,
        Locale locale, Log log) {

    String message = messageSource.getMessage(messageKey, messageParameters, null, locale);

    if (log != null) {
        log.info(" LeaveaTrace.trace() this.message =>" + message);
    }

    if (traceHandlerServices == null)
        return;
    for (TraceHandlerService traceHandlerService : traceHandlerServices) {
        if (traceHandlerService.hasReqExpMatcher()) {
            traceHandlerService.setReqExpMatcher(pm);
        }
        traceHandlerService.setPackageName(clazz.getCanonicalName());
        traceHandlerService.trace(clazz, message);
    }

}

From source file:info.archinnov.achilles.persistence.AbstractPersistenceManager.java

protected <T> EntityMeta typedQueryInternal(Class<T> entityClass, Statement statement, Object... boundValues) {
    log.debug("Execute typed query for entity class {}", entityClass);
    Validator.validateNotNull(entityClass, "The entityClass for typed query should not be null");
    Validator.validateNotNull(statement, "The regularStatement for typed query should not be null");
    Validator.validateTrue(entityMetaMap.containsKey(entityClass),
            "Cannot perform typed query because the entityClass '%s' is not managed by Achilles",
            entityClass.getCanonicalName());

    EntityMeta meta = entityMetaMap.get(entityClass);
    typedQueryValidator.validateTypedQuery(entityClass, statement, meta);
    return meta;/*www  .  j ava  2 s  .c  o  m*/
}

From source file:azkaban.execapp.AzkabanExecutorServer.java

private void registerMbean(String name, Object mbean) {
    Class<?> mbeanClass = mbean.getClass();
    ObjectName mbeanName;/*from   ww  w . jav  a  2  s. c  o m*/
    try {
        mbeanName = new ObjectName(mbeanClass.getName() + ":name=" + name);
        mbeanServer.registerMBean(mbean, mbeanName);
        logger.info("Bean " + mbeanClass.getCanonicalName() + " registered.");
        registeredMBeans.add(mbeanName);
    } catch (Exception e) {
        logger.error("Error registering mbean " + mbeanClass.getCanonicalName(), e);
    }

}

From source file:com.chiralbehaviors.CoRE.phantasm.graphql.schemas.JooqSchema.java

@SuppressWarnings({ "rawtypes", "unchecked" })
protected <T> T fetch(UUID id, Class<?> record, DataFetchingEnvironment env) {
    Table<?> table = TABLES.get(record);
    Field field;/* w  w w .  ja v a2  s . c o m*/
    try {
        field = (Field) table.getClass().getField("ID").get(table);
    } catch (DataAccessException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException
            | SecurityException e) {
        throw new IllegalStateException(
                String.format("Cannot access 'id' field on %s", record.getCanonicalName()), e);
    }
    return (T) WorkspaceSchema.ctx(env).create().selectFrom(table).where(field.eq(id)).fetchOne();
}

From source file:com.haulmont.cuba.web.gui.components.WebEntityLinkField.java

@Override
public void setValue(Object value) {
    if (value != null) {
        if (datasource == null && metaClass == null) {
            throw new IllegalStateException("Datasource or metaclass must be set for field");
        }/*from   ww  w.ja v  a2  s. co  m*/

        component.removeStyleName(EMPTY_VALUE_STYLENAME);

        MetaClass fieldMetaClass = getMetaClass();
        if (fieldMetaClass != null) {
            Class fieldClass = fieldMetaClass.getJavaClass();
            Class<?> valueClass = value.getClass();
            //noinspection unchecked
            if (!fieldClass.isAssignableFrom(valueClass)) {
                throw new IllegalArgumentException(
                        String.format("Could not set value with class %s to field with class %s",
                                fieldClass.getCanonicalName(), valueClass.getCanonicalName()));
            }
        }
    } else {
        component.addStyleName("empty-value");
    }

    super.setValue(value);
}