BundleUtil Abstract Extension Question

I have a feeling I know the answer, but I want to see what the experts think.

I have a lot of different Script Modules that get loaded into my module and I will have others to add.

Based on what I originally was learning how the scripting modules worked the SDK example included the BundleUtil section in the static{}

    static {
        BundleUtil.get().addBundle(
                myScriptModule.class.getSimpleName(),
                myScriptModule.class.getClassLoader(),
                myScriptModule.class.getName().replace('.', '/'));
    }

Initially I thought I would make an abstract class to house the Bundle section so I could not have to have the same code in every script module class.

abstract class
public abstract class ScriptModule {

    public ScriptModule () {
        
        BundleUtil.get().addBundle(
                this.getClass().getSimpleName(),
                this.getClass().getClassLoader(),
                this.getClass().getName().replace('.', '/'));
    }

}

I think this causes a problem since it would attempt to addBundle every time the class is created which makes sense based on it being in the constructor and not static.

Any ideas on making the code cleaner or should I just roll with the punches and just have the code be in each class?

I could also be going about this all wrong, so guidance is much appreciated.

I create a single Meta class in my common-scope section of the module that loads a single bundle at hook setup/startup. The bundle carries all content for the property files doc provider. (Triggered by the appropriate annotations.)

3 Likes

To Phil's point: Our examples (and internal code, for the most part) use a single properties file per script module, but there's nothing in the rules that says a dog can't play basketball you can't have multiple script modules in one properties file.

1 Like

Same here.

2 Likes