Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Object References(Pass values between functions)
Object References [message #1015518] Fri, 01 March 2013 04:05 Go to next message
David Good is currently offline David GoodFriend
Messages: 41
Registered: September 2012
Member
Hi,

I have built a package containing some public classes and loaded the JAR into my report resources. It works as expected by creating an object which stores some information.

I build the object in beforeFactory(), but need to its attributes in other parts of the report. When I reference the object name, BIRT throws an error.

Is it possible to have something like:

beforeFactory()

var fName = some_value;
var newObject = new BuildAnObject();
newObject.setFieldName(fName);

initialize()

var fn = newObject.getFieldName(); //throws an error on newObject


I have simplified my actual situation but the object is being created and the set and get functions are ok. I have tried serialization without success but am not sure how to make an object persistent so that its attributes and methods remain available to other BIRT methods during report generation process. Is it possible?

I know that I can set parameters in beforeFactory() but am trying to do this without creating them manually. They may be able to be created at runtime (?) but I may have many users using the report at the same time so I don't think that that method would work. Creating object instances was my plan.

Thanks very much.

Dave
Re: Object References [message #1015737 is a reply to message #1015518] Sat, 02 March 2013 01:11 Go to previous messageGo to next message
David Good is currently offline David GoodFriend
Messages: 41
Registered: September 2012
Member
HI All,

Having researched this further I can see that initialize executes prior to beforeFactory() in generation phase, so that was part of my problem.

I am trying to serialize the object and can see it written to disk. When the report tries to read it I get a ClassNotFoundException, indicating that the JVM can not find the class. It is part of my resources and the resource folder is part of my machine's class path. Does anyone have any idea why it can not find the class?

Below, the newData object is being created, and I can manually open myobject.ser and see the object attributes.

Why am I getting a java.lang.ClassNotFoundException?

//serialize this object
var f_out = new FileOutputStream("C:\\myobject.ser");
var obj_out = new ObjectOutputStream (f_out);
obj_out.writeObject(newData);
obj_out.close();
f_out.close()

//de-serialize this object
var f_in = new FileInputStream("C:\\myobject.ser");
var obj_in = new ObjectInputStream (f_in);

var newDataObject = obj_in.readObject(); // ********** ERROR at this line
obj_in.close();
f_in.close();
Re: Object References [message #1015871 is a reply to message #1015737] Mon, 04 March 2013 04:32 Go to previous message
David Good is currently offline David GoodFriend
Messages: 41
Registered: September 2012
Member
HI,

I have this resolved using serialization.

I placed both the serializaton and de-serialization group of methods in external JAR files (rather than coding it within the BIRT initialize method) and created objects from BIRT. It appears that the statement "var newDataObject = obj_in.readObject();" is not sufficient in BIRT, the entire package name declaration is required with a type reference, which can not be done (as far as I know - please correct me if I am wrong)

i.e. in my de-serialization class:

FileInputStream f_in = new FileInputStream(sSavedObjectDirRef);
ObjectInputStream obj_in = new ObjectInputStream (f_in);
com.dgi.birt.BuildExternal newData = (com.dgi.birt.BuildExternal) obj_in.readObject();
obj_in.close();


Thanks,
David
Previous Topic:Chart - Ticks alignment
Next Topic:Birt don't start
Goto Forum:
  


Current Time: Fri Apr 26 21:33:14 GMT 2024

Powered by FUDForum. Page generated in 0.02868 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top