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:info.archinnov.achilles.internal.metadata.parsing.PropertyParser.java

public <T> Class<T> inferValueClassForListOrSet(Type genericType, Class<?> entityClass) {
    log.debug("Infer parameterized value class for collection type {} of entity class {} ",
            genericType.toString(), entityClass.getCanonicalName());

    Class<T> valueClass;/*from   ww  w.  ja  va2  s.  c  o  m*/
    if (genericType instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) genericType;
        Type[] actualTypeArguments = pt.getActualTypeArguments();
        if (actualTypeArguments.length > 0) {
            Type type = actualTypeArguments[actualTypeArguments.length - 1];
            valueClass = getClassFromType(type);
        } else {
            throw new AchillesBeanMappingException("The type '" + genericType.getClass().getCanonicalName()
                    + "' of the entity '" + entityClass.getCanonicalName() + "' should be parameterized");
        }
    } else {
        throw new AchillesBeanMappingException("The type '" + genericType.getClass().getCanonicalName()
                + "' of the entity '" + entityClass.getCanonicalName() + "' should be parameterized");
    }

    log.trace("Inferred value class : {}", valueClass.getCanonicalName());

    return valueClass;
}

From source file:com.bbm.common.aspect.ExceptionTransfer.java

/**
 * ? Exception ? ?  ??   ??  ? ./*from   w  w w  .  j  a v  a2s  . c  o m*/
 * 
 * @param clazz Exception ? ? 
 * @param methodName Exception ?  
 * @param exception ? Exception 
 * @param pm ? PathMatcher(default : AntPathMatcher) 
 * @param exceptionHandlerServices[] ??  ExceptionHandlerService 
 */
