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:io.swagger.inflector.processors.JacksonProcessor.java

@Override
public Object process(MediaType mediaType, InputStream entityStream, Class<?> cls) throws ConversionException {
    try {/*  w  w w.  ja  v  a  2s . com*/
        if (String.class.equals(cls)) {
            OutputStream outputStream = new ByteArrayOutputStream();
            IOUtils.copy(entityStream, outputStream);
            return outputStream.toString();
        }
        if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)) {
            return Json.mapper().readValue(entityStream, cls);
        }
        if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaType)) {
            return XML.readValue(entityStream, cls);
        }
        if (APPLICATION_YAML_TYPE.isCompatible(mediaType)) {
            return Yaml.mapper().readValue(entityStream, cls);
        }
    } catch (Exception e) {
        LOGGER.trace(
                "unable to extract entity from content-type `" + mediaType + "` to " + cls.getCanonicalName(),
                e);
        throw new ConversionException().message(new ValidationMessage().code(ValidationError.UNACCEPTABLE_VALUE)
                .message("unable to convert input to " + cls.getCanonicalName()));
    }

    return null;
}

From source file:com.link_intersystems.lang.reflect.ReflectFacade.java

/**
 * {@inheritDoc}// w w  w  .j av  a  2s  .c  o  m
 * <p>
 * Compares two {@link Class}es by their canonical name.
 * </p>
 *
 * @since 1.0.0.0
 */
public int compare(Class<?> o1, Class<?> o2) {
    int compareValue = 0;
    if (o1 == null) {
        if (o2 == null) {
            compareValue = 0;
        } else {
            compareValue = -1;
        }
    } else {
        if (o2 == null) {
            compareValue = 1;
        } else {
            String canonicalName1 = o1.getCanonicalName();
            String canonicalName2 = o2.getCanonicalName();
            compareValue = canonicalName1.compareTo(canonicalName2);
        }
    }
    return compareValue;
}

From source file:plugins.PlayReader.java

public String getFullMethodName(Class clazz, Method method) {

    String fullName = clazz.getCanonicalName() + "." + method.getName();
    if (fullName.contains("controllers.")) {
        fullName = fullName.replace("controllers.", "");
    }//from w w  w .  j  a  v a  2 s.  co m
    return fullName;
}

From source file:com.impetus.kundera.examples.twitter.TwissandraTest.java

/**
 * Load data.//  ww  w  . ja  v a  2 s  .co  m
 * 
 * @throws ConfigurationException
 *             the configuration exception
 * @throws TException
 *             the t exception
 * @throws NotFoundException
 *             the not found exception
 * @throws InvalidRequestException
 *             the invalid request exception
 */
public void loadData() throws org.apache.cassandra.config.ConfigurationException, TException, NotFoundException,
        InvalidRequestException {

    Class<? extends AbstractReplicationStrategy> simple = SimpleStrategy.class;
    Map<String, String> ret = new HashMap<String, String>();
    ret.put("replication_factor", "1");
    CfDef user_Def = new CfDef("Kundera-Examples", "users");
    user_Def.setComparator_type("UTF8Type");
    user_Def.setColumn_type("Super");
    user_Def.setSubcomparator_type("UTF8Type");
    user_Def.setDefault_validation_class("UTF8Type");
    CfDef preference_Def = new CfDef("Kundera-Examples", "preference");
    CfDef external_Def = new CfDef("Kundera-Examples", "externalLinks");
    List<CfDef> cfDefs = new ArrayList<CfDef>();
    cfDefs.add(user_Def);
    cfDefs.add(preference_Def);
    cfDefs.add(external_Def);

    client.send_system_add_keyspace(new KsDef("Examples", simple.getCanonicalName(), 1, cfDefs));

    KSMetaData metadata = new KSMetaData("Kundera-Examples", simple, ret, 1,
            standardCFMD("Kundera-Examples", "users", ColumnFamilyType.Super),
            standardCFMD("Kundera-Examples", "preference", ColumnFamilyType.Standard),
            standardCFMD("Kundera-Examples", "externalLinks", ColumnFamilyType.Standard));
    for (CFMetaData cfm : metadata.cfMetaData().values()) {
        CFMetaData.map(cfm);
    }

    DatabaseDescriptor.setTableDefinition(metadata, DatabaseDescriptor.getDefsVersion());

}

