List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:com.eucalyptus.www.X509Download.java
private static Optional<String> remotePublicify(final Class<? extends ComponentId> componentClass) { Optional<String> url = Optional.absent(); if (Topology.isEnabled(componentClass)) try {/*from w w w .ja v a2 s .c o m*/ url = Optional.of(hostMap(ServiceUris.remotePublicify(Topology.lookup(componentClass))).toString()); } catch (final Exception e) { LOG.error("Failed to get URL for service " + componentClass.getSimpleName(), e); } return url; }
From source file:br.gov.frameworkdemoiselle.ldap.internal.ClazzUtils.java
public static Field getFieldAnnotatedAs(Class<?> clazz, Class<? extends Annotation> aclazz, boolean required) { for (Field field : getSuperClassesFields(clazz)) if (field.isAnnotationPresent(aclazz)) return field; if (required) throw new EntryException( "Field with @" + aclazz.getSimpleName() + " not found on class " + clazz.getSimpleName()); else/*w w w . java 2 s .co m*/ return null; }
From source file:com.intuit.autumn.utils.PropertyFactory.java
private static Properties readZip(final Class base, final URL jar, final String property, final Properties properties) { try (ZipInputStream zip = new ZipInputStream(jar.openStream())) { for (ZipEntry ze = zip.getNextEntry(); ze != null; ze = zip.getNextEntry()) { if (ze.getName().equals(property)) { properties.load(zip);// w ww . j ava2 s.c o m break; } } } catch (IOException e) { LOGGER.warn("unable to read jar: {}, property: {}, class: {}, cause: {}", new Object[] { jar, property, base.getSimpleName(), e.getMessage() }, e); } return properties; }
From source file:com.baasbox.configuration.PropertiesConfigurationHelper.java
public static String dumpConfigurationSectionAsFlatJson(String section) { Class en = CONFIGURATION_SECTIONS.get(section); try {// w ww .j a va 2s .c om JsonFactory jfactory = new JsonFactory(); StringWriter sw = new StringWriter(); String enumDescription = ""; JsonGenerator gen = jfactory.createJsonGenerator(sw); gen.writeStartArray(); EnumSet values = EnumSet.allOf(en); for (Object v : values) { String key = (String) (en.getMethod("getKey")).invoke(v); boolean isVisible = (Boolean) (en.getMethod("isVisible")).invoke(v); String valueAsString; if (isVisible) valueAsString = (String) (en.getMethod("getValueAsString")).invoke(v); else valueAsString = "--HIDDEN--"; boolean isEditable = (Boolean) (en.getMethod("isEditable")).invoke(v); boolean isOverridden = (Boolean) (en.getMethod("isOverridden")).invoke(v); String valueDescription = (String) (en.getMethod("getValueDescription")).invoke(v); Class type = (Class) en.getMethod("getType").invoke(v); gen.writeStartObject(); // { gen.writeStringField("key", key); gen.writeStringField("value", valueAsString); gen.writeStringField("description", valueDescription); // ,"description":"description" gen.writeStringField("type", type.getSimpleName()); // ,"type":"type" gen.writeBooleanField("editable", isEditable); gen.writeBooleanField("overridden", isOverridden); gen.writeEndObject(); // } } if (gen.getOutputContext().inArray()) gen.writeEndArray(); // ] gen.close(); return sw.toString(); } catch (Exception e) { BaasBoxLogger.error("Cannot generate a json for " + en.getSimpleName() + " Enum. Is it an Enum that implements the IProperties interface?", e); } return "{}"; }
From source file:ch.sdi.core.impl.cfg.ConfigUtils.java
/** * Converts the given classname into a properties file name according following rules: * * <ul>/* ww w . ja va2 s . c o m*/ * <li> if class is annotated with SdiProps the value of the annotation is used, suffixed by * ".properties" (unless already present).</li> * <li>if annotation is missing or no value configured:</li> * <ul> * <li> if class name ends with "Properties" this suffix will be truncated and replaced by * ".properties"</li> * <li> any other class name is used as is and suffixed with ".properties"</li> * </ul> * </ul> * */ public static String makePropertyResourceName(Class<?> aClass) { String found = null; SdiProps ann = aClass.getAnnotation(SdiProps.class); if (ann != null) { found = ann.value(); } // if ann != null if (StringUtils.hasText(found)) { if (found.endsWith(".properties")) { return found; } // if condition return found + ".properties"; } String classname = aClass.getSimpleName(); if (classname.endsWith("Properties") || classname.endsWith("properties")) { return classname.substring(0, classname.length() - "Properties".length()) + ".properties"; } // if condition return classname + ".properties"; }
From source file:com.opengamma.component.tool.ToolContextUtils.java
private static ComponentInfo getComponentInfo(ComponentServer componentServer, List<String> preferenceList, Class<?> type) { Map<String, ComponentInfo> infos = componentServer.getComponentInfoMap(type); if (preferenceList != null) { for (String preference : preferenceList) { ComponentInfo componentInfo = infos.get(preference); if (componentInfo != null) { return componentInfo; }// w ww . ja v a 2 s .c om } } infos.remove("test"); if (infos.size() == 0) { return null; } if (infos.size() > 1) { s_logger.warn("Multiple remote components match: " + type.getSimpleName() + "::" + infos.keySet()); return null; } return infos.values().iterator().next(); }
From source file:com.github.tomakehurst.wiremock.matching.StringValuePatternJsonDeserializer.java
@SuppressWarnings("unchecked") private static Constructor<? extends StringValuePattern> findConstructor( Class<? extends StringValuePattern> clazz) { Optional<Constructor<?>> optionalConstructor = tryFind(asList(clazz.getDeclaredConstructors()), new Predicate<Constructor<?>>() { @Override/*from w w w . j a v a 2 s .c o m*/ public boolean apply(Constructor<?> input) { return input.getParameterTypes().length == 1 && input.getGenericParameterTypes()[0].equals(String.class); } }); if (!optionalConstructor.isPresent()) { throw new IllegalStateException( "Constructor for " + clazz.getSimpleName() + " must have a single string argument constructor"); } return (Constructor<? extends StringValuePattern>) optionalConstructor.get(); }
From source file:net.pms.external.ExternalFactory.java
public static void instantiateDownloaded(JLabel update) { // These are found in the downloadedListenerClasses list for (Class<?> clazz : downloadedListenerClasses) { ExternalListener instance;/*from www . j a v a2 s . c o m*/ try { doUpdate(update, Messages.getString("NetworkTab.48") + " " + clazz.getSimpleName()); postInstall(clazz); LOGGER.debug("do inst of " + clazz.getSimpleName()); instance = (ExternalListener) clazz.newInstance(); doUpdate(update, instance.name() + " " + Messages.getString("NetworkTab.49")); registerListener(instance); if (PMS.get().getFrame() instanceof LooksFrame) { LooksFrame frame = (LooksFrame) PMS.get().getFrame(); if (!frame.getPt().appendPlugin(instance)) { LOGGER.warn("Plugin limit of 30 has been reached"); } } } catch (InstantiationException | IllegalAccessException e) { LOGGER.error("Error instantiating plugin", e); } } downloadedListenerClasses.clear(); }
From source file:org.hawkular.wildfly.agent.itest.util.AbstractITest.java
public static String readNode(Class<?> caller, String nodeFileName) throws IOException { URL url = caller.getResource(caller.getSimpleName() + "." + nodeFileName); if (url != null) { StringBuilder result = new StringBuilder(); try (Reader r = new InputStreamReader(url.openStream(), "utf-8")) { char[] buff = new char[1024]; int len = 0; while ((len = r.read(buff, 0, buff.length)) != -1) { result.append(buff, 0, len); }/* w w w .j a v a 2 s. c om*/ } return result.toString(); } else { return null; } }
From source file:com.netflix.spinnaker.halyard.config.model.v1.node.Node.java
/** * @param clazz the class to check against. * @param name is the name to match on.//from www . j a v a 2 s . c o m * @return a NodeMatcher that matches all nodes of given clazz that also have the right name. */ static public NodeMatcher namedNodeAcceptor(Class clazz, String name) { return new NodeMatcher() { @Override public boolean matches(Node n) { return clazz.isAssignableFrom(n.getClass()) && n.getNodeName().equals(name); } @Override public String getName() { return "Match against [" + clazz.getSimpleName() + ":" + name + "]"; } }; }