Earthly Powers
- All
- Fast Infoset
- General
- Java
- REST
Fast Infoset 1.1: Improvements to API when using External Vocabularies
I bumped up the latest stable version of FastInfoset to 1.1, to reflect changes i made to the org.jvnet.fastinfoset API (in addition to general tidying up and removing some crud) that improves support for external vocabularies.
In a previous blog i presented some code that showed how to create and utilize external vocabularies. This code is a bit messy and also depends on stuff that can potentially change in the future. So in an attempt not to pull the rug from under developers feet i have created some classes in the org.jvnet.fastinfoset package. You can still use the mechanism but i cannot guarantee that it will not change in the future.
As in the previous blog the following code will prepare information from schema and sample documents to generate a vocabulary:
String args[] = ... // e.g. args from mainOnce all information has been generated and sorted a Vocabulary instance can be obtained from the FrequenceHandler:
// Process the schema
SchemaProcessor sp = new SchemaProcessor(
new File(args[0]).toURL(), true);
sp.process();
// Procese the sample documents
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
SAXParser p = spf.newSAXParser();
FrequencyHandler fh = new FrequencyHandler(sp);
for (int i = 1; i < args.length; i++) {
p.parse(new File(args[i]), fh);
}
(Much simpler than before and there is no need to specify an API for which the vocabulary is intended for).
Vocabulary v = fh.getVocabulary();
String externalVocabularyURI = args[0];
Next the vocabulary can be set on the SAX serializer as an external vocabulary:
(Note that FastInfosetWriter interface is being used. I would encourage developers when they instantiate concrete instances of Fast Infoset parsers/serializers that they use the appropriate API interfaces where possible so to minimize possible change if upgrading).
ExternalVocabulary ev = new ExternalVocabulary(
externalVocabularyURI,
v);
FastInfosetWriter writer =
new SAXDocumentSerializer();
writer.setExternalVocabulary(ev);
Then the external vocabulary can be set on the SAX parser:
Hopefully you will agree that this is a improvement!
FastInfosetReader reader = new SAXDocumentParser();
Map externalVocabularyMap = new HashMap();
externalVocabularyMap.put(externalVocabularyURI,
ev);
reader.setExternalVocabularies(externalVocabularyMap);
Posted at 10:28AM Jun 02, 2006 by Paul Sandoz in Fast Infoset | Comments[1]
Hi,
This is interesting to me but the code sample seems to be out of date, or I am missing something. Is there an update for fast infoset 1.2?
Posted by Mike on October 31, 2008 at 07:52 PM CET #