Hi Ilya,
Well, the answer is yes, but .... If your FinanceWindow.bxml has the
top-level object as a FinanceWindow, then if in the FinanceWindow constructor
you load that bxml file, you will get into an infinite recursion. But, if your
FinanceWindow.bxml has just the content of your window and you create the
top-level Window object some other way (i.e. just do a "new FinanceWindow" in
the startup code as you have it), then you could just read the contents of the
window and set the window's child from the BXML file (which is NOT what you
have in your code), then that should work.
I'm curious why you want to do this? It is pretty much the same code
either way, but if you let the BXMLSerializer create all the objects (including
the top-level window) it is a tiny bit less work in your code. Or is there a
design pattern you're trying to achieve?
HTH,
~Roger
-----Original Message-----
From: Ilya Zimnovich [mailto:[email protected]]
Sent: Monday, March 24, 2014 9:26 AM
To: [email protected]
Subject: Unserialize an object in class constructor
Dear Apache Pivot experts,
All the Apache Pivot examples unserialize an objects with BXMLSerializer's
readObject method:
....
public void startup(Display display, Map<String, String> properties) throws
Exception
{
String language = properties.get("language");
Locale locale = (language == null) ? Locale.getDefault() : new
Locale(language);
Resources resources = new
Resources(FinanceWindow.class.getName(), locale);
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window =
(FinanceWindow)bxmlSerializer.readObject(getClass().getResource("FinanceWindow.bxml"),
resources);
window.open(display);
}
....
Is there a way to unserialize the object in its constructor? I mean something
like the below:
....
public void startup(Display display, Map<String, String> properties) throws
Exception
{
window = new FinanceWindow();
window.open(display);
}
....
public class FinanceWindow extends Frame implements Bindable { ....
public FinanceWindow()
{
BXMLSerializer bxmlSerializer = new BXMLSerializer();
// Load localized resources and unserialize the object
String language = properties.get("language");
Locale locale = (language == null) ? Locale.getDefault() : new
Locale(language);
Resources resources = new Resources(getClass().getName(), locale);
bxmlSerializer.readObjectXXXX(this, "FinanceWindow.bxml");
....
Best Regards,
Ilya A. Zimnovich