可以在Ecore和OCL中保留派生属性并禁用派生功能吗? [英] Can derived attributes be persisted and derivation disabled in Ecore and OCL?

查看:184
本文介绍了可以在Ecore和OCL中保留派生属性并禁用派生功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想移植一种旧数据格式,该格式包含类似于Eclipse Modeling Framework(EMF)Ecore:具有参数的元素的元素,这些元素具有不同的数据类型和默认值.

I want to port a legacy data format, which consists of concepts similar to Eclipse Modeling Framework (EMF) Ecore: Elements with Parameters which have different datatypes and default values.

使用定制工具,您可以通过基于花式表格的GUI编辑此类模型实例.

A custom-made tool lets you edit such model instances by a fancy table-based GUI.

此外,Parameters的一个共同特征是可以添加 Derivation Rule ,该规则指定从其他参数自动计算出Parameter值.这似乎也类似于可以通过Java代码或OCLinEcore实现的Ecore派生的属性.

Also, a common feature for the Parameters is that a Derivation Rule can be added which specifies that the Parameter value gets computed automatically from other parameters. That also seems similar to Ecore derived Attributes which could be implemented by Java Code or OCLinEcore.

但是,以旧版格式自动导出参数是可选的. IE.用户始终可以选择这样的派生参数,并选择他或她想要手动输入值.因此,即使派生的参数值也不是瞬态的,而是始终存在的,包括参数处于自动"还是手动"模式的状态.

However, the automatic derivation of a Parameter in the legacy format is optional. I.e. a user can always select such a derived parameter and select that he or she wants to enter the value manually. Hence, even derived Parameter values are not transient but always persisted, including the state whether the parameter is in "auto" or "manual" mode.

Ecore(包括诸如OCLinEcore之类的扩展名)中是否可以保留派生属性并在运行时选择性/临时启用/禁用派生?

Is there any way in Ecore (including extensions like OCLinEcore) to persist derived attributes and to selectively/temporarily enable/disable derivation at runtime?

解决方法可能不是使用Ecore的派生属性功能,而是手动在客户端代码中实现可选派生.但是,可选派生规则的声明不是标准方法.有什么办法可以重用OCLinEcore或类似的东西吗?

Workaround could be not to use Ecore's derived Attribute feature but to implement the optional derivation in the client code manually. However, the declaration of the optional derivation rule would be no Standard way. Any way to reuse OCLinEcore or alike?

推荐答案

这是我如何在 Xcore中做到这一点:

interface Identifier {
    id String uid
    boolean derive_enabled = "true"
    unsettable String uid_derived

    readonly String uid_generated get {  // this is the 'derived' parameter
        if (uid_derived == null || uid_derived.isEmpty) {
            uid_derived  = EcoreUtil.generateUUID().toString
        }
        if (derive_enabled) {
            uid = uid_derived
        }
        return uid
    }
}

您也可以在Ecore/OCL-in-Ecore中轻松实现它.

You can easily implement it in Ecore/OCL-in-Ecore as well.

我坚持使用参数的派生值,但是我总是可以通过更改布尔参数的值来手动更改它(如果我喜欢的话).然后,我为需要的任何类实现此接口,因此我在全局上具有此功能.

I persist the derived value of the parameter, but I can always change it manually (if I like) by changing the value of the boolean parameter. Then, I implement this interface for any class I need, so I have this feature globally.

这篇关于可以在Ecore和OCL中保留派生属性并禁用派生功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