|
|
|
|
Re: How to add a custom data type? [message #1699416 is a reply to message #1699402] |
Wed, 24 June 2015 08:03 |
Denis Nikiforov Messages: 346 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 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 |
Ed Willink Messages: 7670 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 #1701310 is a reply to message #1701307] |
Fri, 10 July 2015 19:18 |
|
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 |
Denis Nikiforov Messages: 346 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 |
Ed Willink Messages: 7670 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 = ...
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06035 seconds