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.persistence.AbstractPersistenceManager.java

protected <T> AchillesFuture<T> asyncFind(final Class<T> entityClass, final Object primaryKey,
        Options options) {/*from   www.  ja  va 2 s .c  om*/
    Validator.validateNotNull(entityClass, "Entity class should not be null for find by id");
    Validator.validateNotNull(primaryKey, "Entity primaryKey should not be null for find by id");
    Validator.validateTrue(entityMetaMap.containsKey(entityClass),
            "The entity class '%s' is not managed by Achilles", entityClass.getCanonicalName());
    Validator.validateTrue(entityMetaMap.containsKey(entityClass),
            "The entity class '%s' is not managed by Achilles", entityClass.getCanonicalName());
    PersistenceManagerOperations context = initPersistenceContext(entityClass, primaryKey, options);
    entityValidator.validatePrimaryKey(context.getIdMeta(), primaryKey);
    return context.find(entityClass);
}

From source file:com.thoughtworks.go.plugin.infra.FelixGoPluginOSGiFramework.java

private <T> ServiceReference<T> validateAndGetTheOnlyReferenceWithGivenSymbolicName(
        Collection<ServiceReference<T>> matchingServiceReferences, Class<T> serviceReference, String pluginId) {
    if (matchingServiceReferences.isEmpty()) {
        throw new GoPluginFrameworkException(format(
                "No reference found for the given Service Reference: %s and Plugin Id %s. It is likely that the plugin is missing.",
                serviceReference.getCanonicalName(), pluginId));
    }//  ww  w .j  a va2  s  .  c o  m

    if (matchingServiceReferences.size() > 1) {
        throw new GoPluginFrameworkException(format(
                "More than one reference found for the given "
                        + "Service Reference: %s and Plugin Id %s; References: %s",
                serviceReference.getCanonicalName(), pluginId, matchingServiceReferences));
    }

    return matchingServiceReferences.iterator().next();
}

From source file:com.rapid.server.RapidServletContextListener.java

public static int loadSecurityAdapters(ServletContext servletContext) throws Exception {

    int adapterCount = 0;

    // retain our class constructors in a hashtable - this speeds up initialisation
    HashMap<String, Constructor> securityConstructors = new HashMap<String, Constructor>();

    // create a JSON Array object which will hold json for all of the available security adapters
    JSONArray jsonSecurityAdapters = new JSONArray();

    // get the directory in which the control xml files are stored
    File dir = new File(servletContext.getRealPath("/WEB-INF/security/"));

    // create a filter for finding .securityadapter.xml files
    FilenameFilter xmlFilenameFilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".securityadapter.xml");
        }//from  ww  w .  j  av a 2s  .c o  m
    };

    // create a schema object for the xsd
    Schema schema = _schemaFactory
            .newSchema(new File(servletContext.getRealPath("/WEB-INF/schemas/") + "/securityAdapter.xsd"));
    // create a validator
    Validator validator = schema.newValidator();

    // loop the xml files in the folder
    for (File xmlFile : dir.listFiles(xmlFilenameFilter)) {

        // read the xml into a string
        String xml = Strings.getString(xmlFile);

        // validate the control xml file against the schema
        validator.validate(new StreamSource(new ByteArrayInputStream(xml.getBytes("UTF-8"))));

        // convert the string into JSON
        JSONObject jsonSecurityAdapter = org.json.XML.toJSONObject(xml).getJSONObject("securityAdapter");

        // get the type from the json
        String type = jsonSecurityAdapter.getString("type");
        // get the class name from the json
        String className = jsonSecurityAdapter.getString("class");
        // get the class 
        Class classClass = Class.forName(className);
        // check the class extends com.rapid.security.SecurityAdapter
        if (!Classes.extendsClass(classClass, com.rapid.security.SecurityAdapter.class))
            throw new Exception(type + " security adapter class " + classClass.getCanonicalName()
                    + " must extend com.rapid.security.SecurityAdapter");
        // check this type is unique
        if (securityConstructors.get(type) != null)
            throw new Exception(type + " security adapter already loaded. Type names must be unique.");
        // add to constructors hashmap referenced by type
        securityConstructors.put(type, classClass.getConstructor(ServletContext.class, Application.class));

        // add to our collection
        jsonSecurityAdapters.put(jsonSecurityAdapter);

        // increment the count
        adapterCount++;

    }

    // put the jsonControls in a context attribute (this is available via the getJsonActions method in RapidHttpServlet)
    servletContext.setAttribute("jsonSecurityAdapters", jsonSecurityAdapters);

    // put the constructors hashmapin a context attribute (this is available via the getContructor method in RapidHttpServlet)
    servletContext.setAttribute("securityConstructors", securityConstructors);

    _logger.info(adapterCount + " security adapters loaded in .securityAdapter.xml files");

    return adapterCount;

}

