Documentation Inconsistencies

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Documentation Inconsistencies

Postby Kristina Hildebrand » Thu Nov 10, 2005 12:57 pm

I am in the process of converting a plugin from 9.5 to 10, and I need
some information that is not available in the user documentation (near
as I can tell).

On page 4-26 of the October 2005 edition of the MagicDraw Open API
user's guide, reference is made to the methods
ModelHelper.setSupplierElement() and ModelHelper.setClientElement(), for
creating "Relationship"s. These methods are not mentioned in the
javadoc for ModelHelper in ../openapi/docs/javadoc/index.html The only
information I can gather from the method signature is that these methods
require two "Element"s as parameters.

Am I looking in the wrong place for documentation, or is this something
that was left out when the documentation was generated? If it's the
latter, could someone please explain how these methods are to be used?
I have noticed this problem a few times - something will be in the API
(which I can see in my IDE) and not in the javadoc, or vice versa.

Thank you,
Kristina Hildebrand
Kristina Hildebrand
 
Posts Rating:

Re: Documentation Inconsistencies

Postby Kristina Hildebrand » Thu Nov 10, 2005 3:42 pm

As an addendum to my earlier message, when I try to use:
ModelHelper.setSupplierElement(supplierClass, dep);

I get:
"NOT IMPLEMENTED!!! For null
com.nomagic.uml2.ext.jmi.helpers.ModelHelper.setSupplierElement(ModelHelper.java:1102)"

When I switch the order of the arguments, as below:
ModelHelper.setSupplierElement(dep, supplierClass);

I get a null pointer error where it appears to be trying to find
something by type.

Kristina Hildebrand wrote:
> I am in the process of converting a plugin from 9.5 to 10, and I need
> some information that is not available in the user documentation (near
> as I can tell).
>
> On page 4-26 of the October 2005 edition of the MagicDraw Open API
> user's guide, reference is made to the methods
> ModelHelper.setSupplierElement() and ModelHelper.setClientElement(), for
> creating "Relationship"s. These methods are not mentioned in the
> javadoc for ModelHelper in ../openapi/docs/javadoc/index.html The only
> information I can gather from the method signature is that these methods
> require two "Element"s as parameters.
>
> Am I looking in the wrong place for documentation, or is this something
> that was left out when the documentation was generated? If it's the
> latter, could someone please explain how these methods are to be used? I
> have noticed this problem a few times - something will be in the API
> (which I can see in my IDE) and not in the javadoc, or vice versa.
>
> Thank you,
> Kristina Hildebrand
Kristina Hildebrand
 
Posts Rating:

RE: Documentation Inconsistencies

Postby Tomas Pugzlys » Thu Nov 17, 2005 12:13 am

Hello,

>Am I looking in the wrong place for documentation, or is this something
>that was left out when the documentation was generated?

This is a bug in JavaDoc documentation.

>If it's the latter, could someone please explain how these methods are to
be used?
setSupplierElement(relationship, supplier)
setClientEement(relationship, client)
The first parameter is relationship model element.
The second parameter is supplier/client element.

Here is example code how to create Dependency and set supplier/client
element:
ElementsFactory f =
Application.getInstance().getProject().getElementsFactory();
Dependency dep = f.createDependencyInstance();
dep.setOwner(owningModelElement);

ModelHelper.setSupplierElement(dep, supplierClass);
ModelHelper.setClientElement(dep, clientClass);

Different relationship types have different supplier/client property names.
setSupplierElement/setClientEement encapsulates this logic and provides a
uniform way to set supplier/client.

For instance above code is equivalent to this code:
ElementsFactory f =
Application.getInstance().getProject().getElementsFactory();
Dependency dep = f.createDependencyInstance();
dep.setOwner(owningModelElement);

//set supplier
dep.getTarget().clear();
dep.getTarget().add(supplierClass);

//set client
dep.getSource().clear();
dep.getSource().add(clientClass);

But still it is more preferred way to use setSupplierElement/setClientEement
methods.
Because you do not need to care what are exact
supplier/client property names in various relationships.

Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com

Tomas Pugzlys
 
Posts Rating:

RE: Documentation Inconsistencies

Postby Tomas Pugzlys » Thu Nov 17, 2005 12:19 am

Hello,

The correct usage is ModelHelper.setSupplierElement(dep, supplierClass);
You get nullpointer because dep is null

Use the following code to create dependency model element:
ElementsFactory f =
Application.getInstance().getProject().getElementsFactory();
Dependency dep = f.createDependencyInstance();

Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com

Tomas Pugzlys
 
Posts Rating:

Re: Documentation Inconsistencies

Postby Kristina Hildebrand » Thu Nov 17, 2005 3:43 pm


Tomas Pugzlys wrote:
> Here is example code how to create Dependency and set supplier/client
> element:
> ElementsFactory f =
> Application.getInstance().getProject().getElementsFactory();
> Dependency dep = f.createDependencyInstance();
> dep.setOwner(owningModelElement);
>
> ModelHelper.setSupplierElement(dep, supplierClass);
> ModelHelper.setClientElement(dep, clientClass);

Thank you for the information. Out of curiosity, is there a difference
in functionality between:

ModelElementsManager.getInstance().addElement(dep, owner);

and

dep.setOwner(owner);

?? I understand that ModelElementsManager can only be used in
conjunction with SessionManager. Is this the only difference?

Thank you for all your help. I really do appreciate it!
~Kristina Hildebrand
Kristina Hildebrand
 
Posts Rating:

RE: Documentation Inconsistencies

Postby Tomas Pugzlys » Mon Nov 21, 2005 1:03 am

Hello,

ModelElementsManager.getInstance().addElement(dep, owner);

is equivalent to dep.setOwner(owner);

Plus additional checks are performed:
check if model session is created (otherwise IllegalStateException
exception is thrown).
check if element can be added to owner (otherwise IllegalArgumentException
exception is thrown).
check if owner is not read only (otherwise ReadOnlyElementException
exception is thrown).

Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com

Tomas Pugzlys
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 1 guest