protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) { String beanClassName = interceptorDefinition.getBeanClassName(); return (StringUtils.hasLength(beanClassName) ? StringUtils.uncapitalize(ClassUtils.getShortName(beanClassName)) : ""); }
/** * Obtains the collection name to use for the provided class * * @param entityClass The class to determine the preferred collection name for * @return The preferred collection name */ public static String getPreferredCollectionName(Class<?> entityClass) { return StringUtils.uncapitalize(entityClass.getSimpleName()); }
private String resolveName() { if (this.readMethod != null) { int index = this.readMethod.getName().indexOf("get"); if (index != -1) { index += 3; } else { index = this.readMethod.getName().indexOf("is"); if (index == -1) { throw new IllegalArgumentException("Not a getter method"); } index += 2; } return StringUtils.uncapitalize(this.readMethod.getName().substring(index)); } else if (this.writeMethod != null) { int index = this.writeMethod.getName().indexOf("set"); if (index == -1) { throw new IllegalArgumentException("Not a setter method"); } index += 3; return StringUtils.uncapitalize(this.writeMethod.getName().substring(index)); } else { throw new IllegalStateException("Property is neither readable nor writeable"); } }
@Nullable PropertyDescriptor getPropertyDescriptor(String name) { PropertyDescriptor pd = this.propertyDescriptorCache.get(name); if (pd == null && StringUtils.hasLength(name)) { // Same lenient fallback checking as in Property... pd = this.propertyDescriptorCache.get(StringUtils.uncapitalize(name)); if (pd == null) { pd = this.propertyDescriptorCache.get(StringUtils.capitalize(name)); } } return (pd == null || pd instanceof GenericTypeAwarePropertyDescriptor ? pd : buildGenericTypeAwarePropertyDescriptor(getBeanClass(), pd)); }
@Nullable private Field getField() { String name = getName(); if (!StringUtils.hasLength(name)) { return null; } Field field = null; Class<?> declaringClass = declaringClass(); if (declaringClass != null) { field = ReflectionUtils.findField(declaringClass, name); if (field == null) { // Same lenient fallback checking as in CachedIntrospectionResults... field = ReflectionUtils.findField(declaringClass, StringUtils.uncapitalize(name)); if (field == null) { field = ReflectionUtils.findField(declaringClass, StringUtils.capitalize(name)); } } } return field; }
private String resolveName() { if (this.readMethod != null) { int index = this.readMethod.getName().indexOf("get"); if (index != -1) { index += 3; } else { index = this.readMethod.getName().indexOf("is"); if (index == -1) { throw new IllegalArgumentException("Not a getter method"); } index += 2; } return StringUtils.uncapitalize(this.readMethod.getName().substring(index)); } else if (this.writeMethod != null) { int index = this.writeMethod.getName().indexOf("set"); if (index == -1) { throw new IllegalArgumentException("Not a setter method"); } index += 3; return StringUtils.uncapitalize(this.writeMethod.getName().substring(index)); } else { throw new IllegalStateException("Property is neither readable nor writeable"); } }
@Nullable PropertyDescriptor getPropertyDescriptor(String name) { PropertyDescriptor pd = this.propertyDescriptorCache.get(name); if (pd == null && StringUtils.hasLength(name)) { // Same lenient fallback checking as in Property... pd = this.propertyDescriptorCache.get(StringUtils.uncapitalize(name)); if (pd == null) { pd = this.propertyDescriptorCache.get(StringUtils.capitalize(name)); } } return (pd == null || pd instanceof GenericTypeAwarePropertyDescriptor ? pd : buildGenericTypeAwarePropertyDescriptor(getBeanClass(), pd)); }
@Test public void scanAndRefresh() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.scan("org.springframework.context.annotation6"); context.refresh(); context.getBean(uncapitalize(ConfigForScanning.class.getSimpleName())); context.getBean("testBean"); // contributed by ConfigForScanning context.getBean(uncapitalize(ComponentForScanning.class.getSimpleName())); context.getBean(uncapitalize(Jsr330NamedForScanning.class.getSimpleName())); Map<String, Object> beans = context.getBeansWithAnnotation(Configuration.class); assertEquals(1, beans.size()); }
@Nullable private Field getField() { String name = getName(); if (!StringUtils.hasLength(name)) { return null; } Field field = null; Class<?> declaringClass = declaringClass(); if (declaringClass != null) { field = ReflectionUtils.findField(declaringClass, name); if (field == null) { // Same lenient fallback checking as in CachedIntrospectionResults... field = ReflectionUtils.findField(declaringClass, StringUtils.uncapitalize(name)); if (field == null) { field = ReflectionUtils.findField(declaringClass, StringUtils.capitalize(name)); } } } return field; }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (cache.containsKey(beanName)) { // add interceptor for each RestTemplate with @SentinelRestTemplate annotation StringBuilder interceptorBeanName = new StringBuilder(); SentinelRestTemplate sentinelRestTemplate = cache.get(beanName); interceptorBeanName .append(StringUtils.uncapitalize( SentinelProtectInterceptor.class.getSimpleName())) .append("_") .append(sentinelRestTemplate.blockHandlerClass().getSimpleName()) .append(sentinelRestTemplate.blockHandler()).append("_") .append(sentinelRestTemplate.fallbackClass().getSimpleName()) .append(sentinelRestTemplate.fallback()); RestTemplate restTemplate = (RestTemplate) bean; registerBean(interceptorBeanName.toString(), sentinelRestTemplate); SentinelProtectInterceptor sentinelProtectInterceptor = applicationContext .getBean(interceptorBeanName.toString(), SentinelProtectInterceptor.class); restTemplate.getInterceptors().add(0, sentinelProtectInterceptor); } return bean; }
@Test public void testUncapitalize() { String capitalized = "I am capitalized"; assertEquals("i am capitalized", StringUtils.uncapitalize(capitalized)); }
@Test public void testAddMap() throws Exception { Map<String, String> map = new HashMap<>(); map.put("one", "one-value"); map.put("two", "two-value"); ModelMap model = new ModelMap(); model.addAttribute(map); assertEquals(1, model.size()); String key = StringUtils.uncapitalize(ClassUtils.getShortName(map.getClass())); assertTrue(model.containsKey(key)); }
@Override public String getCollectionResourceRelFor(Class<?> type) { return StringUtils.uncapitalize(type.getSimpleName()); } }
/** * Obtains the collection name to use for the provided class * * @param entityClass The class to determine the preferred collection name for * @return The preferred collection name */ public static String getPreferredCollectionName(Class<?> entityClass) { return StringUtils.uncapitalize(entityClass.getSimpleName()); }
@Override public String getItemResourceRelFor(Class<?> type) { return StringUtils.uncapitalize(type.getSimpleName()); } }
private String getSimpleTypeName(Class<?> type) { return StringUtils.uncapitalize(type.getSimpleName()); } }
@Override public String getCollectionResourceRelFor(Class<?> type) { return StringUtils.uncapitalize(type.getSimpleName()) + "List"; }
/** * Adds a projection type for the given source types. The name of the projection will be defaulted to the * uncapitalized simply class name. * * @param projectionType must not be {@literal null}. * @param sourceTypes must not be {@literal null} or empty. * @return */ public ProjectionDefinitionConfiguration addProjection(Class<?> projectionType, Class<?>... sourceTypes) { Assert.notNull(projectionType, "Projection type must not be null!"); return addProjection(projectionType, StringUtils.uncapitalize(projectionType.getSimpleName()), sourceTypes); }
private void setId(String id) { if (StringUtils.hasText(id)) { this.id = id; } else { this.id = StringUtils.uncapitalize(StringUtils.delete(ClassUtils.getShortName(className), "FlowBuilder")); } }
public static String findPath(Class<?> type) { RestResource anno = findAnnotation(type, RestResource.class); if (anno != null) { if (hasTextExceptSlash(anno.path())) { return removeLeadingSlash(anno.path()); } } return uncapitalize(type.getSimpleName().replaceAll("Repository", "")); }