net.sourceforge.jbarcodebean.model
Class AbstractBarcodeStrategy

java.lang.Object
  extended by net.sourceforge.jbarcodebean.model.AbstractBarcodeStrategy
All Implemented Interfaces:
BarcodeStrategy
Direct Known Subclasses:
BaseCode39, Codabar, Code11, Code128, Code93, Ean13, Interleaved25, MSI

public abstract class AbstractBarcodeStrategy
extends java.lang.Object
implements BarcodeStrategy

This abstract class, which implements the BarcodeStrategy interface, provides a basic implementation that is subclassed by all the concrete classes that provide Code39, Interleaved Code25, Codabar, MSI and all derivative encoding strategies.


Nested Class Summary
static class AbstractBarcodeStrategy.CharacterCode
          Inner class representing a character and its barcode encoding.
 
Field Summary
 
Fields inherited from interface net.sourceforge.jbarcodebean.model.BarcodeStrategy
MANDATORY_CHECKSUM, NO_CHECKSUM, OPTIONAL_CHECKSUM
 
Constructor Summary
AbstractBarcodeStrategy()
           
 
Method Summary
protected abstract  java.lang.String augmentWithChecksum(java.lang.String text)
          Subclasses implement this method to calculate the checksum from the text to encode, and return a String containing the text with the checksum included.
protected  int computeSize(java.lang.String text)
          Computes the length of the barcode (in bar/space modules) based on the text to encode.
 EncodedBarcode encode(java.lang.String textToEncode, boolean checked)
          This implementation carries out the following steps: Call preprocess(java.lang.String) Call augmentWithChecksum(java.lang.String) to add in the checksum Call postprocess(java.lang.String) Adds in the start and end sentinels Use the CharacterCode array returned by getCodes to encode the text into a barcode Insert left and right margins Return EncodedBarcode object
protected abstract  java.lang.String getBarcodeLabelText(java.lang.String text)
          Subclasses implement this method to return the text which appears below the barcode.
protected  AbstractBarcodeStrategy.CharacterCode getCharacterCode(char character)
          Looks for the specified character to encode in the CharacterCode array returned by the getCodes() method.
protected  AbstractBarcodeStrategy.CharacterCode getCharacterCode(int check)
          Looks for an entry in the CharacterCode array returned by the getCodes() method, by its check attribute.
protected abstract  AbstractBarcodeStrategy.CharacterCode[] getCodes()
          Subclasses implement this method to return an array of CharacterCode objects, representing all possible encodings of bars and spaces for every encodable character.
protected abstract  byte getMarginWidth()
          Sublclasses implement this method to return the width of the whitespace that must appear on each side of the barcode.
protected abstract  char getStartSentinel()
          Subclasses implement this method to return the start sentinel character.
protected abstract  char getStopSentinel()
          Subclasses implement this method to return the stop sentinel character.
protected abstract  boolean isInterleaved()
          Subclasses must implement this method to return true or false depending on whether the barcode type is interleaved.
protected abstract  java.lang.String postprocess(java.lang.String text)
          Subclasses implement this method to perform any postprocessing required to the text after including the checksum.
protected abstract  java.lang.String preprocess(java.lang.String text)
          Subclasses implement this method to perform any preprocessing necessary on the original text to encode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.jbarcodebean.model.BarcodeStrategy
requiresChecksum
 

Constructor Detail

AbstractBarcodeStrategy

public AbstractBarcodeStrategy()
Method Detail

getCodes

protected abstract AbstractBarcodeStrategy.CharacterCode[] getCodes()
Subclasses implement this method to return an array of CharacterCode objects, representing all possible encodings of bars and spaces for every encodable character.

Returns:
An array of CharacterCode objects, one for each possible character that can be encoded using this strategy.

augmentWithChecksum

protected abstract java.lang.String augmentWithChecksum(java.lang.String text)
                                                 throws BarcodeException
Subclasses implement this method to calculate the checksum from the text to encode, and return a String containing the text with the checksum included.

