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.glassfish.tyrus.tests.qa.tools.GlassFishToolkit.java

private File getFileForClazz(Class clazz) {
    logger.log(Level.FINE, "Obtaining file for : {0}", clazz.getCanonicalName());

    String clazzBasename = new File(clazz.getCanonicalName().replace('.', '/')).getName();

    return new File(getDirname(new File(clazz.toString())), clazzBasename);
}

From source file:io.teak.sdk.FacebookAccessTokenBroadcast.java

public FacebookAccessTokenBroadcast(Context context) {
    this.broadcastManager = LocalBroadcastManager.getInstance(context);

    // Get the Facebook SDK Version string
    Class<?> com_facebook_FacebookSdkVersion = null;
    try {// ww  w. ja  va  2 s.c  o  m
        com_facebook_FacebookSdkVersion = Class.forName(FACEBOOK_SDK_VERSION_CLASS_NAME);
    } catch (ClassNotFoundException e) {
        Log.e(LOG_TAG, "Facebook SDK not found.");
    }

    Field fbSdkVersionField = null;
    if (com_facebook_FacebookSdkVersion != null) {
        try {
            fbSdkVersionField = com_facebook_FacebookSdkVersion.getDeclaredField("BUILD");
        } catch (NoSuchFieldException e) {
            Log.e(LOG_TAG, "Facebook SDK version field not found.");
        }
    }

    String fbSdkVersion = null;
    if (fbSdkVersionField != null) {
        try {
            fbSdkVersion = fbSdkVersionField.get(null).toString();
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "Facebook SDK version string: " + fbSdkVersion);
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, Log.getStackTraceString(e));
        }
    }

    if (fbSdkVersion != null) {
        String[] fbSDKs = fbSdkVersion.split("/");
        String[] versionStrings = fbSDKs[0].split("\\.");
        int[] versionInts = new int[versionStrings.length];
        for (int i = 0; i < versionStrings.length; i++) {
            versionInts[i] = Integer.parseInt(versionStrings[i]);
        }

        switch (versionInts[0]) {
        case 3: {
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "Listening for Facebook SDK 3.x broadcast actions.");
            }

            Class<?> com_facebook_Session;
            try {
                com_facebook_Session = Class.forName(FACEBOOK_3_x_SESSION_CLASS_NAME);
                if (Teak.isDebug) {
                    Log.d(LOG_TAG, "Found " + com_facebook_Session.toString());
                }

                this.com_facebook_Session_getActiveSession = com_facebook_Session.getMethod("getActiveSession");
                try {
                    this.com_facebook_Session_getAccessToken = com_facebook_Session.getMethod("getAccessToken");
                } catch (NoSuchMethodException e) {
                    Log.e(LOG_TAG, FACEBOOK_3_x_SESSION_CLASS_NAME + ".getAccessToken() not found: "
                            + Log.getStackTraceString(e));
                }

                Field f = com_facebook_Session.getDeclaredField(FACEBOOK_3_x_BROADCAST_ACTION_FIELD);
                this.facebook_3_x_BroadcastAction = (String) f.get(null);
                if (Teak.isDebug) {
                    Log.d(LOG_TAG, "Found broadcast action: " + this.facebook_3_x_BroadcastAction);
                }
            } catch (ClassNotFoundException e) {
                Log.e(LOG_TAG, FACEBOOK_3_x_SESSION_CLASS_NAME + " not found.");
            } catch (NoSuchMethodException e) {
                Log.e(LOG_TAG, FACEBOOK_3_x_SESSION_CLASS_NAME + ".getActiveSession() not found: "
                        + Log.getStackTraceString(e));
            } catch (Exception e) {
                Log.e(LOG_TAG,
                        "Error occured working with reflected Facebook SDK: " + Log.getStackTraceString(e));
            }

            if (this.com_facebook_Session_getActiveSession != null
                    && this.com_facebook_Session_getAccessToken != null
                    && this.facebook_3_x_BroadcastAction != null) {
                IntentFilter filter = new IntentFilter();
                filter.addAction(this.facebook_3_x_BroadcastAction);

                this.broadcastManager.registerReceiver(this.broadcastReceiver, filter);
            }
        }
            break;

        case 4: {
            Class<?> com_facebook_AccessToken;
            try {
                com_facebook_AccessToken = Class.forName(FACEBOOK_4_x_ACCESS_TOKEN_CLASS_NAME);
                if (Teak.isDebug) {
                    Log.d(LOG_TAG, "Found " + com_facebook_AccessToken.toString());
                }

                this.com_facebook_AccessToken_getToken = com_facebook_AccessToken.getMethod("getToken");
            } catch (ClassNotFoundException e) {
                Log.e(LOG_TAG, FACEBOOK_4_x_ACCESS_TOKEN_CLASS_NAME + " not found.");
            } catch (NoSuchMethodException e) {
                Log.e(LOG_TAG, FACEBOOK_4_x_ACCESS_TOKEN_CLASS_NAME + ".getToken() not found: "
                        + Log.getStackTraceString(e));
            } catch (Exception e) {
                Log.e(LOG_TAG,
                        "Error occured working with reflected Facebook SDK: " + Log.getStackTraceString(e));
            }

            try {
                Class<?> com_facebook_AccessTokenManager;
                com_facebook_AccessTokenManager = Class.forName(FACEBOOK_4_x_ACCESS_TOKEN_MANAGER_CLASS_NAME);
                if (Teak.isDebug) {
                    Log.d(LOG_TAG, "Found " + com_facebook_AccessTokenManager.toString());
                }

                Field f = com_facebook_AccessTokenManager.getDeclaredField(FACEBOOK_4_x_BROADCAST_ACTION_FIELD);
                f.setAccessible(true);
                this.facebook_4_x_BroadcastAction = (String) f.get(null);
                if (Teak.isDebug) {
                    Log.d(LOG_TAG, "Found broadcast action: " + this.facebook_4_x_BroadcastAction);
                }
            } catch (ClassNotFoundException e) {
                Log.e(LOG_TAG, FACEBOOK_4_x_ACCESS_TOKEN_MANAGER_CLASS_NAME + " not found.");
            } catch (Exception e) {
                Log.e(LOG_TAG,
                        "Error occured working with reflected Facebook SDK: " + Log.getStackTraceString(e));
            }

            if (this.com_facebook_AccessToken_getToken != null && this.facebook_4_x_BroadcastAction != null) {
                IntentFilter filter = new IntentFilter();
                filter.addAction(this.facebook_4_x_BroadcastAction);

                this.broadcastManager.registerReceiver(this.broadcastReceiver, filter);
            }
        }
            break;

        default: {
            Log.e(LOG_TAG, "Don't know how to use Facebook SDK version " + versionInts[0]);
        }
        }
    }
}

