FileDocCategorySizeDatePackage
CDReleaseImportExport.javaAPI DocExample1846Thu Oct 13 12:12:28 BST 2005com.samscdrental.importexport

CDReleaseImportExport

public class CDReleaseImportExport 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_TITLE
private static final String
ERROR_CDRELEASE_TOKEN_COUNT
Constructors Summary
Methods Summary
public static CDReleaseparseLine(java.lang.String line)
parseLine

param
aString String

		// The line is expected to be in <UPCCode><categoryid> <title>

		String[] tokens = line.split( "\\|" );
		if ( tokens.length < 3 )
		{
			throw new ParseLineDeviation( ERROR_CDRELEASE_TOKEN_COUNT +
										  tokens.length );
		}

		String upcCodeString = tokens[0];
		String categoryIDString = tokens[1];
		String titleString = tokens[2];

		try
		{
			UPCCode aUPCCode = UPCCode.parseString( upcCodeString );

			CDCategory aCDCategory = CDCategory.parseString( categoryIDString );

			if ( titleString.length() < 1 )

			{
				throw new ParseLineDeviation( ERROR_TITLE + line );
			}
			Name aTitle = Name.parseString( titleString );
			return new CDRelease( aCDCategory, aTitle, aUPCCode );
		}

		catch ( CDCategoryFormatDeviation e )
		{
			throw new ParseLineDeviation( e.getMessage()
										  + categoryIDString );
		}
		catch ( UPCCodeFormatDeviation e )
		{
			throw new ParseLineDeviation( e.getMessage()
										  + upcCodeString );
		}
		catch ( NameFormatDeviation e )
		{
			throw new ParseLineDeviation( e.getMessage()
										  + titleString );
		}