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:ca.uhn.fhir.context.ModelScanner.java

private void scanBlock(Class<? extends IBase> theClass) {
    ourLog.debug("Scanning resource block class: {}", theClass.getName());

    String resourceName = theClass.getCanonicalName();
    if (isBlank(resourceName)) {
        throw new ConfigurationException("Block type @" + Block.class.getSimpleName()
                + " annotation contains no name: " + theClass.getCanonicalName());
    }/*from   www  . java  2 s .  c  om*/

    RuntimeResourceBlockDefinition blockDef = new RuntimeResourceBlockDefinition(resourceName, theClass,
            isStandardType(theClass), myContext, myClassToElementDefinitions);
    myClassToElementDefinitions.put(theClass, blockDef);
}

From source file:org.agiso.tempel.core.DefaultTemplateExecutor.java

/**
 * @param value//from w  w  w  .j a v  a  2  s  .c  om
 * @param type
 * @param converter
 * @return
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object convertParamValue(Object value, String type, TemplateParamConverter converter) {
    Class<?> valueClass = (value == null ? null : value.getClass());
    ITemplateParamConverter typeConverter = converter.getInstance();
    if (typeConverter == null) {
        if (type == null || valueClass == null || type.equals(valueClass.getCanonicalName())) {
            return value;
        } else {
            Class<?> typeClass;
            if (paramTypes.containsKey(type)) {
                typeClass = paramTypes.get(type);
            } else {
                try {
                    typeClass = Class.forName(type);
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                }
            }
            for (ITemplateParamConverter<?, ?> paramConverter : paramConverters) {
                if (paramConverter.canConvert(valueClass, typeClass)) {
                    typeConverter = paramConverter;
                    break;
                }
            }
            if (typeConverter == null) {
                throw new RuntimeException("Brak konwertera dla parametru typu: " + type);
            }
        }
    }
    return typeConverter.convert(value);
}

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

protected <T> EntityMeta rawTypedQueryInternal(Class<T> entityClass, Statement statement,
        Object... boundValues) {//from  w w w.  j a v a  2  s.c om
    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.validateRawTypedQuery(entityClass, statement, meta);
    return meta;
}

From source file:me.st28.flexseries.flexcore.plugin.FlexPlugin.java

@Override
public final void onEnable() {
    // Mark plugin as enabling and start enabling registered modules.
    status = PluginStatus.ENABLING;//  w w  w  . j  a  va2s .c  o  m

    long loadStartTime = System.currentTimeMillis();

    // Register self as a listener if implemented.
    if (this instanceof Listener) {
        Bukkit.getPluginManager().registerEvents((Listener) this, this);
    }

    // Determine if the plugin has a configuration file or not, and save it if there is one.
    if (getResource("config.yml") != null) {
        saveDefaultConfig();
        getConfig().options().copyDefaults(true);
        saveConfig();

        hasConfig = true;
        reloadConfig();
    }

    // Load modules
    //TODO: Detect circular dependencies
    List<String> disabledDependencies = hasConfig ? getConfig().getStringList("disabled modules") : null;
    List<Class<? extends FlexModule>> loadOrder = new ArrayList<>();

    for (FlexModule module : modules.values()) {
        addToLoadOrder(loadOrder, module);
    }

    // !!DEBUG!! //
    StringBuilder loadOrderDebug = new StringBuilder("\n--MODULE LOAD ORDER--\n");
    for (Class<? extends FlexModule> clazz : loadOrder) {
        if (loadOrderDebug.length() > 0) {
            loadOrderDebug.append("\n");
        }
        loadOrderDebug.append(clazz.getCanonicalName());
    }
    loadOrderDebug.append("\n\n--MODULE LOAD ORDER--\n");

    LogHelper.debug(this, loadOrderDebug.toString());
    // !!DEBUG!! //

    // This monstrosity of a loop determines the order in which modules should be loaded and loads them in the appropriate order.
    _moduleLoop: // EWWWWWWWWWW. Yeah, I know.
    for (Class<? extends FlexModule> clazz : loadOrder) {
        FlexModule<?> module = modules.get(clazz);
        LogHelper.info(this, "Loading module: " + module.getIdentifier());

        // Check if the module is disabled via the configuration file.
        if (disabledDependencies != null && disabledDependencies.contains(module.getIdentifier())) {
            moduleStatuses.put(clazz, ModuleStatus.DISABLED_CONFIG);
            LogHelper.info(this, "Module '" + module.getIdentifier() + "' disabled via the config.");
            continue;
        }

        // Locate dependencies to make sure all are present.
        for (Class<? extends FlexModule> dep : module.getDependencies()) {
            // Checks if the dependency is present on the server.
            if (!REGISTERED_MODULES.containsKey(dep)) {
                moduleStatuses.put(clazz, ModuleStatus.DISABLED_DEPENDENCY);
                LogHelper.severe(this, "Unable to load module '" + module.getIdentifier() + "': dependency '"
                        + dep.getCanonicalName() + "' is not a valid module on the server.");
                continue _moduleLoop;
            }

            // Checks if the dependency is enabled.
            if (REGISTERED_MODULES.get(dep).getModuleStatus(dep) != ModuleStatus.ENABLED) {
                moduleStatuses.put(clazz, ModuleStatus.DISABLED_DEPENDENCY);
                LogHelper.severe(this, "Unable to load module '" + module.getIdentifier() + "': dependency '"
                        + dep.getCanonicalName() + "' is disabled.");
                continue _moduleLoop;
            }
        }

        // Attempts to load the module.
        try {
            module.loadAll();

            moduleStatuses.put(clazz, ModuleStatus.ENABLED);
            LogHelper.info(this, "Successfully loaded module: " + module.getIdentifier());
        } catch (Exception ex) {
            moduleStatuses.put(clazz, ModuleStatus.DISABLED_ERROR);
            LogHelper.severe(this, "An error occurred while loading module '" + module.getIdentifier() + "': "
                    + ex.getMessage());
            ex.printStackTrace();
        }

        if (moduleStatuses.get(clazz) != ModuleStatus.ENABLED) {
            modules.remove(clazz);
        }
    }

    // If the plugin has a messages.yml file, a MessageProvider will be created for it.
    if (getResource("messages.yml") != null) {
        MessageManager.registerMessageProvider(this);
    }

    // Attempts to enable the plugin.
    try {
        handlePluginEnable();
        handlePluginReload();
    } catch (Exception ex) {
        LogHelper.severe(this, "An error occurred while enabling: " + ex.getMessage());
        status = PluginStatus.LOADED_ERROR;
        ex.printStackTrace();
        return;
    }

    status = PluginStatus.ENABLED;
    LogHelper.info(this, String.format("%s v%s by %s ENABLED (%dms)", getName(), getDescription().getVersion(),
            getDescription().getAuthors(), System.currentTimeMillis() - loadStartTime));
}

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

/**
 * Registers the given model and controller with a database persister, getting the bucket name
 * from the @Table annotation on the model.
 *
 * @param model//from   www .j  av a  2 s  . co  m
 * @param controller
 * @param stash
 * @return
 */