From source file:com.strandls.alchemy.rest.client.stubgenerator.RestProxyGenerator.java

/**
 * Generate service stubs./*from  ww w.java 2 s.  c om*/
 *
 * @throws IOException
 */
private void generateServiceStubs() throws IOException {
    final ServiceStubGenerator stubGenerator = new ServiceStubGenerator(new RestInterfaceAnalyzer());

    final File generatedSourceDirectory = outputDir;

    final Set<Class<?>> classes = getServiceClasses();
    @Cleanup
    final FileCodeWriter codeWriter = new FileCodeWriter(generatedSourceDirectory);

    log("Generating service stubs", Project.MSG_ERR);

    for (final Class<?> klass : classes) {
        final String stubClassName = getStubClassName(klass);
        try {

            stubGenerator.generateStubInterface(klass, stubClassName, destinationPackage, codeWriter);
            log("Generated " + stubClassName, Project.MSG_INFO);
        } catch (final Exception e) {
            log("Stub generation failed for " + klass.getCanonicalName(), Project.MSG_ERR);
            throw new RuntimeException(e);
        }
    }
}

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

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
    if (bean instanceof AopInfrastructureBean) {
        return bean;
    }/*from  w w  w .  j a v a2s  . co m*/

    final Class<?> targetClass = AopUtils.getTargetClass(bean);

    if (AopUtils.canApply(pointcut, targetClass)) {
        final Advice advice = adviceFactory.getAdvice(bean, targetClass);
        final Advisor advisor = new DefaultPointcutAdvisor(pointcut, advice);

        if (bean instanceof Advised) {
            LOG.debug("Bean {} is already proxied, adding Advisor to existing proxy", beanName);

            ((Advised) bean).addAdvisor(0, advisor);

            return bean;
        } else {
            LOG.debug("Proxying bean {} of type {}", beanName, targetClass.getCanonicalName());

            final ProxyFactory proxyFactory = new ProxyFactory(bean);
            if (proxyConfig != null) {
                proxyFactory.copyFrom(proxyConfig);
            }
            proxyFactory.addAdvisor(advisor);

            final Object proxy = proxyFactory.getProxy(this.beanClassLoader);

            return proxy;
        }
    }

    return bean;
}

From source file:com.github.nmorel.gwtjackson.rebind.RebindConfiguration.java

/**
 * @param clazz class to find the type/*from ww w  . j ava 2 s  . c o  m*/
 *
 * @return the {@link JType} denoted by the class given in parameter
 */

private JType findType(Class<?> clazz) {
    if (clazz.isPrimitive()) {

        return JPrimitiveType.parse(clazz.getCanonicalName());

    } else if (clazz.isArray()) {

        try {
            return context.getTypeOracle().parse(clazz.getCanonicalName());
        } catch (TypeOracleException e) {
            logger.log(TreeLogger.WARN,
                    "Cannot find the array denoted by the class " + clazz.getCanonicalName());
            return null;
        }

    } else {
        return findClassType(clazz);
    }
}

From source file:com.rapid.server.RapidServletContextListener.java