Parameters:
text - The text to encode (after preprocessing - see preprocess(java.lang.String)).
Returns:
A String containing the text passed into the method, augmented with the checksum. For barcode types that don't support a checksum, this would simply be the text passed to the method.
Throws:
BarcodeException

preprocess

protected abstract java.lang.String preprocess(java.lang.String text)
                                        throws BarcodeException
Subclasses implement this method to perform any preprocessing necessary on the original text to encode. The result of this method is the string that gets passed to the augmentWithChecksum(java.lang.String) method.

Parameters:
text - The raw text to encode.
Returns:
The string after preprocessing. If no preprocessing is required, the String passed to the method is returned.
Throws:
BarcodeException - Typically caused by passing in a String containing illegal characters (characters that cannot be encoded in this type of barcode).

isInterleaved

protected abstract boolean isInterleaved()
Subclasses must implement this method to return true or false depending on whether the barcode type is interleaved.

Returns:
true if barcode type is interleaved, false if it is not.

getStartSentinel

protected abstract char getStartSentinel()
Subclasses implement this method to return the start sentinel character.

Returns:
The character, which when encoded into bars and spaces, appears on the left edge of every barcode (immediately after the left margin).

getStopSentinel

protected abstract char getStopSentinel()
Subclasses implement this method to return the stop sentinel character.

Returns:
The character, which when encoded into bars and spaces, appears on the right edge of every barcode (just before the right margin).

getMarginWidth

protected abstract byte getMarginWidth()
Sublclasses implement this method to return the width of the whitespace that must appear on each side of the barcode.

Returns:
The space that must appear on the left and right sides of the barcode expressed as a multiple of the narrowest bar width.

getBarcodeLabelText

protected abstract java.lang.String getBarcodeLabelText(java.lang.String text)
Subclasses implement this method to return the text which appears below the barcode.

Parameters:
text - The raw text to encode.
Returns:
A String containing the text that will appear beneath the barcode.

postprocess

protected abstract java.lang.String postprocess(java.lang.String text)
Subclasses implement this method to perform any postprocessing required to the text after including the checksum.

Parameters:
text - String to process (returned by augmentWithChecksum(java.lang.String)).
Returns:
String after postprocessing. If no postprocessing is required, the String passed to the method is returned.

encode

public EncodedBarcode encode(java.lang.String textToEncode,
                             boolean checked)
                      throws BarcodeException
This implementation carries out the following steps:

Specified by:
encode in interface BarcodeStrategy
Parameters:
textToEncode - The raw text to encode.
checked - True if a checksum is to be calculated, False if not.
Returns:
The fully encoded barcode, represented as bars and spaces, wrapped in a EncodedBarcode object.
Throws:
BarcodeException - Typically caused by passing in a String containing illegal characters (characters that cannot be encoded in this type of barcode).

computeSize

protected int computeSize(java.lang.String text)
                   throws BarcodeException
Computes the length of the barcode (in bar/space modules) based on the text to encode.

Parameters:
text - The text to encode including any check digit, start and end sentinels.
Returns:
The number of module segments in this barcode (including margins).
Throws:
BarcodeException - Typically occurs if attempting to encode invalid characters.

getCharacterCode

protected AbstractBarcodeStrategy.CharacterCode getCharacterCode(char character)
Looks for the specified character to encode in the CharacterCode array returned by the getCodes() method.

Parameters:
character - The character to encode.
Returns:
CharacterCode The element in the CharacterCode array (returned by getCodes) that corresponds to the character passed to the method.

getCharacterCode

protected AbstractBarcodeStrategy.CharacterCode getCharacterCode(int check)
Looks for an entry in the CharacterCode array returned by the getCodes() method, by its check attribute.

Parameters:
check - The check attribute of the character being sought.
Returns:
CharacterCode The element in the CharacterCode array (returned by getCodes) that corresponds to the character whose check attribute was passed to the method.


Copyright © 2004-2009 The JBarcodeBean project. All Rights Reserved.