public synchronized XMLParser getXMLParser() { if (xmlParser == null) { xmlParser = new DefaultXMLParser(this); } return xmlParser; }
/** * {@inheritDoc} */ @Override public void parse(Message theMessage, String theString) throws HL7Exception { Document doc = parseStringIntoDocument(theString); parse(theMessage, doc.getDocumentElement()); applySuperStructureName(theMessage); }
/** * <p>Creates and populates a Message object from an XML Document that contains an XML-encoded HL7 message.</p> * <p>The easiest way to implement this method for a particular message structure is as follows: * <ol><li>Create an instance of the Message type you are going to handle with your subclass * of XMLParser</li> * <li>Go through the given Document and find the Elements that represent the top level of * each message segment. </li> * <li>For each of these segments, call <code>parse(Segment segmentObject, Element segmentElement)</code>, * providing the appropriate Segment from your Message object, and the corresponding Element.</li></ol> * At the end of this process, your Message object should be populated with data from the XML * Document.</p> * @throws HL7Exception if the message is not correctly formatted. * @throws EncodingNotSupportedException if the message encoded * is not supported by this parser. */ public Message parseDocument(Document xmlMessage, String version) throws HL7Exception { assertNamespaceURI(xmlMessage.getDocumentElement().getNamespaceURI()); Message message = instantiateMessage(xmlMessage.getDocumentElement().getLocalName(), version, true); // Note: this will change in future to reuse the Parser's/HapiContext's // ValidationContext. // message.setValidationContext(getValidationContext()); parse(message, xmlMessage.getDocumentElement()); return message; }
private void parseReps(Element groupElement, Group groupObject, String messageName, String childName, String childIndexName) throws HL7Exception { String groupName = makeGroupElementName(messageName, childName); List<Element> reps = getChildElementsByTagName(groupElement, groupName); log.trace("# of elements matching {}: {}", groupName, reps.size()); parseRep(reps.get(i), groupObject.get(childIndexName, i)); parseRep(reps.get(0), groupObject.get(childIndexName, 0)); newIndexName = childName+(i+1); Structure st = groupObject.get(newIndexName); parseRep(reps.get(i), st); newIndexName = groupObject.addNonstandardSegment(childName); for (int j = i; j < reps.size(); j++) { parseRep(reps.get(j), groupObject.get(newIndexName, j-i));
String name = node.getLocalName(); if (node.getNodeType() == Node.ELEMENT_NODE && !unparsedElementList.contains(name)) { assertNamespaceURI(node.getNamespaceURI()); unparsedElementList.add(name); String childName = nextChildName; if(groupObject.isGroup(nextChildName)) { childName = makeGroupElementName(groupObject.getMessage().getName(), nextChildName); log.trace("Skipping rep segment: {}", nextChildName); } else { parseReps(groupElement, groupObject, messageName, nextChildName, nextChildName); parseReps(groupElement, groupObject, messageName, segName, segIndexName);
Structure[] reps = groupObject.getAll(name); for (Structure rep : reps) { String elementName = makeGroupElementName(messageName, name); Element childElement; try { encode((Group) rep, childElement); encode((Segment) rep, childElement);
private List<Element> getChildElementsByTagName(Element theElement, String theName) throws HL7Exception { List<Element> result = new ArrayList<Element>(10); NodeList children = theElement.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE && child.getLocalName().equals(theName)) { assertNamespaceURI(child.getNamespaceURI()); result.add((Element)child); } } return result; }
/** * <p>Creates an XML Document that corresponds to the given Message object. </p> * <p>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 * <code>encode(Segment segmentObject, Element segmentElement)</code> using the Element for * that segment and the corresponding Segment object from the given Message.</p> */ public Document encodeDocument(Message source) throws HL7Exception { String messageClassName = source.getClass().getName(); String messageName = messageClassName.substring(messageClassName.lastIndexOf('.') + 1); try { Document doc = XMLUtils.emptyDocument(messageName); //Element root = doc.createElement(messageName); //doc.appendChild(root); encode(source, doc.getDocumentElement()); return doc; } catch (Exception e) { throw new HL7Exception( "Can't create XML document - " + e.getClass().getName(), e); } }
private void parseReps(Element groupElement, Group groupObject, String messageName, String childName, String childIndexName) throws HL7Exception { String groupName = makeGroupElementName(messageName, childName); List<Element> reps = getChildElementsByTagName(groupElement, groupName); log.trace("# of elements matching {}: {}", groupName, reps.size()); parseRep(reps.get(i), groupObject.get(childIndexName, i)); parseRep(reps.get(0), groupObject.get(childIndexName, 0)); newIndexName = childName+(i+1); Structure st = groupObject.get(newIndexName); parseRep(reps.get(i), st); newIndexName = groupObject.addNonstandardSegment(childName); for (int j = i; j < reps.size(); j++) { parseRep(reps.get(j), groupObject.get(newIndexName, j-i));
String name = node.getLocalName(); if (node.getNodeType() == Node.ELEMENT_NODE && !unparsedElementList.contains(name)) { assertNamespaceURI(node.getNamespaceURI()); unparsedElementList.add(name); String childName = nextChildName; if(groupObject.isGroup(nextChildName)) { childName = makeGroupElementName(groupObject.getMessage().getName(), nextChildName); log.trace("Skipping rep segment: {}", nextChildName); } else { parseReps(groupElement, groupObject, messageName, nextChildName, nextChildName); parseReps(groupElement, groupObject, messageName, segName, segIndexName);
Structure[] reps = groupObject.getAll(name); for (Structure rep : reps) { String elementName = makeGroupElementName(messageName, name); Element childElement; try { encode((Group) rep, childElement); encode((Segment) rep, childElement);
private List<Element> getChildElementsByTagName(Element theElement, String theName) throws HL7Exception { List<Element> result = new ArrayList<Element>(10); NodeList children = theElement.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE && child.getLocalName().equals(theName)) { assertNamespaceURI(child.getNamespaceURI()); result.add((Element)child); } } return result; }
/** * <p>Creates an XML Document that corresponds to the given Message object. </p> * <p>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 * <code>encode(Segment segmentObject, Element segmentElement)</code> using the Element for * that segment and the corresponding Segment object from the given Message.</p> */ public Document encodeDocument(Message source) throws HL7Exception { String messageClassName = source.getClass().getName(); String messageName = messageClassName.substring(messageClassName.lastIndexOf('.') + 1); try { Document doc = XMLUtils.emptyDocument(messageName); //Element root = doc.createElement(messageName); //doc.appendChild(root); encode(source, doc.getDocumentElement()); return doc; } catch (Exception e) { throw new HL7Exception( "Can't create XML document - " + e.getClass().getName(), e); } }
public synchronized XMLParser getXMLParser() { if (xmlParser == null) { xmlParser = new DefaultXMLParser(this); } return xmlParser; }
/** * {@inheritDoc} */ @Override public void parse(Message theMessage, String theString) throws HL7Exception { Document doc = parseStringIntoDocument(theString); parse(theMessage, doc.getDocumentElement()); applySuperStructureName(theMessage); }
/** * <p>Creates and populates a Message object from an XML Document that contains an XML-encoded HL7 message.</p> * <p>The easiest way to implement this method for a particular message structure is as follows: * <ol><li>Create an instance of the Message type you are going to handle with your subclass * of XMLParser</li> * <li>Go through the given Document and find the Elements that represent the top level of * each message segment. </li> * <li>For each of these segments, call <code>parse(Segment segmentObject, Element segmentElement)</code>, * providing the appropriate Segment from your Message object, and the corresponding Element.</li></ol> * At the end of this process, your Message object should be populated with data from the XML * Document.</p> * @throws HL7Exception if the message is not correctly formatted. * @throws EncodingNotSupportedException if the message encoded * is not supported by this parser. */ public Message parseDocument(Document xmlMessage, String version) throws HL7Exception { assertNamespaceURI(xmlMessage.getDocumentElement().getNamespaceURI()); Message message = instantiateMessage(xmlMessage.getDocumentElement().getLocalName(), version, true); // Note: this will change in future to reuse the Parser's/HapiContext's // ValidationContext. // message.setValidationContext(getValidationContext()); parse(message, xmlMessage.getDocumentElement()); return message; }
/** * @param context the HapiContext to be used */ public GenericParser(HapiContext context) { super(context); pipeParser = new PipeParser(context); xmlParser = new DefaultXMLParser(context); setPipeParserAsPrimary(); }
/** * Creates a new instance of GenericParser * * @param theFactory custom factory to use for model class lookup */ public GenericParser(ModelClassFactory theFactory) { super(theFactory); pipeParser = new PipeParser(theFactory); xmlParser = new DefaultXMLParser(theFactory); setPipeParserAsPrimary(); }