List of usage examples for java.lang Class getName
public String getName()
From source file:Main.java
/** * Convenience method for obtaining most non-null human readable properties of a JComponent. Array properties are not included. * <P>/*w ww . j a v a 2 s. c o m*/ * Implementation note: The returned value is a HashMap. This is subject to change, so callers should code against the interface Map. * * @param component * the component whose proerties are to be determined * @return the class and value of the properties */ public static Map<Object, Object> getProperties(JComponent component) { Map<Object, Object> retVal = new HashMap<>(); Class<?> clazz = component.getClass(); Method[] methods = clazz.getMethods(); Object value = null; for (Method method : methods) { if (method.getName().matches("^(is|get).*") && //$NON-NLS-1$ method.getParameterTypes().length == 0) { try { Class<?> returnType = method.getReturnType(); if (returnType != void.class && !returnType.getName().startsWith("[") && //$NON-NLS-1$ !setExclude.contains(method.getName())) { String key = method.getName(); value = method.invoke(component); if (value != null && !(value instanceof Component)) { retVal.put(key, value); } } // ignore exceptions that arise if the property could not be accessed } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { //no catch } } } return retVal; }
From source file:ShowHTMLViews.java
public static String getShortClassName(Class clazz) { String className = clazz.getName(); return className.substring(className.lastIndexOf(".") + 1); }
From source file:mondrian.spi.DataServicesLocator.java
public static DataServicesProvider getDataServicesProvider(final String className) { if (Util.isEmpty(className)) { return new DefaultDataServicesProvider(); } else {/*from w w w .j a va 2 s . c o m*/ ServiceDiscovery<DataServicesProvider> discovery = ServiceDiscovery .forClass(DataServicesProvider.class); List<Class<DataServicesProvider>> implementors = discovery.getImplementor(); Predicate providerNamePredicate = new Predicate() { public boolean evaluate(Object o) { Class<DataServicesProvider> providerClass = (Class<DataServicesProvider>) o; return providerClass.getName().equals(className); } }; Class<DataServicesProvider> provider = (Class<DataServicesProvider>) find(implementors, providerNamePredicate); if (provider != null) { try { return provider.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } throw new RuntimeException("Unrecognized Service Provider: " + className); } }
From source file:Main.java
/** * Same as a readable name but internal class keep the dollar sign in their name * @param elt//from w w w . j av a 2 s . c o m * @return */ public static String readableSootName(Class<?> elt) { if (elt.isArray()) return readableSootName(elt.getComponentType()) + "[]"; else return elt.getName(); }
From source file:ru.mystamps.web.controller.ErrorController.java
private static Object getNameOrAsIs(Class<?> clazz) { if (clazz == null) { return null; }//w w w. j a v a 2 s .c o m return clazz.getName(); }
From source file:edu.cmu.sv.modelinference.common.Util.java
public static void printHelpAndExit(Class<?> clz, Options opts, int exitVal) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(clz.getName(), opts); System.exit(exitVal);/*from w w w .ja v a 2 s . co m*/ }
From source file:cc.aileron.commons.util.ResourceUtils.java
/** * @param targetClass//from w ww . j av a2 s . co m * @return ? */ public static final String classNameToDirectoryName(final Class<?> targetClass) { return targetClass.getName().replace('.', '/') + "/"; }
From source file:Main.java
/** * Convenience method for obtaining most non-null human readable properties * of a JComponent. Array properties are not included. * <P>/*from w w w.ja v a 2 s . c o m*/ * Implementation note: The returned value is a HashMap. This is subject to * change, so callers should code against the interface Map. * * @param component * the component whose proerties are to be determined * @return the class and value of the properties */ public static Map<Object, Object> getProperties(final JComponent component) { final Map<Object, Object> retVal = new HashMap<Object, Object>(); final Class<?> clazz = component.getClass(); final Method[] methods = clazz.getMethods(); Object value = null; for (final Method method : methods) { if (method.getName().matches("^(is|get).*") && method.getParameterTypes().length == 0) { try { final Class returnType = method.getReturnType(); if (returnType != void.class && !returnType.getName().startsWith("[") && !setExclude.contains(method.getName())) { final String key = method.getName(); value = method.invoke(component); if (value != null && !(value instanceof Component)) { retVal.put(key, value); } } // ignore exceptions that arise if the property could not be // accessed } catch (final IllegalAccessException ex) { } catch (final IllegalArgumentException ex) { } catch (final InvocationTargetException ex) { } } } return retVal; }
From source file:Main.java
private static JAXBContext getJAXBContext(Class<?>[] clazzs) throws JAXBException { if (clazzs != null) { StringBuilder sb = new StringBuilder(); for (Class<?> c : clazzs) { sb.append(c.getName()).append(","); }/*from w w w. j av a2s. co m*/ String str = sb.toString(); if (contextbuf.containsKey(str)) { return contextbuf.get(str); } else { JAXBContext c = JAXBContext.newInstance(clazzs); contextbuf.put(str, c); return c; } } else { throw new JAXBException(new NullPointerException("Class")); } }
From source file:com.netflix.config.jmx.ConfigJMXManager.java
private static ObjectName getJMXObjectName(AbstractConfiguration config, ConfigMBean bean) throws Exception { try {/* ww w .j a v a 2 s . c o m*/ Class<? extends ConfigMBean> c = bean.getClass(); String className = c.getName(); int lastDot = className.lastIndexOf('.'); ObjectName name = new ObjectName( "Config-" + className.substring(0, lastDot) + ":class=" + className.substring(lastDot + 1)); return name; } catch (MalformedObjectNameException e) { throw new RuntimeException("MalformedObjectNameException", e); } catch (NullPointerException e) { throw new RuntimeException("NullPointerException", e); } }