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.entity.parsing.EmbeddedIdParser.java

private Map<Integer, Field> extractComponentsOrdering(Class<?> embeddedIdClass) {

    String embeddedIdClassName = embeddedIdClass.getCanonicalName();
    Map<Integer, Field> components = new TreeMap<Integer, Field>();

    @SuppressWarnings("unchecked")
    Set<Field> candidateFields = getFields(embeddedIdClass, ReflectionUtils.<Field>withAnnotation(Order.class));

    Set<Integer> orders = new HashSet<Integer>();
    int orderSum = 0;
    int componentCount = candidateFields.size();

    for (Field candidateField : candidateFields) {
        Order orderAnnotation = candidateField.getAnnotation(Order.class);
        int order = orderAnnotation.value();
        Class<?> componentType = candidateField.getType();
        orderSum = validateNoDuplicateOrderAndType(embeddedIdClassName, orders, orderSum, order, componentType);
        components.put(order, candidateField);
    }/*from www  . jav  a2s .co  m*/

    validateConsistentOrdering(embeddedIdClassName, orderSum, componentCount);
    Validator.validateBeanMappingTrue(componentCount > 1,
            "There should be at least 2 fields annotated with @Order for the @EmbeddedId class '%s'",
            embeddedIdClass.getCanonicalName());
    return components;

}

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

public EmbeddedIdProperties parseEmbeddedId(Class<?> embeddedIdClass) {
    log.debug("Parse embedded id class {} ", embeddedIdClass.getCanonicalName());

    checkForDefaultConstructor(embeddedIdClass);

    Map<Integer, Field> components = extractComponentsOrdering(embeddedIdClass);
    Integer reversedField = extractReversedClusteredKey(embeddedIdClass);
    validateConsistentPartitionKeys(components, embeddedIdClass.getCanonicalName());
    validateReversedClusteredKey(components, reversedField, embeddedIdClass.getCanonicalName());
    EmbeddedIdProperties embeddedIdProperties = buildComponentMetas(embeddedIdClass, components, reversedField);

    log.trace("Built embeddedId properties : {}", embeddedIdProperties);
    return embeddedIdProperties;
}

From source file:com.delphix.session.module.rmi.RmiTestServer.java

@Override
protected ProtocolHandlerFactory getProtocolHandlerFactory() {
    return new ProtocolHandlerFactory() {
        @Override/* w  w w .j  a v  a 2 s . co  m*/
        public List<? extends ProtocolHandler<?>> getHandlers(ServiceTerminus terminus) {
            return ImmutableList.of(rmiFactory.createServer(new ObjectCreator() {
                @Override
                public <T> T create(Class<T> type) {
                    T obj = objs.getInstance(type);
                    if (obj == null) {
                        throw new RuntimeException(
                                "test did not add() object of type " + type.getCanonicalName());
                    }
                    return obj;
                }
            }));
        }
    };
}

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

public List<Field> getInheritedPrivateFields(Class<?> type) {
    log.debug("Find inherited private fields from hierarchy for entity class {}", type.getCanonicalName());

    List<Field> fields = new ArrayList<Field>();

    Class<?> i = type;/*from  w ww .  j ava  2  s  .  c  o m*/
    while (i != null && i != Object.class) {
        for (Field declaredField : i.getDeclaredFields()) {
            if (filter.matches(declaredField)) {
                fields.add(declaredField);
            }
        }
        i = i.getSuperclass();
    }
    if (log.isTraceEnabled()) {
        log.trace("Found inherited private fields : {}", Lists.transform(fields, fieldToStringFn));
    }
    return fields;
}

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

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

    Method[] accessors = new Method[2];

    accessors[0] = findGetter(beanClass, field);
    accessors[1] = findSetter(beanClass, field);

    return accessors;
}

From source file:gobblin.instrumented.Instrumented.java

/**
 * Get a {@link gobblin.metrics.MetricContext} to be used by an object needing instrumentation.
 *
 * <p>//from w  w  w.j  av a 2 s  .  co  m
 * This method will read the property "metrics.context.name" from the input State, and will attempt
 * to find a MetricContext with that name in the global instance of {@link gobblin.metrics.GobblinMetricsRegistry}.
 * If it succeeds, the generated MetricContext will be a child of the retrieved Context, otherwise it will
 * be a parent-less context.
 * </p>
 * <p>
 * The method will automatically add two tags to the context:
 * <ul>
 *  <li> construct will contain the name of the {@link gobblin.Constructs} that klazz represents. </li>
 *  <li> class will contain the canonical name of the input class. </li>
 * </ul>
 * </p>
 *
 * @param state {@link gobblin.configuration.State} used to find the parent MetricContext.
 * @param klazz Class of the object needing instrumentation.
 * @param tags Additional tags to add to the returned context.
 * @return A {@link gobblin.metrics.MetricContext} with the appropriate tags and parent.
 */
