Example usage for org.apache.commons.lang.text StrBuilder setCharAt

List of usage examples for org.apache.commons.lang.text StrBuilder setCharAt

Introduction

In this page you can find the example usage for org.apache.commons.lang.text StrBuilder setCharAt.

Prototype

public StrBuilder setCharAt(int index, char ch) 

Source Link

Document

Sets the character at the specified index.

Usage

From source file:bboss.org.apache.velocity.runtime.parser.node.SetPropertyExecutor.java

/**
 * @param clazz//w w w  .  j a v a  2  s .c o m
 * @param property
 * @param arg
 */
protected void discover(final Class clazz, final String property, final Object arg) {
    Object[] params = new Object[] { arg };

    try {
        StrBuilder sb = new StrBuilder("set");
        sb.append(property);

        setMethod(introspector.getMethod(clazz, sb.toString(), params));

        if (!isAlive()) {
            /*
             *  now the convenience, flip the 1st character
             */

            char c = sb.charAt(3);

            if (Character.isLowerCase(c)) {
                sb.setCharAt(3, Character.toUpperCase(c));
            } else {
                sb.setCharAt(3, Character.toLowerCase(c));
            }

            setMethod(introspector.getMethod(clazz, sb.toString(), params));
        }
    }
    /**
     * pass through application level runtime exceptions
     */
    catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String msg = "Exception while looking for property setter for '" + property;
        log.error(msg, e);
        throw new VelocityException(msg, e);
    }
}

From source file:org.apache.velocity.runtime.parser.node.SetPropertyExecutor.java

/**
 * @param clazz// www .  j  a  v  a  2 s . c o m
 * @param property
 * @param arg
 */
protected void discover(final Class clazz, final String property, final Object arg) {
    Object[] params = new Object[] { arg };

    try {
        StrBuilder sb = new StrBuilder("set");
        sb.append(property);

        setMethod(introspector.getMethod(clazz, sb.toString(), params));

        if (!isAlive()) {
            /*
             *  now the convenience, flip the 1st character
             */

            char c = sb.charAt(3);

            if (Character.isLowerCase(c)) {
                sb.setCharAt(3, Character.toUpperCase(c));
            } else {
                sb.setCharAt(3, Character.toLowerCase(c));
            }

            setMethod(introspector.getMethod(clazz, sb.toString(), params));
        }
    }
    /**
     * pass through application level runtime exceptions
     */
    catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String msg = "Exception while looking for property setter for '" + property;
        Logger.error(this, msg, e);
        throw new VelocityException(msg, e);
    }
}