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() });
}
});
}
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[] {});
}
});
}
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");
}
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());
}
Aggregations