Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How to add a custom data type?
How to add a custom data type? [message #1699336] Tue, 23 June 2015 13:24 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 170
Registered: August 2013
Senior Member
Hi

Here is a simple UML model:
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_yvcV4BWREeWRmaooDOvO2g" name="model">
  <packagedElement xmi:type="uml:Class" xmi:id="_noersBWVEeWSierZQWePVw" name="Person">
    <ownedAttribute xmi:id="_noersRWVEeWSierZQWePVw" name="age">
      <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
    </ownedAttribute>
    <ownedAttribute xmi:id="_noershWVEeWSierZQWePVw" name="fullName">
      <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
    </ownedAttribute>
    <ownedAttribute xmi:id="_BNWxABmwEeWMHsyn7E5fJw" name="custom" type="_JKMEsBmwEeWMHsyn7E5fJw"/>
  </packagedElement>
  <packagedElement xmi:type="uml:DataType" xmi:id="_JKMEsBmwEeWMHsyn7E5fJw" name="CustomType">
    <ownedOperation xmi:id="_L2er0BmwEeWMHsyn7E5fJw" name="size" isQuery="true">
      <ownedParameter xmi:id="_O_BKEBmwEeWMHsyn7E5fJw" name="result" direction="return">
        <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
      </ownedParameter>
    </ownedOperation>
  </packagedElement>
</uml:Model>


The Person class has the "custom" property with type CustomType.

I have two questions...

1) Why the following constraint is invalid:

import 'My.uml'

package model

context Person
inv:
    custom.size() <= 70

endpackage


I receive the following error:
Unresolved Operation 'model::CustomType::size()'


2) What is a preferred way to add to the CustomType all operations defined for the String type?
The problem is that my CustomType is UML::DataType. It's not UML::PrimitiveType.
An so, I can't inherit it from UMLPrimitiveType::String, because the later one is a UML::PrimitiveType. And UML::DataType can't be inherited from UML::PrimitiveType.
And also I can't apply EDataType stereotype to the CustomType. Because the stereotype can only be applied to UML::PrimitiveType.

