Example usage for java.lang Class toString

List of usage examples for java.lang Class toString

Introduction

In this page you can find the example usage for java.lang Class toString.

Prototype

public String toString() 

Source Link

Document

Converts the object to a string.

Usage

From source file:org.energyos.espi.common.repositories.jpa.ResourceRepositoryImpl.java

@SuppressWarnings("unchecked")
@Override/*from  w  w  w .ja va  2  s.  c om*/
public <T> T findByUUID(UUID uuid, Class<T> clazz) {
    try {
        String queryFindById = (String) clazz.getDeclaredField("QUERY_FIND_BY_UUID").get(String.class);

        return (T) em.createNamedQuery(queryFindById).setParameter("uuid", uuid.toString().toUpperCase())
                .getSingleResult();
    } catch (IllegalAccessException | NoSuchFieldException e) {
        System.out.printf("**** findByUUID(UUID uuid) Exception: %s - %s\n", clazz.toString(), e.toString());
        throw new RuntimeException(e);
    }

}

From source file:com.gdevelop.gwt.syncrpc.SyncClientSerializationStreamReader.java

public Object deserializeValue(Class<?> type) throws SerializationException {
    ValueReader valueReader = CLASS_TO_VALUE_READER.get(type);
    if (valueReader != null) {
        Log.d("PROBLEMA", "Before parsing " + type.toString() + ": " + index);
        Object object = valueReader.readValue(this);
        Log.d("PROBLEMA", "After " + type.toString() + ": " + index);
        return object;
    } else {//from   ww  w  .j a  v a2  s  . c  o m
        // Arrays of primitive or reference types need to go through readObject.
        return SyncClientSerializationStreamReader.ValueReader.OBJECT.readValue(this);
    }
}

From source file:net.nicholaswilliams.java.licensing.encryption.TestRSAKeyPairGenerator.java

@Test
public void testGenerateJavaCode02()
        throws ClassNotFoundException, IllegalAccessException, InstantiationException, InterruptedException {
    String code = this.generator.generateJavaCode("com.nicholaswilliams.java.mock", "TestGenerateJavaCode02",
            "TestRSAKeyPairGenerator.TestDynamicCompileInterface",
            new String[] { "net.nicholaswilliams.java.licensing.encryption.TestRSAKeyPairGenerator" },
            "public long getSystemTimeInSeconds()", "System.currentTimeMillis() / 1000L");

    assertNotNull("The code should not be null.", code);
    assertTrue("The code should have length.", code.length() > 0);
    assertEquals("The code is not correct.", "package com.nicholaswilliams.java.mock;\r\n" + "\r\n"
            + "import net.nicholaswilliams.java.licensing.encryption.TestRSAKeyPairGenerator;\r\n" + "\r\n"
            + "public final class TestGenerateJavaCode02 implements TestRSAKeyPairGenerator.TestDynamicCompileInterface\r\n"
            + "{\r\n" + "\t@Override\r\n" + "\tpublic long getSystemTimeInSeconds()\r\n" + "\t{\r\n"
            + "\t\treturn System.currentTimeMillis() / 1000L;\r\n" + "\t}\r\n" + "}", code);

    JavaFileManager compiled = this.compileClass("com.nicholaswilliams.java.mock.TestGenerateJavaCode02", code);

    Class<?> classObject = compiled.getClassLoader(null)
            .loadClass("com.nicholaswilliams.java.mock.TestGenerateJavaCode02");
    System.out.println("Successfully compiled " + classObject.toString() + ".");

    TestDynamicCompileInterface instance = (TestDynamicCompileInterface) classObject.newInstance();

    long seconds = System.currentTimeMillis() / 1000L;
    assertTrue("The return value is not correct (1).", instance.getSystemTimeInSeconds() >= seconds);
    Thread.sleep(1000);/*w  ww .j a v  a2s  . c o m*/
    assertTrue("The return value is not correct (2).", instance.getSystemTimeInSeconds() >= (seconds + 1));
}

