Example usage for java.beans Expression execute

List of usage examples for java.beans Expression execute

Introduction

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

Prototype

@Override
public void execute() throws Exception 

Source Link

Document

If the invoked method completes normally, the value it returns is copied in the value property.

Usage

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();
    byte[] bytes = (byte[]) expr.getValue();

    Statement stmt = new Statement(o, "setProp3", new Object[] { new byte[] { 0x12, 0x23 } });
    stmt.execute();//w w  w  .j  a  va 2 s  . c o  m
}

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();
    int i = ((Integer) expr.getValue()).intValue();

    // Set the value of prop2
    Statement stmt = new Statement(o, "setProp2", new Object[] { new Integer(123) });
    stmt.execute();// w  ww.  j av  a  2  s.c om
}

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();
    String s = (String) expr.getValue();

    // Set the value of prop1
    Statement stmt = new Statement(o, "setProp1", new Object[] { "new string" });
    stmt.execute();// ww  w .ja v a  2  s.  co  m
}

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();
    System.out.println("Name: " + person.getName());

    System.out.println();/*  w w w .ja  v  a2s  . c  om*/
    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 w w .  ja  v  a 2 s.co m

    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;
}