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:Main.java

public static void main(String[] args) {
    Field[] fields = java.lang.Integer.class.getDeclaredFields();

    for (int i = 0; i < fields.length; i++) {
        Field f = fields[i];//from  ww w.jav  a 2  s.c  om
        Class type = f.getType();
        System.out.println(type.getCanonicalName());
    }
}

From source file:Main.java

public static void main(String[] args) {

    Main c = new Main();
    Class cls = c.getClass();

    // returns the canonical name of the underlying class if it exists
    System.out.println("Class = " + cls.getCanonicalName());
}

From source file:Main.java

public static void main(String[] args) {
    Field[] fields = java.lang.Integer.class.getDeclaredFields();

    for (int i = 0; i < fields.length; i++) {
        Field f = fields[i];/*ww  w  .  ja  va2  s  .  co m*/
        Class type = f.getType();
        String name = f.getName();
        System.out.print(Modifier.toString(f.getModifiers()));
        System.out.println(" " + type.getCanonicalName() + " " + name + ";");
    }
}

From source file:com.krawler.runtime.utils.URLClassLoaderUtil.java

public static void main(String[] args) {
    try {/*  w w  w  . j ava  2 s  . co m*/
        URLClassLoaderUtil urlcu = new URLClassLoaderUtil(
                new URL[] { new URL("file:///home/krawler/KrawlerJsonLib.jar") });
        urlcu.addFile("/home/krawler/KrawlerJsonLib.jar");
        Class c = Class.forName("com.krawler.utils.json.base.JSONObject");
        System.out.print(c.getCanonicalName());

    } catch (Exception ex) {
        Logger.getLogger(URLClassLoaderUtil.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:Main.java

public static void main(String... args) {
    try {//from   ww  w .j  a v a 2 s .c o m
        Class<?> c = Class.forName(args[0]);
        out.format("Class:%n  %s%n%n", c.getCanonicalName());
        out.format("Modifiers:%n  %s%n%n", Modifier.toString(c.getModifiers()));

        out.format("Type Parameters:%n");
        TypeVariable[] tv = c.getTypeParameters();
        if (tv.length != 0) {
            out.format("  ");
            for (TypeVariable t : tv)
                out.format("%s ", t.getName());
            out.format("%n%n");
        } else {
            out.format("  -- No Type Parameters --%n%n");
        }

        out.format("Implemented Interfaces:%n");
        Type[] intfs = c.getGenericInterfaces();
        if (intfs.length != 0) {
            for (Type intf : intfs)
                out.format("  %s%n", intf.toString());
            out.format("%n");
        } else {
            out.format("  -- No Implemented Interfaces --%n%n");
        }

        out.format("Inheritance Path:%n");
        List<Class> l = new ArrayList<Class>();
        printAncestor(c, l);
        if (l.size() != 0) {
            for (Class<?> cl : l)
                out.format("  %s%n", cl.getCanonicalName());
            out.format("%n");
        } else {
            out.format("  -- No Super Classes --%n%n");
        }

        out.format("Annotations:%n");
        Annotation[] ann = c.getAnnotations();
        if (ann.length != 0) {
            for (Annotation a : ann)
                out.format("  %s%n", a.toString());
            out.format("%n");
        } else {
            out.format("  -- No Annotations --%n%n");
        }

        // production code should handle this exception more gracefully
    } catch (ClassNotFoundException x) {
        x.printStackTrace();
    }
}

From source file:name.ikysil.beanpathdsl.sandbox.describe.Main.java

/**
 * @param args the command line arguments
 *///from   w  ww.j av a 2  s . c o  m
public static void main(String[] args) {
    PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
    Reflections reflections = new Reflections(TestBean.class, new SubTypesScanner(false));
    Set<Class<?>> classes = reflections.getSubTypesOf(Object.class);
    for (Class<?> clazz : classes) {
        System.out.println(String.format("Class name: %s", clazz.getName()));
        System.out.println(String.format("Class simple name: %s", clazz.getSimpleName()));
        System.out.println(String.format("Class canonical name: %s", clazz.getCanonicalName()));
        PropertyDescriptor[] pds = propertyUtilsBean.getPropertyDescriptors(clazz);
        for (PropertyDescriptor pd : pds) {
            System.out.println(String.format("    Property name: %s", pd.getName()));
            Class<?> pc = pd.getPropertyType();
            System.out.println(String.format("    Class name: %s", pc.getName()));
            System.out.println(String.format("    Class simple name: %s", pc.getSimpleName()));
            System.out.println(String.format("    Class canonical name: %s", pc.getCanonicalName()));
        }
    }
}

From source file:io.janusproject.Boot.java

/** Main function that is parsing the command line and launching
 * the first agent./*from  w  ww.j  a  v a2 s. co  m*/
 *
 * @param args - command line arguments
 * @see #startJanus(Class, Class, Object...)
 */
public static void main(String[] args) {
    try {
        List<URL> propertyFiles = new ArrayList<>();
        Object[] freeArgs = parseCommandLine(args, propertyFiles);
        if (JanusConfig.getSystemPropertyAsBoolean(JanusConfig.JANUS_LOGO_SHOW_NAME,
                JanusConfig.JANUS_LOGO_SHOW)) {
            showJanusLogo();
        }
        if (freeArgs.length == 0) {
            showError(Locale.getString("NO_AGENT_QUALIFIED_NAME"), //$NON-NLS-1$
                    null);
        }
        String agentToLaunch = freeArgs[0].toString();
        freeArgs = Arrays.copyOfRange(freeArgs, 1, freeArgs.length, String[].class);
        // Load the agent class
        Class<? extends Agent> agent = loadAgentClass(agentToLaunch);
        assert (agent != null);
        // Load property files
        Properties systemProperties = System.getProperties();
        for (URL url : propertyFiles) {
            try (InputStream stream = url.openStream()) {
                systemProperties.load(stream);
            }
        }
        // Set the boot agent classname
        System.setProperty(JanusConfig.BOOT_AGENT, agent.getCanonicalName());

        startJanus(null, (Class<? extends Agent>) agent, freeArgs);
    } catch (Exception e) {
        showError(Locale.getString("LAUNCHING_ERROR", //$NON-NLS-1$
                e.getLocalizedMessage()), e);
        return;
    }
}

From source file:kieker.tools.bridge.cli.CLIServerMain.java

/**
 * CLI server main./*from  w w w .  j  a  v  a 2 s. co  m*/
 *
 * @param args
 *            command line arguments
 */
public static void main(final String[] args) {
    Configuration configuration;

    int exitCode = 0;
    CLIServerMain.declareOptions();
    try {
        // parse the command line arguments
        commandLine = new BasicParser().parse(options, args);

        // verbosity setup
        verbose = commandLine.hasOption(CMD_VERBOSE);

        // statistics
        stats = commandLine.hasOption(CMD_STATS);

        // daemon mode
        if (commandLine.hasOption(CMD_DAEMON)) {
            System.out.close();
            System.err.close();
            CLIServerMain.getPidFile().deleteOnExit();
        }

        // Find libraries and setup mapping
        final ConcurrentMap<Integer, LookupEntity> lookupEntityMap = ServiceConnectorFactory
                .createLookupEntityMap(CLIServerMain.createRecordMap());

        // Kieker setup
        if (commandLine.hasOption(CMD_KIEKER_CONFIGURATION)) {
            configuration = ConfigurationFactory.createConfigurationFromFile(commandLine.getOptionValue("c"));
        } else {
            configuration = ConfigurationFactory.createSingletonConfiguration();
        }

        // reconfigure kieker configuration
        if (commandLine.hasOption(CMD_PORT) && commandLine.hasOption(CMD_TYPE)) {
            final String type = commandLine.getOptionValue(CMD_TYPE);
            if ("jms-embedded".equals(type)) {
                configuration.setProperty(JMSEmbeddedConnector.PORT, commandLine.getOptionValue(CMD_PORT));
            } else if ("tcp-single-server".equals(type)) {
                configuration.setProperty(TCPSingleServerConnector.PORT, commandLine.getOptionValue(CMD_PORT));
            } else if ("tcp-server".equals(type)) {
                configuration.setProperty(TCPMultiServerConnector.PORT, commandLine.getOptionValue(CMD_PORT));
            } else if ("tcp-client".equals(type)) {
                configuration.setProperty(TCPClientConnector.PORT, commandLine.getOptionValue(CMD_PORT));
            } else if ("http-rest".equals(type)) {
                configuration.setProperty(HTTPConnector.PORT, commandLine.getOptionValue(CMD_PORT));
            }
        }
        if (commandLine.hasOption(CMD_HOST)) {
            configuration.setProperty(TCPClientConnector.HOSTNAME, commandLine.getOptionValue(CMD_HOST));
        }
        if (commandLine.hasOption(CMD_USER)) {
            configuration.setProperty(JMSClientConnector.USERNAME, commandLine.getOptionValue(CMD_USER));
        }
        if (commandLine.hasOption(CMD_PASSWORD)) {
            configuration.setProperty(JMSClientConnector.PASSWORD, commandLine.getOptionValue(CMD_PASSWORD));
        }
        if (commandLine.hasOption(CMD_URL)) {
            configuration.setProperty(JMSClientConnector.URI, commandLine.getOptionValue(CMD_URL));
            configuration.setProperty(HTTPConnector.REST_URL, commandLine.getOptionValue(CMD_URL));
        }
        if (commandLine.hasOption(CMD_CONTEXT)) {
            configuration.setProperty(HTTPConnector.CONTEXT, commandLine.getOptionValue(CMD_CONTEXT));
        }
        if (commandLine.hasOption(CMD_TYPE)) {
            final Reflections reflections = new Reflections("kieker.tools.bridge.connector");
            final Set<Class<?>> connectors = reflections
                    .getTypesAnnotatedWith(kieker.tools.bridge.connector.ConnectorProperty.class);

            for (final Class<?> connector : connectors) {
                if (connector.getAnnotation(kieker.tools.bridge.connector.ConnectorProperty.class).cmdName()
                        .equals(commandLine.getOptionValue(CMD_TYPE))) {
                    configuration.setProperty(CLI_CONNECTOR, connector.getCanonicalName());
                    break;
                }
            }
        }

        // start service depending on type
        final IServiceConnector connector = CLIServerMain.createService(configuration, lookupEntityMap);
        CLIServerMain.getLog().info("Service " + connector.getClass()
                .getAnnotation(kieker.tools.bridge.connector.ConnectorProperty.class).name());
        CLIServerMain.runService(configuration, connector);

    } catch (final ParseException e) {
        CLIServerMain.usage("Parsing failed.  Reason: " + e.getMessage());
        exitCode = 4;
    } catch (final IOException e) {
        CLIServerMain.usage("Mapping file read error: " + e.getMessage());
        exitCode = 1;
    } catch (final CLIConfigurationErrorException e) {
        CLIServerMain.usage("Configuration error: " + e.getMessage());
        exitCode = 2;
    } catch (final ConnectorDataTransmissionException e) {
        CLIServerMain.usage("Communication error: " + e.getMessage());
        exitCode = 3;
    }
    // finally {
    // // The URLClassLoader does not have a close method in Java 1.5
    // // if (classLoader != null) {
    // // try {
    // // classLoader.close();
    // // } catch (final IOException e) {
    // // LOG.error("Classloader failed on close.");
    // // exitCode = 5;
    // // }
    // // }
    // }
    System.exit(exitCode);
}

From source file:Main.java

/**
 * Creates a human-readable representation, from a Class.
 *///  ww w . j av a 2  s  .co  m
public static String human(Class n) {
    return n.getCanonicalName();
}

From source file:Main.java

public static String buildKey(Class<?> clazz, String name) {
    return clazz.getCanonicalName() + "." + name;
}