public static int loadConnectionAdapters(ServletContext servletContext) throws Exception {

    int adapterCount = 0;

    // retain our class constructors in a hashtable - this speeds up initialisation
    HashMap<String, Constructor> connectionConstructors = new HashMap<String, Constructor>();

    // create an array list of json objects which we will sort later according to the order
    ArrayList<JSONObject> connectionAdapters = new ArrayList<JSONObject>();

    // get the directory in which the control xml files are stored
    File dir = new File(servletContext.getRealPath("/WEB-INF/database/"));

    // create a filter for finding .control.xml files
    FilenameFilter xmlFilenameFilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".connectionadapter.xml");
        }/*from w  w w.  j  a va  2  s  . co m*/
    };

    // create a schema object for the xsd
    Schema schema = _schemaFactory
            .newSchema(new File(servletContext.getRealPath("/WEB-INF/schemas/") + "/connectionAdapter.xsd"));
    // create a validator
    Validator validator = schema.newValidator();

    // loop the xml files in the folder
    for (File xmlFile : dir.listFiles(xmlFilenameFilter)) {

        // read the xml into a string
        String xml = Strings.getString(xmlFile);

        // validate the control xml file against the schema
        validator.validate(new StreamSource(new ByteArrayInputStream(xml.getBytes("UTF-8"))));

        // convert the string into JSON
        JSONObject jsonConnectionAdapter = org.json.XML.toJSONObject(xml).getJSONObject("connectionAdapter");

        // get the class name from the json
        String className = jsonConnectionAdapter.getString("class");
        // get the class 
        Class classClass = Class.forName(className);
        // check the class extends com.rapid.data.ConnectionAdapter
        if (!Classes.extendsClass(classClass, com.rapid.data.ConnectionAdapter.class))
            throw new Exception(
                    classClass.getCanonicalName() + " must extend com.rapid.data.ConnectionAdapter");
        // check this class is unique
        if (connectionConstructors.get(className) != null)
            throw new Exception(className + " connection adapter already loaded.");
        // add to constructors hashmap referenced by type
        connectionConstructors.put(className, classClass.getConstructor(ServletContext.class, String.class,
                String.class, String.class, String.class));

        // add to to our array list
        connectionAdapters.add(jsonConnectionAdapter);

        // increment the count
        adapterCount++;

    }

    // sort the connection adapters according to their order property
    Collections.sort(connectionAdapters, new Comparator<JSONObject>() {
        @Override
        public int compare(JSONObject o1, JSONObject o2) {
            try {
                return o1.getInt("order") - o2.getInt("order");
            } catch (JSONException e) {
                return 999;
            }
        }
    });

    // create a JSON Array object which will hold json for all of the available security adapters
    JSONArray jsonConnectionAdapters = new JSONArray();

    // loop the sorted connection adapters and add to the json array
    for (JSONObject jsonConnectionAdapter : connectionAdapters)
        jsonConnectionAdapters.put(jsonConnectionAdapter);

    // put the jsonControls in a context attribute (this is available via the getJsonActions method in RapidHttpServlet)
    servletContext.setAttribute("jsonConnectionAdapters", jsonConnectionAdapters);

    // put the constructors hashmapin a context attribute (this is available via the getContructor method in RapidHttpServlet)
    servletContext.setAttribute("securityConstructors", connectionConstructors);

    _logger.info(adapterCount + " connection adapters loaded in .connectionAdapter.xml files");

    return adapterCount;

}

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

private Criteria createSourceMetadataTermCriteria(String metadataSourceName, Class<?> metadataClass,
        String metadataTermCode) {
    Criteria criteria = getCurrentSession().createCriteria(MetadataTermMapping.class)
            .add(Restrictions.eq("retired", false));
    if (metadataClass != null) {
        criteria.add(Restrictions.eq("metadataClass", metadataClass.getCanonicalName()));
    }/*from  w  ww.j  av a  2  s  .  co  m*/
    if (metadataTermCode != null) {
        criteria.add(Restrictions.eq("code", metadataTermCode));
    }

    criteria = criteria.createCriteria("metadataSource").add(Restrictions.eq("name", metadataSourceName));

    return criteria;
}

From source file:com.simiacryptus.mindseye.lang.Layer.java

/**
 * As t./*from   ww w . j a  va2 s.  c om*/
 *
 * @param <T>         the type parameter
 * @param targetClass the target class
 * @return the t
 */
@Nonnull
@SuppressWarnings("unchecked")
default <T extends Layer> T as(@Nonnull final Class<T> targetClass) {
    @Nonnull
    HashMap<CharSequence, byte[]> resources = new HashMap<>();
    final JsonObject json = getJson(resources, SerialPrecision.Double);
    json.remove("class");
    json.addProperty("class", targetClass.getCanonicalName());
    return (T) fromJson(json, resources);
}

From source file:com.nxttxn.vramel.impl.converter.AnnotationTypeConverterLoader.java

private CachingInjector<?> handleHasConverterAnnotation(TypeConverterRegistry registry, Class<?> type,
        CachingInjector<?> injector, Method method) {
    if (isValidConverterMethod(method)) {
        int modifiers = method.getModifiers();
        if (isAbstract(modifiers) || !isPublic(modifiers)) {
            LOG.warn("Ignoring bad converter on type: " + type.getCanonicalName() + " method: " + method
                    + " as a converter method is not a public and concrete method");
        } else {/*from ww w.  j  a v  a2s. com*/
            Class<?> toType = method.getReturnType();
            if (toType.equals(Void.class)) {
                LOG.warn("Ignoring bad converter on type: " + type.getCanonicalName() + " method: " + method
                        + " as a converter method returns a void method");
            } else {
                Class<?> fromType = method.getParameterTypes()[0];
                if (isStatic(modifiers)) {
                    registerTypeConverter(registry, method, toType, fromType,
                            new StaticMethodTypeConverter(method));
                } else {
                    if (injector == null) {
                        injector = new CachingInjector<Object>(registry, CastUtils.cast(type, Object.class));
                    }
                    registerTypeConverter(registry, method, toType, fromType,
                            new InstanceMethodTypeConverter(injector, method, registry));
                }
            }
        }
    } else {
        LOG.warn("Ignoring bad converter on type: " + type.getCanonicalName() + " method: " + method
                + " as a converter method should have one parameter");
    }
    return injector;
}