Java 类java.beans.Encoder 实例源码

项目:javify    文件:ClassPersistenceDelegate.java   
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class oldClass = (Class) oldInstance;

  // Due to the special handling of String instances in the Encoder
  // this Expression does not lead to further class resolutions.
  if (oldClass == String.class)
    return new Expression(oldClass, "", "getClass", null);

  // This Expression will lead to the class resolution of String.class.
  if (oldClass == Class.class)
    return new Expression(oldClass, String.class, "getClass", null);

  // This Expression will lead to the class resolution of Class.class.
  return new Expression(oldClass, Class.class, "forName",
                        new Object[] { oldClass.getName() });
}
项目:javify    文件:ArrayPersistenceDelegate.java   
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class type = oldInstance.getClass().getComponentType();

  // oldInstance is expected to be an array, then
  // getClass().getComponentType() should lead
  // to its component type.
  assert (type != null);

  // Not handling primitive types in a special way here
  // causes that Class.forName("int") is built as an Expression
  // later which would cause an exception if executed. A special
  // handling to avoid the execution for primitive types can be
  // java.beans.Encoder.writeExpression() .
  return new Expression(
                        oldInstance,
                        Array.class,
                        "newInstance",
                        new Object[] {
                          type,
                          new Integer(Array.getLength(oldInstance)) });
}
项目:jvm-stm    文件:ClassPersistenceDelegate.java   
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class oldClass = (Class) oldInstance;

  // Due to the special handling of String instances in the Encoder
  // this Expression does not lead to further class resolutions.
  if (oldClass == String.class)
    return new Expression(oldClass, "", "getClass", null);

  // This Expression will lead to the class resolution of String.class.
  if (oldClass == Class.class)
    return new Expression(oldClass, String.class, "getClass", null);

  // This Expression will lead to the class resolution of Class.class. 
  return new Expression(oldClass, Class.class, "forName",
                        new Object[] { oldClass.getName() });
}
项目:jvm-stm    文件:ArrayPersistenceDelegate.java   
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class type = oldInstance.getClass().getComponentType();

  // oldInstance is expected to be an array, then
  // getClass().getComponentType() should lead
  // to its component type.
  assert (type != null);

  // Not handling primitive types in a special way here
  // causes that Class.forName("int") is built as an Expression
  // later which would cause an exception if executed. A special
  // handling to avoid the execution for primitive types can be
  // java.beans.Encoder.writeExpression() .
  return new Expression(
                        oldInstance,
                        Array.class,
                        "newInstance",
                        new Object[] {
                          type,
                          new Integer(Array.getLength(oldInstance)) });
}
项目:swingx    文件:PainterUtil.java   
@Override
protected Expression instantiate( Object oldInstance, Encoder out ) {
    Class type = oldInstance.getClass();
    if ( !Modifier.isPublic( type.getModifiers() ) )
        throw new IllegalArgumentException( "Could not instantiate instance of non-public class: " + oldInstance );

    for ( Field field : type.getFields() ) {
        int mod = field.getModifiers();
        if ( Modifier.isPublic( mod ) && Modifier.isStatic( mod ) && Modifier.isFinal( mod ) && ( type == field.getDeclaringClass() ) ) {
            try {
                if ( oldInstance == field.get( null ) )
                    return new Expression( oldInstance, field, "get", new Object[]{null} );
            } catch ( IllegalAccessException exception ) {
                throw new IllegalArgumentException( "Could not get value of the field: " + field, exception );
            }
        }
    }
    throw new IllegalArgumentException( "Could not instantiate value: " + oldInstance );
}
项目:swingx    文件:PainterUtil.java   
@Override
        protected void initialize(Class type, Object oldInstance,
                Object newInstance, Encoder out) {
//            p("image painter delegate called");
            super.initialize(type, oldInstance,  newInstance, out);
            //p("old instance = " + oldInstance);
            //p("owner = " + ((XMLEncoder)out).getOwner());
            PersistenceOwner owner = (PersistenceOwner)((XMLEncoder)out).getOwner();
            ImagePainter ip = (ImagePainter)oldInstance;
//            p("need to convert string: " + ip.getImageString());
//            String s = owner.toXMLURL(ip.getImageString());
//            p("converted to: " + s);
                //out.writeExpression(new Expression(oldInstance,owner,"fromXMLURL",new Object[]{ip.getImageString()}));
                //out.writeStatement(new Statement(owner,"fromXMLURL",new Object[]{ip.getImageString()}));
                //out.writeStatement(new Statement(oldInstance,"setImageString",new Object[]{
                //new Expression(oldInstance,owner,"fromXMLURL",new Object[]{ip.getImageString()})
                //}));

            out.writeStatement(new Statement(oldInstance,"setResolver",new Object[]{owner}));
//            out.writeStatement(new Statement(oldInstance,"setImageString",new Object[]{s}));
        }
