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 main
// 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);
}
Once all information has been generated and sorted a Vocabulary instance can be obtained from the FrequenceHandler:

Vocabulary v = fh.getVocabulary();
String externalVocabularyURI = args[0];

(Much simpler than before and there is no need to specify an API for which the vocabulary is intended for).

Next the vocabulary can be set on the SAX serializer as an external vocabulary:

ExternalVocabulary ev = new ExternalVocabulary(
externalVocabularyURI,
v);
  FastInfosetWriter writer =
new SAXDocumentSerializer();
  writer.setExternalVocabulary(ev);

(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).

Then the external vocabulary can be set on the SAX parser:

  FastInfosetReader reader = new SAXDocumentParser();
  Map externalVocabularyMap = new HashMap();
  externalVocabularyMap.put(externalVocabularyURI,
      ev);
  reader.setExternalVocabularies(externalVocabularyMap);

Hopefully you will agree that this is a improvement!
Comments:

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 12:52 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

sandoz

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today