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.RuntimeCompositeDatatypeDefinition.java

public RuntimeCompositeDatatypeDefinition(DatatypeDef theDef,
        Class<? extends ICompositeType> theImplementingClass, boolean theStandardType, FhirContext theContext,
        Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
    super(theDef.name(), theImplementingClass, theStandardType, theContext, theClassToElementDefinitions);

    String resourceName = theDef.name();
    if (isBlank(resourceName)) {
        throw new ConfigurationException("Resource type @" + ResourceDef.class.getSimpleName()
                + " annotation contains no resource name: " + theImplementingClass.getCanonicalName());
    }// ww  w . ja  v  a2 s  .c  om

    mySpecialization = theDef.isSpecialization();
    myProfileOfType = theDef.profileOf();
    if (myProfileOfType.equals(IBaseDatatype.class)) {
        myProfileOfType = null;
    }

}

From source file:org.jsconf.core.ConfigurationFactory.java

public ConfigurationFactory withBean(String path, Class<?> bean, String id, boolean proxy) {
    Map<String, Object> properties = new HashMap<>(2);
    if (StringUtils.hasText(id)) {
        properties.put("\"" + ID + "\"", id);
    }/* w w w.j  a v  a 2 s.  c  o  m*/
    if (proxy) {
        properties.put("\"" + PROXY + "\"", true);
    }
    if (bean.isInterface()) {
        properties.put("\"" + INTERFACE + "\"", bean.getCanonicalName());
    } else {
        properties.put("\"" + CLASS + "\"", bean.getCanonicalName());
    }
    String[] splitedPath = path.split("/");
    Map<String, Map<String, ? extends Object>> object = new HashMap<>(2);
    object.put(splitedPath[splitedPath.length - 1], properties);
    for (int i = splitedPath.length - 2; i >= 0; i--) {
        Map<String, Map<String, ? extends Object>> child = object;
        object = new HashMap<>(2);
        object.put(splitedPath[i], child);
    }
    this.config = this.config.withFallback(ConfigFactory.parseMap(object));
    return this;
}

From source file:de.decoit.simu.cbor.ifmap.deserializer.IdentifierDeserializerManager.java

/**
 * Deserialize an object of the specified class from the specified data items.
 * The attributes and nested tags arrays may be empty but never null.
 *
 * @param <T> Type of the object to be deserialized, must be a subclass of {@link AbstractIdentifier}
 * @param namespace CBOR data item representing the element namespace
 * @param cborName CBOR data item representing the element name
 * @param attributes CBOR array data item containing the element's attributes
 * @param nestedTags CBOR array data item containing the element's nested tags
 * @param identifierType Type of the object to be deserialized
 * @return The deserialized object/* w  w  w .jav  a  2  s. co m*/
 * @throws CBORDeserializationException if deserialization failed
 */
public static <T extends AbstractIdentifier> T deserialize(final DataItem namespace, final DataItem cborName,
        final Array attributes, final Array nestedTags, final Class<T> identifierType)
        throws CBORDeserializationException {
    if (namespace == null) {
        throw new IllegalArgumentException("Namespace must not be null");
    }

    if (cborName == null) {
        throw new IllegalArgumentException("CBOR name must not be null");
    }

    if (attributes == null) {
        throw new IllegalArgumentException("Attributes array must not be null");
    }

    if (nestedTags == null) {
        throw new IllegalArgumentException("Nested tags array must not be null");
    }

    if (identifierType == null) {
        throw new IllegalArgumentException("Target identifier type must not be null");
    }

    try {
        // If default deserializers were not registered yet, do so
        if (!initialized) {
            init();
        }

        // Check if a deserializer for this type was registered
        if (registeredDeserializers.containsKey(identifierType)) {
            DictionarySimpleElement elementEntry = getTopLevelElement(namespace, cborName);

            return identifierType.cast(registeredDeserializers.get(identifierType).deserialize(attributes,
                    nestedTags, elementEntry));
        }

        // If no deserializer was found, fail with exception
        throw new UnsupportedOperationException(
                "Cannot deserialize class: " + identifierType.getCanonicalName());
    } catch (RuntimeException ex) {
        throw new CBORDeserializationException(
                "RuntimeException during deserialization, see nested exception" + "for details", ex);
    }
}

From source file:com.netflix.genie.web.services.impl.JobSpecificationServiceImpl.java

