ca.uhn.hl7v2.parser
Class DefaultXMLParser

java.lang.Object
  extended by ca.uhn.hl7v2.parser.Parser
      extended by ca.uhn.hl7v2.parser.XMLParser
          extended by ca.uhn.hl7v2.parser.DefaultXMLParser

public class DefaultXMLParser
extends XMLParser

A default XMLParser. This class assigns segment elements (in an XML-encoded message) to Segment objects (in a Message object) using the name of a segment and the names of any groups in which the segment is nested. The names of group classes must correspond to the names of group elements (they must be identical except that a dot in the element name, following the message name, is replaced with an underscore, in order to consitute a valid class name).

At the time of writing, the group names in the XML spec are changing. Many of the group names have been automatically generated based on the group contents. However, these automatic names are gradually being replaced with manually assigned names. This process is expected to be complete by November 2002. As a result, mismatches are likely. Messages could be transformed prior to parsing (using XSLT) as a work-around. Alternatively the group class names could be changed to reflect updates in the XML spec. Ultimately, HAPI group classes will be changed to correspond with the official group names, once these are all assigned.

Author:
Bryan Tripp

Constructor Summary
DefaultXMLParser()
          Creates a new instance of DefaultXMLParser
DefaultXMLParser(ModelClassFactory theFactory)
          Creates a new instance of DefaultXMLParser
 
Method Summary
 org.w3c.dom.Document encodeDocument(Message source)
          Creates an XML Document that corresponds to the given Message object.
static void main(java.lang.String[] args)
          Test harness
protected static java.lang.String makeGroupElementName(java.lang.String messageName, java.lang.String className)
          Given the name of a message and a Group class, returns the corresponding group element name in an XML-encoded message.
 Message parseDocument(org.w3c.dom.Document XMLMessage, java.lang.String version)
          Creates and populates a Message object from an XML Document that contains an XML-encoded HL7 message.
 
Methods inherited from class ca.uhn.hl7v2.parser.XMLParser
doEncode, doEncode, doEncode, doEncode, doParse, encode, getAckID, getCriticalResponseData, getDefaultEncoding, getEncoding, getKeepAsOriginalNodes, getTextEncoding, getVersion, keepAsOriginal, parse, parse, parse, parse, parse, parseLeaf, removeWhitespace, setKeepAsOriginalNodes, setTextEncoding, supportsEncoding
 
Methods inherited from class ca.uhn.hl7v2.parser.Parser
encode, encode, getFactory, getMessageStructureForEvent, getMessageStructures, getValidationContext, getValidVersions, instantiateMessage, makeControlMSH, parse, setValidationContext, validVersion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultXMLParser

public DefaultXMLParser()
Creates a new instance of DefaultXMLParser


DefaultXMLParser

public DefaultXMLParser(ModelClassFactory theFactory)
Creates a new instance of DefaultXMLParser

Parameters:
theFactory - custom factory to use for model class lookup
Method Detail

encodeDocument

public org.w3c.dom.Document encodeDocument(Message source)
                                    throws HL7Exception

Creates an XML Document that corresponds to the given Message object.

If you are implementing this method, you should create an XML Document, and insert XML Elements into it that correspond to the groups and segments that belong to the message type that your subclass of XMLParser supports. Then, for each segment in the message, call the method encode(Segment segmentObject, Element segmentElement) using the Element for that segment and the corresponding Segment object from the given Message.

Specified by:
encodeDocument in class XMLParser
Throws:
HL7Exception

parseDocument

public Message parseDocument(org.w3c.dom.Document XMLMessage,
                             java.lang.String version)
                      throws HL7Exception

Creates and populates a Message object from an XML Document that contains an XML-encoded HL7 message.

The easiest way to implement this method for a particular message structure is as follows:

  1. Create an instance of the Message type you are going to handle with your subclass of XMLParser
  2. Go through the given Document and find the Elements that represent the top level of each message segment.
  3. For each of these segments, call parse(Segment segmentObject, Element segmentElement), providing the appropriate Segment from your Message object, and the corresponding Element.
At the end of this process, your Message object should be populated with data from the XML Document.

Specified by:
parseDocument in class XMLParser
Throws:
HL7Exception - if the message is not correctly formatted.
EncodingNotSupportedException - if the message encoded is not supported by this parser.

makeGroupElementName

protected static java.lang.String makeGroupElementName(java.lang.String messageName,
                                                       java.lang.String className)
Given the name of a message and a Group class, returns the corresponding group element name in an XML-encoded message. This is the message name and group name separated by a dot. For example, ADT_A01.INSURANCE. If it looks like a segment name (i.e. has 3 characters), no change is made.


main

public static void main(java.lang.String[] args)
Test harness



Copyright © 2001-2011 University Health Network. All Rights Reserved.