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.nmorel.gwtjackson.rebind.bean.BeanProcessor.java

public static Optional<BeanIdentityInfo> processIdentity(TreeLogger logger, JacksonTypeOracle typeOracle,
        RebindConfiguration configuration, JClassType type, Optional<JsonIdentityInfo> jsonIdentityInfo,
        Optional<JsonIdentityReference> jsonIdentityReference) throws UnableToCompleteException {

    if (!jsonIdentityInfo.isPresent()) {
        jsonIdentityInfo = findFirstEncounteredAnnotationsOnAllHierarchy(configuration, type,
                JsonIdentityInfo.class);
    }//from  w  w w .  j  a  va  2s. c  o m

    if (jsonIdentityInfo.isPresent() && ObjectIdGenerators.None.class != jsonIdentityInfo.get().generator()) {
        if (!jsonIdentityReference.isPresent()) {
            jsonIdentityReference = findFirstEncounteredAnnotationsOnAllHierarchy(configuration, type,
                    JsonIdentityReference.class);
        }

        String propertyName = jsonIdentityInfo.get().property();
        boolean alwaysAsId = jsonIdentityReference.isPresent() && jsonIdentityReference.get().alwaysAsId();
        Class<? extends ObjectIdGenerator<?>> generator = jsonIdentityInfo.get().generator();
        Class<?> scope = jsonIdentityInfo.get().scope();

        BeanIdentityInfo beanIdentityInfo;
        if (generator.isAssignableFrom(PropertyGenerator.class)) {

            beanIdentityInfo = new BeanIdentityInfo(propertyName, alwaysAsId, generator, scope);

        } else {

            JType identityType;
            if (IntSequenceGenerator.class == generator) {
                identityType = typeOracle.getType(Integer.class.getName());
            } else if (UUIDGenerator.class == generator) {
                identityType = typeOracle.getType(UUID.class.getName());
            } else {
                JClassType generatorType = typeOracle.getType(generator.getCanonicalName());
                JClassType objectIdGeneratorType = generatorType.getSuperclass();
                while (!objectIdGeneratorType.getQualifiedSourceName()
                        .equals(ObjectIdGenerator.class.getName())) {
                    objectIdGeneratorType = objectIdGeneratorType.getSuperclass();
                }
                identityType = objectIdGeneratorType.isParameterized().getTypeArgs()[0];
            }

            beanIdentityInfo = new BeanIdentityInfo(propertyName, alwaysAsId, generator, scope, identityType);

        }
        return Optional.of(beanIdentityInfo);
    }
    return Optional.absent();
}

From source file:info.archinnov.achilles.helper.EntityIntrospector.java

public Method findSetter(Class<?> beanClass, Field field) {
    log.debug("Find setter for field {} in class {}", field.getName(), beanClass.getCanonicalName());

    String fieldName = field.getName();

    try {//from   w  w  w .  j a v  a  2  s .  co  m
        String setter = this.deriveSetterName(field);
        Method setterMethod = beanClass.getMethod(setter, field.getType());

        if (!setterMethod.getReturnType().toString().equals("void")) {
            throw new AchillesBeanMappingException("The setter for field '" + fieldName + "' of type '"
                    + field.getDeclaringClass().getCanonicalName()
                    + "' does not return correct type or does not have the correct parameter");
        }

        log.trace("Derived setter method : {}", setterMethod.getName());
        return setterMethod;

    } catch (NoSuchMethodException e) {
        throw new AchillesBeanMappingException("The setter for field '" + fieldName + "' of type '"
                + field.getDeclaringClass().getCanonicalName() + "' does not exist or is incorrect");
    }
}

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

@Override
@SuppressWarnings("unchecked")
protected <T> JAXBElement<T> createType(final T obj) {
    Object element = null;//from   www .  ja v a2  s  . c  o  m
    Class<? extends Object> clazz = obj.getClass();
    if (clazz.equals(ESearchResult.class)) {
        element = ESEARCH_XML_FACTORY.createESearchResult();
    } else {
        throw new IllegalArgumentException("Unsupported type: " + clazz.getCanonicalName());
    }
    return (JAXBElement<T>) element;
}

From source file:info.archinnov.achilles.internals.metamodel.ComputedProperty.java

@Override
VALUEFROM decodeFromRawInternal(Object o) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace(format("Decode computed property %s from raw data %s", this.toString(), o));
    }//from w  w w  .ja  v a  2  s  .  co  m
    final Class<?> cqlClass = computedColumnInfo.cqlClass;
    Validator.validateTrue(cqlClass.isAssignableFrom(o.getClass()),
            "The class of object %s to decode should be %s", o, cqlClass.getCanonicalName());
    return valueCodec.decode((VALUETO) o);
}

From source file:info.archinnov.achilles.helper.EntityIntrospector.java

public Method findGetter(Class<?> beanClass, Field field) {
    log.debug("Find getter for field {} in class {}", field.getName(), beanClass.getCanonicalName());

    Method getterMethod = null;//from  www.j  av a 2 s  . c  o m
    String fieldName = field.getName();
    String[] getters = this.deriveGetterName(field);

    for (String getter : getters) {
        try {
            getterMethod = beanClass.getMethod(getter);
            if (getterMethod.getReturnType() != field.getType()) {
                throw new AchillesBeanMappingException("The getter for field '" + fieldName + "' of type '"
                        + field.getDeclaringClass().getCanonicalName() + "' does not return correct type");
            }
        } catch (NoSuchMethodException e) {
            // Do nothing here
        }
    }
    if (getterMethod == null) {
        throw new AchillesBeanMappingException("The getter for field '" + fieldName + "' of type '"
                + field.getDeclaringClass().getCanonicalName() + "' does not exist");
    }

    log.trace("Derived getter method : {}", getterMethod.getName());
    return getterMethod;
}

