eclipse-ee4j / jaxb-fi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add support to read the vocabulary after a file has been parsed

Tomas-Kraus opened this issue · comments

It would be really helpful to be able to read the vocabulary of a parsed file, as a Fast Infoset file could be exchanged to share an external vocabulary. Unfortunately, there isn't an API to read the vocabulary. Additionally, the vocabulary object returned needs to be an instance of org.jvnet.fastinfoset.Vocabulary so that the returned vocabulary can be later used to initialize an ExternalVocabulary object.

There are probably a few different techniques that could be taken here. For example, we could just subclass SAXDocumentParser and add a new method that analyses the _v ParserVocabulary member variable and returns an instance of org.jvnet.fastinfoset.Vocabulary. Another approach was to just add a getVocabulary method to the Decoder class, which ensures that all classes that inherit off of Decoder have the getVocabulary() method. That's the approach we took. I'll post a patch shortly.

Also, sorry for copy & pasting code inline, as attachments aren't allowed. If you'd prefer me to send something directly, or post a dropbox link, just let me know.

@glassfishrobot Commented
Reported by khiggins

@glassfishrobot Commented
khiggins said:
Here's the method we added to the Decoder class:

public org.jvnet.fastinfoset.Vocabulary getInitialVocabulary() {
org.jvnet.fastinfoset.Vocabulary tempVocab = new org.jvnet.fastinfoset.Vocabulary();

//copy over the restricted alphabets
int size = _v.restrictedAlphabet.getSize();
int counter = 0;

for (counter = 0; counter < size; counter++)

{ com.sun.xml.fastinfoset.util.CharArray tempArray = _v.restrictedAlphabet.get(counter); tempVocab.restrictedAlphabets.add(tempArray.toString()); }

//copy over the encoding-algorithms
size = _v.encodingAlgorithm.getSize();
for (counter = 0; counter < size; counter++)

{ tempVocab.restrictedAlphabets.add(_v.encodingAlgorithm.get(counter)); }

size = _v.prefix.getSize();
for (counter = 0; counter < size; counter++)

{ tempVocab.prefixes.add(_v.prefix.get(counter)); }

//copy over the namespace-names
size = _v.namespaceName.getSize();
for (counter = 0; counter < size; counter++)

{ tempVocab.namespaceNames.add(_v.namespaceName.get(counter)); }

//copy over the local-names
size = _v.localName.getSize();
for (counter = 0; counter < size; counter++)

{ tempVocab.localNames.add(_v.localName.get(counter)); }

//copy over the other-ncnames
size = _v.otherNCName.getSize();
for (counter = 0; counter < size; counter++)

{ tempVocab.otherNCNames.add(_v.otherNCName.get(counter)); }

//copy over the other-uris
size = _v.otherURI.getSize();
for (counter = 0; counter < size; counter++)

{ tempVocab.otherURIs.add(_v.otherURI.get(counter)); }

//copy over the attribute-values
size = _v.attributeValue.getSize();
for (counter = 0; counter < size; counter++)

{ tempVocab.attributeValues.add(_v.attributeValue.get(counter)); }

//copy over the content-character-chunks
size = _v.characterContentChunk.getSize();
for (counter = 0; counter < size; counter++)

{ tempVocab.characterContentChunks.add(_v.characterContentChunk.getString(counter)); }

//copy over the other-strings
size = _v.otherString.getSize();
for (counter = 0; counter < size; counter++)

{ com.sun.xml.fastinfoset.util.CharArray tempArray = _v.otherString.get(counter); tempVocab.otherStrings.add(tempArray.toString()); }

//copy over the element-name-surrogates
size = _v.elementName.getSize();
QualifiedName[] qNameArray = _v.elementName.getCompleteArray();
for (counter = 0; counter < size; counter++)

{ tempVocab.elements.add(qNameArray[counter].getQName()); }

//copy over the attribute-name-surrogates
size = _v.attributeName.getSize();
qNameArray = _v.attributeName.getCompleteArray();
for (counter = 0; counter < size; counter++)

{ tempVocab.attributes.add(qNameArray[counter].getQName()); }

return tempVocab;
}

@glassfishrobot Commented
This issue was imported from java.net JIRA FI-51