protected void processHandling(Class clazz, String methodName, Exception exception, PathMatcher pm,
        ExceptionHandlerService[] exceptionHandlerServices) {
    try {
        for (ExceptionHandlerService ehm : exceptionHandlerServices) {

            if (!ehm.hasReqExpMatcher())
                ehm.setReqExpMatcher(pm);

            ehm.setPackageName(clazz.getCanonicalName() + "." + methodName);
            ehm.run(exception);

        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        getLog(clazz).error(e.getMessage(), e.getCause());
    }
}

From source file:com.haulmont.cuba.gui.ControllerDependencyInjector.java

protected void doInjection(AnnotatedElement element, Class annotationClass) {
    Class<?> type;//from  ww w.  j a  v a 2 s  .  c  om
    String name = null;
    if (annotationClass == Named.class)
        name = element.getAnnotation(Named.class).value();
    else if (annotationClass == Resource.class)
        name = element.getAnnotation(Resource.class).name();
    else if (annotationClass == WindowParam.class)
        name = element.getAnnotation(WindowParam.class).name();

    boolean required = true;
    if (element.isAnnotationPresent(WindowParam.class))
        required = element.getAnnotation(WindowParam.class).required();

    if (element instanceof Field) {
        type = ((Field) element).getType();
        if (StringUtils.isEmpty(name))
            name = ((Field) element).getName();
    } else if (element instanceof Method) {
        Class<?>[] types = ((Method) element).getParameterTypes();
        if (types.length != 1)
            throw new IllegalStateException("Can inject to methods with one parameter only");
        type = types[0];
        if (StringUtils.isEmpty(name)) {
            if (((Method) element).getName().startsWith("set"))
                name = StringUtils.uncapitalize(((Method) element).getName().substring(3));
            else
                name = ((Method) element).getName();
        }
    } else {
        throw new IllegalStateException("Can inject to fields and setter methods only");
    }

    Object instance = getInjectedInstance(type, name, annotationClass, element);

    if (instance != null) {
        assignValue(element, instance);
    } else if (required) {
        Class<?> declaringClass = ((Member) element).getDeclaringClass();
        Class<? extends Frame> frameClass = frame.getClass();

        String msg;
        if (frameClass == declaringClass) {
            msg = String.format("CDI - Unable to find an instance of type '%s' named '%s' for instance of '%s'",
                    type, name, frameClass.getCanonicalName());
        } else {
            msg = String.format(
                    "CDI - Unable to find an instance of type '%s' named '%s' declared in '%s' for instance of '%s'",
                    type, name, declaringClass.getCanonicalName(), frameClass.getCanonicalName());
        }

        Logger log = LoggerFactory.getLogger(ControllerDependencyInjector.class);
        log.warn(msg);
    }
}

From source file:com.eucalyptus.simpleworkflow.common.client.WorkflowClientStandalone.java

private void handleClassFile(final File f, final JarEntry j) throws IOException, RuntimeException {
    final String classGuess = j.getName().replaceAll("/", ".").replaceAll("\\.class.{0,1}", "");
    try {//from ww  w . java  2 s . c o m
        final Class candidate = ClassLoader.getSystemClassLoader().loadClass(classGuess);
        final Ats ats = Ats.inClassHierarchy(candidate);
        if ((this.allowedClassNames.isEmpty() || this.allowedClassNames.contains(candidate.getName())
                || this.allowedClassNames.contains(candidate.getCanonicalName())
                || this.allowedClassNames.contains(candidate.getSimpleName()))
                && (ats.has(Workflow.class) || ats.has(Activities.class))
                && !Modifier.isAbstract(candidate.getModifiers())
                && !Modifier.isInterface(candidate.getModifiers()) && !candidate.isLocalClass()
                && !candidate.isAnonymousClass()) {
            if (ats.has(Workflow.class)) {
                this.workflowClasses.add(candidate);
                LOG.debug("Discovered workflow implementation class: " + candidate.getName());
            } else {
                this.activityClasses.add(candidate);
                LOG.debug("Discovered activity implementation class: " + candidate.getName());
            }
        }
    } catch (final ClassNotFoundException e) {
        LOG.debug(e, e);
    }
}

From source file:info.archinnov.achilles.internal.metadata.parsing.EmbeddedIdParser.java

private boolean buildPartitionAndClusteringKeys(Class<?> embeddedIdClass, Map<Integer, Field> components,
        Integer reversedField, EmbeddedIdPropertiesBuilder partitionKeysBuilder,
        EmbeddedIdPropertiesBuilder clusteringKeysBuilder,
        EmbeddedIdPropertiesBuilder embeddedIdPropertiesBuilder) {
    log.debug("Build Components meta data for embedded id class {}", embeddedIdClass.getCanonicalName());

    boolean hasPartitionKeyAnnotation = false;
    for (Integer order : components.keySet()) {
        Field compositeKeyField = components.get(order);
        Class<?> componentClass = compositeKeyField.getType();
        String componentName;//from ww w .  j  a va 2 s . co  m
        Method componentGetter = entityIntrospector.findGetter(embeddedIdClass, compositeKeyField);
        Method componentSetter = entityIntrospector.findSetter(embeddedIdClass, compositeKeyField);

        Column column = compositeKeyField.getAnnotation(Column.class);

        if (column != null && isNotBlank(column.name()))
            componentName = column.name();
        else
            componentName = compositeKeyField.getName();

        embeddedIdPropertiesBuilder.addComponentName(componentName);
        embeddedIdPropertiesBuilder.addComponentClass(componentClass);
        embeddedIdPropertiesBuilder.addComponentField(compositeKeyField);
        embeddedIdPropertiesBuilder.addComponentGetter(componentGetter);
        embeddedIdPropertiesBuilder.addComponentSetter(componentSetter);

        if (filter.hasAnnotation(compositeKeyField, TimeUUID.class)) {
            embeddedIdPropertiesBuilder.addTimeUUIDComponent(componentName);
        }

        if (filter.hasAnnotation(compositeKeyField, PartitionKey.class)) {
            partitionKeysBuilder.addComponentName(componentName);
            partitionKeysBuilder.addComponentClass(componentClass);
            partitionKeysBuilder.addComponentField(compositeKeyField);
            partitionKeysBuilder.addComponentGetter(componentGetter);
            partitionKeysBuilder.addComponentSetter(componentSetter);
            hasPartitionKeyAnnotation = true;
        } else {
            clusteringKeysBuilder.addComponentName(componentName);
            clusteringKeysBuilder.addComponentClass(componentClass);
            clusteringKeysBuilder.addComponentField(compositeKeyField);
            clusteringKeysBuilder.addComponentGetter(componentGetter);
            clusteringKeysBuilder.addComponentSetter(componentSetter);
        }
        if (reversedField != null && order.intValue() == reversedField.intValue()) {
            clusteringKeysBuilder.setReversedComponentName(componentName);
        }
    }
    return hasPartitionKeyAnnotation;
}

From source file:com.spotify.docgenerator.DocgeneratorMojo.java

private Class<?> getClassForNameIsh(Sink sink, String className) {
    try {//from w w w .  j  a  v  a  2  s .  co m
        return getClassForName(className);
    } catch (ClassNotFoundException e) {
        final List<String> bits = Splitter.on(".").splitToList(className);
        final String childClassName = Joiner.on('.').join(bits.subList(0, bits.size() - 1));
        try {
            Class<?> clazz = getClassForName(childClassName);
            for (Class<?> clazzy : clazz.getDeclaredClasses()) {
                if (className.equals(clazzy.getCanonicalName())) {
                    return clazzy;
                }
            }
            return null;
        } catch (ClassNotFoundException e1) {
            sink.text(" -- can't find class");
            sink.lineBreak();
            return null;
        } catch (MalformedURLException e1) {
            sink.text(" -- inner url is hosed");
            sink.lineBreak();
            return null;
        }
    } catch (MalformedURLException e) {
        sink.text(" -- url is hosed");
        sink.lineBreak();
        return null;
    }
}

From source file:me.st28.flexseries.flexcore.cookie.CookieManager.java

/**
 * Retrieves a cookie value for a player.
 *
 * @param userId The ID of the user to retrieve the value of.
 * @param defaultValue The value to return if the cookie value is null.
 * @param plugin The plugin that owns the cookie.
 * @param identifier The identifier of the cookie.
 * @return The value of the cookie.<br />
 *         Null if no value is set.// ww w  . jav  a 2s  .  c  om
 */
public String getValue(String userId, String defaultValue, Class<? extends FlexPlugin> plugin,
        String identifier) {
    Validate.notNull(userId, "User ID cannot be null.");
    Validate.notNull(plugin, "Plugin cannot be null.");
    Validate.notNull(identifier, "Identifier cannot be null.");

    Map<String, String> cookies = loadedCookies.get(userId);

    if (cookies == null || cookies.isEmpty()) {
        return defaultValue;
    }

    String value = cookies.get(plugin.getCanonicalName() + "-" + identifier);
    return value == null ? defaultValue : value;
}

From source file:org.seedstack.spring.internal.SpringModule.java

@SuppressWarnings("unchecked")
private void bindFromApplicationContext() {
    boolean debugEnabled = LOGGER.isDebugEnabled();

    ConfigurableListableBeanFactory currentBeanFactory = this.beanFactory;
    do {//from   w  w  w.j  a  v  a 2  s . c  o m
        for (String beanName : currentBeanFactory.getBeanDefinitionNames()) {
            BeanDefinition beanDefinition = currentBeanFactory.getMergedBeanDefinition(beanName);
            if (!beanDefinition.isAbstract()) {
                Class<?> beanClass;
                try {
                    beanClass = Class.forName(beanDefinition.getBeanClassName());
                } catch (ClassNotFoundException e) {
                    LOGGER.warn("Cannot bind spring bean " + beanName + " because its class "
                            + beanDefinition.getBeanClassName() + " failed to load", e);
                    continue;
                }

                // FactoryBean special case: retrieve it and query for the object type it creates
                if (FactoryBean.class.isAssignableFrom(beanClass)) {
                    beanClass = ((FactoryBean) currentBeanFactory.getBean('&' + beanName)).getObjectType();
                    if (beanClass == null) {
                        LOGGER.warn("Cannot bind spring bean " + beanName
                                + " because its factory bean cannot determine its class");
                        continue;
                    }
                }

                SpringBeanDefinition springBeanDefinition = new SpringBeanDefinition(beanName,
                        currentBeanFactory);

                // Adding bean with its base type
                addBeanDefinition(beanClass, springBeanDefinition);

                // Adding bean with its parent type if enabled
                Class<?> parentClass = beanClass.getSuperclass();
                if (parentClass != null && parentClass != Object.class) {
                    addBeanDefinition(parentClass, springBeanDefinition);
                }

                // Adding bean with its immediate interfaces if enabled
                for (Class<?> i : beanClass.getInterfaces()) {
                    addBeanDefinition(i, springBeanDefinition);
                }
            }
        }
        BeanFactory factory = currentBeanFactory.getParentBeanFactory();
        if (factory != null) {
            if (factory instanceof ConfigurableListableBeanFactory) {
                currentBeanFactory = (ConfigurableListableBeanFactory) factory;
            } else {
                LOGGER.info(
                        "Cannot go up further in the bean factory hierarchy, parent bean factory doesn't implement ConfigurableListableBeanFactory");
                currentBeanFactory = null;
            }
        } else {
            currentBeanFactory = null;
        }
    } while (currentBeanFactory != null);

    for (Map.Entry<Class<?>, Map<String, SpringBeanDefinition>> entry : this.beanDefinitions.entrySet()) {
        Class<?> type = entry.getKey();
        Map<String, SpringBeanDefinition> definitions = entry.getValue();

        // Bind by name for each bean of this type and by type if there is no ambiguity
        for (SpringBeanDefinition candidate : definitions.values()) {
            if (debugEnabled) {
                LOGGER.info("Binding spring bean " + candidate.getName() + " by name and type "
                        + type.getCanonicalName());
            }

            bind(type).annotatedWith(Names.named(candidate.getName()))
                    .toProvider(new SpringBeanProvider(type, candidate.getName(), candidate.getBeanFactory()));
        }
    }
}

From source file:info.archinnov.achilles.query.slice.SliceQuery.java

public SliceQuery(Class<T> entityClass, EntityMeta meta, List<Object> partitionComponents,
        List<Object> clusteringsFrom, List<Object> clusteringsTo, OrderingMode ordering, BoundingMode bounding,
        ConsistencyLevel consistencyLevel, int limit, int batchSize, boolean limitSet) {

    this.limitSet = limitSet;
    Validator.validateTrue(CollectionUtils.isNotEmpty(partitionComponents),
            "Partition components should be set for slice query for entity class '%s'",
            entityClass.getCanonicalName());

    this.entityClass = entityClass;
    this.meta = meta;

    this.partitionComponents = partitionComponents;
    this.noComponent = clusteringsFrom.isEmpty() && clusteringsTo.isEmpty();

    PropertyMeta idMeta = meta.getIdMeta();

    List<Object> componentsFrom = new ArrayList<Object>();
    componentsFrom.addAll(partitionComponents);
    componentsFrom.addAll(clusteringsFrom);

    this.clusteringsFrom = idMeta.encodeToComponents(componentsFrom);

    List<Object> componentsTo = new ArrayList<>();
    componentsTo.addAll(partitionComponents);
    componentsTo.addAll(clusteringsTo);/*from  w ww.j a  v a2  s.c o  m*/

    this.clusteringsTo = idMeta.encodeToComponents(componentsTo);

    this.ordering = ordering;
    this.bounding = bounding;
    this.consistencyLevel = consistencyLevel;
    this.limit = limit;
    this.batchSize = batchSize;
}

From source file:info.archinnov.achilles.query.SliceQuery.java

public SliceQuery(Class<T> entityClass, EntityMeta meta, List<Object> partitionComponents,
        List<Object> clusteringsFrom, List<Object> clusteringsTo, OrderingMode ordering, BoundingMode bounding,
        ConsistencyLevel consistencyLevel, int limit, int batchSize, boolean limitSet) {

    this.limitSet = limitSet;
    Validator.validateTrue(CollectionUtils.isNotEmpty(partitionComponents),
            "Partition components should be set for slice query for entity class '%s'",
            entityClass.getCanonicalName());

    this.entityClass = entityClass;
    this.meta = meta;

    this.partitionComponents = partitionComponents;
    this.noComponent = clusteringsFrom.isEmpty() && clusteringsTo.isEmpty();

    PropertyMeta idMeta = meta.getIdMeta();

    List<Object> componentsFrom = new ArrayList<Object>();
    componentsFrom.addAll(partitionComponents);
    componentsFrom.addAll(clusteringsFrom);

    this.clusteringsFrom = idMeta.encodeToComponents(componentsFrom);

    List<Object> componentsTo = new ArrayList<Object>();
    componentsTo.addAll(partitionComponents);
    componentsTo.addAll(clusteringsTo);//from w w w .  ja v  a  2s .c om

    this.clusteringsTo = idMeta.encodeToComponents(componentsTo);

    this.ordering = ordering;
    this.bounding = bounding;
    this.consistencyLevel = consistencyLevel;
    this.limit = limit;
    this.batchSize = batchSize;
}