From source file:org.obsidian.test.TestAbstract.java

public <T> void appendEqualityMethodTypes(Class<T> type) {
    Boolean ignore = false;// w w  w .  j a  va 2 s .  com

    //Make sure: not already in Equality Method Types
    for (Class c : getEqualityMethodTypes()) {
        if (type.toString().compareToIgnoreCase(c.toString()) == 0) {
            ignore = true;
        }
    }

    //Make sure: not a Throwable
    Class superClass = type.getSuperclass();//first check immediate super

    if (superClass != null) {
        while (!superClass.equals(Object.class)) {//while still has superclasses

            //#### Patch Submitted by Joanna Illing (illing.joanna@gmail.com) 2/13/13
            if (superClass.equals(Throwable.class)) {
                ignore = true;//if Throwable: ignore
            }
            superClass = superClass.getSuperclass();
        }

    }

    if (type.getSimpleName().compareToIgnoreCase("string") == 0) {
        ignore = true;
    }

    if (type.getSimpleName().compareToIgnoreCase("Exception") == 0) {
        ignore = true;
    }

    if (type.getSimpleName().compareToIgnoreCase("Throwable") == 0) {
        ignore = true;
    }

    if (Modifier.isStatic(type.getModifiers()) && type.getSuperclass() != null) {
        appendDynamicImports(type.getSuperclass());
    }

    if (!ignore) {
        getEqualityMethodTypes().add(type);
    }

}

From source file:org.apache.hama.bsp.GroomServer.java

public static GroomServer constructGroomServer(Class<? extends GroomServer> groomServerClass,
        final Configuration conf2) {
    try {//from w ww  .j a v a 2  s  .com
        Constructor<? extends GroomServer> c = groomServerClass.getConstructor(Configuration.class);
        return c.newInstance(conf2);
    } catch (Exception e) {
        throw new RuntimeException("Failed construction of " + "Master: " + groomServerClass.toString(), e);
    }
}

From source file:es.urjc.mctwp.pacs.impl.DcmStorageServerImpl.java

/**
 * Return new instance of command identified by clazz
 * /* ww  w  .  ja  v  a 2  s  . c om*/
 * @param clase
 * @return
 */
private Command getCommand(Class<?> clazz) {
    Command command = null;

    //Build a new command using Web Application Context (wac)
    try {
        Constructor<?> c = clazz.getConstructor(BeanFactory.class);
        command = (Command) c.newInstance(bf);
    } catch (Exception e) {
        logger.error("Error creating new command [" + clazz.toString() + "] : " + e.getMessage());
    }

    return command;
}

From source file:com.smartitengineering.util.rest.client.AbstractClientResource.java

