001 package org.vmdb.hl7;
002
003 /**
004 * <p><Title:> Generic HL7 Object Abstract Base Class. </p>
005 * <p>Description: Network Connectivity For VMDB. </p>
006 * <p>Copyright: Copyright (c) 2002-2003. </p>
007 * <p>Company: Veterinary Medical Database (VMDB). </p>
008 * <p>This provides a generic interface supported by all HL7 objects as well
009 * as providing some general implementation.</p>
010 * @author Michael K. Martin
011 * @version 1.0
012 */
013
014 public abstract class HL7Object {
015 static final int FIELD_SEP = 0;
016 static final int COMP_SEP = 1;
017 static final int REP_SEP = 2;
018 static final int ESC_SEP = 3;
019 static final int SUB_SEP = 4;
020 protected String sName;
021 protected String sSeparators = "|^~\\&";
022 protected String sRule = "*";
023
024 public HL7Object() {
025 }
026
027 void setName( String sName ) {
028 this.sName = sName;
029 }
030
031 String getName() { return sName; }
032
033 void setRule( String sRule ) {
034 this.sRule = sRule;
035 }
036
037 void setSeparators( String sSeparators ) {
038 this.sSeparators = sSeparators;
039 }
040
041 String getSeparators() { return sSeparators; }
042 char getSeparator( int i ) {
043 if( sSeparators == null || i > sSeparators.length() ) return ' ';
044 return sSeparators.charAt(i);
045 }
046
047 /**
048 * Output the rule string for this object.<br><br>
049 * This follows generally the HL7 convention of using [] for optionality
050 * and {} for repeatablility. Whitespace separates sequential non-repeating
051 * required elements.
052 * @return Rule as a string.
053 */
054 public String getRule() { return sRule; }
055
056 /**
057 * Output the object as XML.<br><br>
058 * For HL7Message, this will be a full message. For all other objects it
059 * will be the DOM element for that object and all its contained objects.
060 * @param iDepth int value for the number of spaces to indent this object. Used just
061 * to make the XML easier to read as unformatted text.
062 * @return foratted XML text.
063 */
064 public String toXML( int iDepth ) {
065 StringBuffer sb = new StringBuffer();
066 for( int x = 0; x < iDepth; x++ ) sb.append( " " );
067 sb.append( '<' );
068 sb.append( getName() );
069 sb.append( '>' );
070 sb.append( toString() );
071 sb.append( '<' );
072 sb.append( '/' );
073 sb.append( getName() );
074 sb.append( '>' );
075 return sb.toString();
076 }
077
078 }// End class HL7Object