use of org.whole.lang.testevents.model.Rectangle in project whole by wholeplatform.
the class DerivedBehaviorFactory method createDerivationContext.
public static DerivationContext createDerivationContext() {
DerivationContext dc = new DerivationContext();
dc.addDerivationRules(TestEventsEntityDescriptorEnum.Rectangle, new AbstractEntityDerivationRule<Rectangle>() {
public IEntity derive(Rectangle entity, FeatureDescriptor fd, IEntity value) {
switch(fd.getOrdinal()) {
case TestEventsFeatureDescriptorEnum.base_ord:
try {
return TestEventsEntityFactory.instance.createVal(entity.getPerimeter().wIntValue() / 2 - entity.getHeight().wIntValue());
} catch (Exception e) {
}
try {
return TestEventsEntityFactory.instance.createVal(entity.getArea().wIntValue() / entity.getHeight().wIntValue());
} catch (ArithmeticException e) {
throw new RequestException();
}
case TestEventsFeatureDescriptorEnum.height_ord:
try {
return TestEventsEntityFactory.instance.createVal(entity.getPerimeter().wIntValue() / 2 - entity.getBase().wIntValue());
} catch (Exception e) {
}
try {
return TestEventsEntityFactory.instance.createVal(entity.getArea().wIntValue() / entity.getBase().wIntValue());
} catch (ArithmeticException e) {
throw new RequestException();
}
case TestEventsFeatureDescriptorEnum.area_ord:
return TestEventsEntityFactory.instance.createVal(entity.getBase().wIntValue() * entity.getHeight().wIntValue());
case TestEventsFeatureDescriptorEnum.perimeter_ord:
return TestEventsEntityFactory.instance.createVal((entity.getBase().wIntValue() + entity.getHeight().wIntValue()) * 2);
default:
return value;
}
}
public void invalidate(Labels entity, FeatureDescriptor fd, IEntity oldValue, IEntity newValue) {
// switch (fd.getOrdinal()) {
//
// case TestEventsFeatureDescriptorEnum.base_ord:
// case TestEventsFeatureDescriptorEnum.height_ord:
// entity.wRemove(TestEventsFeatureDescriptorEnum.area);
// entity.wRemove(TestEventsFeatureDescriptorEnum.perimeter);
// break;
// }
}
});
dc.addDerivationRules(TestEventsEntityDescriptorEnum.Labels, new AbstractEntityDerivationRule<Labels>() {
public IEntity derive(Labels entity, FeatureDescriptor fd, IEntity value) {
switch(fd.getOrdinal()) {
case TestEventsFeatureDescriptorEnum.simpleDerived_ord:
return TestEventsEntityFactory.instance.createLabel(entity.getSimple().wStringValue() + ".suffix");
case TestEventsFeatureDescriptorEnum.simpleDerivedDerived_ord:
return TestEventsEntityFactory.instance.createLabel("prefix." + entity.getSimpleDerived().wStringValue());
default:
return value;
}
}
public void invalidate(Labels entity, FeatureDescriptor fd, IEntity oldValue, IEntity newValue) {
switch(fd.getOrdinal()) {
case TestEventsFeatureDescriptorEnum.simple_ord:
// FIXME initialization rule remove only if derived
entity.wRemove(TestEventsFeatureDescriptorEnum.simpleDerived);
break;
case TestEventsFeatureDescriptorEnum.simpleDerived_ord:
entity.wRemove(TestEventsFeatureDescriptorEnum.simpleDerivedDerived);
break;
}
}
});
return dc;
}
Aggregations