Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How to import an UML element into a pivot model?
How to import an UML element into a pivot model? [message #1699194] Mon, 22 June 2015 13:09 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 170
Registered: August 2013
Senior Member
Hi

I have a following code based on Eclipse OCL 5.0:
    public static ExpressionInOCL toExpressionInOCL(org.eclipse.uml2.uml.Constraint constraint) throws ParserException
    {
        org.eclipse.uml2.uml.Namespace context = constraint.getContext();
        MetaModelManager mm = PivotUtil.findMetaModelManager(context);
        org.eclipse.ocl.pivot.Element type = UML2Pivot.importFromUML(mm, null, context);
        oclHelper.setInstanceContext(type);
        if (constraint.getSpecification() instanceof OpaqueExpression) {
            OpaqueExpression opaqueExpression = (OpaqueExpression)constraint.getSpecification();
            int indexOfOCLBody = opaqueExpression.getLanguages().indexOf("OCL");
            if (indexOfOCLBody != -1) {
                String body = opaqueExpression.getBodies().get(indexOfOCLBody);
                return oclHelper.createInvariant(body);
            }
        }
        return null;
    }


The code parses an UML Constraint. At first it finds an context element of the constraint. And then it imports the UML element into a pivot model.
The problem is that I can't find neither PivotUtil.findMetaModelManager(), nor UML2Pivot in the Eclipse OCL 6.0.

How should I change my code to make it work?

Also I need to convert a pivot element into an UML element:
    public static org.eclipse.uml2.uml.NamedElement getETarget(org.eclipse.ocl.pivot.NamedElement el)
    {
        return (org.eclipse.uml2.uml.NamedElement)el.getETarget();
    }


But getETarget() method seems to be obsolete. Is there an alternative approach?

Thanks!
Re: How to import an UML element into a pivot model? [message #1699219 is a reply to message #1699194] Mon, 22 June 2015 16:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5570
Registered: July 2009
Senior Member
Hi

The UML support is now built-in but optional, so you should call
UMLStandaloneSetup.init() before you do anything to emulate the
registrations that Equinox would have done automatically.

The MetamodelManager is still there but no longer the universal
interface monolith. Minimal usage can get away with the OCL
facade/handle. More advanced users can probelmby get away with
OCL.getEnvironmentFactory since EnvironmentFactory is the key to all
underlying functionality. See the updates in the OCL Documentation.

Really advanced users can use OCLInternal.getMetaModelManager().

UML2Pivot is now UML2AS. ("Abstract Syntax")

getETarget is now getESObject. ("External Syntax")

Tentatively I would hope that something like the following should work

RsourceSet resourceSet = ...
Resource umlResource = resourceSet.getResource( ... );
org.eclipse.uml2.uml.Constraint umlConstraint = ... f(umlResource) ...
....
OCL ocl = OCL.newInstance(resourceSet);
org.eclipse.ocl.pivot.Constraint asConstraint =
ocl.getMetamodelManager().getASOf(org.eclipse.ocl.pivot.Constraint.class, umlConstraint);
org.eclipse.ocl.pivot.ExpressionInOCL asExpression =
ocl.getSpecfication(asConstraint);
.....
ocl.dispose();

(Looks like getASOf should be promoted to the OCL facade.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=470734 raised to
accumulate ideas for API help.)

Regards

Ed Willink

On 22/06/2015 14:09, Denis Nikiforov wrote:
> Hi
>
> I have a following code based on Eclipse OCL 5.0:
> public static ExpressionInOCL
> toExpressionInOCL(org.eclipse.uml2.uml.Constraint constraint) throws
> ParserException
> {
> org.eclipse.uml2.uml.Namespace context = constraint.getContext();
> MetaModelManager mm = PivotUtil.findMetaModelManager(context);
> org.eclipse.ocl.pivot.Element type =
> UML2Pivot.importFromUML(mm, null, context);
> oclHelper.setInstanceContext(type);
> if (constraint.getSpecification() instanceof OpaqueExpression) {
> OpaqueExpression opaqueExpression =
> (OpaqueExpression)constraint.getSpecification();
> int indexOfOCLBody =
> opaqueExpression.getLanguages().indexOf("OCL");
> if (indexOfOCLBody != -1) {
> String body =
> opaqueExpression.getBodies().get(indexOfOCLBody);
> return oclHelper.createInvariant(body);
> }
> }
> return null;
> }
>
> The code parses an UML Constraint. At first it finds an context
> element of the constraint. And then it imports the UML element into a
> pivot model.
> The problem is that I can't find neither
> PivotUtil.findMetaModelManager(), nor UML2Pivot in the Eclipse OCL 6.0.
>
> How should I change my code to make it work?
>
> Also I need to convert a pivot element into an UML element:
> public static org.eclipse.uml2.uml.NamedElement
> getETarget(org.eclipse.ocl.pivot.NamedElement el)
> {
> return (org.eclipse.uml2.uml.NamedElement)el.getETarget();
> }
>
> But getETarget() method seems to be obsolete. Is there an alternative
> approach?
>
> Thanks!
Re: How to import an UML element into a pivot model? [message #1699257 is a reply to message #1699219] Tue, 23 June 2015 05:49 Go to previous message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 170
Registered: August 2013
Senior Member
Thanks a lot! It works!
Previous Topic:Applying OCL at models (vs metamodels)
Next Topic:How to create an invariant for an UML class in OCL 6.0?
Goto Forum:
  


Current Time: Tue Jan 16 10:04:49 GMT 2018

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

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