Talk:Builder
(New page: Created the page --~~~~) |
(A link to a Statefule Builder that builds Composites from XML files) |
||
Line 1: | Line 1: | ||
Created the page --[[User:Elliot Fisher|Elliot Fisher]] 23:50, 6 October 2008 (UTC) | Created the page --[[User:Elliot Fisher|Elliot Fisher]] 23:50, 6 October 2008 (UTC) | ||
+ | |||
+ | Thought I might share a link to this "[[http://www.neocoders.com:8080/neocoders/projects/vgl/design-documentation/package-vgldocument-utils|Stateful Builder"]], where a SAX parser drives a Builder that builds a Composite. The Builder implements the State pattern, and is in a particular state for each XML element that it is currently parsing. | ||
+ | |||
+ | Incidentally, for a lot less code, you can also use use a kind of Interpretor pattern to parse an XML file into a Composite; where the Composite is also an Interpretor. You make yourself a SAXParser, then when you get a "startElement" event from it (for the root XML element) you instantiate the root Composite element, passing the parser to the element's constructor. The root Composite element attaches itself as a listener to the parser. For each "startElement" event the root gets, it creates the appropriate child, to which it passes the parser. The children in turn listen to the parser and make appropriate children for each "startElement" event that they hear. Of course, this lumps the loading function into the Composite, which is a little quick-and-dirty. | ||
+ | |||
+ | You can also pass a DOM down into the construction of a Composite in the same way. | ||
+ | |||
+ | [[User:Lindsay|Lindsay Kay]] |
Revision as of 02:26, 7 October 2008
Created the page --Elliot Fisher 23:50, 6 October 2008 (UTC)
Thought I might share a link to this "[Builder"], where a SAX parser drives a Builder that builds a Composite. The Builder implements the State pattern, and is in a particular state for each XML element that it is currently parsing.
Incidentally, for a lot less code, you can also use use a kind of Interpretor pattern to parse an XML file into a Composite; where the Composite is also an Interpretor. You make yourself a SAXParser, then when you get a "startElement" event from it (for the root XML element) you instantiate the root Composite element, passing the parser to the element's constructor. The root Composite element attaches itself as a listener to the parser. For each "startElement" event the root gets, it creates the appropriate child, to which it passes the parser. The children in turn listen to the parser and make appropriate children for each "startElement" event that they hear. Of course, this lumps the loading function into the Composite, which is a little quick-and-dirty.
You can also pass a DOM down into the construction of a Composite in the same way.