From source file:ca.uhn.fhir.context.ModelScanner.java

private String scanPrimitiveDatatype(Class<? extends IPrimitiveType<?>> theClass,
        DatatypeDef theDatatypeDefinition) {
    ourLog.debug("Scanning resource class: {}", theClass.getName());

    String resourceName = theDatatypeDefinition.name();
    if (isBlank(resourceName)) {
        throw new ConfigurationException("Resource type @" + ResourceDef.class.getSimpleName()
                + " annotation contains no resource name: " + theClass.getCanonicalName());
    }/*from w w  w . j a va  2  s .  com*/

    BaseRuntimeElementDefinition<?> elementDef;
    if (theClass.equals(XhtmlDt.class)) {
        @SuppressWarnings("unchecked")
        Class<XhtmlDt> clazz = (Class<XhtmlDt>) theClass;
        elementDef = new RuntimePrimitiveDatatypeNarrativeDefinition(resourceName, clazz,
                isStandardType(clazz));
    } else if (IBaseXhtml.class.isAssignableFrom(theClass)) {
        @SuppressWarnings("unchecked")
        Class<? extends IBaseXhtml> clazz = (Class<? extends IBaseXhtml>) theClass;
        elementDef = new RuntimePrimitiveDatatypeXhtmlHl7OrgDefinition(resourceName, clazz,
                isStandardType(clazz));
    } else if (IIdType.class.isAssignableFrom(theClass)) {
        elementDef = new RuntimeIdDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
    } else {
        elementDef = new RuntimePrimitiveDatatypeDefinition(theDatatypeDefinition, theClass,
                isStandardType(theClass));
    }
    myClassToElementDefinitions.put(theClass, elementDef);
    if (!theDatatypeDefinition.isSpecialization()) {
        if (myVersion.isRi() && IDatatype.class.isAssignableFrom(theClass)) {
            ourLog.debug("Not adding non RI type {} to RI context", theClass);
        } else if (!myVersion.isRi() && !IDatatype.class.isAssignableFrom(theClass)) {
            ourLog.debug("Not adding RI type {} to non RI context", theClass);
        } else {
            myNameToElementDefinitions.put(resourceName, elementDef);
        }
    }

    return resourceName;
}

From source file:org.apache.sling.testing.clients.AbstractSlingClient.java

/**
 * <p>Returns an instance of any class extending the AbstractSlingClient. The new client will
 * use the the same {@link HttpClient} and {@link SlingClientConfig} </p>
 *
 * @param clientClass the type of client requested, identified by its Class
 * @param <T>         any class extending the AbstractSlingClient
 * @return instance of a class extending the AbstractSlingClient
 * @throws ClientException if client can't be instantiated
 *//*w  w w. jav a  2 s .co  m*/
@SuppressWarnings("unchecked")
public <T extends AbstractSlingClient> T adaptTo(Class<T> clientClass) throws ClientException {
    T client;
    try {
        Constructor cons = clientClass.getConstructor(CloseableHttpClient.class, SlingClientConfig.class);
        client = (T) cons.newInstance(this.http, this.config);
    } catch (Exception e) {
        throw new ClientException("Could not initialize client: '" + clientClass.getCanonicalName() + "'.", e);
    }
    return client;
}

From source file:com.ebay.erl.mobius.core.mapred.MultiInputsHelpersRepository.java

public MultiInputsHelper getHelper(Class<? extends InputFormat> inputFormat) {
    // get the closest helper
    Iterator<Class<? extends InputFormat>> it = this.mapping.keySet().iterator();

    while (it.hasNext()) {
        Class<? extends InputFormat> anRegisteredInputFormat = it.next();

        if (anRegisteredInputFormat.isAssignableFrom(inputFormat)) {
            // the keys in the mapping have been sorted, the most
            // generic classes will be put at the end of the mapping
            // keys set, so the first input format class from the set
            // which is the equals or super class of the <code>inputFormat</code>
            // is the best helper.

            return this.mapping.get(anRegisteredInputFormat);
        }//from   ww  w.  ja  v  a2  s.co  m
    }

    throw new IllegalArgumentException("There is no " + MultiInputsHelper.class.getSimpleName()
            + " for handling " + inputFormat.getCanonicalName()
            + " please provide one using the register method in " + this.getClass().getSimpleName());
}

