Example usage for java.beans Expression getValue

List of usage examples for java.beans Expression getValue

Introduction

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

Prototype

public Object getValue() throws Exception 

Source Link

Document

If the value property of this instance is not already set, this method dynamically finds the method with the specified methodName on this target with these arguments and calls it.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object o = new MyBean();
    // Get the value of prop2
    Expression expr = new Expression(o, "getProp2", new Object[0]);
    expr.execute();/*from   ww  w  .  ja  va  2  s  .  c o m*/
    int i = ((Integer) expr.getValue()).intValue();

    // Set the value of prop2
    Statement stmt = new Statement(o, "setProp2", new Object[] { new Integer(123) });
    stmt.execute();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object o = new MyBean();
    // Get the value of prop1
    Expression expr = new Expression(o, "getProp1", new Object[0]);
    expr.execute();/*from  ww  w .  j  a v a 2s  .  co  m*/
    String s = (String) expr.getValue();

    // Set the value of prop1
    Statement stmt = new Statement(o, "setProp1", new Object[] { "new string" });
    stmt.execute();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object o = new MyBean();

    Expression expr = new Expression(o, "getProp3", new Object[0]);
    expr.execute();//from  w w w. j  av a  2s . c o m
    byte[] bytes = (byte[]) expr.getValue();

    Statement stmt = new Statement(o, "setProp3", new Object[] { new byte[] { 0x12, 0x23 } });
    stmt.execute();
}

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();/*www.j av a  2  s.  c o  m*/
    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:ca.oson.json.util.ObjectUtil.java

@SuppressWarnings("unchecked")
public static <E, R> R getMethodValue(E obj, Method method, Object... args) {
    R value = null;//w  ww  . j  a va  2 s  . c  om

    try {
        method.setAccessible(true);

        value = (R) method.invoke(obj, args);
    } catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
        // e.printStackTrace();
        try {
            if (obj != null) {
                Expression expr = new Expression(obj, method.getName(), args);
                expr.execute();
                value = (R) expr.getValue();
            }

            if (value == null) {
                value = (R) method.getDefaultValue();
            }

        } catch (Exception e1) {
            // e1.printStackTrace();
        }
    }

    return value;
}

From source file:org.op4j.functions.Get.java

@SuppressWarnings("unchecked")
public R execute(final T input, final ExecCtx ctx) throws Exception {

    final Class<? super R> resultClass = this.resultType.getRawClass();

    final Expression expression = new Expression(input, "get" + StringUtils.capitalize(this.attributeName),
            null);/*from w  w w.jav  a  2 s .  c om*/
    final R result = (R) expression.getValue();

    if (result != null && resultClass != null && !Object.class.equals(resultClass)) {
        if (!(resultClass.isAssignableFrom(result.getClass()))) {
            throw new IllegalStateException("Result of calling method \"" + this.attributeName + "\" is not "
                    + "assignable from class " + resultClass.getName());
        }
    }

    return result;

}

From source file:org.op4j.functions.Call.java

@SuppressWarnings("unchecked")
public R execute(final T input, final ExecCtx ctx) throws Exception {

    final Class<? super R> resultClass = this.resultType.getRawClass();

    final Expression expression = new Expression(input, this.methodName, this.parameters);
    final R result = (R) expression.getValue();

    if (result != null && resultClass != null && !Object.class.equals(resultClass)) {
        if (!(resultClass.isAssignableFrom(result.getClass()))) {
            throw new IllegalStateException("Result of calling method \"" + this.methodName + "\" is not "
                    + "assignable from class " + resultClass.getName());
        }/*from  w ww  .j av  a 2s  .c  o  m*/
    }

    return result;

}