public ModelController registerDbModel(Class<? extends Model> model,
        Class<? extends ModelController> controller, Class<? extends Stash> stash, String bucket) {
    Table anno = model.getAnnotation(Table.class);
    if (anno == null) {
        throw new UsageException("A @Table annotation is required on the model " + model.getCanonicalName()
                + " in order to register it.");
    }
    bucket = or(bucket, anno.name());
    String table = anno.name();
    DataAccessRegistration registration = new DataAccessRegistration().setDatabaseBacked(true)
            .setPersisterClass(DbPersister.class).setBucket(bucket).setTableName(table)
            .setControllerClass(controller).setStashClass(stash).setModelClass(model);
    return register(registration);
}

From source file:com.sqewd.open.dal.core.persistence.DataManager.java

private void initPersisters(final Element root) throws Exception {
    List<AbstractPersister> pers = new ArrayList<AbstractPersister>();

    NodeList pernl = XMLUtils.search(_CONFIG_PERSISTER_XPATH_, root);
    if (pernl != null && pernl.getLength() > 0) {
        for (int ii = 0; ii < pernl.getLength(); ii++) {
            Element pelm = (Element) pernl.item(ii);
            String vk = pelm.getAttribute(XMLUtils._PARAM_ATTR_NAME_);
            String cn = pelm.getAttribute(InstanceParam._PARAM_ATTR_CLASS_);
            InstanceParam ip = new InstanceParam(vk, cn);
            ip.parse(pelm);/* w  w w. j  a v  a  2  s  . com*/
            Class<?> cls = Class.forName(ip.getClassname());
            Object pobj = cls.newInstance();
            if (pobj instanceof AbstractPersister) {
                AbstractPersister ap = (AbstractPersister) pobj;
                ap.init(ip.getParams());
                persistmap.put(cls.getCanonicalName(), ap);
                persistmap.put(ap.key(), ap);
                pers.add(ap);
            } else
                throw new Exception("Invalid Configuration : Persister class [" + cls.getCanonicalName()
                        + "] does not extend [" + AbstractPersister.class.getCanonicalName() + "]");
        }
    }
    NodeList mapnl = XMLUtils.search(_CONFIG_PERSISTMAP_XPATH_, root);
    if (mapnl != null && mapnl.getLength() > 0) {
        for (int ii = 0; ii < mapnl.getLength(); ii++) {
            Element melm = (Element) mapnl.item(ii);
            String classname = melm.getAttribute(InstanceParam._PARAM_ATTR_CLASS_);
            if (classname == null || classname.isEmpty())
                throw new Exception("Invalid Configuration : Missing map parameter ["
                        + InstanceParam._PARAM_ATTR_CLASS_ + "]");
            String persister = melm.getAttribute(_CONFIG_ATTR_PERSISTER_);
            if (persister == null || persister.isEmpty())
                throw new Exception(
                        "Invalid Configuration : Missing map parameter [" + _CONFIG_ATTR_PERSISTER_ + "]");
            if (persistmap.containsKey(persister)) {
                persistmap.put(classname, persistmap.get(persister));
            } else
                throw new Exception(
                        "Invalid Configuration : Persister class [" + persister + "] does not exist.");
        }
    }
    for (AbstractPersister per : pers) {
        per.postinit();
    }
}

