Since there has been some continued discussion about it, I want to clarify what 
BXML is and what it is not:

- BXML is an XML-based markup language for simplifying the construction of an 
object hierarchy (often a WTK component hierarchy).

- Unlike some other similar markup langauges (e.g. MXML and XAML), BXML is not 
compiled into a Java class. It is a serialized representation of an object 
hierarchy (though it may optionally include embedded or externally-referenced 
script code).

- BXML is processed using the StAX API defined in the javax.xml.stream pacakge. 
This is a stream-based API that processes XML elements and attributes in the 
order in which they are written. 

- Element and attribute ordering is relevant in BXML:
  - In an element's start tag, the corresponding class is instantiated.
  - As sub-elements are processed, they are either added to the element or 
applied as properties.
  - In the element's end tag, the attributes are applied. This is because 
certain attributes will not make sense until the element has been fully 
constructed.
  - If the element's parent is a sequence, the object is added to the parent.

BXML is simply a shortcut to coding this logic by hand. 

- BXML supports the declaration of page-level variables via the bxml:id 
attribute or in script code. These variables can be dereferenced elsewhere in 
the page using the "$" operator. As in procedural code, variables must be 
declared before they are referenced. The only exception is namespace bindings, 
which are not processed until the entire document has been processed. This is 
because namespace bindings are a shortcut to wiring up event listeners, which 
is generally done after a page has been completely loaded and all required 
variables have been initialized.

- Root elements that implement Bindable will be called to initialize() once the 
BXML document has been completely processed. This allows the Bindable to get 
access to the document's namespace (i.e. page variables), the resources that 
were used to load it, and the location it was loaded from, to perform any 
necessary post-processing (e.g. registering event listeners). Only the root 
element is initialized, because the bindable properties (namespace, resources, 
and location) apply to the document as a whole, not to individual sub-elements.

I'm sure there are lots of other things that BXML could do, but which may come 
at the expense of simplicity and maintainability. The current implementation 
may not address absolutely every use case, but it does address the primary use 
cases quite well. Doing anything else would be over-designing it.

Reply via email to