View Javadoc

1   /**
2    *  This library is free software; you can redistribute it and/or modify it
3    *  under the terms of the GNU Lesser General Public License (LGPL) as
4    *  published by the Free Software Foundation; either version 3.0 of the
5    *  License, or (at your option) any later version.
6    *
7    *  This library is distributed in the hope that it will be useful, but
8    *  WITHOUT ANY WARRANTY; without even the implied warranty of
9    *  MERCHANTABILITY of FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10   *  Lesser General Public License for more details. 
11   */
12  
13  /**
14   * Title:        JBarcodeBean
15   * Description:  Barcode JavaBeans Component
16   * Copyright:    Copyright (C) 2004
17   * Company:      Dafydd Walters
18   */
19  package net.sourceforge.jbarcodebean.model;
20  
21  import net.sourceforge.jbarcodebean.BarcodeException;
22  import net.sourceforge.jbarcodebean.EncodedBarcode;
23  
24  /**
25   * Interface which defines the barcode strategy for any
26   * given type of barcode.  Classes that implement this interface exist for each
27   * of the barcode types such as Code39, Interleaved25, etc.
28   */
29  public interface BarcodeStrategy {
30  
31    /**
32     * When returned by {@link #requiresChecksum}, indicates that this type of
33     * barcode does not support a checksum.
34     */
35    public static final int NO_CHECKSUM = 0;
36  
37    /**
38     * When returned by {@link #requiresChecksum}, indicates that this type of
39     * barcode always has a checksum.
40     */
41    public static final int MANDATORY_CHECKSUM = 1;
42  
43    /**
44     * When returned by {@link #requiresChecksum}, indicates that this type of
45     * barcode may have an optional checksum.
46     */
47    public static final int OPTIONAL_CHECKSUM = 2;
48  
49    /**
50     * Subclasses implement this method to encode some text into a barcode.
51     *
52     * @param text The raw text to encode.
53     * @param checked <tt>true</tt> if a checksum is to be calculated, <tt>false</tt> if not.
54     *
55     * @return The fully encoded barcode, represented as bars and spaces, wrapped
56     * in a {@link EncodedBarcode} object.
57     *
58     * @throws BarcodeException Typically caused by passing in
59     * a String containing illegal characters (characters that cannot be encoded in
60     * this type of barcode).
61     */
62    public EncodedBarcode encode(String text, boolean checked) throws BarcodeException;
63  
64    /**
65     * Subclasses implement this method to determine whether this type of barcode
66     * has a mandatory, optional or no checksum.  Returns one of the constants
67     * defined in the interface.
68     */
69    public int requiresChecksum();
70  }