Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Comparision operator definition
Comparision operator definition [message #1219281] Tue, 03 December 2013 01:57 Go to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
Hi

There is a custom data types in my UML model. When I'm trying to parse OCL expressions I get an exception:

3: Unresolved Operation 'ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType::>(Real)'
3: Unresolved Operation 'ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType::<(UnlimitedNatural)'
7: Unresolved Operation 'ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType::>(UnlimitedNatural)'
7: Unresolved Operation 'ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType::<(UnlimitedNatural)'

How to define > operator for my MeasureType?
Re: Comparision operator definition [message #1219311 is a reply to message #1219281] Tue, 03 December 2013 04:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

Provide an implementation of

public int MeasureType.compareTo(MeasureType)

Regards

Ed Willink



On 03/12/2013 06:57, Denis Nikiforov wrote:
> Hi
>
> There is a custom data types in my UML model. When I'm trying to parse
> OCL expressions I get an exception:
>
> 3: Unresolved Operation
> 'ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType::>(Real)'
> 3: Unresolved Operation
> 'ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType::<(UnlimitedNatural)'
> 7: Unresolved Operation
> 'ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType::>(UnlimitedNatural)'
> 7: Unresolved Operation
> 'ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType::<(UnlimitedNatural)'
> How to define > operator for my MeasureType?
Re: Comparision operator definition [message #1219326 is a reply to message #1219281] Tue, 03 December 2013 05:59 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
Hi

Actually I don't need an operator implementation. I need only to parse OCL and to get its AST. In any case I don't understand where to start.

I created an extension:
library 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'

import 'ReferenceModel.uml'

package ReferenceModel

context ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType
def: compareTo(x : Real) : Boolean = true
def: compareTo(x : UnlimitedNatural) : Boolean = true
def: compareTo(x : ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType) : Boolean = true
def: greaterThan(x : Real) : Boolean = true
def: greaterThan(x : UnlimitedNatural) : Boolean = true
def: greaterThan(x : ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType) : Boolean = true

endpackage

And I'm trying to load it:
Resource resource = rs.getResource("model2/SMDataModel.uml", true);
MetaModelManager metaModelManager = PivotUtil.getMetaModelManager(resource);
metaModelManager.setDefaultStandardLibraryURI("model2/ReferenceModel.ocl");
PivotEnvironmentFactory envFactory = new PivotEnvironmentFactory(null, metaModelManager);
PivotEnvironment environment = envFactory.createEnvironment();
OCL ocl = OCL.newInstance(environment);
OCLHelper oclHelper = ocl.createOCLHelper();
Resource rules = ocl.load(createFileURI("model2/ReferenceModel.ocl"));

I'm sure that my code is completly wrong but I have no idea what is a right way to do it...
Re: Comparision operator definition [message #1219329 is a reply to message #1219326] Tue, 03 December 2013 06:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

Provide a JAVA implementation of

public int MeasureType.compareTo(MeasureType)

Regards

Ed Willink


On 03/12/2013 10:59, Denis Nikiforov wrote:
> Hi
>
> Actually I don't need an operator implementation. I need only to parse
> OCL and to get its AST. In any case I don't understand where to start.
>
> I created an extension:
> library 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'
>
> import 'ReferenceModel.uml'
>
> package ReferenceModel
>
> context
> ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType
> def: compareTo(x : Real) : Boolean = true
> def: compareTo(x : UnlimitedNatural) : Boolean = true
> def: compareTo(x :
> ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType)
> : Boolean = true
> def: greaterThan(x : Real) : Boolean = true
> def: greaterThan(x : UnlimitedNatural) : Boolean = true
> def: greaterThan(x :
> ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType)
> : Boolean = true
>
> endpackage
> And I'm trying to load it:
> Resource resource = rs.getResource("model2/SMDataModel.uml", true);
> MetaModelManager metaModelManager =
> PivotUtil.getMetaModelManager(resource);
> metaModelManager.setDefaultStandardLibraryURI("model2/ReferenceModel.ocl");
>
> PivotEnvironmentFactory envFactory = new PivotEnvironmentFactory(null,
> metaModelManager);
> PivotEnvironment environment = envFactory.createEnvironment();
> OCL ocl = OCL.newInstance(environment);
> OCLHelper oclHelper = ocl.createOCLHelper();
> Resource rules = ocl.load(createFileURI("model2/ReferenceModel.ocl"));
> I'm sure that my code is completly wrong but I have no idea what is a
> right way to do it...
Re: Comparision operator definition [message #1219332 is a reply to message #1219329] Tue, 03 December 2013 06:41 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
But I have not a MeasureType class... I have only an UML model. How should I associate the Java class with a UML class?

Here is my another attempt. I created oclstdlib file:
import 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib';

import 'ReferenceModel.uml';

library lib : lib = 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib' {

    type ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType {
        operation compareTo(x : Real) : Boolean; 
        operation ">"(x : Real) : Boolean; 
    }
}

But oclstdlib-editor says me that ReferenceModel.uml isn't resolved and :: is a syntax error.
Re: Comparision operator definition [message #1219334 is a reply to message #1219281] Tue, 03 December 2013 06:57 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
I think I've got it! I need to create a genmodel...
Re: Comparision operator definition [message #1219335 is a reply to message #1219332] Tue, 03 December 2013 06:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
http://wiki.eclipse.org/OCL/ForumNetiquette

On 03/12/2013 11:41, Denis Nikiforov wrote:
> But I have not a MeasureType class... I have only an UML model. How
> should I associate the Java class with a UML class?
>
> Here is my another attempt. I created oclstdlib file:
> import 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib';
>
> import 'ReferenceModel.uml';
>
> library lib : lib = 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib' {
>
> type
> ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType
> {
> operation compareTo(x : Real) : Boolean; operation ">"(x
> : Real) : Boolean; }
> }
>
> But oclstdlib-editor says me that ReferenceModel.uml isn't resolved
> and :: is a syntax error.
Re: Comparision operator definition [message #1219469 is a reply to message #1219335] Tue, 03 December 2013 23:27 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
Hi

I removed all local jars from buildpath:
https://github.com/AresEkb/OclToXPath (main project)
https://github.com/AresEkb/EMFTextXPath2 (XPath2-metamodel)

org.emftext.language.xpath2.resource.xpath2 depends on external org.emftext.access. But the dependence is optional. It should work without EMFText.

I added a compareTo method into
ReferenceModel.EECReferenceModel.EECReferenceDataModel.BDT.MeasureType and
ReferenceModel.EECReferenceModel.EECReferenceDataModel.BDT.impl.MeasureTypeImpl
but nothing is changed.

You can run OclToXPath project.
Re: Comparision operator definition [message #1219471 is a reply to message #1219469] Tue, 03 December 2013 23:29 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
Should I provide a Java implementation of
public int MeasureType.compareTo(MeasureType)
?

I need only to parse OCL, I won't execute it. Is it possible to define abstract operator without implementation?
Re: Comparision operator definition [message #1219569 is a reply to message #1219281] Wed, 04 December 2013 12:09 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
No Message Body
Re: Comparision operator definition [message #1219570 is a reply to message #1219569] Wed, 04 December 2013 12:09 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
Hi

The problem looked absolutely unsolvable for me. But I think I found an answer.
// Load data types
Resource rmRes = rs.getResource(createFileURI("model2/ReferenceModel.uml"), true);
Root rm = UML2Pivot.importFromUML(metaModelManager, null, rmRes);

// Let's find a type
final TreeIterator<EObject> iterator = rm.eAllContents();
while (iterator.hasNext()) {
    EObject obj = iterator.next();
        if (obj instanceof Type) {
            Type type = (Type)obj;
            if (type.getName().equals("MeasureType")) {
                // Create operation
                Operation lessThan = PivotFactory.eINSTANCE.createOperation();
                lessThan.setName("<");
                lessThan.setType(metaModelManager.getBooleanType());
                Parameter param = PivotFactory.eINSTANCE.createParameter();
                param.setType(metaModelManager.getRealType());
                lessThan.getOwnedParameter().add(param);
                type.getOwnedOperation().add(lessThan);
            }
        }
    }
}

It seems that a following operation doesn't replace "<":
                lessThan.setName("compareTo");
                lessThan.setType(metaModelManager.getIntegerType());
Re: Comparision operator definition [message #1219613 is a reply to message #1219570] Wed, 04 December 2013 17:16 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
HI

You asked for a custom datatype so I assumed you wanted the extended
Java instance class support for Ecore models.

For UML, you can define operations for your DataTypes so why not just
define the operations you want in models rather than Java code?

Regards

Ed Willink

On 04/12/2013 17:09, Denis Nikiforov wrote:
> Hi
>
> The problem looked absolutely unsolvable for me. But I think I found
> an answer.
> // Load data types
> Resource rmRes =
> rs.getResource(createFileURI("model2/ReferenceModel.uml"), true);
> Root rm = UML2Pivot.importFromUML(metaModelManager, null, rmRes);
>
> // Let's find a type
> final TreeIterator<EObject> iterator = rm.eAllContents();
> while (iterator.hasNext()) {
> EObject obj = iterator.next();
> if (obj instanceof Type) {
> Type type = (Type)obj;
> if (type.getName().equals("MeasureType")) {
> // Create operation
> Operation lessThan =
> PivotFactory.eINSTANCE.createOperation();
> lessThan.setName("<");
> lessThan.setType(metaModelManager.getBooleanType());
> Parameter param =
> PivotFactory.eINSTANCE.createParameter();
> param.setType(metaModelManager.getRealType());
> lessThan.getOwnedParameter().add(param);
> type.getOwnedOperation().add(lessThan);
> }
> }
> }
> }
> It seems that a following operation doesn't replace "<":
> lessThan.setName("compareTo");
> lessThan.setType(metaModelManager.getIntegerType());
>
Re: Comparision operator definition [message #1219630 is a reply to message #1219613] Wed, 04 December 2013 23:49 Go to previous message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 58
Registered: August 2013
Member
Hi

I added testOp() to MeasureType DataType and someOp() to AddressText Class
https://github.com/AresEkb/OclToXPath/blob/master/model2/ReferenceModel.uml

Parser finds someOp(), but ignores testOp()!

Here is a debug output of my program, that indicates that someOp() is found in the UML model:
>>>>>>>>>> ReferenceModel::EECReferenceModel::EECReferenceDataModel::CSDO::CSDE::AddressText.someOp() : PrimitiveTypes::Boolean

But it doesn't find any operations for MeasureType DataType:
Found operations for MeasureType: 0
Unresolved Operation 'ReferenceModel::EECReferenceModel::EECReferenceDataModel::BDT::MeasureType::testOp()'

It seems that DataType operations isn't supported.
Previous Topic:Generating Java code for OCL constraints
Next Topic:Installing Dresden OCL plugin in Juno
Goto Forum:
  


Current Time: Tue Jul 22 23:48:48 EDT 2014

Powered by FUDForum. Page generated in 0.02851 seconds