Plugin Namespace

Post here questions and problems related to oXygen frameworks/document types.
jlpoole
Posts: 23
Joined: Sun Jan 15, 2017 3:15 pm
Location: Salem, Oregon

Plugin Namespace

Post by jlpoole »

I would like to be able to call code among Plugins or have a Global space where my plugin can call.
For instance, if I have a plugin "A" that has a function foo(myParam), I'd like to be able to call foo("test") from plugin "B". From what I can tell the namespaces for each plugin are isolated... or way down a tree branch not meant to be followed.

Here's another example, I have the following code:

Code: Select all

function print (msg) {
if (typeof(msg) == "undefined"){
// getting an undefined causes error as interpreter does not
// know if string or object
Packages.java.lang.System.out.println("undefined");
return;
}
// next line for debugging
//Packages.java.lang.System.out.println("[print 59] typeof msg = " + typeof(msg));
if (typeof(msg) == "object"){
Packages.java.lang.System.out.println(msg.toString);
} else {
Packages.java.lang.System.out.println(msg);
}
}

which if included in each and every plugin works, but it would be nice to be able to have print() defined just once in a location where any plugin may call it. Is there a way to accomplish this or a way of contributing to the global namespace?
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: Plugin Namespace

Post by Radu »

Hi,

By default each plugin is loaded in its own class loader, meaning that indeed they cannot access methods from another plugin's code. We do this to avoid conflicts between plugins created by separate vendors/developers.
When you refer to libraries in the plugin.xml you can add a @scope attribute to the reference:

https://www.oxygenxml.com/doc/versions/ ... lugin.html

Maybe specifying a "global" scope when referencing libraries containing common code would work in your case.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
jlpoole
Posts: 23
Joined: Sun Jan 15, 2017 3:15 pm
Location: Salem, Oregon

Re: Plugin Namespace

Post by jlpoole »

Maybe specifying a "global" scope when referencing libraries containing common code would work in your case.
What I'd like to be able to do is reference the JavaScript functions. It appears that specifying global relates to java jars which I believe can only contain Java classes. Is there a way to have JavaScript objects made global? I'm used to developing in Arbortext using JavaScript using encapsulation of our JavaScript classes within a single global namespace. In Arbortext, we created JavaScript, not Java, objects within hierarchies, e.g. com.oracle.xxx.yyy.zzz.MyClass

Is there some way to have the JavaScript share namespaces? If not, then it looks like I will have to place everything into one JavaScript file.

2nd question: Can the loader load more than one JavaScript file so in a plugin, called "red", I might have several JavaScript files such as red.js, red2.js and red3.js?

I tried using the "this.classname" within my JavaScript to see where in the global namespace it might be, even if in temporary named areas, and I got "undefined."
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: Plugin Namespace

Post by Radu »

Hi,

So:
Is there some way to have the JavaScript share namespaces? If not, then it looks like I will have to place everything into one JavaScript file.
Right now there is no way for a Javascript in one plugin to call methods from a Javascript in another. We'll try to remove this limitation in the future.
2nd question: Can the loader load more than one JavaScript file so in a plugin, called "red", I might have several JavaScript files such as red.js, red2.js and red3.js?
Also unfortunately we do not have this. We have an internal issue registered for this and I will update this forum thread when an Oxygen version containing this improvement is available.

So you will probably need to create a small build process which takes the modular Javscript files and creates a large Javascript file used in the plugin.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
jlpoole
Posts: 23
Joined: Sun Jan 15, 2017 3:15 pm
Location: Salem, Oregon

Re: Plugin Namespace

Post by jlpoole »

Thank you. I suspected the monolithic approach might end up being the current avenue.

We look forward to the new features.
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Re: Plugin Namespace

Post by Radu »

Hi,

We released Oxygen 21.1 and it should allow specifying multiple Javascript module files in the plugin.xml like:

Code: Select all

 <extension type="WorkspaceAccessJS" href="wsAccess.js"/>
 <extension type="WorkspaceAccessJSModule" href="wsAccessModule1.js"/>
 <extension type="WorkspaceAccessJSModule" href="wsAccessModule2.js"/>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
jlpoole
Posts: 23
Joined: Sun Jan 15, 2017 3:15 pm
Location: Salem, Oregon

Re: Plugin Namespace

Post by jlpoole »

Hurrah! Thank you. Installing 21.1 and testing ho!
Post Reply