List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:io.fabric8.core.jmx.BeanUtils.java
public static List<String> getFields(Class clazz) { List<String> answer = new ArrayList<String>(); try {// ww w . j a v a 2 s.c o m for (PropertyDescriptor desc : PropertyUtils.getPropertyDescriptors(clazz)) { if (desc.getReadMethod() != null) { answer.add(desc.getName()); } } } catch (Exception e) { throw new FabricException("Failed to get property descriptors for " + clazz.toString(), e); } // few tweaks to maintain compatibility with existing views for now... if (clazz.getSimpleName().equals("Container")) { answer.add("parentId"); answer.add("versionId"); answer.add("profileIds"); answer.add("childrenIds"); answer.remove("fabricService"); } else if (clazz.getSimpleName().equals("Profile")) { answer.add("id"); answer.add("parentIds"); answer.add("childIds"); answer.add("containerCount"); answer.add("containers"); answer.add("fileConfigurations"); } else if (clazz.getSimpleName().equals("Version")) { answer.add("id"); answer.add("defaultVersion"); } return answer; }
From source file:com.starlink.rest.util.Reflections.java
/** * ??, Class?.// w ww. j a v a 2s . co m * , Object.class. * * public UserDao extends HibernateDao<User,Long> * * @param clazz clazz The class to introspect * @param index the Index of the generic ddeclaration,start from 0. * @return the index generic declaration, or Object.class if cannot be determined */ public static Class getClassGenricType(final Class clazz, final int index) { // getGenericSuperclass() // Type Java ??????? Type genType = clazz.getGenericSuperclass(); // ParameterizedType?? if (!(genType instanceof ParameterizedType)) { logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); return Object.class; } // getActualTypeArguments??? Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if ((index >= params.length) || (index < 0)) { logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + params.length); return Object.class; } if (!(params[index] instanceof Class)) { logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return Object.class; } return (Class) params[index]; }
From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java
private static ObjectNode buildSyntaxNode(final ObjectMapper objectMapper, final Type heapValueType, final SyntaxLoader syntaxLoader) { if (!String.class.equals(heapValueType) && heapValueType instanceof Class<?>) { // TODO: Make it easy/possible to get the Syntax Document's title and uri final Class<?> heapValueClass = (Class<?>) heapValueType; final URI syntaxUri = syntaxLoader.getSyntaxUri(heapValueClass); final String syntaxName = heapValueClass.getSimpleName(); final ObjectNode syntaxNode = objectMapper.createObjectNode(); syntaxNode.put(PropertyName.title.name(), syntaxName); syntaxNode.put(PropertyName.uri.name(), syntaxUri.toString()); return syntaxNode; }// w w w.jav a 2 s . c o m return null; }
From source file:org.grails.datastore.mapping.gemfire.query.GemfireQuery.java
private static void validateProperty(PersistentEntity entity, String name, Class criterionType) { if (entity.getIdentity().getName().equals(name)) return;/*from w w w .j av a 2s . c o m*/ PersistentProperty prop = entity.getPropertyByName(name); if (prop == null) { throw new InvalidDataAccessResourceUsageException("Cannot use [" + criterionType.getSimpleName() + "] criterion on non-existent property: " + name); } }
From source file:com.alta189.bukkit.script.event.EventScanner.java
public static void scanPlugin(Plugin plugin) { if (pluginEvents.containsKey(plugin)) { return;/*from w w w . j av a 2 s.com*/ } BScript.getInstance().debug("Scanning plugin " + plugin.getName()); if (plugin instanceof JavaPlugin) { ClassLoader loader = ReflectionUtil.getFieldValue(JavaPlugin.class, plugin, "classLoader"); Reflections reflections = new Reflections(new ConfigurationBuilder() .filterInputsBy(new FilterBuilder().exclude(FilterBuilder.prefix("org.bukkit"))) .setUrls(ClasspathHelper.forClassLoader(loader))); Set<Class<? extends Event>> classes = reflections.getSubTypesOf(Event.class); BScript.getInstance().info("Found " + classes.size() + " classes extending " + Event.class.getCanonicalName() + " in " + plugin.getName()); for (Class<? extends Event> clazz : classes) { if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { continue; } BScript.getInstance().debug(clazz.getCanonicalName()); String className = clazz.getCanonicalName(); if (className == null) { className = clazz.getName(); } BScript.getInstance().debug(className); events.put(className, clazz); String simpleName = clazz.getSimpleName(); if (simpleNameEvents.get(simpleName) != null) { simpleNameEvents.remove(simpleName); } else { simpleNameEvents.put(simpleName, clazz); } } if (classes.size() > 0) { pluginEvents.put(plugin, classes); } } else { BScript.getInstance().debug("Plugin is not JavaPlugin " + plugin.getName()); } }
From source file:com.sunchenbin.store.feilong.core.lang.ClassUtil.java
/** * class info map for LOGGER.//from w w w . jav a 2 s. co m * * @param klass * the clz * @return the map for log */ public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) { if (Validator.isNullOrEmpty(klass)) { return Collections.emptyMap(); } Map<String, Object> map = new LinkedHashMap<String, Object>(); map.put("clz.getCanonicalName()", klass.getCanonicalName());//"com.sunchenbin.store.feilong.core.date.DatePattern" map.put("clz.getName()", klass.getName());//"com.sunchenbin.store.feilong.core.date.DatePattern" map.put("clz.getSimpleName()", klass.getSimpleName());//"DatePattern" map.put("clz.getComponentType()", klass.getComponentType()); // ?? ,voidboolean?byte?char?short?int?long?float double? map.put("clz.isPrimitive()", klass.isPrimitive()); // ??, map.put("clz.isLocalClass()", klass.isLocalClass()); // ????,?,????? map.put("clz.isMemberClass()", klass.isMemberClass()); //isSynthetic()?Class????java??false,?true,JVM???,java?????? map.put("clz.isSynthetic()", klass.isSynthetic()); map.put("clz.isArray()", klass.isArray()); map.put("clz.isAnnotation()", klass.isAnnotation()); //??true map.put("clz.isAnonymousClass()", klass.isAnonymousClass()); map.put("clz.isEnum()", klass.isEnum()); return map; }
From source file:org.cybercat.automation.annotations.AnnotationBuilder.java
@SuppressWarnings("unchecked") private final static <T extends IFeature> T createFeature(Class<T> eType) throws AutomationFrameworkException { try {// w ww . ja v a 2s . c o m Constructor<T> cons = eType.getDeclaredConstructor(); T result = cons.newInstance(); AnnotationBuilder.processCCFeature(result); AnnotationBuilder.processCCPageObject(result); AspectJProxyFactory proxyFactory = new AspectJProxyFactory(result); proxyFactory.addAspect(TestStepAspect.class); result = (T) proxyFactory.getProxy(); log.info(eType.getSimpleName() + " feature has been created."); return result; } catch (Exception e) { // handle test fail throw new AutomationFrameworkException("Feature factoring exception. ", e); } }
From source file:com.pandich.dropwizard.curator.refresh.Refresher.java
private static String getNodePath(final Class<?> clazz, final String name, final CuratorInject curatorInject) { final String path; if (startsWith(curatorInject.value(), PATH_DELIMITER)) { path = curatorInject.value();/*from w ww . j av a 2 s . c om*/ } else { final String rootPath; final CuratorRoot curatorRoot = clazz.getAnnotation(CuratorRoot.class); if (curatorRoot != null && !isBlank(curatorRoot.value())) { rootPath = curatorRoot.value(); } else { final String underscoreClassName = UPPER_CAMEL.to(LOWER_UNDERSCORE, clazz.getSimpleName()); final String[] pieces = split(underscoreClassName, "_"); rootPath = join(subarray(pieces, 0, pieces.length - 1)); } final String nodeSubPath = defaultIfBlank(curatorInject.value(), name); final String normalizedRootPath = strip(rootPath, PATH_DELIMITER); path = lowerCase(PATH_DELIMITER + normalizedRootPath + PATH_DELIMITER + nodeSubPath); } log.debug("path: {}.{}={}", new Object[] { clazz.getSimpleName(), name, path }); return path; }
From source file:gr.abiss.calipso.tiers.util.ModelContext.java
public static String getPath(Class<?> domainClass) { ModelResource ar = domainClass.getAnnotation(ModelResource.class); ModelRelatedResource anr = domainClass.getAnnotation(ModelRelatedResource.class); String result;/*from w ww . jav a 2 s .c o m*/ if (ar != null) { result = ar.path(); } else if (anr != null) { result = anr.path(); } else { throw new IllegalStateException("Not an entity"); } if (result == null || result.trim().isEmpty()) { result = domainClass.getSimpleName(); result = result.toLowerCase().charAt(0) + result.substring(1) + "s"; } return result; }
From source file:net.bull.javamelody.MonitoringSpringInterceptor.java
private static String getClassPart(MethodInvocation invocation) { // si guice et pas Spring, alors remplacer AopUtils.getTargetClass() par getMethod().getDeclaringClass() // http://ninomartinez.wordpress.com/2010/05/14/guice-caching-interceptors/ // (faire exemple avec un interceptor static) final Class<?> targetClass = AopUtils.getTargetClass(invocation.getThis()); final MonitoredWithSpring classAnnotation = targetClass.getAnnotation(MonitoredWithSpring.class); if (classAnnotation == null || classAnnotation.name() == null || classAnnotation.name().length() == 0) { final Class<?> declaringClass = invocation.getMethod().getDeclaringClass(); final MonitoredWithSpring declaringClassAnnotation = declaringClass .getAnnotation(MonitoredWithSpring.class); if (declaringClassAnnotation == null || declaringClassAnnotation.name() == null || declaringClassAnnotation.name().length() == 0) { return targetClass.getSimpleName(); }/*from w w w.j a v a 2s . c o m*/ return declaringClassAnnotation.name(); } return classAnnotation.name(); }