Search in sources :

Example 1 with DerivationContext

use of org.whole.lang.events.DerivationContext in project whole by wholeplatform.

the class DerivedBehaviorFactory method deploy.

public static void deploy(ITestEventsEntity entity) {
    DerivationContext dc = createDerivationContext();
    ICompoundModel model = entity.wGetModel().getCompoundModel();
    model.addRequestEventHandler(dc);
    model.addChangeEventHandler(dc);
}
Also used : DerivationContext(org.whole.lang.events.DerivationContext) ICompoundModel(org.whole.lang.model.ICompoundModel)

Example 2 with DerivationContext

use of org.whole.lang.events.DerivationContext 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;
}
Also used : DerivationContext(org.whole.lang.events.DerivationContext) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntity(org.whole.lang.model.IEntity) Rectangle(org.whole.lang.testevents.model.Rectangle) Labels(org.whole.lang.testevents.model.Labels) RequestException(org.whole.lang.events.RequestException) RequestException(org.whole.lang.events.RequestException)

Aggregations

DerivationContext (org.whole.lang.events.DerivationContext)2 RequestException (org.whole.lang.events.RequestException)1 ICompoundModel (org.whole.lang.model.ICompoundModel)1 IEntity (org.whole.lang.model.IEntity)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1 Labels (org.whole.lang.testevents.model.Labels)1 Rectangle (org.whole.lang.testevents.model.Rectangle)1