From source file:org.auraframework.integration.test.util.AuraHttpTestCase.java

/**
 * Convenience method for executing an Action
 *
 * @param serverControllerClass controller class
 * @param methodName name of controller action method
 * @return a {@link HttpPost}
 * @throws Exception//from  w  w w .  j  a v  a  2 s  .c o m
 */
protected HttpPost executeAuraAction(Class<?> serverControllerClass, String methodName,
        Map<String, String> actionParams, Map<String, String> postParams) throws Exception {
    Map<String, Object> message = new HashMap<>();
    Map<String, Object> actionInstance = new HashMap<>();
    String descriptor = "java://" + serverControllerClass.getCanonicalName() + "/ACTION$" + methodName;
    actionInstance.put("descriptor", descriptor);
    if (actionParams != null) {
        actionInstance.put("params", actionParams);
    }
    Map<?, ?>[] actions = { actionInstance };
    message.put("actions", actions);
    String jsonMessage = JsonEncoder.serialize(message);

    if (postParams == null) {
        postParams = Maps.newHashMap();
    }
    postParams.put("message", jsonMessage);
    if (!postParams.containsKey("aura.token")) {
        postParams.put("aura.token", getCsrfToken());
    }
    if (!postParams.containsKey("aura.context")) {
        postParams.put("aura.context", contextService.getCurrentContext().serialize(EncodingStyle.Normal));
    }
    HttpPost post = obtainPostMethod("/aura", postParams);
    perform(post);
    post.releaseConnection();
    return post;
}

From source file:main.okapi.cf.annotations.AnnotationsInfo.java

public JSONObject getInfo() throws ClassNotFoundException, IOException, JSONException {
    JSONObject obj = new JSONObject();
    ArrayList<JSONObject> cl = new ArrayList<JSONObject>();
    Iterable<Class> classes = getClasses(this.topPackage);
    for (Class c : classes) {
        JSONObject forClass = new JSONObject();
        if (c.getAnnotations().length > 0) {

            ArrayList<JSONObject> parameters = new ArrayList<JSONObject>();
            for (Field field : c.getDeclaredFields()) {
                if (field.isAnnotationPresent(HyperParameter.class)) {
                    HyperParameter hp = field.getAnnotation(HyperParameter.class);
                    JSONObject parJSON = new JSONObject();
                    parJSON.put("parameterName", hp.parameterName());
                    parJSON.put("defaultValue", hp.defaultValue());
                    parJSON.put("minimumValue", hp.minimumValue());
                    parJSON.put("maximumValue", hp.maximumValue());
                    parameters.add(parJSON);
                }//from   www . j av  a2s  .  co  m
            }
            JSONObject method = new JSONObject();
            method.put("hyperParameters", parameters);
            method.put("class", c.getCanonicalName());
            cl.add(method);
        }
    }
    obj.put("methods", cl);
    return obj;
}

From source file:com.glaf.core.util.ReflectUtils.java

/**
 * Returns the setter-method for the given field name or null if no setter
 * exists.// w ww  .  ja  v a 2s.com
 */
public static Method getSetter(String fieldName, Class<?> clazz, Class<?> fieldType) {
    String setterName = "set" + Character.toTitleCase(fieldName.charAt(0))
            + fieldName.substring(1, fieldName.length());
    try {
        // Using getMathods(), getMathod(...) expects exact parameter type
        // matching and ignores inheritance-tree.
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            if (method.getName().equals(setterName)) {
                Class<?>[] paramTypes = method.getParameterTypes();
                if (paramTypes != null && paramTypes.length == 1 && paramTypes[0].isAssignableFrom(fieldType)) {
                    return method;
                }
            }
        }
        return null;
    } catch (SecurityException e) {
        throw new RuntimeException(
                "Not allowed to access method " + setterName + " on class " + clazz.getCanonicalName());
    }
}