Example usage for java.beans Expression Expression

List of usage examples for java.beans Expression Expression

Introduction

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

Prototype

public Expression(Object value, Object target, String methodName, Object[] arguments) 

Source Link

Document

Creates a new Expression object with the specified value for the specified target object to invoke the method specified by the name and by the array of arguments.

Usage

From source file:Test.java

public static void main(String args[]) throws Exception {
    Person person = new Person();
    String arguments[] = { "AAA" };
    Expression expression = new Expression(null, person, "setName", arguments);

    System.out.println("Name: " + person.getName());
    expression.execute();// ww w . java 2  s . c om
    System.out.println("Name: " + person.getName());

    System.out.println();
    expression = new Expression(null, person, "getName", null);
    System.out.println("Name: " + person.getName());
    expression.execute();
    System.out.println("getValue: " + expression.getValue());
}

From source file:com.swingtech.commons.util.ClassUtil.java

/**
 * NOTE: When using this to print an object it will not display the
 * primitive type boolean. Must use the wrapper class. All other primitives
 * work fine.//from w w w  .j  av a 2  s. c  om
 *
 * NOTE: If an int value has a 0 it won't display.
 *
 * NOTE: Object must have a public constructor.
 *
 * @param object
 * @return
 */
public static String getXMLForObject(final Object object) {
    ByteArrayOutputStream baos = null;
    XMLEncoder e = null;

    baos = new ByteArrayOutputStream();
    e = new XMLEncoder(new BufferedOutputStream(baos));

    e.setPersistenceDelegate(Date.class, new PersistenceDelegate() {
        @Override
        protected Expression instantiate(final Object oldInstance, final Encoder out) {
            final Date date = (Date) oldInstance;
            final Long time = new Long(date.getTime());
            return new Expression(date, date.getClass(), "new", new Object[] { time });
        }
    });

    e.setPersistenceDelegate(BigDecimal.class, new PersistenceDelegate() {
        @Override
        protected Expression instantiate(final Object oldInstance, final Encoder out) {
            final BigDecimal bigDec = (BigDecimal) oldInstance;
            final double doubleVal = bigDec.doubleValue();
            return new Expression(bigDec, bigDec.getClass(), "new", new Object[] { new Double(doubleVal) });
        }
    });

    e.writeObject(object);
    e.close();

    return baos.toString();
}