001    /*******************************************************************************
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     *******************************************************************************/
019    package org.apache.commons.convert;
020    
021    import java.util.Locale;
022    import java.util.TimeZone;
023    
024    /** Localized converter interface. Classes implement this interface
025     * to convert one object type to another. Methods are provided to
026     * localize the conversion.
027     * <p>Localized converters are necessary for things like dates, times, and numbers. Those
028     * conversions are dependent on a locale and/or time zone. Java's default conversions
029     * (<code>toString</code>, <code>valueOf</code>) use the JVM's default locale and
030     * time zone - which might not be what the application requires. Implementations of
031     * <code>LocalizedConverter</code> will use the specified locale and time zone instead of
032     * the JVM defaults.</p>
033     */
034    public interface LocalizedConverter<S, T> extends Converter<S, T> {
035        /** Converts <code>obj</code> to <code>T</code>.
036         *
037         * @param obj The source <code>Object</code> to convert
038         * @param locale The locale used for conversion - must not be <code>null</code>
039         * @param timeZone The time zone used for conversion - must not be <code>null</code>
040         * @return The converted <code>Object</code>
041         * @throws ConversionException
042         */
043        public T convert(S obj, Locale locale, TimeZone timeZone) throws ConversionException;
044    
045        /** Converts <code>obj</code> to <code>T</code>.
046         *
047         * @param obj The source <code>Object</code> to convert
048         * @param locale The locale used for conversion - must not be <code>null</code>
049         * @param timeZone The time zone used for conversion - must not be <code>null</code>
050         * @param formatString Optional formatting string
051         * @return The converted <code>Object</code>
052         * @throws ConversionException
053         */
054        public T convert(S obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException;
055    }