[Biojava-dev] help with ids in stax
Matthew Pocock
matthew_pocock@yahoo.co.uk
Wed, 18 Sep 2002 23:49:36 +0100
Hi Michael,
So - the handlers for the protein elements would call
IDMapper.registerItemForID(id, value) using the id/name pairs (or
whatever), and the protein_ref elements would call the
IDMapper.addIDListener(IDListener listener, Object id) with a listener.
If/when an id matching the one the listener is registered for (or if it
has been registered already) then the IDListener will have it's callback
method invoked and you can sure up all of thsoe dangling references.
Oh, nearly forgot, StAXContext has a method getIDMapper() and the
context objects are passed around for most callback methods, and
startElement gets a StAXDelegationContext which extends StAXContext.
If the id has already be resolved, then the callback will be called
during registering the listener e.g. within the invocation of
addIDListener. If the id is not yet resolved, then it will be invoked
during the invocation of the appropreate registerItemForID.
e.g.
public void startElement(...
Attributes attrs,
StAXContext ctxt)
throws SAXException {
IDMapper mapper = ctxt.getIDMapper();
mapper.registerItemForID(attrs.getValue("id"),
attrs.getValue("name"));
}
and:
public void startElement(...
Attributes attrs,
StAXContext ctxt)
throws SAXException {
IDMapper mapper = ctxt.getIDMapper();
mapper.addListener(attrs.getValue("id"), new IDListener() {
public void idRegistered(Object id, Object item)
throws SAXException {
// do the stuff we need to do once we have resolved the id
}
});
}
Does that help at all?
Matthew
Michael L. Heuer wrote:
> Hello Matthew,
>
> I just took a look at the updates to the stax project on sourceforge -- I
> like the changes, especially the DispatchOnChild and DispatchOnElement
> helper classes. Nice work.
>
> I can't quite figure out how to use the ID mapping feature, however.
>
> Consider this example
>
> <result>
>
> <protein id="0" name="protein0" />
> <protein id="1" name="protein1" />
>
> <similarity score="1E-50">
> <protein_ref id="0" />
> <protein_ref id="1" />
> </similarity>
> </result>
>
> Could you or Thomas provide a quick solution to this example, or instead
> point me to some existing code that uses the new ID mapping feature?
>
> Thank you in advance,
>
> michael
>
> _______________________________________________
> biojava-dev mailing list
> biojava-dev@biojava.org
> http://biojava.org/mailman/listinfo/biojava-dev
>
--
BioJava Consulting LTD - Support and training for BioJava
http://www.biojava.co.uk