001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: Hl7Parser.java 6084 2007-03-19 18:38:23Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.parser.impl;
025:
026: import java.io.File;
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029:
030: import com.bostechcorp.cbesb.runtime.parser.ParserException;
031:
032: public class Hl7Parser extends VariantParser {
033:
034: private static final Log log = LogFactory.getLog(Hl7Parser.class);
035:
036: /* (non-Javadoc)
037: * @see com.bostechcorp.cbesb.runtime.parser.impl.VariantParser#getFsmClassName(java.lang.String)
038: */
039: @Override
040: protected String getFsmClassName(String messageName) {
041: String retVal;
042: if (getVariant() == null || getVariant().equals(""))
043: retVal = "com.bostechcorp.cbesb.fsmparser.hl7."
044: + getVersion() + "." + "messages." + messageName
045: + "." + messageName + "." + messageName;
046: else {
047: retVal = "com.bostechcorp.cbesb.fsmparser."
048: + getProjectName().replace(File.separatorChar, '.')
049: + ".hl7." + getVersion() + "." + getVariant()
050: + ".messages." + messageName + "." + messageName
051: + "." + messageName;
052: }
053: return retVal;
054: }
055:
056: /* (non-Javadoc)
057: * @see com.bostechcorp.cbesb.runtime.parser.impl.VariantParser#preProcessMessage(java.lang.StringBuffer)
058: */
059: @Override
060: protected void preProcessMessage(StringBuffer msgData)
061: throws ParserException {
062: char fieldSeparator;
063: char componentSeparator;
064: char subComponentSeparator;
065: char repetitionSeparator;
066: char escapeChar;
067:
068: String msh = msgData.substring(0, 3);
069: if (!"MSH".equals(msh)) {
070: throw new ParserException(
071: "HL7 parser expected \"MSH\", got \"" + msh + "\"");
072: }
073:
074: fieldSeparator = msgData.charAt(3);
075: componentSeparator = msgData.charAt(4);
076: repetitionSeparator = msgData.charAt(5);
077: escapeChar = msgData.charAt(6);
078: subComponentSeparator = msgData.charAt(7);
079:
080: //Escape the special chars in the MSH segment so the parser
081: // doesn't interpret them
082: msgData.insert(7, escapeChar);
083: msgData.insert(6, escapeChar);
084: msgData.insert(5, escapeChar);
085: msgData.insert(3, String.valueOf(fieldSeparator)
086: + String.valueOf(escapeChar)
087: + String.valueOf(fieldSeparator));
088:
089: //Override the special characters in the message definition
090: overrideMsgDefProperty("FieldSeparator", String
091: .valueOf(fieldSeparator));
092: overrideMsgDefProperty("ComponentSeparator", String
093: .valueOf(componentSeparator));
094: overrideMsgDefProperty("SubcomponentSeparator", String
095: .valueOf(subComponentSeparator));
096: overrideMsgDefProperty("RepetitionSeparator", String
097: .valueOf(repetitionSeparator));
098: overrideMsgDefProperty("EscapeCharacter", String
099: .valueOf(escapeChar));
100: }
101:
102: }
|