Thanks!
Re: How to add a custom data type? [message #1699347 is a reply to message #1699336] Tue, 23 June 2015 13:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5523
Registered: July 2009
Senior Member
Hi

One of the major simplifications of UML 2.5. Clause 10.2 DataTypes
unambiguously have Operations.

UML 2.4.1 (Basic). Clause 10.3 DataTypes do not have Operations
UML 2.4.1 (Core). Clause 11.6 DataTypes do have Operations

Unfortunately the Pivot UML2AS conversion follows the first UML 2.4.1
diagram and hasn't been updated since aligning to UML 2.5.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=470805 raised.

You can perhaps workaround it with a Complete OCL definition.

context CustomType
def: size() : Integer = ...

Regards

Ed Willink On 23/06/2015 14:24, Denis Nikiforov wrote:
> Hi
>
> Here is a simple UML model:
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="20131001"
> xmlns:xmi="http://www.omg.org/spec/XMI/20131001"
> xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML"
> xmi:id="_yvcV4BWREeWRmaooDOvO2g" name="model">
> <packagedElement xmi:type="uml:Class"
> xmi:id="_noersBWVEeWSierZQWePVw" name="Person">
> <ownedAttribute xmi:id="_noersRWVEeWSierZQWePVw" name="age">
> <type xmi:type="uml:PrimitiveType"
> href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
> </ownedAttribute>
> <ownedAttribute xmi:id="_noershWVEeWSierZQWePVw" name="fullName">
> <type xmi:type="uml:PrimitiveType"
> href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
> </ownedAttribute>
> <ownedAttribute xmi:id="_BNWxABmwEeWMHsyn7E5fJw" name="custom"
> type="_JKMEsBmwEeWMHsyn7E5fJw"/>
> </packagedElement>
> <packagedElement xmi:type="uml:DataType"
> xmi:id="_JKMEsBmwEeWMHsyn7E5fJw" name="CustomType">
> <ownedOperation xmi:id="_L2er0BmwEeWMHsyn7E5fJw" name="size"
> isQuery="true">
> <ownedParameter xmi:id="_O_BKEBmwEeWMHsyn7E5fJw" name="result"
> direction="return">
> <type xmi:type="uml:PrimitiveType"
> href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
> </ownedParameter>
> </ownedOperation>
> </packagedElement>
> </uml:Model>
>
> The Person class has the "custom" property with type CustomType.
>
> I have two questions...
>
> 1) Why the following constraint is invalid:
>
> import 'My.uml'
>
> package model
>
> context Person
> inv:
> custom.size() <= 70
>
> endpackage
>
>
> I receive the following error:
> Unresolved Operation 'model::CustomType::size()'
>
> 2) What is a preferred way to add to the CustomType all operations
> defined for the String type?
> The problem is that my CustomType is UML::DataType. It's not
> UML::PrimitiveType.
> An so, I can't inherit it from UMLPrimitiveType::String, because the
> later one is a UML::PrimitiveType. And UML::DataType can't be
> inherited from UML::PrimitiveType.
> And also I can't apply EDataType stereotype to the CustomType. Because
> the stereotype can only be applied to UML::PrimitiveType.
>
> Thanks!
Re: How to add a custom data type? [message #1699401 is a reply to message #1699347] Wed, 24 June 2015 05:36 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 170
Registered: August 2013
Senior Member
Hi

Is there a workaround for Essential OCL? I have embeded OCL-rules in my UML model. The rules are parsed fine in Rational Software Architect 9.1. But I can't parse them in Eclipse OCL.
Re: How to add a custom data type? [message #1699402 is a reply to message #1699401] Wed, 24 June 2015 05:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5523
Registered: July 2009
Senior Member
Hi

What rules do not parse?

Regards

Ed Willink

On 24/06/2015 06:36, Denis Nikiforov wrote:
> Hi
>
> Is there a workaround for Essential OCL? I have embeded OCL-rules in
> my UML model. The rules are parsed fine in Rational Software Architect
> 9.1. But I can't parse them in Eclipse OCL.
Re: How to add a custom data type? [message #1699416 is a reply to message #1699402] Wed, 24 June 2015 08:03 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 170
Registered: August 2013
Senior Member
Hi

For now, I could not provide a simple project to illustrate my problem. Here is a full project: https://github.com/AresEkb/uml2xsd

The model https://github.com/AresEkb/uml2xsd/blob/master/model/ISO20022.uml contains the following rule owned by PartyIdentification32 class:
Name.size() <= 70

Name property has Max140Text data type which is inherited from Text inherited from String.
The String data type owns the operation size() : Integer:
https://github.com/AresEkb/uml2xsd/blob/master/model/ISO20022DataTypes.uml

Rational Software Architect 9.1 parses the OCL constraint presented above without problems.
But Eclipse OCL couln't resolve size() operation.

I wrote a following hack method which clones UML DataTypes operations to corresponding Pivot DataTypes:
    private static void addDataTypeOperations(ResourceSet rs, Model model) throws ParserException
    {
        MetamodelManager mm = UtilitiesLibrary.ocl.getMetamodelManager();

        Set<DataType> dataTypes = new HashSet<DataType>();
        final TreeIterator<EObject> iterator = model.eAllContents();
        while (iterator.hasNext()) {
            EObject obj = iterator.next();
            if (obj instanceof DataType) {
                DataType type = (DataType)obj;
                dataTypes.add(type);
                for (Classifier general : type.allParents()) {
                    dataTypes.add((DataType)general);
                }
            }
        }

        for (DataType dataType : dataTypes) {
            // DataTypes doens't inherit operations. So we add operations to each inherited DataType
            for (Operation oper : dataType.getAllOperations()) {
                createOperation(mm, dataType, oper);
            }
        }
    }

    private static org.eclipse.ocl.pivot.Operation createOperation(MetamodelManager mm, DataType dataType, Operation operation) throws ParserException
    {
        org.eclipse.ocl.pivot.DataType asDataType = mm.getASOf(org.eclipse.ocl.pivot.DataType.class, dataType);
        org.eclipse.ocl.pivot.Operation asOperation = PivotFactory.eINSTANCE.createOperation();
        asOperation.setName(operation.getName());
        org.eclipse.ocl.pivot.Type returnType = mm.getASOf(org.eclipse.ocl.pivot.Type.class, operation.getType());
        asOperation.setType(returnType);
        for (Parameter param : operation.getOwnedParameters()) {
            if (param.getDirection() == ParameterDirectionKind.RETURN_LITERAL) {
                continue;
            }
            org.eclipse.ocl.pivot.Parameter asParam = PivotFactory.eINSTANCE.createParameter();
            org.eclipse.ocl.pivot.Type asParamType = mm.getASOf(org.eclipse.ocl.pivot.Type.class, param.getType());
            asParam.setType(asParamType);
            asOperation.getOwnedParameters().add(asParam);
        }
        asDataType.getOwnedOperations().add(asOperation);
        return asOperation;
    }
Re: How to add a custom data type? [message #1699428 is a reply to message #1699416] Wed, 24 June 2015 09:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5523
Registered: July 2009
Senior Member
Hi

You confused me. I thought you had a new problem.

You should find the UML DataType Operation limitation and stale Pivot
Standalone setup documentation fixed in

http://www.eclipse.org/modeling/download.php?file=/modeling/mdt/ocl/downloads/drops/6.0.1/N201506240506/mdt-ocl-Update-N201506240506.zip

or

http://download.eclipse.org/modeling/mdt/ocl/updates/nightly/6.0.1

Regards

Ed Willink


On 24/06/2015 09:03, Denis Nikiforov wrote:
> Hi
>
> For now, I could not provide a simple project to illustrate my
> problem. Here is a full project: https://github.com/AresEkb/uml2xsd
>
> The model
> https://github.com/AresEkb/uml2xsd/blob/master/model/ISO20022.uml
> contains the following rule owned by PartyIdentification32 class:
> Name.size() <= 70
> Name property has Max140Text data type which is inherited from Text
> inherited from String.
> The String data type owns the operation size() : Integer:
> https://github.com/AresEkb/uml2xsd/blob/master/model/ISO20022DataTypes.uml
>
>
> Rational Software Architect 9.1 parses the OCL constraint presented
> above without problems.
> But Eclipse OCL couln't resolve size() operation.
>
> I wrote a following hack method which clones UML DataTypes operations
> to corresponding Pivot DataTypes:
> private static void addDataTypeOperations(ResourceSet rs, Model
> model) throws ParserException
> {
> MetamodelManager mm = UtilitiesLibrary.ocl.getMetamodelManager();
>
> Set<DataType> dataTypes = new HashSet<DataType>();
> final TreeIterator<EObject> iterator = model.eAllContents();
> while (iterator.hasNext()) {
> EObject obj = iterator.next();
> if (obj instanceof DataType) {
> DataType type = (DataType)obj;
> dataTypes.add(type);
> for (Classifier general : type.allParents()) {
> dataTypes.add((DataType)general);
> }
> }
> }
>
> for (DataType dataType : dataTypes) {
> // DataTypes doens't inherit operations. So we add
> operations to each inherited DataType
> for (Operation oper : dataType.getAllOperations()) {
> createOperation(mm, dataType, oper);
> }
> }
> }
>
> private static org.eclipse.ocl.pivot.Operation
> createOperation(MetamodelManager mm, DataType dataType, Operation
> operation) throws ParserException
> {
> org.eclipse.ocl.pivot.DataType asDataType =
> mm.getASOf(org.eclipse.ocl.pivot.DataType.class, dataType);
> org.eclipse.ocl.pivot.Operation asOperation =
> PivotFactory.eINSTANCE.createOperation();
> asOperation.setName(operation.getName());
> org.eclipse.ocl.pivot.Type returnType =
> mm.getASOf(org.eclipse.ocl.pivot.Type.class, operation.getType());
> asOperation.setType(returnType);
> for (Parameter param : operation.getOwnedParameters()) {
> if (param.getDirection() ==
> ParameterDirectionKind.RETURN_LITERAL) {
> continue;
> }
> org.eclipse.ocl.pivot.Parameter asParam =
> PivotFactory.eINSTANCE.createParameter();
> org.eclipse.ocl.pivot.Type asParamType =
> mm.getASOf(org.eclipse.ocl.pivot.Type.class, param.getType());
> asParam.setType(asParamType);
> asOperation.getOwnedParameters().add(asParam);
> }
> asDataType.getOwnedOperations().add(asOperation);
> return asOperation;
> }
Re: How to add a custom data type? [message #1701277 is a reply to message #1699428] Fri, 10 July 2015 12:32 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 170
Registered: August 2013
Senior Member
Thanks a lot! It works.

But inherited operations aren't supported.

Here is a test model https://github.com/AresEkb/ocl6_test/blob/master/model/My.uml
And test OCL: https://github.com/AresEkb/ocl6_test/blob/master/model/NewOCLFile.ocl

It doesn't resolve inherited size() operation.

Also you can run https://github.com/AresEkb/ocl6_test/blob/master/src/ocl6_test/Main.java
8th and 9th tests a failed.
Re: How to add a custom data type? [message #1701307 is a reply to message #1701277] Fri, 10 July 2015 18:29 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5523
Registered: July 2009
Senior Member
Hi

You are now going into dark corners of the UML spec.

DataTypes are not StructuredClasses and do not have superclasses,
however they do have generals.

My instinct therefore tells me that DataTypes do not have inherited
operations, but it's probably debateable. Of couse dynamic dispatch in
OCL is totally undefined.

In the pivot model DataTypes are Classes so they could have more useful
superclasses if UML2AS populated them, but I'm not inclined to change
anything here at the moment.

Regards

Ed Willink


On 10/07/2015 13:32, Denis Nikiforov wrote:
> Thanks a lot! It works.
>
> But inherited operations aren't supported.
>
> Here is a test model
> https://github.com/AresEkb/ocl6_test/blob/master/model/My.uml
> And test OCL:
> https://github.com/AresEkb/ocl6_test/blob/master/model/NewOCLFile.ocl
>
> It doesn't resolve inherited size() operation.
>
> Also you can run
> https://github.com/AresEkb/ocl6_test/blob/master/src/ocl6_test/Main.java
> 8th and 9th tests a failed.
Re: How to add a custom data type? [message #1701310 is a reply to message #1701307] Fri, 10 July 2015 19:18 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1162
Registered: July 2009
Location: Canada
Senior Member

Hi, Ed,

I think the fact of DataType::ownedOperation subsetting
redefinableElement implies that operations are inherited from general
data types. Otherwise, redefinition of operations would have no
meaning; the concept is tied to inheritance.

Also, DataType doesn't redefine Classifier::inheritedMember or any of
the related operations(inheritableMembers(...) etc.), so it would seem
to have the default inheritance rules, which means it inherits
operations and attributes from its generals just as Class does.

HTH,

Christian


On 2015-07-10 18:29:05 +0000, Ed Willink said:

> Hi
>
> You are now going into dark corners of the UML spec.
>
> DataTypes are not StructuredClasses and do not have superclasses,
> however they do have generals.
>
> My instinct therefore tells me that DataTypes do not have inherited
> operations, but it's probably debateable. Of couse dynamic dispatch in
> OCL is totally undefined.
>
> In the pivot model DataTypes are Classes so they could have more useful
> superclasses if UML2AS populated them, but I'm not inclined to change
> anything here at the moment.
>
> Regards
>
> Ed Willink
>
>
> On 10/07/2015 13:32, Denis Nikiforov wrote:
>> Thanks a lot! It works.
>>
>> But inherited operations aren't supported.
>>
>> Here is a test model
>> https://github.com/AresEkb/ocl6_test/blob/master/model/My.uml
>> And test OCL:
>> https://github.com/AresEkb/ocl6_test/blob/master/model/NewOCLFile.ocl
>>
>> It doesn't resolve inherited size() operation.
>>
>> Also you can run
>> https://github.com/AresEkb/ocl6_test/blob/master/src/ocl6_test/Main.java
>> 8th and 9th tests a failed.
Re: How to add a custom data type? [message #1701326 is a reply to message #1699336] Sat, 11 July 2015 18:01 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 170
Registered: August 2013
Senior Member
Hi

There are a lot of custom data types in our UML model (several hundreds). Some of these types are numeric, some of them are string-based types. And we need to define for these types some generic operations. For example, for all string-based types we need size() operation.

The most straightforward solution for us is the following: 1) define several base data types (string, integer, real, ...), 2) define all needed operations for these base data types, 3) and inherit all of our custom data types from these base data types. This approach works fine in Rational Software Architect. We can use this operations in ownedRules.

But how can we achive a simillar thing in Eclipse OCL? For example there is a Max35Text data type in our UML model. This is a string data type limited to 35 characters maximum length. We need to use all usual string operations for this data type (for example, size()). How can we force Eclipse OCL to treat Max35Text as EString?

The problem is that we use only Essential OCL, our constraints are embeded into UML model (ownedRule). We can't write something like
context Max35Text
def: size() : Integer = ...
Re: How to add a custom data type? [message #1701330 is a reply to message #1701326] Sat, 11 July 2015 19:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5523
Registered: July 2009
Senior Member
Hi

If you submit a Bugzilla with a smallish *.uml file that uses the
facilities you would like to see on DataTypes and which misbehaves in
the UML Model Editor for ->Validate or ->OCL->Validate, I'll see what I
can do.

Regards

Ed Willink


On 11/07/2015 19:01, Denis Nikiforov wrote:
> Hi
>
> There are a lot of custom data types in our UML model (several
> hundreds). Some of these types are numeric, some of them are
> string-based types. And we need to define for these types some generic
> operations. For example, for all string-based types we need size()
> operation.
>
> The most straightforward solution for us is the following: 1) define
> several base data types (string, integer, real, ...), 2) define all
> needed operations for these base data types, 3) and inherit all of our
> custom data types from these base data types. This approach works fine
> in Rational Software Architect. We can use this operations in ownedRules.
>
> But how can we achive a simillar thing in Eclipse OCL? For example
> there is a Max35Text data type in our UML model. This is a string data
> type limited to 35 characters maximum length. We need to use all usual
> string operations for this data type (for example, size()). How can we
> force Eclipse OCL to treat Max35Text as EString?
>
> The problem is that we use only Essential OCL, our constraints are
> embeded into UML model (ownedRule). We can't write something like
> context Max35Text
> def: size() : Integer = ...
Re: How to add a custom data type? [message #1701440 is a reply to message #1701307] Mon, 13 July 2015 13:31 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 170
Registered: August 2013
Senior Member
Hi, Ed,

Here is a bugzilla:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=472469

As far I understand the main difference between Simple Classifiers and Structured Classifiers is that the later one can have internal structure (embeded classifiers). They contains roles, ports (see fig. 11.5 (ii) in UML version 2.5 spec).

The main difference between DataTypes and Classes is the following (section 10.2.3):
Quote:
DataType differs from Class in that instances of a DataType are identified only by their value. All instances of a DataType with the same value are considered to be equal instances.


I think that from the OCL point of view DataTypes and Classes must behave identically... Maybe except equality operator. All DataTypes has equality operator from scratch.
Re: How to add a custom data type? [message #1701470 is a reply to message #1701440] Mon, 13 July 2015 14:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5523
Registered: July 2009
Senior Member
Hi

Try

http://www.eclipse.org/modeling/download.php?file=/modeling/mdt/ocl/downloads/drops/6.0.1/N201507131005/mdt-ocl-Update-N201507131005.zip

Regards

Ed Willink

On 13/07/2015 14:31, Denis Nikiforov wrote:
> Hi, Ed,
>
> Here is a bugzilla:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=472469
>
> As far I understand the main difference between Simple Classifiers and
> Structured Classifiers is that the later one can have internal
> structure (embeded classifiers). They contains roles, ports (see fig.
> 11.5 (ii) in UML version 2.5 spec).
>
> The main difference between DataTypes and Classes is the following
> (section 10.2.3):
> Quote:
>> DataType differs from Class in that instances of a DataType are
>> identified only by their value. All instances of a DataType with the
>> same value are considered to be equal instances.
>
>
> I think that from the OCL point of view DataTypes and Classes must
> behave identically... Maybe except equality operator. All DataTypes
> has equality operator from scratch.
Re: How to add a custom data type? [message #1701564 is a reply to message #1701470] Tue, 14 July 2015 07:56 Go to previous message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 170
Registered: August 2013
Senior Member
As always thanks a lot for your help, everithing works!
Previous Topic:uml:Signal context for OCL constraint
Next Topic:What specification to use
Goto Forum:
  


Current Time: Tue Dec 12 18:06:25 GMT 2017

Powered by FUDForum. Page generated in 0.02395 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software