Constants in Plugin

Hi, I am trying to include some constants in my plugin. I tried the following steps but still, I couldn’t see my constants in Servoy IDE.

  1. Implement IConstantsObject in client plugin
  2. Add final static int and String variable in client plugin

Did I miss out a step on how to place a static constant in a plugin?

Hi Erikd,

have you seen any top level node plugin with constants? nope? This doesn’t work.
You need to return a new object implementing IConstantsObject and return it in the getAllReturnedTypes() method of your IScriptObject.

Thanks for this. I can see the constants already. Adding an instance in getAllReturnedTypes did the trick.

Here a-noob-question comes!!
Entering the Patrick’s nightmare! :D

I have to return into the getAllReturnedTypes some compiled classes that in total have 300/400 constant.
If I return them directly into the getAllReturnedTypes nothing appears (because they don’t implement IConstantsObject I suppose), all the other class in wich I need only property and functions are returned as they are (by using the reflection I suppose).

Can someone suggest me a way to don’t rebuild one by one all the constants?
I’ve tried to implements or extends these classes but without results, eclipse tell me that these classes can’t be resolved as a type (and they aren’t abstract so no implements).

Thanks in advance!

Marco

Marco R.:
I have to return into the getAllReturnedTypes some compiled classes that in total have 300/400 constant.
If I return them directly into the getAllReturnedTypes nothing appears (because they don’t implement IConstantsObject I suppose), all the other class in wich I need only property and functions are returned as they are (by using the reflection I suppose).

All you can do is subclass this class and in the subclass implements IConstantsObject.
That being said, here’s my 2 cents:

You should think of wrapping only the functions and objects you really need into JavaScript and Servoy aware classes.
JavaScript is not Java and returning plain Java classes to be used as-is in Servoy is a very bad idea IMHO.
Also there is an overhead in using Reflection, so if you really need Java object, you might as well script it directly using the Packages.xxx.xxx notation in Servoy.

As to wrapping 300/400 constants, try to think whether you will really need them in Servoy? Seems mad to me, and I wouldn’t like to have to deal with a 400 constants object in Servoy, really.
Better create an object that will do useful things than throwing a huge amount of constants to the user in Servoy.

Try do DESIGN your plugin instead of just returning Java classes.

I’m agree Patrick, I’ll keep this all in mind!

I’ve done some smart wrapping, the problem is that the third part will use the plugin, doesn’t know exactly what methods/properties and constants he needs to cover all the cases.
I wouldn’t have to reopen the project each time that a new methods/properties/constants is needed. This plugin wrap a driver that follow the Jpos standard to use the fiscal printer.

However I’ll try to make a collection of needed-constants as you have suggest me :)

Thanks Patrick!

Marco