protected final Class<? extends T> initializeEntityClassFromGenerics() {
    Class<? extends T> extractedEntityClass = null;
    try {/*w  w  w. j a va2s  .c o  m*/
        Type paramType = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        if (paramType instanceof ParameterizedType) {
            paramType = ((ParameterizedType) paramType).getRawType();
        }
        Class<T> pesistenceRegistryClass = paramType instanceof Class ? (Class<T>) paramType : null;
        if (logger.isDebugEnabled()) {
            logger.debug("Entity class predicted to: " + pesistenceRegistryClass.toString());
        }
        extractedEntityClass = pesistenceRegistryClass;
    } catch (Exception ex) {
        logger.warn("Could not predict entity class ", ex);
    }
    return extractedEntityClass;
}

From source file:org.iterx.miru.spring.beans.SpringBeanFactory.java

public Object getBeanOfType(Class type) {
    assert (type != null) : "type == null";
    try {/* w w w . jav a  2s .c o m*/
        Map map;

        if ((factory instanceof ListableBeanFactory) && (map = BeanFactoryUtils
                .beansOfTypeIncludingAncestors((ListableBeanFactory) factory, type, true, false)).size() > 0)
            return ((map.values()).iterator()).next();

    } catch (BeansException e) {
        if (logger.isDebugEnabled())
            logger.debug("Failed to create bean implementation [" + type.toString() + "]", e);
    }

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

From source file:com.sonicle.webtop.core.app.JaxRsServiceApplication.java

private void configureServiceApis(WebTopApp wta, ServletConfig servletConfig) {
    ServiceManager svcMgr = wta.getServiceManager();

    String serviceId = servletConfig.getInitParameter(RestApi.INIT_PARAM_WEBTOP_SERVICE_ID);
    if (StringUtils.isBlank(serviceId))
        throw new WTRuntimeException(
                "Invalid servlet init parameter [" + RestApi.INIT_PARAM_WEBTOP_SERVICE_ID + "]");

    ServiceDescriptor desc = svcMgr.getDescriptor(serviceId);
    if (desc == null)
        throw new WTRuntimeException("Service descriptor not found [{0}]", serviceId);

    if (desc.hasOpenApiDefinitions()) {
        for (ServiceDescriptor.OpenApiDefinition apiDefinition : desc.getOpenApiDefinitions()) {
            // Register resources
            for (Class clazz : apiDefinition.resourceClasses) {
                javax.ws.rs.Path pathAnnotation = (javax.ws.rs.Path) ClassHelper
                        .getClassAnnotation(clazz.getSuperclass(), javax.ws.rs.Path.class);
                String resourcePath = "/"
                        + PathUtils.concatPathParts(apiDefinition.context, pathAnnotation.value());
                logger.debug("[{}] Registering JaxRs resource [{}] -> [{}]", servletConfig.getServletName(),
                        clazz.toString(), resourcePath);
                registerResources(Resource.builder(clazz).path(resourcePath).build());
            }//from   w ww  .j  a  v  a  2 s .  c om

            // Configure OpenApi listing
            OpenAPI oa = new OpenAPI();
            oa.info(desc.buildOpenApiInfo(apiDefinition));

            SwaggerConfiguration oaConfig = new SwaggerConfiguration().openAPI(oa).prettyPrint(true)
                    .resourcePackages(Stream.of(apiDefinition.implPackage).collect(Collectors.toSet()));

            try {
                new JaxrsOpenApiContextBuilder().servletConfig(servletConfig).application(this)
                        .ctxId(apiDefinition.context).openApiConfiguration(oaConfig).buildContext(true);
            } catch (OpenApiConfigurationException ex) {
                logger.error("Unable to init swagger", ex);
            }
        }
    }
}

From source file:com.decody.android.core.json.JSONClient.java

public <T> T put(String url, Class<T> classOfT, T data)
        throws ResourceNotFoundException, UnauthorizedException {
    HttpPut put = new HttpPut(url);
    put.addHeader("Content-Type", CONTENT_TYPE);

    try {/*from w  w  w .  j a v a2  s.  co  m*/
        put.setEntity(new StringEntity(factory.newInstance().toJson(data)));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(
                "input data is not valid, check the input data to call the post service: " + url + " - "
                        + classOfT.toString());
    }

    return performCall(put, classOfT);
}

From source file:com.decody.android.core.json.JSONClient.java

public <T> T post(String url, Class<T> classOfT, T data)
        throws ResourceNotFoundException, UnauthorizedException {
    HttpPost post = new HttpPost(url);
    post.addHeader("Content-Type", CONTENT_TYPE);

    try {/*from   www.  j a  v a 2s . c  o m*/
        post.setEntity(new StringEntity(factory.newInstance().toJson(data)));
    } catch (UnsupportedEncodingException e1) {
        throw new IllegalArgumentException(
                "input data is not valid, check the input data to call the post service: " + url + " - "
                        + classOfT.toString());
    }

    return performCall(post, classOfT);
}