public static MetricContext getMetricContext(State state, Class<?> klazz, List<Tag<?>> tags) {
    int randomId = RAND.nextInt(Integer.MAX_VALUE);

    List<Tag<?>> generatedTags = Lists.newArrayList();
    Constructs construct = null;
    if (Converter.class.isAssignableFrom(klazz)) {
        construct = Constructs.CONVERTER;
    } else if (ForkOperator.class.isAssignableFrom(klazz)) {
        construct = Constructs.FORK_OPERATOR;
    } else if (RowLevelPolicy.class.isAssignableFrom(klazz)) {
        construct = Constructs.ROW_QUALITY_CHECKER;
    } else if (Extractor.class.isAssignableFrom(klazz)) {
        construct = Constructs.EXTRACTOR;
    } else if (DataWriter.class.isAssignableFrom(klazz)) {
        construct = Constructs.WRITER;
    }

    if (construct != null) {
        generatedTags.add(new Tag<>(GobblinMetricsKeys.CONSTRUCT_META, construct.toString()));
    }
    if (!klazz.isAnonymousClass()) {
        generatedTags.add(new Tag<>(GobblinMetricsKeys.CLASS_META, klazz.getCanonicalName()));
    }

    Optional<GobblinMetrics> gobblinMetrics = state.contains(METRIC_CONTEXT_NAME_KEY)
            ? GobblinMetricsRegistry.getInstance().get(state.getProp(METRIC_CONTEXT_NAME_KEY))
            : Optional.<GobblinMetrics>absent();

    MetricContext.Builder builder = gobblinMetrics.isPresent()
            ? gobblinMetrics.get().getMetricContext().childBuilder(klazz.getCanonicalName() + "." + randomId)
            : MetricContext.builder(klazz.getCanonicalName() + "." + randomId);
    return builder.addTags(generatedTags).addTags(tags).build();
}

From source file:org.apache.usergrid.chop.runner.drivers.ResultsLog.java

/**
 * Sets up the JSON preamble to start streaming results into the entity. This must be
 * protected via isOpen. This is an unsafe call, make sure you know how it is used.
 *///from   w  w w.  ja  v  a  2  s  .  c o m
private void setupJsonStream() throws IOException {
    Class<?> testClass = tracker.getTestClass();
    jgen.writeStartObject();
    jgen.writeStringField("testClass", testClass.getCanonicalName());
    jgen.writeNumberField("startTime", tracker.getStartTime());

    if (testClass.isAnnotationPresent(TimeChop.class)) {
        jgen.writeStringField("chopType", "TimeChop");
        jgen.writeObjectField("chopParameters", testClass.getAnnotation(TimeChop.class));
    } else if (tracker.getTestClass().isAnnotationPresent(IterationChop.class)) {
        jgen.writeStringField("chopType", "IterationChop");
        jgen.writeObjectField("chopParameters", testClass.getAnnotation(IterationChop.class));
    } else {
        throw new IllegalStateException(
                "Supplied testClass " + testClass.getCanonicalName() + "has no chop annotation.");
    }

    jgen.writeFieldName("runResults");
    jgen.writeStartArray();
    jgen.flush();
}

From source file:com.mmnaseri.dragonfly.runtime.repo.impl.CrudRepositoryContext.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    for (int i = 0; i < repositories.size(); i++) {
        Class repository = repositories.get(i);
        final Class[] typeArguments = ClassUtils.resolveTypeArguments(repository, EntityRepository.class);
        if (Object.class.equals(typeArguments[0])) {
            log.info("Discarding repository " + repository.getCanonicalName()
                    + " because it is not bound tightly enough");
            continue;
        }/*from  w ww .jav  a 2  s  . c  o  m*/
        log.info("Registering repository " + repository.getSimpleName() + " for entities of type "
                + typeArguments[0].getCanonicalName());
        beanFactory.registerSingleton("_repo" + repository.getSimpleName() + i, Enhancer.create(Object.class,
                new Class[] { repository },
                new CrudRepositoryInterceptor(beanFactory, repository, typeArguments[0], typeArguments[1])));
    }
}

From source file:com.delphix.session.module.rmi.impl.RmiFactoryImpl.java

@Override
public RmiProtocolServer createServer() {
    return createServer(new ObjectCreator() {

        @Override// w  ww .ja va  2  s. c  o  m
        public <T> T create(Class<T> type) {
            String[] names = context.getBeanNamesForType(type);
            if (names.length == 0) {
                throw new RuntimeException("there is no spring bean of type " + type.getCanonicalName());
            } else if (names.length > 1) {
                throw new RuntimeException(
                        "there is more than one spring bean of type " + type.getCanonicalName());
            }

            if (!context.isPrototype(names[0])) {
                throw new RuntimeException(String.format("the spring bean '%s' of type '%s' is not a prototype",
                        names[0], type.getCanonicalName()));
            }

            return type.cast(context.getBean(names[0]));
        }
    });
}

From source file:com.vaadin.spring.server.SpringUIProvider.java

@SuppressWarnings("unchecked")
protected void detectUIs() {
    logger.info("Checking the application context for Vaadin UIs");
    final String[] uiBeanNames = getWebApplicationContext().getBeanNamesForAnnotation(SpringUI.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;
            String tempPath = deriveMappingForUI(uiBeanName);
            if (tempPath.length() > 0 && !tempPath.startsWith("/")) {
                path = "/".concat(tempPath);
            } else {
                // remove terminal slash from mapping
                path = tempPath.replaceAll("/$", "");
            }/*  w w w. ja  v  a2 s . c o  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);
        }
    }
}