From source file:org.energyos.espi.common.repositories.jpa.ResourceRepositoryImpl.java

@SuppressWarnings("unchecked")
@Override//from  w w w  .ja v  a  2  s.  co m
public <T extends IdentifiedObject> List<Long> findAllIdsByXPath(Long id1, Class<T> clazz) {
    try {
        String findAllIdsByXPath = (String) clazz.getDeclaredField("QUERY_FIND_ALL_IDS_BY_XPATH_1")
                .get(String.class);
        Query query = em.createNamedQuery(findAllIdsByXPath).setParameter("o1Id", id1);
        return query.getResultList();
    } catch (NoSuchFieldException | IllegalAccessException e) {
        System.out.printf("**** findAllIdsByXPath(Long id1) Exception: %s - %s\n", clazz.toString(),
                e.toString());
        throw new RuntimeException(e);
    }

}

From source file:org.energyos.espi.common.repositories.jpa.ResourceRepositoryImpl.java

@Override
public <T extends IdentifiedObject> Long findIdByXPath(Long id1, Long id2, Class<T> clazz) {
    try {// w w  w  .j a  va2  s .co m
        String findIdByXPath = (String) clazz.getDeclaredField("QUERY_FIND_ID_BY_XPATH").get(String.class);
        Query query = em.createNamedQuery(findIdByXPath).setParameter("o1Id", id1).setParameter("o2Id", id2);
        return (Long) query.getSingleResult();
    } catch (NoSuchFieldException | IllegalAccessException e) {
        System.out.printf("**** findIdByXPath(Long id1, Long id2) Exception: %s - %s\n", clazz.toString(),
                e.toString());
        throw new RuntimeException(e);
    }
}

From source file:org.energyos.espi.common.repositories.jpa.ResourceRepositoryImpl.java

@SuppressWarnings("unchecked")
@Override/*from ww  w.  j  a  v  a 2s  . co m*/
public <T extends IdentifiedObject> T findByResourceUri(String uri, Class<T> clazz) {
    try {
        String findByResourceURI = (String) clazz.getDeclaredField("QUERY_FIND_BY_RESOURCE_URI")
                .get(String.class);
        Query query = em.createNamedQuery(findByResourceURI).setParameter("uri", uri);
        return (T) query.getSingleResult();

    } catch (NoSuchFieldException | IllegalAccessException e) {
        System.out.printf("**** findByResourceUri(String uri) Exception: %s - %s\n", clazz.toString(),
                e.toString());
        throw new RuntimeException(e);
    }
}

From source file:ome.formats.enums.IQueryEnumProvider.java

public <T extends IObject> T getEnumeration(Class<T> klass, String value, boolean loaded) {
    if (klass == null)
        throw new NullPointerException("Expecting not-null klass.");
    if (value == null) {
        log.warn("Enumeration " + klass + " with value of null.");
    } else if (value.length() == 0) {
        log.warn("Enumeration " + klass + " with value of zero length.");
    }// w  w w . ja  v a2 s  . c o m

    HashMap<String, T> enumerations = getEnumerations(klass);
    EnumerationHandler handler = enumHandlerFactory.getHandler(klass);
    IObject otherEnumeration = enumerations.get("Other");
    // Step 1, check if we've got an exact match for our enumeration value.
    if (enumerations.containsKey(value)) {
        log.debug(String.format("Returning %s exact match for: %s", klass.toString(), value));
        if (!loaded) {
            return (T) copyEnumeration(enumerations.get(value));
        }
        return enumerations.get(value);
    }
    // Step 2, check if our enumeration handler can find a match.
    IObject enumeration = handler.findEnumeration((HashMap<String, IObject>) enumerations, value);
    if (enumeration != null) {
        log.debug(String.format("Handler found %s match for: %s", klass.toString(), value));
        if (!loaded) {
            return (T) copyEnumeration(enumeration);
        }
        return (T) enumeration;
    }
    // Step 3, fall through to an "Other" enumeration if we have one.
    if (otherEnumeration != null) {
        log.warn("Enumeration '" + value + "' does not exist in '" + klass + "' setting to 'Other'");
        return (T) otherEnumeration;
    }
    // Step 4, warn we have no enumeration to return.
    log.warn("Enumeration '" + value + "' does not exist in '" + klass + "' returning 'null'");
    return (T) enumeration;
}

