Example usage for java.lang Class getName

List of usage examples for java.lang Class getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String .

Usage

From source file:ipc.RPC.java

static void setProtocolEngine(Configuration conf, Class protocol, Class engine) {
    conf.setClass(ENGINE_PROP + "." + protocol.getName(), engine, RpcEngine.class);
}

From source file:com.manydesigns.portofino.pageactions.PageActionLogic.java

public static String getDescriptionKey(Class<?> actionClass) {
    PageActionName annotation = actionClass.getAnnotation(PageActionName.class);
    if (annotation != null) {
        return annotation.value();
    } else {//from   w  w w.ja  v a 2  s .co  m
        return actionClass.getName();
    }
}

From source file:com.sixt.service.framework.servicetest.helper.DockerComposeHelper.java

@SuppressWarnings("unchecked")
private static void setEnv(Map<String, String> newEnv) {
    try {//from  w ww  .  j a v  a 2s .c om
        Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
        Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
        theEnvironmentField.setAccessible(true);
        Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
        env.putAll(newEnv);
        Field theCaseInsensitiveEnvironmentField = processEnvironmentClass
                .getDeclaredField("theCaseInsensitiveEnvironment");
        theCaseInsensitiveEnvironmentField.setAccessible(true);
        Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
        cienv.putAll(newEnv);
    } catch (NoSuchFieldException e) {
        try {
            Class[] classes = Collections.class.getDeclaredClasses();
            Map<String, String> env = System.getenv();
            for (Class cl : classes) {
                if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
                    Field field = cl.getDeclaredField("m");
                    field.setAccessible(true);
                    Object obj = field.get(env);
                    Map<String, String> map = (Map<String, String>) obj;
                    map.clear();
                    map.putAll(newEnv);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

From source file:dk.netarkivet.common.utils.ApplicationUtils.java

/**
 * Starts up an application. The applications class must:
 * (i) Have a static getInstance() method which returns a
 *     an instance of itself.//from w  w  w  .  jav  a2 s  .c  o m
 * (ii) Implement CleanupIF.
 * If the class cannot be started and a shutdown hook added, the JVM
 * exits with a return code depending on the problem:
 * 1 means wrong arguments
 * 2 means no factory method exists for class
 * 3 means couldn't instantiate class
 * 4 means couldn't add shutdown hook
 * 5 means couldn't add liveness logger
 * 6 means couldn't add remote management
 * @param c The class to be started.
 * @param args The arguments to the application (should be empty).
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void startApp(Class c, String[] args) {
    String appName = c.getName();
    Settings.set(CommonSettings.APPLICATION_NAME, appName);
    logAndPrint("Starting " + appName + "\n" + Constants.getVersionString());
    log.info("Using settings files '" + StringUtils.conjoin(File.pathSeparator, Settings.getSettingsFiles())
            + "'");
    checkArgs(args);
    dirMustExist(FileUtils.getTempDir());
    Method factoryMethod = null;
    CleanupIF instance = null;
    // Start the remote management connector
    try {
        MBeanConnectorCreator.exposeJMXMBeanServer();
        log.trace("Added remote management for " + appName);
    } catch (Throwable e) {
        logExceptionAndPrint("Could not add remote management for class " + appName, e);
        System.exit(EXCEPTION_WHEN_ADDING_MANAGEMENT);
    }
    // Get the factory method
    try {
        factoryMethod = c.getMethod("getInstance", (Class[]) null);
        int modifier = factoryMethod.getModifiers();
        if (!Modifier.isStatic(modifier)) {
            throw new Exception("getInstance is not static");
        }
        logAndPrint(appName + " Running");
    } catch (Throwable e) {
        logExceptionAndPrint("Class " + appName + " does not have required" + "factory method", e);
        System.exit(NO_FACTORY_METHOD);
    }
    // Invoke the factory method
    try {
        log.trace("Invoking factory method.");
        instance = (CleanupIF) factoryMethod.invoke(null, (Object[]) null);
        log.trace("Factory method invoked.");
    } catch (Throwable e) {
        logExceptionAndPrint("Could not start class " + appName, e);
        System.exit(EXCEPTION_WHILE_INSTANTIATING);
    }
    // Add the shutdown hook
    try {
        log.trace("Adding shutdown hook for " + appName);
        Runtime.getRuntime().addShutdownHook((new CleanupHook(instance)));
        log.trace("Added shutdown hook for " + appName);
    } catch (Throwable e) {
        logExceptionAndPrint("Could not add shutdown hook for class " + appName, e);
        System.exit(EXCEPTION_WHEN_ADDING_SHUTDOWN_HOOK);
    }
}

From source file:com.netflix.nicobar.core.utils.ClassPathUtils.java

/**
 * Get the resource name for the class file for the given class
 * @param clazz the class to convert/*from w  w w. j a v  a 2 s  .  c om*/
 * @return resource name appropriate for using with {@link ClassLoader#getResource(String)}
 */
public static String classToResourceName(Class<?> clazz) {
    return classNameToResourceName(clazz.getName());
}

From source file:Main.java

public static final int typeIndex(Class type)
/*     */ {/*from  ww w.  ja  va 2  s  .co  m*/
    /*  65 */Class[] list = primitiveTypes;
    /*  66 */int n = list.length;
    /*  67 */for (int i = 0; i < n; i++) {
        /*  68 */if (list[i] == type)
            /*  69 */return i;
        /*     */}
    /*  71 */throw new RuntimeException("bad type:" + type.getName());
    /*     */}

From source file:com.github.rvesse.airline.parser.ParserUtil.java

public static <T> T createInstance(Class<T> type) {
    if (type != null) {
        try {/*  w ww. ja  v  a2s . co  m*/
            return type.getConstructor().newInstance();
        } catch (Exception e) {
            throw new ParseException(e, "Unable to create instance %s", type.getName());
        }
    }
    return null;
}

From source file:com.weibo.api.motan.protocol.yar.YarProtocolUtil.java

/**
 * convert yar request to motan rpc request
 * /*from   ww w  .  j  ava  2s  .  c  om*/
 * @param yarRequest
 * @param interfaceClass
 * @return
 */
public static Request convert(YarRequest yarRequest, Class<?> interfaceClass) {
    DefaultRequest request = new DefaultRequest();
    request.setInterfaceName(interfaceClass.getName());
    request.setMethodName(yarRequest.getMethodName());
    request.setRequestId(yarRequest.getId());
    addArguments(request, interfaceClass, yarRequest.getMethodName(), yarRequest.getParameters());
    if (yarRequest instanceof AttachmentRequest) {
        request.setAttachments(((AttachmentRequest) yarRequest).getAttachments());
    }
    return request;
}

From source file:ca.psiphon.tunneledwebview.WebViewProxySettings.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@SuppressWarnings("rawtypes")
private static boolean setWebkitProxyKitKat(Context appContext, String host, int port) {
    System.setProperty("http.proxyHost", host);
    System.setProperty("http.proxyPort", port + "");
    System.setProperty("https.proxyHost", host);
    System.setProperty("https.proxyPort", port + "");
    try {/*from  w w  w  . ja va  2 s.co m*/
        Class applicationClass = Class.forName("android.app.Application");
        Field loadedApkField = applicationClass.getDeclaredField("mLoadedApk");
        loadedApkField.setAccessible(true);
        Object loadedApk = loadedApkField.get(appContext);
        Class loadedApkClass = Class.forName("android.app.LoadedApk");
        Field receiversField = loadedApkClass.getDeclaredField("mReceivers");
        receiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object receiver : ((ArrayMap) receiverMap).keySet()) {
                Class receiverClass = receiver.getClass();
                if (receiverClass.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = receiverClass.getDeclaredMethod("onReceive", Context.class,
                            Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);

                    final String CLASS_NAME = "android.net.ProxyProperties";
                    Class proxyPropertiesClass = Class.forName(CLASS_NAME);
                    Constructor constructor = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE,
                            String.class);
                    constructor.setAccessible(true);
                    Object proxyProperties = constructor.newInstance(host, port, null);
                    intent.putExtra("proxy", (Parcelable) proxyProperties);

                    onReceiveMethod.invoke(receiver, appContext, intent);
                }
            }
        }
        return true;
    } catch (ClassNotFoundException e) {
    } catch (NoSuchFieldException e) {
    } catch (IllegalAccessException e) {
    } catch (IllegalArgumentException e) {
    } catch (NoSuchMethodException e) {
    } catch (InvocationTargetException e) {
    } catch (InstantiationException e) {
    }
    return false;
}

From source file:com.flexive.cmis.spi.SPIUtils.java

static void notImplemented(Class cls, String method) {
    System.out.println(cls.getName() + "#" + method + " not implemented yet.");
}