private Cluster selectClusterWithLoadBalancer(final Set<Tag> counterTags, final Set<Cluster> clusters,
        final String id, final JobRequest jobRequest) throws GeniePreconditionException {
    Cluster cluster = null;/*from  w  w  w .j a v a 2s . c o m*/
    for (final ClusterLoadBalancer loadBalancer : this.clusterLoadBalancers) {
        final String loadBalancerClass;
        if (loadBalancer instanceof TargetClassAware) {
            final Class<?> targetClass = ((TargetClassAware) loadBalancer).getTargetClass();
            if (targetClass != null) {
                loadBalancerClass = targetClass.getCanonicalName();
            } else {
                loadBalancerClass = loadBalancer.getClass().getCanonicalName();
            }
        } else {
            loadBalancerClass = loadBalancer.getClass().getCanonicalName();
        }
        counterTags.add(Tag.of(MetricsConstants.TagKeys.CLASS_NAME, loadBalancerClass));
        try {
            final Cluster selectedCluster = loadBalancer.selectCluster(clusters,
                    this.toV3JobRequest(id, jobRequest));
            if (selectedCluster != null) {
                // Make sure the cluster existed in the original list of clusters
                if (clusters.contains(selectedCluster)) {
                    log.debug("Successfully selected cluster {} using load balancer {}",
                            selectedCluster.getId(), loadBalancerClass);
                    counterTags.add(Tag.of(MetricsConstants.TagKeys.STATUS, LOAD_BALANCER_STATUS_SUCCESS));
                    this.registry.counter(SELECT_LOAD_BALANCER_COUNTER_NAME, counterTags).increment();
                    cluster = selectedCluster;
                    break;
                } else {
                    log.error(
                            "Successfully selected cluster {} using load balancer {} but it wasn't in original cluster "
                                    + "list {}",
                            selectedCluster.getId(), loadBalancerClass, clusters);
                    counterTags.add(Tag.of(MetricsConstants.TagKeys.STATUS, LOAD_BALANCER_STATUS_INVALID));
                    this.registry.counter(SELECT_LOAD_BALANCER_COUNTER_NAME, counterTags).increment();
                }
            } else {
                counterTags.add(Tag.of(MetricsConstants.TagKeys.STATUS, LOAD_BALANCER_STATUS_NO_PREFERENCE));
                this.registry.counter(SELECT_LOAD_BALANCER_COUNTER_NAME, counterTags).increment();
            }
        } catch (final Exception e) {
            log.error("Cluster load balancer {} threw exception:", loadBalancer, e);
            counterTags.add(Tag.of(MetricsConstants.TagKeys.STATUS, LOAD_BALANCER_STATUS_EXCEPTION));
            this.registry.counter(SELECT_LOAD_BALANCER_COUNTER_NAME, counterTags).increment();
        }
    }

    // Make sure we selected a cluster
    if (cluster == null) {
        this.noClusterSelectedCounter.increment();
        throw new GeniePreconditionException(
                "Unable to select a cluster from using any of the available load balancer's.");
    }

    return cluster;
}

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

protected <T> T getProxyInternal(final Class<T> entityClass, final Object primaryKey, Options options) {
    Validator.validateNotNull(entityClass, "Entity class should not be null for get proxy");
    Validator.validateNotNull(primaryKey, "Entity primaryKey should not be null for get proxy");
    Validator.validateTrue(entityMetaMap.containsKey(entityClass),
            "The entity class '%s' is not managed by Achilles", entityClass.getCanonicalName());

    optionsValidator.validateNoAsyncListener(options);
    PersistenceManagerOperations context = initPersistenceContext(entityClass, primaryKey, options);
    entityValidator.validatePrimaryKey(context.getIdMeta(), primaryKey);
    return context.getProxy(entityClass);
}

From source file:com.mirth.connect.server.MirthWebServer.java

private String joinClasses(Set<Class<?>> classes) {
    StringBuilder builder = new StringBuilder();

    if (CollectionUtils.isNotEmpty(classes)) {
        boolean added = false;
        for (Class<?> clazz : classes) {
            if (clazz != null) {
                String name = clazz.getCanonicalName();
                if (name != null) {
                    if (added) {
                        builder.append(',');
                    }//w  w  w.  j  av  a  2 s .  co m
                    builder.append(name);
                    added = true;
                }
            }
        }
    }

    return builder.toString();
}

From source file:edu.harvard.i2b2.fhir.query.nonx.SearchParameterMap.java

public SearchParameter getSearchParameter(Class c, String parName) throws FhirCoreException {

    for (SearchParameter sp : list) {
        //logger.trace("sp:" + sp);
        String resourceClassString = sp.getBase().getValue();
        Class foundClass = FhirUtil.getResourceClass(resourceClassString);
        String foundName = sp.getName().getValue();

        if (c.equals(foundClass) && foundName.equals(parName)) {
            return sp;
        }/*from   w w  w . j a v a2 s.com*/
    }
    throw new FhirCoreException(
            "No SearchParameterSearchParam found for class:" + c.getCanonicalName() + " for param:" + parName);
}

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

/**
 * @param clazz class to find the type//from w ww  .j av a  2 s . c om
 *
 * @return the {@link JClassType} denoted by the class given in parameter
 */
private JClassType findClassType(Class<?> clazz) {
    JClassType mapperType = context.getTypeOracle().findType(clazz.getCanonicalName());
    if (null == mapperType) {
        logger.log(Type.WARN, "Cannot find the type denoted by the class " + clazz.getCanonicalName());
        return null;
    }
    return mapperType;
}

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

protected <T> T getProxyForUpdateInternal(final Class<T> entityClass, final Object primaryKey) {
    Validator.validateNotNull(entityClass, "Entity class should not be null for get proxy for update");
    Validator.validateNotNull(primaryKey, "Entity primaryKey should not be null for get proxy for update");
    Validator.validateTrue(entityMetaMap.containsKey(entityClass),
            "The entity class '%s' is not managed by Achilles", entityClass.getCanonicalName());

    PersistenceManagerOperations context = initPersistenceContext(entityClass, primaryKey, noOptions());
    entityValidator.validatePrimaryKey(context.getIdMeta(), primaryKey);
    return context.getProxyForUpdate(entityClass);
}

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

public static int loadFormAdapters(ServletContext servletContext) throws Exception {

    int adapterCount = 0;

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

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

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

    // create a filter for finding .formadapter.xml files
    FilenameFilter xmlFilenameFilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".formadapter.xml");
        }/*from   ww  w.j  a  v a2 s . c om*/
    };

    // create a schema object for the xsd
    Schema schema = _schemaFactory
            .newSchema(new File(servletContext.getRealPath("/WEB-INF/schemas/") + "/formAdapter.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 jsonFormAdapter = org.json.XML.toJSONObject(xml).getJSONObject("formAdapter");

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

        // add to our collection
        jsonAdapters.put(jsonFormAdapter);

        // increment the count
        adapterCount++;

    }

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

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

    _logger.info(adapterCount + " form adapters loaded in .formAdapter.xml files");

    return adapterCount;

}