Search in sources :

Example 1 with PersistenceDelegate

use of java.beans.PersistenceDelegate 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() });
        }
    });
}
Also used : BaseTree(org.antlr.runtime.tree.BaseTree) Expression(java.beans.Expression) CommonTree(org.antlr.runtime.tree.CommonTree) XMLEncoder(java.beans.XMLEncoder) Encoder(java.beans.Encoder) Statement(java.beans.Statement) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) CommonToken(org.antlr.runtime.CommonToken) PersistenceDelegate(java.beans.PersistenceDelegate)

Example 2 with PersistenceDelegate

use of java.beans.PersistenceDelegate 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");
}
Also used : XMLEncoder(java.beans.XMLEncoder) Encoder(java.beans.Encoder) XMLEncoder(java.beans.XMLEncoder) DefaultPersistenceDelegate(java.beans.DefaultPersistenceDelegate) PersistenceDelegate(java.beans.PersistenceDelegate)

Example 3 with PersistenceDelegate

use of java.beans.PersistenceDelegate 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[] {});
        }
    });
}
Also used : Expression(java.beans.Expression) Encoder(java.beans.Encoder) XMLEncoder(java.beans.XMLEncoder) PersistenceDelegate(java.beans.PersistenceDelegate)

Example 4 with PersistenceDelegate

use of java.beans.PersistenceDelegate in project jdk8u_jdk by JetBrains.

the class Test4646747 method main.

public static void main(String[] args) {
    XMLEncoder encoder = new XMLEncoder(System.out);
    encoder.setPersistenceDelegate(Test4646747.class, new MyPersistenceDelegate());
    // WARNING: This can eat up a lot of memory
    Object[] obs = new Object[10000];
    while (obs != null) {
        try {
            obs = new Object[obs.length + obs.length / 3];
        } catch (OutOfMemoryError error) {
            obs = null;
        }
    }
    PersistenceDelegate pd = encoder.getPersistenceDelegate(Test4646747.class);
    if (!(pd instanceof MyPersistenceDelegate))
        throw new Error("persistence delegate has been lost");
}
Also used : XMLEncoder(java.beans.XMLEncoder) DefaultPersistenceDelegate(java.beans.DefaultPersistenceDelegate) PersistenceDelegate(java.beans.PersistenceDelegate)

Aggregations

PersistenceDelegate (java.beans.PersistenceDelegate)4 XMLEncoder (java.beans.XMLEncoder)4 Encoder (java.beans.Encoder)3 DefaultPersistenceDelegate (java.beans.DefaultPersistenceDelegate)2 Expression (java.beans.Expression)2 Statement (java.beans.Statement)1 CommonToken (org.antlr.runtime.CommonToken)1 BaseTree (org.antlr.runtime.tree.BaseTree)1 CommonTree (org.antlr.runtime.tree.CommonTree)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1