From source file:org.atteo.moonshine.springdata.SpringData.java

@Override
public Module configure() {
    return new PrivateModule() {
        @Override/*w  w  w .ja v  a 2  s. c  o m*/
        protected void configure() {
            bind(RepositoryFactorySupport.class).toProvider(new RepositoryFactoryProvider());

            if (Strings.isNullOrEmpty(packagePrefix)) {
                return;
            }
            Set<Class<?>> classes = new HashSet<>();
            for (Class<? extends Repository> klass : ClassIndex.getSubclasses(Repository.class)) {
                configureProvider(klass);
                classes.add(klass);
            }
            for (Class<?> klass : ClassIndex.getAnnotated(RepositoryDefinition.class)) {
                if (classes.contains(klass)) {
                    continue;
                }
                configureProvider(klass);
            }
        }

        private <T> void configureProvider(Class<T> klass) {
            if (klass.getAnnotation(NoRepositoryBean.class) != null) {
                return;
            }
            if (!klass.getCanonicalName().startsWith(packagePrefix + ".")) {
                return;
            }
            bind(klass).toProvider(new RepositoryProvider<>(klass));
            expose(klass);
        }
    };
}

From source file:com.impetus.kundera.persistence.AssociationBuilder.java

/**
 * Retrieves associated entities via running query into Lucene indexing.
 *//* w  ww. j  av  a  2  s.c  o  m*/
private List getAssociatedEntitiesFromLucene(Object entity, String entityId, Class<?> childClass,
        Client childClient) {
    List associatedEntities;
    // Lucene query, where entity class is child class, parent class is
    // entity's class
    // and parent Id is entity ID! that's it!
    String query = LuceneQueryUtils.getQuery(DocumentIndexer.PARENT_ID_CLASS,
            entity.getClass().getCanonicalName().toLowerCase(), DocumentIndexer.PARENT_ID_FIELD, entityId,
            childClass.getCanonicalName().toLowerCase());

    Map<String, String> results = childClient.getIndexManager().search(query);
    Set<String> rsSet = new HashSet<String>(results.values());

    if (childClass.equals(entity.getClass())) {
        associatedEntities = (List<Object>) childClient.findAll(childClass, rsSet.toArray(new String[] {}));
    } else {
        associatedEntities = (List<Object>) childClient.findAll(childClass, rsSet.toArray(new String[] {}));
    }
    return associatedEntities;
}

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

@Override
protected void withMethod(final Object bean, String beanName, Class<?> targetClass, final Method method) {
    if (method.getParameterTypes().length > 0) {
        throw new IllegalStateException(
                "Method " + method.getName() + " is annotated with @Gauge but requires parameters.");
    }/*from w  w  w.  j a va2s  . c  o m*/

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

    metrics.register(metricName, new com.codahale.metrics.Gauge<Object>() {
        @Override
        public Object getValue() {
            return ReflectionUtils.invokeMethod(method, bean);
        }
    });

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

From source file:org.openmrs.module.metadatamapping.api.db.hibernate.HibernateMetadataMappingDAO.java

@Override
public <T extends OpenmrsMetadata> T getMetadataItem(Class<T> type, String metadataSourceName,
        String metadataTermCode) {
    Criteria criteria = createSourceMetadataTermCriteria(metadataSourceName, null, metadataTermCode);
    MetadataTermMapping metadataTermMapping = (MetadataTermMapping) criteria.uniqueResult();

    T metadataItem = null;//from  ww  w .  j  a  v  a 2 s  .  com
    if (metadataTermMapping != null) {
        if (!type.getCanonicalName().equals(metadataTermMapping.getMetadataClass())) {
            throw new InvalidMetadataTypeException(
                    "requested type " + type + " of metadata term mapping " + metadataTermMapping.getUuid()
                            + " refers to type " + metadataTermMapping.getMetadataClass());
        }
        metadataItem = internalGetByUuid(type, metadataTermMapping.getMetadataUuid());
    }
    return metadataItem;
}