FileDocCategorySizeDatePackage
CustomerImportExport.javaAPI DocExample1616Thu May 05 05:37:36 BST 2005com.samscdrental.importexport

CustomerImportExport

public class CustomerImportExport extends Object

Title: Sams CD Rental Store

Description:

Copyright: Copyright (c) 2004

Company:

author
Ken Pugh
version
1.0

Fields Summary
private static final String
ERROR_NO_NAME
private static final String
ERROR_CUSTOMER_TOKEN_COUNT
Constructors Summary
Methods Summary
public static CustomerparseLine(java.lang.String line)
parseLine

param
aString String

		// The line is expected to be in <customerID> <name> format

		String[] tokens = line.split( "\\|" );
		if ( tokens.length < 2 )
		{
			throw new ParseLineDeviation( ERROR_CUSTOMER_TOKEN_COUNT +
										  tokens.length );
		}
		String customerIDString = tokens[0];
		String customerNameString = tokens[1];
		try
		{
			CustomerID aCustomerID = CustomerID.parseString( customerIDString );
			if ( customerNameString.length() < 1 )
			{
				throw new ParseLineDeviation( ERROR_NO_NAME + line );
			}
			Name aName = Name.parseString( customerNameString );

			return new Customer( aName, aCustomerID );
		}
		catch ( CustomerIDFormatDeviation e )
		{
			throw new ParseLineDeviation( e.getMessage() +
										  customerIDString );
		}
		catch ( NameFormatDeviation e )
		{
			throw new ParseLineDeviation( e.getMessage() +
										  customerNameString );
		}