项目:cn1    文件:DefaultPersistenceDelegateTest.java   
public void test_initialize() {
    MockBean3 bean1 = new MockBean3();
    bean1.setValue("bean1");
    MockBean3 bean2 = new MockBean3();
    bean2.setValue("bean2");

    // clear flags
    bean1.setValueCalled = false;
    bean2.setValueCalled = false;

    MockPersistenceDelegate mockPersistenceDelegate = new MockPersistenceDelegate();
    mockPersistenceDelegate.initialize(MockBean3.class, bean1, bean2,
            new Encoder());
    assertEquals("bean1", bean1.getValue());
    assertEquals("bean2", bean2.getValue());
    assertFalse(bean1.setValueCalled);
    assertFalse(bean2.setValueCalled);
}
项目:cn1    文件:DefaultPersistenceDelegateTest.java   
public void testInitialize_NullClass() {
    MockPersistenceDelegate pd = new MockPersistenceDelegate();
    Encoder enc = new Encoder();
    Object o1 = new Object();
    Object o2 = new Object();
    // enc.setPersistenceDelegate(MockFooStop.class,
    // new MockPersistenceDelegate());
    try {
        enc.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                CallVerificationStack.getInstance().push(e);
            }
        });
        pd.initialize(null, o1, o2, enc);
        fail("Should throw NullPointerException!");
    } catch (NullPointerException ex) {
        // expected
    }
    assertTrue(CallVerificationStack.getInstance().empty());
}
项目:cn1    文件:DefaultPersistenceDelegateTest.java   
public void testInitialize_NullInstances() {
    MockPersistenceDelegate pd = new MockPersistenceDelegate();
    Encoder enc = new Encoder();
    MockFoo b = new MockFoo();
    b.setName("myName");
    // enc.setPersistenceDelegate(MockFooStop.class,
    // new MockPersistenceDelegate());
    enc.setExceptionListener(new ExceptionListener() {
        public void exceptionThrown(Exception e) {
            CallVerificationStack.getInstance().push(e);
        }
    });
    try {
        pd.initialize(MockFoo.class, null, b, enc);
        fail("Should throw NullPointerException!");
    } catch (NullPointerException ex) {
        // expected
    }
    assertTrue(CallVerificationStack.getInstance().empty());
    pd.initialize(MockFoo.class, b, null, enc);
    assertFalse(CallVerificationStack.getInstance().empty());
}
项目:cn1    文件:EncoderTest.java   
public void testGetPersistenceDelegate_Default() {
    Encoder enc = new Encoder();
    Encoder enc2 = new Encoder();

    PersistenceDelegate pd1 = enc.getPersistenceDelegate(SampleBean.class);
    assertTrue(pd1 instanceof DefaultPersistenceDelegate);

    PersistenceDelegate pd2 = enc.getPersistenceDelegate(SampleBean.class);
    assertTrue(pd2 instanceof DefaultPersistenceDelegate);

    PersistenceDelegate pd3 = enc2
            .getPersistenceDelegate(MockBean4Codec.class);
    assertTrue(pd3 instanceof DefaultPersistenceDelegate);

    assertSame(pd1, pd2);
    assertSame(pd1, pd3);
}
项目:JamVM-PH    文件:ClassPersistenceDelegate.java   
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class oldClass = (Class) oldInstance;

  // Due to the special handling of String instances in the Encoder
  // this Expression does not lead to further class resolutions.
  if (oldClass == String.class)
    return new Expression(oldClass, "", "getClass", null);

  // This Expression will lead to the class resolution of String.class.
  if (oldClass == Class.class)
    return new Expression(oldClass, String.class, "getClass", null);

  // This Expression will lead to the class resolution of Class.class. 
  return new Expression(oldClass, Class.class, "forName",
                        new Object[] { oldClass.getName() });
}
项目:JamVM-PH    文件:ArrayPersistenceDelegate.java   
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class type = oldInstance.getClass().getComponentType();

  // oldInstance is expected to be an array, then
  // getClass().getComponentType() should lead
  // to its component type.
  assert (type != null);

  // Not handling primitive types in a special way here
  // causes that Class.forName("int") is built as an Expression
  // later which would cause an exception if executed. A special
  // handling to avoid the execution for primitive types can be
  // java.beans.Encoder.writeExpression() .
  return new Expression(
                        oldInstance,
                        Array.class,
                        "newInstance",
                        new Object[] {
                          type,
                          new Integer(Array.getLength(oldInstance)) });
}
项目:oscm    文件:XMLSerializer.java   
@Override
protected Expression instantiate(Object oldInstance, Encoder out) {
    byte[] e = (byte[]) oldInstance;
    return new Expression(e, ByteArrayPersistenceDelegate.class,
            "decode",
            new Object[] { ByteArrayPersistenceDelegate.encode(e) });
}
项目:jdk8u-jdk    文件:Test5023552.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(Container.class, new PersistenceDelegate() {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            Container container = (Container) oldInstance;
            Component component = container.getComponent();
            return new Expression(container, component, "create", new Object[] {component});
        }
    });
}
项目:jdk8u-jdk    文件:Test4936682.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(
            OuterClass.InnerClass.class,
            new DefaultPersistenceDelegate() {
                protected Expression instantiate(Object oldInstance, Encoder out) {
                    OuterClass.InnerClass inner = (OuterClass.InnerClass) oldInstance;
                    OuterClass outer = inner.getOuter();
                    return new Expression(inner, outer, "getInner", new Object[0]);
                }
            }
    );
}
项目:jdk8u-jdk    文件:Test8013416.java   
@Override
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
    super.initialize(type, oldInstance, newInstance, out);

    Public<String, String> map = (Public) oldInstance;
    for (Entry<String, String> entry : map.getAll()) {
        String[] args = {entry.getKey(), entry.getValue()};
        out.writeStatement(new Statement(oldInstance, "put", args));
    }
}
项目:jdk8u-jdk    文件:Test4679556.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(C.class, new DefaultPersistenceDelegate() {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            C c = (C) oldInstance;
            return new Expression(c, c.getX(), "createC", new Object[] {});
        }
    });
}
项目:jdk8u-jdk    文件:Test4968523.java   
private static void test(Class<?> type, PersistenceDelegate pd) {
    Encoder encoder1 = new Encoder();
    Encoder encoder2 = new XMLEncoder(System.out);

    PersistenceDelegate pd1 = encoder1.getPersistenceDelegate(type);
    PersistenceDelegate pd2 = encoder2.getPersistenceDelegate(type);

    encoder1.setPersistenceDelegate(type, pd);

    if (pd1 == encoder1.getPersistenceDelegate(type))
        throw new Error("first persistence delegate is not changed");

    if (pd2 != encoder2.getPersistenceDelegate(type))
        throw new Error("second persistence delegate is changed");
}
项目:jdk8u-jdk    文件:Test8005065.java   
private static void testDefaultPersistenceDelegate() {
    Encoder encoder = new Encoder();
    String[] array = { "array" };
    MyDPD dpd = new MyDPD(array);
    dpd.instantiate(dpd, encoder);
    array[0] = null;
    dpd.instantiate(dpd, encoder);
}
项目:openjdk-jdk10    文件:Test5023552.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(Container.class, new PersistenceDelegate() {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            Container container = (Container) oldInstance;
            Component component = container.getComponent();
            return new Expression(container, component, "create", new Object[] {component});
        }
    });
}
项目:openjdk-jdk10    文件:Test4936682.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(
            OuterClass.InnerClass.class,
            new DefaultPersistenceDelegate() {
                protected Expression instantiate(Object oldInstance, Encoder out) {
                    OuterClass.InnerClass inner = (OuterClass.InnerClass) oldInstance;
                    OuterClass outer = inner.getOuter();
                    return new Expression(inner, outer, "getInner", new Object[0]);
                }
            }
    );
}
项目:openjdk-jdk10    文件:Test8013416.java   
@Override
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
    super.initialize(type, oldInstance, newInstance, out);

    Public<String, String> map = (Public) oldInstance;
    for (Entry<String, String> entry : map.getAll()) {
        String[] args = {entry.getKey(), entry.getValue()};
        out.writeStatement(new Statement(oldInstance, "put", args));
    }
}
项目:openjdk-jdk10    文件:Test4679556.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(C.class, new DefaultPersistenceDelegate() {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            C c = (C) oldInstance;
            return new Expression(c, c.getX(), "createC", new Object[] {});
        }
    });
}
项目:openjdk-jdk10    文件:Test4968523.java   
private static void test(Class<?> type, PersistenceDelegate pd) {
    Encoder encoder1 = new Encoder();
    Encoder encoder2 = new XMLEncoder(System.out);

    PersistenceDelegate pd1 = encoder1.getPersistenceDelegate(type);
    PersistenceDelegate pd2 = encoder2.getPersistenceDelegate(type);

    encoder1.setPersistenceDelegate(type, pd);

    if (pd1 == encoder1.getPersistenceDelegate(type))
        throw new Error("first persistence delegate is not changed");

    if (pd2 != encoder2.getPersistenceDelegate(type))
        throw new Error("second persistence delegate is changed");
}
项目:openjdk-jdk10    文件:Test8005065.java   
private static void testDefaultPersistenceDelegate() {
    Encoder encoder = new Encoder();
    String[] array = { "array" };
    MyDPD dpd = new MyDPD(array);
    dpd.instantiate(dpd, encoder);
    array[0] = null;
    dpd.instantiate(dpd, encoder);
}
项目:openjdk9    文件:Test5023552.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(Container.class, new PersistenceDelegate() {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            Container container = (Container) oldInstance;
            Component component = container.getComponent();
            return new Expression(container, component, "create", new Object[] {component});
        }
    });
}
项目:openjdk9    文件:Test4936682.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(
            OuterClass.InnerClass.class,
            new DefaultPersistenceDelegate() {
                protected Expression instantiate(Object oldInstance, Encoder out) {
                    OuterClass.InnerClass inner = (OuterClass.InnerClass) oldInstance;
                    OuterClass outer = inner.getOuter();
                    return new Expression(inner, outer, "getInner", new Object[0]);
                }
            }
    );
}
项目:openjdk9    文件:Test8013416.java   
@Override
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
    super.initialize(type, oldInstance, newInstance, out);

    Public<String, String> map = (Public) oldInstance;
    for (Entry<String, String> entry : map.getAll()) {
        String[] args = {entry.getKey(), entry.getValue()};
        out.writeStatement(new Statement(oldInstance, "put", args));
    }
}
项目:openjdk9    文件:Test4679556.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(C.class, new DefaultPersistenceDelegate() {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            C c = (C) oldInstance;
            return new Expression(c, c.getX(), "createC", new Object[] {});
        }
    });
}
项目:openjdk9    文件:Test4968523.java   
private static void test(Class<?> type, PersistenceDelegate pd) {
    Encoder encoder1 = new Encoder();
    Encoder encoder2 = new XMLEncoder(System.out);

    PersistenceDelegate pd1 = encoder1.getPersistenceDelegate(type);
    PersistenceDelegate pd2 = encoder2.getPersistenceDelegate(type);

    encoder1.setPersistenceDelegate(type, pd);

    if (pd1 == encoder1.getPersistenceDelegate(type))
        throw new Error("first persistence delegate is not changed");

    if (pd2 != encoder2.getPersistenceDelegate(type))
        throw new Error("second persistence delegate is changed");
}
项目:openjdk9    文件:Test8005065.java   
private static void testDefaultPersistenceDelegate() {
    Encoder encoder = new Encoder();
    String[] array = { "array" };
    MyDPD dpd = new MyDPD(array);
    dpd.instantiate(dpd, encoder);
    array[0] = null;
    dpd.instantiate(dpd, encoder);
}
项目:hive-phoenix-handler    文件:Utilities.java   
@Override
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
  java.util.Collection oldO = (java.util.Collection) oldInstance;
  java.util.Collection newO = (java.util.Collection) newInstance;

  if (newO.size() != 0) {
    out.writeStatement(new Statement(oldInstance, "clear", new Object[] {}));
  }
  for (Iterator i = oldO.iterator(); i.hasNext();) {
    out.writeStatement(new Statement(oldInstance, "add", new Object[] {i.next()}));
  }
}
项目:hive-phoenix-handler    文件:Utilities.java   
@Override
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
  java.util.Collection oldO = (java.util.Collection) oldInstance;
  java.util.Collection newO = (java.util.Collection) newInstance;

  if (newO.size() != 0) {
    out.writeStatement(new Statement(oldInstance, "clear", new Object[] {}));
  }
  for (Iterator i = oldO.iterator(); i.hasNext();) {
    out.writeStatement(new Statement(oldInstance, "add", new Object[] {i.next()}));
  }
}
项目:hive-phoenix-handler    文件:Utilities.java   
@Override
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
  java.util.Collection oldO = (java.util.Collection) oldInstance;
  java.util.Collection newO = (java.util.Collection) newInstance;

  if (newO.size() != 0) {
    out.writeStatement(new Statement(oldInstance, "clear", new Object[] {}));
  }
  for (Iterator i = oldO.iterator(); i.hasNext();) {
    out.writeStatement(new Statement(oldInstance, "add", new Object[] {i.next()}));
  }
}
项目:hive-phoenix-handler    文件:Utilities.java   
@Override
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
  Timestamp ts = (Timestamp)oldInstance;
  Object[] args = { ts.getNanos() };
  Statement stmt = new Statement(oldInstance, "setNanos", args);
  out.writeStatement(stmt);
}
项目:hive-phoenix-handler    文件:Utilities.java   
@Override
protected void initialize(Class type, Object oldInstance, Object newInstance, Encoder out) {
  Iterator ite = ((Collection) oldInstance).iterator();
  while (ite.hasNext()) {
    out.writeStatement(new Statement(oldInstance, "add", new Object[] {ite.next()}));
  }
}
项目:jdk8u_jdk    文件:Test5023552.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(Container.class, new PersistenceDelegate() {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            Container container = (Container) oldInstance;
            Component component = container.getComponent();
            return new Expression(container, component, "create", new Object[] {component});
        }
    });
}
项目:jdk8u_jdk    文件:Test4936682.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(
            OuterClass.InnerClass.class,
            new DefaultPersistenceDelegate() {
                protected Expression instantiate(Object oldInstance, Encoder out) {
                    OuterClass.InnerClass inner = (OuterClass.InnerClass) oldInstance;
                    OuterClass outer = inner.getOuter();
                    return new Expression(inner, outer, "getInner", new Object[0]);
                }
            }
    );
}
项目:jdk8u_jdk    文件:Test8013416.java   
@Override
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
    super.initialize(type, oldInstance, newInstance, out);

    Public<String, String> map = (Public) oldInstance;
    for (Entry<String, String> entry : map.getAll()) {
        String[] args = {entry.getKey(), entry.getValue()};
        out.writeStatement(new Statement(oldInstance, "put", args));
    }
}
项目:jdk8u_jdk    文件:Test4679556.java   
protected void initialize(XMLEncoder encoder) {
    encoder.setPersistenceDelegate(C.class, new DefaultPersistenceDelegate() {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            C c = (C) oldInstance;
            return new Expression(c, c.getX(), "createC", new Object[] {});
        }
    });
}