001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements. See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache license, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License. You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the license for the specific language governing permissions and
015     * limitations under the license.
016     */
017    package org.apache.logging.log4j.message;
018    
019    import java.util.ResourceBundle;
020    
021    /**
022     * Creates {@link org.apache.logging.log4j.message.LocalizedMessage} instances for
023     * {@link #newMessage(String, Object...)}.
024     *
025     * @version $Id:  $
026     */
027    public class LocalizedMessageFactory extends AbstractMessageFactory {
028    
029        private final ResourceBundle bundle;
030        private final String bundleId;
031    
032        public LocalizedMessageFactory(final ResourceBundle bundle) {
033            this.bundle = bundle;
034            this.bundleId = null;
035        }
036    
037    
038        public LocalizedMessageFactory(final String bundleId) {
039            this.bundle = null;
040            this.bundleId = bundleId;
041        }
042    
043    
044        /**
045         * Creates {@link org.apache.logging.log4j.message.StringFormattedMessage} instances.
046         *
047         * @param message The message format String.
048         * @param params The parameters for the message.
049         * @return The Message.
050         *
051         * @see org.apache.logging.log4j.message.MessageFactory#newMessage(String, Object...)
052         */
053        @Override
054        public Message newMessage(final String message, final Object... params) {
055            if (bundle == null) {
056                return new LocalizedMessage(bundleId,  message, params);
057            }
058            return new LocalizedMessage(bundle, message, params);
059        }
060    }