Package java.beans

Examples of java.beans.Expression


                {
                    try
                    {
                        if ( oldInstance == field.get( null ) )
                        {
                            return new Expression( oldInstance, field, "get", new Object[]
                                { null } );
                        }
                    }
                    catch ( IllegalAccessException exception )
                    {
View Full Code Here


                }
            });
            e.setPersistenceDelegate(File.class,new PersistenceDelegate() {
                protected Expression instantiate(Object oldInstance, Encoder out) {
                    File f = (File) oldInstance;
                    return new Expression(oldInstance, oldInstance.getClass(),"new", new Object[]{ f.getAbsolutePath() });
                }

            });
            e.writeObject(settings);
            e.close();
View Full Code Here

   * Java 1.5 workaround. From http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403
   */
  public static class EnumDelegate extends DefaultPersistenceDelegate {
    @Override
    protected Expression instantiate(Object oldInstance, Encoder out) {
      return new Expression(Enum.class, "valueOf", new Object[] {oldInstance.getClass(),
          ((Enum<?>) oldInstance).name()});
    }
View Full Code Here

  public static class MapDelegate extends DefaultPersistenceDelegate {
    @Override
    protected Expression instantiate(Object oldInstance, Encoder out) {
      Map oldMap = (Map) oldInstance;
      HashMap newMap = new HashMap(oldMap);
      return new Expression(newMap, HashMap.class, "new", new Object[] {});
    }
View Full Code Here

  public static class SetDelegate extends DefaultPersistenceDelegate {
    @Override
    protected Expression instantiate(Object oldInstance, Encoder out) {
      Set oldSet = (Set) oldInstance;
      HashSet newSet = new HashSet(oldSet);
      return new Expression(newSet, HashSet.class, "new", new Object[] {});
    }
View Full Code Here

  public static class ListDelegate extends DefaultPersistenceDelegate {
    @Override
    protected Expression instantiate(Object oldInstance, Encoder out) {
      List oldList = (List) oldInstance;
      ArrayList newList = new ArrayList(oldList);
      return new Expression(newList, ArrayList.class, "new", new Object[] {});
    }
View Full Code Here

  }

  public static class CollectionPersistenceDelegate extends DefaultPersistenceDelegate {
    @Override
    protected Expression instantiate(Object oldInstance, Encoder out) {
      return new Expression(oldInstance, oldInstance.getClass(), "new", null);
    }
View Full Code Here

  {
    dummy d = new dummy();

    // Check that we can create and getValue a expression
    Object arg1[] = {"test"};
    Expression expr = new Expression(d, "method", arg1);
    harness.check(expr != null, "Construct an Expression");
    harness.check(expr.getTarget() == d);
    harness.check(expr.getMethodName().equals("method"));
    String res1 = "";
    try
      {
  res1 = (String) expr.getValue();
      }
    catch (Exception e)
      {
  harness.fail("Expression getValue failed");
      }

    harness.check(d.s.equals("test"), "Test getValue with method of single arg");
    harness.check(d.x == 5);
    harness.check(res1.equals("test 5"));

    // Check that we can create and getValue a expression and that a
    // wrapper class resolves to a method taking a primitive.
    Object arg2[] = {"test", new Integer(6) };
    expr = new Expression(d, "method", arg2);
    harness.check(expr != null, "Construct an Expression with 2 args");

    Object exprArgs[] = expr.getArguments();
    harness.check(exprArgs.length == arg2.length && exprArgs[0] == arg2[0]
      && exprArgs[1] == arg2[1]);
    String res2 = "";
    try
      {
  res2 = (String) expr.getValue();
      }
    catch (Exception e)
      {
  harness.fail("Expression getValue failed");
      }

    harness.check(d.s.equals("test"), "Test getValue with method of single arg");
    harness.check(d.x == 7);
    harness.check(res2.equals("test 7"));


    // Check that we can create and getValue a expression for a static method.
    Object arg3[] = {new Integer(1)};
    expr = new Expression(this, "test1", arg3);
    int res3 = 0;

    try
      {
  res3 = ((Integer)expr.getValue()).intValue();
      }
    catch (Exception e)
      {
  harness.fail("Static method getValue " + e.toString());
      }
    harness.check(res3 == 1, "Test Expression with static method");


    // Check that we can call get and set on an array object in a expression
    int iarray[] = {1, 2, 3, 4, 5};
    Object arg4[] = { new Integer(2), new Integer(6) };

    expr = new Expression(iarray, "set", arg4);
    Object res4 = new Object();
    try
      {
  res4 = expr.getValue();
      }
    catch (Exception e)
      {
  harness.fail("Expression set failed");
      }
    //Array.set is public static void and should have no return value
    harness.check(res4 == null);

    harness.check(iarray[2] == 6);

    Object arg5[] = { new Integer(2) };
    expr = new Expression(iarray, "get", arg5);
    int res5 = 0;
    try
      {
  res5 = ((Integer)expr.getValue()).intValue();
      }
    catch (Exception e)
      {
  harness.fail("Expression get failed");
      }

    harness.check(res5 == 6, "Test Expression of array and method named get");

    // check that Expression can call object constructor
    Object arg6[] = { this };
    expr = new Expression(d.getClass(), "new", arg6);
    dummy d1 = null;
    try
      {
  d1 = (dummy) expr.getValue();
      }
    catch (Exception e)
      {
  harness.debug(e);
  harness.fail("Expression using new failed");
      }

    harness.check(d1 != d, "Test expr using new");

    // check that Expression constructer with val uses val
    expr = new Expression(d, d, "new", arg6);
    d1 = null;
    try
      {
  d1 = (dummy) expr.getValue();
      }
    catch (Exception e)
      {
  harness.fail("Constructor failed");
      }

    harness.check(d1 == d, "Test expr constructor with value");
  

    // check that setvalue works and getvalue returns it
    String s1 = "t";
    expr.setValue(s1);
   
    String s2 = "";
    try
      {
  s2 = (String) expr.getValue();
      }
    catch (Exception e)
      {
  harness.fail("Constructor failed");
      }
    harness.check(s1 == s2, "Test expr setValue and getValue");

    // check that tostring does something
    String s3 = expr.toString();
  }
View Full Code Here

       
        @Override
        protected Expression instantiate(Object oldInstance, Encoder out) {
           
            ColorSpaceType e = ((LinearGradientPaint)oldInstance).getColorSpace();
            Expression retValue;
           
            retValue = super.instantiate(oldInstance, out);
            return retValue;
        }
View Full Code Here

        }
        @Override
        protected Expression instantiate(Object oldInstance,
                Encoder out) {
            Insets ins = (Insets)oldInstance;
            return new Expression(oldInstance,
                    oldInstance.getClass(),
                    "new",
                    new Object[]{ ins.top, ins.left, ins.bottom, ins.right });
        }
View Full Code Here

TOP

Related Classes of java.beans.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.