use of java.beans.Encoder in project SQLWindowing by hbutani.
the class SerializationUtils method addAntlrPersistenceDelegates.
public static void addAntlrPersistenceDelegates(XMLEncoder e) {
e.setPersistenceDelegate(ASTNode.class, new PersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out) {
return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] { ((ASTNode) oldInstance).getToken() });
}
});
e.setPersistenceDelegate(CommonTree.class, new PersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out) {
return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] { ((CommonTree) oldInstance).getToken() });
}
});
e.setPersistenceDelegate(BaseTree.class, new PersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out) {
return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] {});
}
@SuppressWarnings("rawtypes")
protected void initialize(Class type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
BaseTree t = (BaseTree) oldInstance;
for (int i = 0; i < t.getChildCount(); i++) {
out.writeStatement(new Statement(oldInstance, "addChild", new Object[] { t.getChild(i) }));
}
}
});
e.setPersistenceDelegate(CommonToken.class, new PersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out) {
return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] { ((CommonToken) oldInstance).getType(), ((CommonToken) oldInstance).getText() });
}
});
}
use of java.beans.Encoder in project jdk8u_jdk by JetBrains.
the class Test4968523 method test.
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");
}
use of java.beans.Encoder in project jdk8u_jdk by JetBrains.
the class Test5023559 method initialize.
protected void initialize(XMLEncoder encoder) {
encoder.setPersistenceDelegate(Parent.class, new PersistenceDelegate() {
protected Expression instantiate(Object old, Encoder out) {
Parent parent = (Parent) old;
return new Expression(old, parent.getParent(), "create", new Object[] {});
}
});
encoder.setPersistenceDelegate(Child.class, new PersistenceDelegate() {
protected Expression instantiate(Object old, Encoder out) {
Child child = (Child) old;
return new Expression(old, child.getParent(), "create", new Object[] {});
}
});
}
use of java.beans.Encoder in project jdk8u_jdk by JetBrains.
the class Test4950122 method main.
public static void main(String[] args) {
TestBean bean = new TestBean(true, 11);
Encoder encoder = new Encoder();
encoder.setExceptionListener(bean);
new TestDPD().instantiate(bean, encoder);
}
use of java.beans.Encoder in project jdk8u_jdk by JetBrains.
the class Test8005065 method testDefaultPersistenceDelegate.
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);
}
Aggregations