Example usage for java.beans Introspector decapitalize

List of usage examples for java.beans Introspector decapitalize

Introduction

In this page you can find the example usage for java.beans Introspector decapitalize.

Prototype

public static String decapitalize(String name) 

Source Link

Document

Utility method to take a string and convert it to normal Java variable name capitalization.

Usage

From source file:grails.plugin.searchable.internal.support.DynamicMethodUtils.java

/**
 * Extract the property names from the given method name suffix
 *
 * @param methodSuffix a method name suffix like 'NameAndAddress'
 * @return a Collection of property names like ['name', 'address']
 *//*w w  w  . j  a  va 2s.c om*/
public static Collection extractPropertyNames(String methodSuffix) {
    String[] splited = methodSuffix.split("And");
    Set propertyNames = new HashSet();
    for (int i = 0; i < splited.length; i++) {
        if (splited[i].length() > 0) {
            propertyNames.add(Introspector.decapitalize(splited[i]));
        }
    }
    return propertyNames;
}

From source file:mojo.view.util.SpringUtils.java

@SuppressWarnings("unchecked")
public static <T> T getComponent(Class<?> klass) {
    String name = Introspector.decapitalize(klass.getSimpleName());
    return (T) applicationContext.getBean(name);
}

From source file:com.beetle.framework.util.ObjectUtil.java

static String decapitalize(String fieldName) {
    return Introspector.decapitalize(fieldName);
}

From source file:ReflectionHelper.java

/**
 * Process bean properties getter by applying the JavaBean naming conventions.
 *
 * @param member the member for which to get the property name.
 *
 * @return The bean method name with the "is" or "get" prefix stripped off, <code>null</code>
 *         the method name id not according to the JavaBeans standard.
 *//*w w  w .  j a  va 2  s. co m*/
public static String getPropertyName(Member member) {
    String name = null;

    if (member instanceof Field) {
        name = member.getName();
    }

    if (member instanceof Method) {
        String methodName = member.getName();
        if (methodName.startsWith("is")) {
            name = Introspector.decapitalize(methodName.substring(2));
        } else if (methodName.startsWith("get")) {
            name = Introspector.decapitalize(methodName.substring(3));
        }
    }
    return name;
}

From source file:org.cometd.annotation.spring.SpringAnnotationTest.java

@Test
public void testSpringWiringOfCometDServices() throws Exception {
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
    applicationContext.setConfigLocation("classpath:applicationContext.xml");
    applicationContext.refresh();/*from   w w w  .ja v  a2s .  co m*/

    String beanName = Introspector.decapitalize(SpringBayeuxService.class.getSimpleName());

    String[] beanNames = applicationContext.getBeanDefinitionNames();
    assertTrue(Arrays.asList(beanNames).contains(beanName));

    SpringBayeuxService service = (SpringBayeuxService) applicationContext.getBean(beanName);
    assertNotNull(service);
    assertNotNull(service.dependency);
    assertNotNull(service.bayeuxServer);
    assertNotNull(service.serverSession);
    assertTrue(service.active);
    assertEquals(1, service.bayeuxServer.getChannel(SpringBayeuxService.CHANNEL).getSubscribers().size());

    applicationContext.close();

    assertFalse(service.active);
}

From source file:org.springmodules.validation.commons.DefaultBeanValidator.java

/**
 * If <code>useFullyQualifiedClassName</code> is false (default value), this function returns a
 * string containing the uncapitalized, short name for the given class
 * (e.g. myBean for the class com.domain.test.MyBean). Otherwise, it  returns the value
 * returned by <code>Class.getName()</code>.
 *
 * @param cls <code>Class</code> of the bean to be validated.
 * @return the bean name./*from ww w .  ja v  a 2s  .c o  m*/
 */
protected String getFormName(Class cls) {
    return (this.useFullyQualifiedClassName) ? cls.getName()
            : Introspector.decapitalize(ClassUtils.getShortName(cls));
}

From source file:org.cometd.oort.spring.OortSpringAnnotationTest.java

@Test
public void testSpringWiringOfOort() throws Exception {
    Server server = new Server();
    ServletContextHandler context = new ServletContextHandler(server, "/");
    WebSocketServerContainerInitializer.configureContext(context);
    context.addEventListener(new ContextLoaderListener());
    context.getInitParams().put(ContextLoader.CONFIG_LOCATION_PARAM, "classpath:/applicationContext.xml");
    server.start();//from   w w w .java2 s. c o m

    ApplicationContext applicationContext = WebApplicationContextUtils
            .getWebApplicationContext(context.getServletContext());

    String beanName = Introspector.decapitalize(OortService.class.getSimpleName());

    String[] beanNames = applicationContext.getBeanDefinitionNames();
    assertTrue(Arrays.asList(beanNames).contains(beanName));

    OortService service = (OortService) applicationContext.getBean(beanName);
    assertNotNull(service);
    Seti seti = service.seti;
    assertNotNull(seti);
    Oort oort = seti.getOort();
    assertNotNull(oort);
    BayeuxServer bayeux = oort.getBayeuxServer();
    assertNotNull(bayeux);

    SecurityPolicy policy = bayeux.getSecurityPolicy();
    assertNotNull(policy);
    assertTrue(policy instanceof OortSecurityPolicy);

    server.stop();
}

From source file:info.novatec.testit.livingdoc.util.NameUtils.java

public static String decapitalize(String s) {
    StringBuilder sb = new StringBuilder();
    String[] parts = s.trim().split("\\s+");

    sb.append(Introspector.decapitalize(parts[0]));
    for (int i = 1; i < parts.length; ++i) {
        sb.append(StringUtils.capitalize(Introspector.decapitalize(parts[i])));
    }/*www  .  j a  v  a2s  . c o  m*/
    return sb.toString();
}

From source file:io.fabric8.cxf.endpoint.BeanValidationAnnotationIntrospector.java

@Override
public boolean hasIgnoreMarker(AnnotatedMember m) {
    Member member = m.getMember();
    int modifiers = member.getModifiers();
    if (Modifier.isTransient(modifiers)) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Ignoring transient member " + m);
        }// ww w.jav  a  2s. co  m
        return true;
    } else if (m instanceof AnnotatedMethod) {
        AnnotatedMethod method = (AnnotatedMethod) m;
        String methodName = method.getName();
        // lets see if there is a transient field of the same name as the getter
        if (methodName.startsWith("get") && method.getParameterCount() == 0) {
            String fieldName = Introspector.decapitalize(methodName.substring(3));
            Class<?> declaringClass = method.getDeclaringClass();
            Field field = findField(fieldName, declaringClass);
            if (field != null) {
                int fieldModifiers = field.getModifiers();
                if (Modifier.isTransient(fieldModifiers)) {
                    LOG.fine("Ignoring member " + m + " due to transient field called " + fieldName);
                    return true;
                }
            }
        }
    }
    return super.hasIgnoreMarker(m);

}

From source file:org.grails.datastore.mapping.model.AbstractPersistentEntity.java

public AbstractPersistentEntity(Class javaClass, MappingContext context) {
    Assert.notNull(javaClass, "The argument [javaClass] cannot be null");
    this.javaClass = javaClass;
    this.context = context;
    decapitalizedName = Introspector.decapitalize(javaClass.getSimpleName());
}