New DataCell Methods and Derived Classes


New DataCell Methods and Derived Classes

We can use most of the DataCell classes and methods we developed in the previous chapters. We need only a few new ones in this chapter to satisfy some of the X12 data type formatting requirements. We'll handle the X12 data types as follows .

  • Numeric : We create a DataCellX12N class from the existing DataCellN class. The DataCellX12N class uses the base class's fromXML and toXML methods but has its own prepareOutput method since a minus sign, if present, is not included when considering the length, and we use only a zero for the fill character.

  • Decimal Number : We create a DataCellX12R class from the existing DataCellReal class. Like the DataCallX12N class, this new class uses the base class's toXML method. However, some different processing is required to handle exponential notation in the fromXML and prepareOutput methods. In addition, the length does not include the leading minus sign, the decimal point, or the E exponent indicator, and we use only a zero for the fill character.

  • Identifier and String : These are handled by the existing DataCellAN class. We modify the prepareOutput method a bit to use an ASCII space as the fill character for these two data types. We also do not truncate an Identifier type.

  • Date : We create a new DataCellX12DT class derived from the DataCellDateYYYYMMDD class. The new class's methods call the base class methods. In addition, the new methods append or remove the two most significant digits of the year if the maximum length is six digits.

  • Time : This data type is handled by a new DataCellX12TM class.

DataCellX12N Class (Extends DataCellN)

As noted above, this class is derived from the DataCellN class developed in Chapter 8. It uses base class methods for everything but the prepareOutput method, which handles the formatting requirements of the X12 Numeric data type.

Logic for the DataCellX12N prepareOutput Method
 Arguments:   None Returns:   Status or throws exception NegativeNumber <- false IF first character in Cell Buffer is "-"   Cell Buffer <- Shift Cell Buffer left one character to remove       Minus sign   Negative Number <- true   Decrement Buffer Length ENDIF Minimum Length <- Call Grammar Element's getAttribute for     "MinLength", converting to integer IF (Buffer Length < Minimum Length)   Call justifyFieldRight, passing Minimum Length and zero       as Fill Character ENDIF Maximum Length <- Call Grammar Element's getAttribute for     "MaxLength", converting to integer IF (Buffer Length > Maximum Length)   Return failure ENDIF IF Negative Number = true   Cell Buffer <- Shift Cell Buffer right one character to insert       Minus sign   Increment Buffer Length ENDIF Return success 

DataCellX12R Class (Extends DataCellReal)

As noted above, this class is derived from the DataCellReal class developed in Chapter 8. It uses that class's toXML method but provides its own fromXML and prepareOutput methods.

Logic for the DataCellX12R fromXML Method
 Arguments:   None Returns:   Error status or throws exception Trim Spaces IF Cell Buffer = -0, INF, -INF, or NaN   Return error for unsupported constant in X12 Decimal date type ENDIF Convert to uppercase since XML schema language data types allow     a lower case 'e' to indicate the exponent IF first Character in Cell Buffer = "+"   Cell Buffer <- Shift Cell Buffer left one character to remove       plus sign   Decrement Buffer Length ENDIF Return success 
Logic for the DataCellX12R prepareOutput Method
 Arguments:   None Returns:   Status or throws exception NegativeNumber <- false ExponentialNotation <- false IF first character in Cell Buffer is "-"   Cell Buffer <- Shift Cell Buffer left one character to remove       Minus sign   Negative Number <- true   Decrement Buffer Length ENDIF Minimum Length <- Call Grammar Element's getAttribute for     "MinLength", converting to integer Maximum Length <- Call Grammar Element's getAttribute for     "MaxLength", converting to integer IF Cell Buffer contains "E"   Increment Minimum Length   Increment Maximum Length   Exponential Notation <- true ENDIF IF Cell Buffer contains a decimal point   Increment Minimum Length   Increment Maximum Length ENDIF IF (Buffer Length < Minimum Length)   Call justifyFieldRight, passing Minimum Length and zero       as Fill Character ENDIF IF (Buffer Length > Maximum Length)   Truncate <- Call Grammar Element's getAttribute for       "Truncatable"   IF Truncate = false OR Exponential Notation = true     Return truncation error   ENDIF   Depending on language features, truncate Cell Buffer contents to       specified Length stopping when Length is achieved or       decimal point is truncated   IF (Buffer Length > Maximum Length)     Return failure   ENDIF   Buffer Length <- Maximum Length ENDIF IF Negative Number = true   Cell Buffer <- Shift Cell Buffer right one character to insert       Minus sign   Increment Buffer Length ENDIF Return success 

