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() });
}
java类java.beans.Encoder的实例源码
ClassPersistenceDelegate.java 文件源码
项目:javify
阅读 21
收藏 0
点赞 0
评论 0
ArrayPersistenceDelegate.java 文件源码
项目:javify
阅读 34
收藏 0
点赞 0
评论 0
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)) });
}
ClassPersistenceDelegate.java 文件源码
项目:jvm-stm
阅读 22
收藏 0
点赞 0
评论 0
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() });
}
ArrayPersistenceDelegate.java 文件源码
项目:jvm-stm
阅读 17
收藏 0
点赞 0
评论 0
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)) });
}
PainterUtil.java 文件源码
项目:swingx
阅读 21
收藏 0
点赞 0
评论 0
@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 );
}
PainterUtil.java 文件源码
项目:swingx
阅读 27
收藏 0
点赞 0
评论 0
@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}));
}
DefaultPersistenceDelegateTest.java 文件源码
项目:cn1
阅读 20
收藏 0
点赞 0
评论 0
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);
}
DefaultPersistenceDelegateTest.java 文件源码
项目:cn1
阅读 21
收藏 0
点赞 0
评论 0
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());
}
DefaultPersistenceDelegateTest.java 文件源码
项目:cn1
阅读 22
收藏 0
点赞 0
评论 0
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());
}
EncoderTest.java 文件源码
项目:cn1
阅读 25
收藏 0
点赞 0
评论 0
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);
}
ClassPersistenceDelegate.java 文件源码
项目:JamVM-PH
阅读 22
收藏 0
点赞 0
评论 0
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() });
}
ArrayPersistenceDelegate.java 文件源码
项目:JamVM-PH
阅读 20
收藏 0
点赞 0
评论 0
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)) });
}
XMLSerializer.java 文件源码
项目:oscm
阅读 30
收藏 0
点赞 0
评论 0
@Override
protected Expression instantiate(Object oldInstance, Encoder out) {
byte[] e = (byte[]) oldInstance;
return new Expression(e, ByteArrayPersistenceDelegate.class,
"decode",
new Object[] { ByteArrayPersistenceDelegate.encode(e) });
}
Test5023552.java 文件源码
项目:jdk8u-jdk
阅读 25
收藏 0
点赞 0
评论 0
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});
}
});
}
Test4936682.java 文件源码
项目:jdk8u-jdk
阅读 21
收藏 0
点赞 0
评论 0
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]);
}
}
);
}
Test8013416.java 文件源码
项目:jdk8u-jdk
阅读 30
收藏 0
点赞 0
评论 0
@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));
}
}
Test4679556.java 文件源码
项目:jdk8u-jdk
阅读 18
收藏 0
点赞 0
评论 0
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[] {});
}
});
}
Test4968523.java 文件源码
项目:jdk8u-jdk
阅读 21
收藏 0
点赞 0
评论 0
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");
}
Test8005065.java 文件源码
项目:jdk8u-jdk
阅读 24
收藏 0
点赞 0
评论 0
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);
}
Test5023552.java 文件源码
项目:openjdk-jdk10
阅读 21
收藏 0
点赞 0
评论 0
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});
}
});
}
Test4936682.java 文件源码
项目:openjdk-jdk10
阅读 20
收藏 0
点赞 0
评论 0
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]);
}
}
);
}
Test8013416.java 文件源码
项目:openjdk-jdk10
阅读 23
收藏 0
点赞 0
评论 0
@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));
}
}
Test4679556.java 文件源码
项目:openjdk-jdk10
阅读 23
收藏 0
点赞 0
评论 0
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[] {});
}
});
}
Test4968523.java 文件源码
项目:openjdk-jdk10
阅读 25
收藏 0
点赞 0
评论 0
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");
}
Test8005065.java 文件源码
项目:openjdk-jdk10
阅读 24
收藏 0
点赞 0
评论 0
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);
}
Test5023552.java 文件源码
项目:openjdk9
阅读 25
收藏 0
点赞 0
评论 0
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});
}
});
}
Test4936682.java 文件源码
项目:openjdk9
阅读 19
收藏 0
点赞 0
评论 0
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]);
}
}
);
}
Test8013416.java 文件源码
项目:openjdk9
阅读 21
收藏 0
点赞 0
评论 0
@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));
}
}
Test4679556.java 文件源码
项目:openjdk9
阅读 18
收藏 0
点赞 0
评论 0
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[] {});
}
});
}
Test4968523.java 文件源码
项目:openjdk9
阅读 21
收藏 0
点赞 0
评论 0
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");
}