001/* 002 * Created on 19-Apr-2004 003 */ 004package ca.uhn.hl7v2.protocol.impl; 005 006import java.util.HashMap; 007import java.util.List; 008import java.util.Map; 009 010import ca.uhn.hl7v2.HL7Exception; 011import ca.uhn.hl7v2.model.Message; 012import ca.uhn.hl7v2.util.Terser; 013 014/** 015 * A utility for getting a list of fields from a <code>Message</code>, 016 * e.g. for inclusion in a <code>Transportable</code>. 017 * 018 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a> 019 * @version $Revision: 1.1 $ updated on $Date: 2007-02-19 02:24:26 $ by $Author: jamesagnew $ 020 */ 021public class MetadataExtractor { 022 023 /** 024 * @param theMessage a message from which to extract fields 025 * @param theTerserPaths a list of paths to desired fields, in the 026 * form required by <code>Terser</code>. 027 * @return a Map from Terser paths to field values 028 */ 029 public static Map<String, String> getFields(Message theMessage, List<String> theTerserPaths) throws HL7Exception { 030 Map<String, String> fields = new HashMap<String, String>(); 031 Terser terser = new Terser(theMessage); 032 for (int i = 0; i < theTerserPaths.size(); i++) { 033 String path = theTerserPaths.get(i); 034 String fieldValue = terser.get(path); 035 fields.put(path, fieldValue); 036 } 037 return fields; 038 } 039 040}