001    /*
002     *  Copyright 2009-2013 Stephen Colebourne
003     *
004     *  Licensed under the Apache License, Version 2.0 (the "License");
005     *  you may not use this file except in compliance with the License.
006     *  You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     *  Unless required by applicable law or agreed to in writing, software
011     *  distributed under the License is distributed on an "AS IS" BASIS,
012     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     *  See the License for the specific language governing permissions and
014     *  limitations under the License.
015     */
016    package org.joda.money.format;
017    
018    import java.io.IOException;
019    
020    import org.joda.money.BigMoney;
021    
022    /**
023     * Prints part of a monetary value to the output appendable.
024     * <p>
025     * The printer may print any part, or the whole, of the input {@link BigMoney}.
026     * Typically, a complete print is constructed from a number of smaller printers
027     * that have been combined using {@link MoneyFormatterBuilder}.
028     * <p>
029     * This interface must be implemented with care to ensure other classes operate correctly.
030     * All instantiable implementations must be thread-safe, and should generally
031     * be final and immutable.
032     */
033    public interface MoneyPrinter {
034    
035        /**
036         * Prints part of a monetary value to the output appendable.
037         * <p>
038         * The implementation determines what to append, which may be some or all
039         * of the data held in the {@code BigMoney}.
040         * <p>
041         * The context is not a thread-safe object and a new instance will be created
042         * for each print. The context must not be stored in an instance variable
043         * or shared with any other threads.
044         * 
045         * @param context  the context being used, not null
046         * @param appendable  the appendable to add to, not null
047         * @param money  the money to print, not null
048         * @throws MoneyFormatException if there is a problem while printing
049         * @throws IOException if an IO exception occurs
050         */
051        void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException;
052    
053    }