|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IdListener
The callback interface for those interested in ids.
An IdMapper may have any number of IdListeners registered. As ids become
associated with objects during parsing, the IdMapper will call idRegistered(Object,
Object)
on all listeners interested in the id.
There is no reason to believe that the IdListener will be informed at the earliest possible time that the id is known, but it will always be informed before the StAX stream has been fully processed.
For example, given an xml document
<?xml version="1.0" ?> <foo> <bar_ref id="0" /> <bar id="0" /> <bar id="1" /> <bar_ref id="1" /> <foo>You can handle normal elements (bar) and reference elements (bar_ref) with
class FooHandler extends StAXContentHandlerBase { private List results = new ArrayList(); public void startElement(..., StAXDelegationContext dctx) { if ("bar".equals(qName)) { dctx.delegate(barHandler); } else if ("bar_ref".equals(qName)) { dctx.delegate(barRefHandler); } } class BarHandler extends StAXContentHandlerBase { private Bar bar; public void startTree(StAXContext ctx) { bar = new Bar(); } public void startElement(..., StAXDelegationContext dctx) { if ("bar".equals(qName)) { // ... IdMapper mapper = dctx.getIdMapper(); mapper.registerItemForId(attrs.getValue("id"), bar); } } public void endElement(...) { if ("bar".equals(qName)) results.add(bar); } } class BarRefHandler extends StAXContentHandlerBase { private Bar bar; public void startElement(..., StAXDelegationContext dctx) { if ("bar".equals(qName)) { final String barRefId = attrs.getValue("id"); IdMapper mapper = dctx.getIdMapper(); mapper.addIdListener(new IdListener() { public void idRegistered(Object id, Object item) { if ((barRefId.equals(id)) && (item instanceof Bar)) { bar = (Bar) item; results.add(bar); } } }); } } } }
Method Summary | |
---|---|
void |
idRegistered(Object id,
Object item)
Notify this listener that the specified id has been associated with the specified item. |
Method Detail |
---|
void idRegistered(Object id, Object item) throws SAXException
id
- the id of the bound objectitem
- the item that has been registered for this id
SAXException
- any SAX exception, possibly wrapping another exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |