简体   繁体   English

在JAVA中解析OCL解析的参数

[英]Parameters for parsing OCL Parsing in JAVA

I'm working on a java application that takes as input a set of valid models and a set of invalid models, OCL constraints are generated automatically, my objective is to check if the models are violating the constraints or no. 我正在使用一个Java应用程序,该应用程序将一组有效模型和一组无效模型作为输入,会自动生成OCL约束,我的目标是检查模型是否违反约束或否。

I found on this topic an answer but the parameters aren't very clear. 我在这个主题上找到了答案,但是参数不是很清楚。

Does anyone know what should I make instead of "EXTLibraryPackage.Literals.LIBRARY" 有人知道我应该做什么,而不是“ EXTLibraryPackage.Literals.LIBRARY”

// create an OCL helper object OCLHelper helper = ocl.createOCLHelper(); //创建一个OCL帮助器对象OCLHelper helper = ocl.createOCLHelper();

    // set the OCL context classifier
    helper.setContext(EXTLibraryPackage.Literals.LIBRARY);

    Constraint invariant = helper.createInvariant(
        "books->forAll(b1, b2 | b1 <> b2 implies b1.title <> b2.title)");

    OCLExpression<EClassifier> query = helper.createQuery(
        "books->collect(b : Book | b.category)->asSet()");

OCL defines expressions upon models for which you must provide the metamodel so that OCL understands your type system. OCL在必须为其提供元模型的模型上定义表达式,以便OCL理解您的类型系统。 EXTLibraryPackage.Literals.LIBRARY is a reference to the genmodeled Package at the root of the EXTLibrary example. EXTLibraryPackage.Literals.LIBRARY是对EXTLibrary示例根目录中的genmodeled Package的引用。

To reuse the same style you should genmodel your models and reference the corresponding EPackages. 要重用相同的样式,应该对模型进行建模并引用相应的EPackage。

However using OCL programmatically in this way is far from the only or best way. 但是,以这种方式以编程方式使用OCL并非唯一或最佳方式。 If you have models then you can load your model in the Sample Ecore Editor and validate there. 如果您有模型,则可以在Sample Ecore Editor中加载模型并在那里进行验证。 See the Validation aspects of the Eclipse OCL Documentation. 请参阅Eclipse OCL文档的Validation方面。 You may even convert your OCL to Java to avoid the costs of executing OCL in an interpreter. 您甚至可以将OCL转换为Java,以避免在解释器中执行OCL的开销。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM