Search in sources :

Example 1 with Expression

use of java.beans.Expression 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 Expression

use of java.beans.Expression 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 3 with Expression

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

the class Test6707226 method main.

public static void main(String[] args) throws Exception {
    Object value = new Object();
    Expression expression = new Expression(value, Object.class, "new", null);
    if (!value.equals(expression.getValue()))
        throw new Error("the value is updated unexpectedly");
    expression.execute();
    if (value.equals(expression.getValue()))
        throw new Error("the value is not updated as expected");
}
Also used : Expression(java.beans.Expression)

Example 4 with Expression

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

the class ObjectElementHandler method getValueObject.

/**
     * Creates the value of this element.
     *
     * @param type  the base class
     * @param args  the array of arguments
     * @return the value of this element
     * @throws Exception if calculation is failed
     */
@Override
protected final ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
    if (this.field != null) {
        return ValueObjectImpl.create(FieldElementHandler.getFieldValue(getContextBean(), this.field));
    }
    if (this.idref != null) {
        return ValueObjectImpl.create(getVariable(this.idref));
    }
    Object bean = getContextBean();
    String name;
    if (this.index != null) {
        name = (args.length == 2) ? PropertyElementHandler.SETTER : PropertyElementHandler.GETTER;
    } else if (this.property != null) {
        name = (args.length == 1) ? PropertyElementHandler.SETTER : PropertyElementHandler.GETTER;
        if (0 < this.property.length()) {
            name += this.property.substring(0, 1).toUpperCase(ENGLISH) + this.property.substring(1);
        }
    } else {
        name = (this.method != null) && (0 < this.method.length()) ? this.method : // NON-NLS: the constructor marker
        "new";
    }
    Expression expression = new Expression(bean, name, args);
    return ValueObjectImpl.create(expression.getValue());
}
Also used : Expression(java.beans.Expression)

Aggregations

Expression (java.beans.Expression)4 Encoder (java.beans.Encoder)2 PersistenceDelegate (java.beans.PersistenceDelegate)2 XMLEncoder (java.beans.XMLEncoder)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