DataCellX12DT Class (Extends DataCellDateYYYYMMDD)

This class relies heavily on the base class methods. The only thing we really need to deal with is X12's support of a YYMMDD date format. We know we're using that format if the maximum length of the data element is six digits.

Logic for the DataCellX12DT fromXML Method
 Arguments:   None Returns:   Error status or throws exception Call base class fromXML method Maximum Length <- Call Grammar Element's getAttribute for     "MaxLength" IF Maximum Length = "6"   Shift Cell Buffer two characters to the left   Buffer Length <- 6 ENDIF Return success 
Logic for the DataCellX12DT toXML Method
 Arguments:   None Returns:   Error status or throws exception Cell Buffer < trim leading and trailing whitespace from     Cell Buffer IF Buffer Length = 6   Cell Buffer <- "20" + Cell Buffer   Buffer Length <- 8 ENDIF Return call to base class toXML method 

In converting from YYMMDD to YYYYMMDD by adding a prefix of 20, we're making a somewhat arbitrary assumption that any six-digit dates are from the 21st century. I think this is fairly reasonable since, by now, if anyone cares about using 20th-century dates in an X12 transaction set, they most likely are using YYYYMMDD so as not to leave anything to chance.

DataCellX12TM Class

This class handles conversion to and from the X12 Time data type to the schema language time data type based on ISO 8601. The differences in representation are shown earlier in the chapter in Table 9.6.

Logic for the DataCellX12TM fromXML Method
 Arguments:   None Returns:   Error status or throws exception IF Buffer Length < 8   Return error ENDIF Hours <- Cell Buffer characters at offsets 0 and 1 Minutes <- Cell Buffer characters at offsets 3 and 4 Seconds <- Cell Buffer characters at offsets 6 and 7 Fractional Seconds <- Cell Buffer characters 9 and beyond,     if present Cell Buffer <- Hours + Minutes + Seconds + Fractional Seconds Buffer Length <- String length of Cell Buffer Return success 
Logic for the DataCellX12TM toXML Method
 Arguments:   None Returns:   Error status or throws exception Cell Buffer < trim leading and trailing whitespace from     Cell Buffer IF Buffer Length < 4   Return error ENDIF Hours <- Cell Buffer characters at offsets 0 and 1 Minutes <- Cell Buffer characters at offsets 2 and 3 Seconds <- Cell Buffer characters at offsets 4 and 5, if present,     otherwise "00" Fractional Seconds <- Cell Buffer characters 6 and beyond     if present Cell Buffer <- Hours + ":" + Minutes + ":" + Seconds + "."     + Fractional Seconds Buffer Length <- String length of Cell Buffer Return success 

The prepareOutput method truncates the data if required. We will somewhat arbitrarily assume that if the X12 target data element is not large enough to handle seconds or fractions of a second, users will not mind if we discard them.

Logic for the DataCellX12TM prepareOutput Method
 Arguments:   None Returns:   Status or throws exception Maximum Length <- Call Grammar Element's getAttribute for     "MaxLength" IF Buffer Length > Maximum Length   Truncate Cell Buffer from left to Maximum Length   Buffer Length <- Maximum Length Return success 


Using XML with Legacy Business Applications
Using XML with Legacy Business Applications
ISBN: 0321154940
EAN: 2147483647
Year: 2003
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net