Supported scripting languages - "java binaries"

Moderator: Moderators

Supported scripting languages - "java binaries"

Postby miyako wilson » Tue Aug 29, 2017 2:03 pm

According to the link below one of Supported scripting languages is "java binaries".
https://docs.nomagic.com/display/CST185 ... +languages
Do you have any examples available?
Do I need to use Opeque Behavior's Language and Body?
How can I specify inputs and outputs?

Thanks
Miyako
miyako wilson
Forum Newbie
Forum Newbie
 
Posts: 7
Posts Rating:0
Joined: Wed Apr 12, 2017 1:42 pm

Re: Supported scripting languages - "java binaries"

Postby rjhudson@mitre.org » Wed Aug 30, 2017 1:14 am

I attached an example I pulled from the docs a while back. It is using a value specification but an opaque behavior/expression is still being used.
You do not have the required permissions to view the files attached to this post.
rjhudson@mitre.org
Forum Newbie
Forum Newbie
 
Posts: 5
Posts Rating:0
Joined: Thu Jun 29, 2017 3:40 pm

Re: Supported scripting languages - "java binaries"

Postby miyako wilson » Wed Aug 30, 2017 9:48 am

Thanks,

How can I use my own java class?
I created Test.jar
and I did Options->Project->General_.Simulation Script Engine and add my Test.jar file in there.
Then change the showMessage Opaque Behavior's Body to
Test.showMessage("aaaaaaa", "bbbbbbb");
But I am getting the error below.

org.mozilla.javascript.EcmaError: ReferenceError: "Test" is not defined. (<Unknown source>#1) in <Unknown source> at line number 1 expression body: Test.showMessage("aaaaaaa", "bbbbbbb");

I reopenedd the CSM and tested but got the same error message.
I added Test.jar's csm.properties CLASSPATH and reopened but got the same error message.

I attached the Test.java, Test.jar etc.. in the attachment.

Thanks
Miyako
You do not have the required permissions to view the files attached to this post.
miyako wilson
Forum Newbie
Forum Newbie
 
Posts: 7
Posts Rating:0
Joined: Wed Apr 12, 2017 1:42 pm

Re: Supported scripting languages - "java binaries"

Postby chanon_s » Thu Aug 31, 2017 3:23 am

Dear Miyako

You need to import your class in the opaque behavior. Normally, the syntax should be as below:

Code: Select all
importClass(com.nomagic.magicdraw.core.Application);


However, because your class is in the default package, you need to use the following syntax instead:

Code: Select all
importClass(Packages.Test);


The result of simulation should be as in the following image:

result.png


Sincerely

Chanon S.
No Magic Customer Support
You do not have the required permissions to view the files attached to this post.
chanon_s
Customer Support
Customer Support
 
Posts: 91
Posts Rating:7
Joined: Thu Dec 04, 2014 2:21 am

Re: Supported scripting languages - "java binaries"

Postby miyako wilson » Thu Aug 31, 2017 9:50 am

Thanks, it worked if I put the jar file in Options->Project->General->Simulation Script Engine->External Libraries->External Libraries, and restarted the CSM.
I put the Test.java in package test, then I put
importClass(test.Test);
but that did not work.
But if I put
importClass(Packages.test.Test);
it worked.
Thanks for your help.

Miyako
miyako wilson
Forum Newbie
Forum Newbie
 
Posts: 7
Posts Rating:0
Joined: Wed Apr 12, 2017 1:42 pm

Re: Supported scripting languages - "java binaries"

Postby chanon_s » Fri Sep 01, 2017 1:29 am

Dear Miyako

If the java class is in the default package or the package does not start with com, net, or edu; you will need to prepend the Packages. word in your import statement. For example,

Code: Select all
//test/Test.class
importClass(Packages.test.Test); //because it starts with package "test".


or

Code: Select all
//Test.class
importClass(Packages.Test); //because it is in the default package.


But, if its packages start with com, net, or edu; it won't need the Packages. word. For instance,

Code: Select all
//com/Test.class
importClass(com.Test); //package starts with com.


Sincerely

Chanon S.
No Magic Customer Support
chanon_s
Customer Support
Customer Support
 
Posts: 91
Posts Rating:7
Joined: Thu Dec 04, 2014 2:21 am

Re: Supported scripting languages - "java binaries"

Postby miyako wilson » Fri Sep 01, 2017 6:56 am

Thank you for the clarification.

Miyako
miyako wilson
Forum Newbie
Forum Newbie
 
Posts: 7
Posts Rating:0
Joined: Wed Apr 12, 2017 1:42 pm


Return to Cameo Simulation Toolkits

Who is online

Users browsing this forum: No registered users and 0 guests