views:

38

answers:

1

Hello, I am trying to call a constructor for a custom collection object. This custom object takes in a parameter of type Class.

In java, this is done like this:

ICollection col = new PersistentCollection(ContentX.class);

This is my first dive into rhino, and I haven't been able to figure out quite how to pass this parameter. I figured out that "class" is a reserved word and therefor not usable.

I figured that I could get the Class from Class.forName like this:

importPackage(Packages.something.collections);
importPackage(Packages.something.content4);
var col = new PersistentCollection(Class.forName(ContentX));

But it just tosses ClassNotFoundException - with the fully qualified path something.content4.ContentX! So obviously it found the class or it wouldn't have known the path to it.

Am I doing it wrong? Sadly, I'm not in any position to change the java library right now, I need to fix the data without a new deploy.

Googling for javascript class just yields DOM/CSS problems.

+1  A: 

I think you simply need to do:

var col = new PersistentCollection(ContentX);

Or, if your class name is a string:

var col = new PersistentCollection(
        java.lang.Class.forName('something.content4.ContentX'));
Maurice Perry
Haha, you are indeed correct with this:var col = new PersistentCollection(ContentX);Sometimes I amaze even myself.. at how dumb I am on weekends.
Jörgen