From source file:org.iterx.miru.support.spring.bean.factory.SpringBeanFactory.java

public Object getBeanOfType(Class type) {
    assert (type != null) : "type == null";

    try {//w  ww.j a v a  2s  .com
        String[] names;

        if ((beanFactory instanceof ListableBeanFactory)
                && (names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
                        (ListableBeanFactory) beanFactory, type, true, false)).length > 0) {
            Object object;
            String name;

            object = beanFactory.getBean(name = names[0]);
            if (object instanceof BeanAware)
                ((BeanAware) object).setId(name);
            return object;
        }
    } catch (BeansException e) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn("Failed to create bean implementation [" + type.toString() + "]", e);
    }

    return (parent != null) ? parent.getBeanOfType(type) : null;
}

From source file:com.ibm.research.govsci.graph.BlueprintsBase.java

/**
 * Gets a reference to the specified index, creating it if it doesn't exist.
 * /* w  ww  .  ja  v a 2s .  c  om*/
 * This probably could be better written if it used generics or something like that
 * 
 * @param idxname the name of the index to load/create
 * @param indexClass the class the index should use, either Vertex or Edge
 * @return a reference to the loaded/created index
 */
public <T extends Element> Index<T> getOrCreateIndex(String idxname, Class<T> idxClass) {
    Index<T> idx = null;
    if (!this.supportsIndexes()) {
        log.error("getOrCreateIndex - graph is not IndexableGraph");
        return null;
    }
    log.trace("Getting index: {} type: {}", idxname, idxClass.toString());
    try {
        idx = igraph.getIndex(idxname, idxClass);
    } catch (NullPointerException e) {
        log.error("Null pointer exception fetching index: {} {}", idxname, e);
    } catch (RuntimeException e) {
        log.debug("Runtime exception encountered getting index {}. Upgrade to newer version of blueprints.",
                idxname);
    }
    if (idx == null) {
        log.warn("Creating index {} for class {}", idxname, idxClass.toString());
        idx = igraph.createIndex(idxname, idxClass);
    }
    return idx;
}

From source file:cascading.flow.hadoop.util.HadoopUtil.java

public static <T> ObjectSerializer instantiateSerializer(Configuration conf, Class<T> type)
        throws ClassNotFoundException {
    Class<ObjectSerializer> flowSerializerClass;

    String serializerClassName = conf.get(ObjectSerializer.OBJECT_SERIALIZER_PROPERTY);

    if (serializerClassName == null || serializerClassName.length() == 0)
        flowSerializerClass = (Class<ObjectSerializer>) DEFAULT_OBJECT_SERIALIZER;
    else/*from  ww  w. ja va2s . c o  m*/
        flowSerializerClass = (Class<ObjectSerializer>) Class.forName(serializerClassName);

    ObjectSerializer objectSerializer;

    try {
        objectSerializer = flowSerializerClass.newInstance();

        if (objectSerializer instanceof Configurable)
            ((Configurable) objectSerializer).setConf(conf);
    } catch (Exception exception) {
        exception.printStackTrace();
        throw new IllegalArgumentException("Unable to instantiate serializer \"" + flowSerializerClass.getName()
                + "\" for class: " + type.getName());
    }

    if (!objectSerializer.accepts(type))
        throw new IllegalArgumentException(
                serializerClassName + " won't accept objects of class " + type.toString());

    return objectSerializer;
}