List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:com.fantasy.Application.java
public static void main(String[] args) throws ParseException, Exception { ConfigurableApplicationContext context; context = SpringApplication.run(AggregatorConfig.class); SpaceDelimitedCommandLineParser<YearFlag, YearContainer> argParser; argParser = context.getBean(SpaceDelimitedCommandLineParser.class); YearContainer container = argParser.parseFor(YearFlag.class, args); String packageName = container.getPackageName(); String className = container.getClassName(); int year = container.getYear(); List<Class> taskRunners = findTypes(packageName); Class runner = null;/* w ww . ja va2s .c o m*/ if (Objects.nonNull(taskRunners)) { for (Class cl : taskRunners) { if (cl.getSimpleName().equalsIgnoreCase(className)) { runner = cl; break; } } if (Objects.nonNull(runner)) { Task task = (Task) context.getBean(runner); if (Objects.nonNull(task)) { if (task instanceof ContextUser) { ((ContextUser) task).haveContext(context); } if (task instanceof YearlyTask) { ((YearlyTask) task).setYear(year); } try { task.run(); } catch (InterruptedException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); } finally { if (Objects.nonNull(context)) { context.close(); } } } } } }
From source file:Main.java
public static void main(String[] args) { Main c = new Main(); Class cls = c.getClass(); // returns the name of the class String name = cls.getName();//from www . j av a 2 s . c o m System.out.println("Class Name = " + name); // returns the simple name of the class String sname = cls.getSimpleName(); System.out.println("Class SimpleName = " + sname); }
From source file:name.ikysil.beanpathdsl.sandbox.describe.Main.java
/** * @param args the command line arguments */// ww w . j a va 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:org.jasig.portlet.data.Exporter.java
public static void main(String[] args) throws Exception { String dir = args[0];// www. j av a2 s . c o m String importExportContext = args[1]; String sessionFactoryBeanName = args[2]; String modelClassName = args[3]; String serviceBeanName = args[4]; String serviceBeanMethodName = args[5]; ApplicationContext context = PortletApplicationContextLocator.getApplicationContext(importExportContext); SessionFactory sessionFactory = context.getBean(sessionFactoryBeanName, SessionFactory.class); Class<?> modelClass = Class.forName(modelClassName); Object service = context.getBean(serviceBeanName); Session session = sessionFactory.getCurrentSession(); Transaction transaction = session.beginTransaction(); JAXBContext jc = JAXBContext.newInstance(modelClass); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); Method method = service.getClass().getMethod(serviceBeanMethodName); List<?> objects = (List<?>) method.invoke(service, null); for (Object o : objects) { session.lock(o, LockMode.NONE); JAXBElement je2 = new JAXBElement(new QName(modelClass.getSimpleName().toLowerCase()), modelClass, o); String output = dir + File.separator + UUID.randomUUID().toString() + ".xml"; try { marshaller.marshal(je2, new FileOutputStream(output)); } catch (Exception exception) { exception.printStackTrace(); } } transaction.commit(); }
From source file:main.RankerOCR.java
/** * Command line interface for RankerOCR. * <p>//w ww . j ava 2 s . c o m * <b>Command line input:</b> * <ul> * usage: java -jar Ranker-OCR [options] * </ul> * <b>Options list:</b> * <ul> * <li>-gui Launch a graphical user interface</li> * <li>-help Show the help</li> * <li>-indoc1 [arg] Set the file name of the original document</li> * <li>-indoc2 [arg] Set the file name of the document to compare</li> * <li>-ranker [arg] Set the ranker used for the comparison</li> * <li>-outdoc [arg] Set the document where write the results</li> * <li>-separator [arg] Set the delimiter char use in the CSV out file</li> * </ul> * <b>Return values are if error:</b> * <ul> * <li>(-1) The precision parameter is not a number.</li> * <li>(-2) The precision parameter is lower than 0.</li> * <li>(-3) The precision parameter is greater than 10.</li> * <li>(-11) The ranker name is wrong</li> * <li>(-21) The separator char is empty</li> * <li>(-22) The separator is not a char</li> * <li>(-31) File name doesn't exist</li> * <li>(-32) File name is not a file</li> * <li>(-33) Error when access to documents files</li> * <li>(-34) Output file can not be write</li> * <li>(-35) Output file can not be created</li> * <li>(-41) Error when parsing parameters</li> * <li>(-100) Internal error when creating the ranker. Please report a * bug</li> * <li>(-101) Internal error when get the ranker list. Please report a * bug.</li> * <li>(-102) Error when access to help file. Please report a bug.</li> * </ul> * <p> * @param args Argument array which can have the values from options list */ public static void main(String[] args) { //Parse command line CommandLineParser parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { showHelp(hf, options); } else if (cmd.hasOption("gui")) { display.DispalyRankerOCR.main(new String[] {}); } else if (cmd.hasOption("indoc1") && cmd.hasOption("indoc2") && cmd.hasOption("outdoc")) { //<editor-fold defaultstate="collapsed" desc="Rank documents"> //Prepare parameter Class ranker = evalRanker(cmd.getOptionValue("ranker", "SimpleRanker")); char separator = evalSeparator(cmd.getOptionValue("separator", "\t")); File f1 = evalInputFile(cmd.getOptionValue("indoc1", "")); File f2 = evalInputFile(cmd.getOptionValue("indoc2", "")); File f3 = evalOutputFile(cmd.getOptionValue("outdoc", ""), separator); //Read file String s1 = readInputDocText(f1); String s2 = readInputDocText(f2); //Compare file double percent = rankDocuments(s1, s2, ranker); //Write result String[] s = { Double.toString(percent), ranker.getSimpleName(), f1.getName(), f2.getName(), f1.getParent(), f2.getParent(), new Date().toString() }; writeOutpuDocCsv(f3, separator, s); //</editor-fold> } else { printFormated("java -jar Ranker-OCR [options] please type " + "-help for more info"); } } catch (ParseException ex) { printFormated(ex.getLocalizedMessage()); System.exit(-41); } }
From source file:at.tuwien.ifs.somtoolbox.doc.RunnablesReferenceCreator.java
public static void main(String[] args) { ArrayList<Class<? extends SOMToolboxApp>> runnables = SubClassFinder.findSubclassesOf(SOMToolboxApp.class, true);/*from www. j a va 2 s. co m*/ Collections.sort(runnables, SOMToolboxApp.TYPE_GROUPED_COMPARATOR); StringBuilder sbIndex = new StringBuilder(runnables.size() * 50); StringBuilder sbDetails = new StringBuilder(runnables.size() * 200); sbIndex.append("\n<table border=\"0\">\n"); Type lastType = null; for (Class<? extends SOMToolboxApp> c : runnables) { try { // Ignore abstract classes and interfaces if (Modifier.isAbstract(c.getModifiers()) || Modifier.isInterface(c.getModifiers())) { continue; } Type type = Type.getType(c); if (type != lastType) { sbIndex.append(" <tr> <td colspan=\"2\"> <h5> " + type + " Applications </h5> </td> </tr>\n"); sbDetails.append("<h2> " + type + " Applications </h2>\n"); lastType = type; } String descr = "N/A"; try { descr = (String) c.getDeclaredField("DESCRIPTION").get(null); } catch (Exception e) { } String longDescr = "descr"; try { longDescr = (String) c.getDeclaredField("LONG_DESCRIPTION").get(null); } catch (Exception e) { } sbIndex.append(" <tr>\n"); sbIndex.append(" <td> <a href=\"#").append(c.getSimpleName()).append("\">") .append(c.getSimpleName()).append("</a> </td>\n"); sbIndex.append(" <td> ").append(descr).append(" </td>\n"); sbIndex.append(" </tr>\n"); sbDetails.append("<h3 id=\"").append(c.getSimpleName()).append("\">").append(c.getSimpleName()) .append("</h3>\n"); sbDetails.append("<p>").append(longDescr).append("</p>\n"); try { Parameter[] options = (Parameter[]) c.getField("OPTIONS").get(null); JSAP jsap = AbstractOptionFactory.registerOptions(options); final ByteArrayOutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); AbstractOptionFactory.printHelp(jsap, c.getName(), ps); sbDetails.append("<pre>").append(StringEscapeUtils.escapeHtml(os.toString())).append("</pre>"); } catch (Exception e1) { // we didn't find the options => let the class be invoked ... } } catch (SecurityException e) { // Should not happen - no Security } catch (IllegalArgumentException e) { e.printStackTrace(); } } sbIndex.append("</table>\n\n"); System.out.println(sbIndex); System.out.println(sbDetails); }
From source file:Main.java
public static String humanShort(Class n) { return n.getSimpleName(); }
From source file:Main.java
public static String getExpectedClassId(Class clazz) { return clazz.getSimpleName() + "." + clazz.getPackage().getName(); }
From source file:Main.java
public static String makeLogTag(Class<?> cls) { return cls.getSimpleName(); }
From source file:Main.java
public static String obtainClassName(Class<?> obj) { return obj.getSimpleName(); }