From source file:net.contextfw.web.application.internal.servlet.UriMappingFactory.java

@SuppressWarnings("unchecked")
public SortedSet<UriMapping> createMappings(Collection<Class<?>> origClasses, ClassLoader classLoader,
        InitializerProvider initializerProvider, InitHandler initHandler, PropertyProvider properties,
        RequestInvocationFilter filter) {

    // Note: This process creates some phantom chains from
    // views that do not have any url. Those chains are
    // however ingnored and are not such problem.

    SortedSet<UriMapping> mappings = new TreeSet<UriMapping>();

    try {/* ww w.  j a v  a2s .  co m*/
        for (Class<?> origClass : origClasses) {
            Class<?> cl = classLoader.loadClass(origClass.getCanonicalName());
            View annotation = cl.getAnnotation(View.class);
            if (annotation != null) {

                if (!Component.class.isAssignableFrom(cl)) {
                    throw new WebApplicationException(
                            "Class " + cl.getName() + " annotated with @View does " + "not extend Component");
                }

                List<Class<? extends Component>> chain = initializerProvider.getInitializerChain(cl);

                InitServlet servlet = new InitServlet(initHandler, chain, filter);

                for (String url : annotation.url()) {
                    if (!"".equals(url)) {
                        mappings.add(this.getMapping((Class<? extends Component>) cl, servlet, url));
                    }
                }

                for (String property : annotation.property()) {
                    if (!"".equals(property)) {
                        if (!properties.get().containsKey(property)) {
                            throw new WebApplicationException("No url bound to property: " + property);
                        }

                        String url = properties.get().getProperty(property);

                        if (url != null && !"".equals(url)) {
                            mappings.add(this.getMapping((Class<? extends Component>) cl, servlet, url));
                        } else {
                            throw new WebApplicationException("No url bound to view component. (class="
                                    + cl.getSimpleName() + ", property=" + property + ")");
                        }
                    }
                }
            }
        }
    } catch (ClassNotFoundException e) {
        throw new WebApplicationException(e);
    }

    return mappings;
}

From source file:com.thoughtworks.go.config.RolesConfig.java

public <T extends Role> T findByNameAndType(final CaseInsensitiveString roleName, Class<T> cls) {
    for (Role role : this) {
        if (role.getName().equals(roleName)
                && (role.getClass().getCanonicalName().equals(cls.getCanonicalName()))) {
            return (T) role;
        }/*from  www. j  a  v  a2s.  c o  m*/
    }
    return null;
}

From source file:com.netflix.paas.config.base.ConfigurationProxyUtils.java

static Supplier<?> getStaticSupplier(Class<?> type, String key, String defaultValue,
        AbstractConfiguration configuration) {
    if (type.isAssignableFrom(String.class)) {
        return Suppliers.ofInstance(configuration.getString(key, defaultValue));
    } else if (type.isAssignableFrom(Integer.class)) {
        return Suppliers.ofInstance(
                configuration.getInteger(key, defaultValue == null ? 0 : Integer.parseInt(defaultValue)));
    } else if (type.isAssignableFrom(Double.class)) {
        return Suppliers.ofInstance(
                configuration.getDouble(key, defaultValue == null ? 0.0 : Double.parseDouble(defaultValue)));
    } else if (type.isAssignableFrom(Long.class)) {
        return Suppliers.ofInstance(
                configuration.getLong(key, defaultValue == null ? 0L : Long.parseLong(defaultValue)));
    } else if (type.isAssignableFrom(Boolean.class)) {
        return Suppliers.ofInstance(configuration.getBoolean(key,
                defaultValue == null ? false : Boolean.parseBoolean(defaultValue)));
    }//from w w w  .ja va2s . c o m
    throw new RuntimeException("Unsupported value type " + type.getCanonicalName());
}

From source file:com.nec.core.container.ContextAwareContainer.java

/**
 * Retrieve an item from the Context/*  ww w  .j ava 2 s  .c  o m*/
 * 
 * @param clazz
 *            A class want to get instance
 * @return A instance of class
 */
@SuppressWarnings("unchecked")
public <T> T getComponent(final Class<T> clazz) {
    Map<String, Object> map = (Map<String, Object>) this.context.getBeansOfType(clazz);
    if (map.size() == 0) {
        throw new ObjectNotFoundException("Object not found for type " + clazz.getCanonicalName());
    }
    if (map.size() > 1) {
        throw new TooManyObjectsException("To many objects found for type " + clazz.getCanonicalName());
    }

    return (T) map.values().iterator().next();
}

From source file:com.otiliouine.configurablefactory.ConfigurableFactory.java

/**
 * Creates an instance of the implementation class mapped to <b>interfazz</b>
 * /*  w w  w .  j a  v a2s.  c o  m*/
 * @param interfazz the Interface or class which represents the abstraction of instance types
 * @param args the arguments to use when creating the new instance
 * @return a new instance of the implementation class mapped to <b>interfazz</b>
 */
public <T> T createInstance(Class<T> interfazz, Object... args) {
    Class<T> clazz = (Class<T>) mapping.get(interfazz);
    if (clazz == null) {
        throw new NoFactoryDefinitionException(
                "No factory is defined for class " + interfazz.getCanonicalName());
    }
    try {
        T instance = (T) ConstructorUtils.invokeConstructor(clazz, args);
        return interfazz.cast(instance);
    } catch (ClassCastException e) {
        throw new InvalidMappingValuesException(
                "invalid factory configuration, class " + clazz.getCanonicalName(), e);
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }

}