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 */
017package org.apache.logging.log4j.message;
018
019import java.io.Serializable;
020
021/**
022 * Provides an abstract superclass for {@link MessageFactory2} implementations with default implementations (and for
023 * {@link MessageFactory} by extension).
024 * <p>
025 * This class is immutable.
026 * </p>
027 * <h4>Note to implementors</h4>
028 * <p>
029 * Subclasses can implement the {@link MessageFactory2} methods when they can most effectively build {@link Message}
030 * instances. If a subclass does not implement {@link MessageFactory2} methods, these calls are routed through
031 * {@link #newMessage(String, Object...)} in this class.
032 * </p>
033 */
034public abstract class AbstractMessageFactory implements MessageFactory2, Serializable {
035    private static final long serialVersionUID = -1307891137684031187L;
036
037    @Override
038    public Message newMessage(final CharSequence message) {
039        return new SimpleMessage(message);
040    }
041
042    /*
043     * (non-Javadoc)
044     *
045     * @see org.apache.logging.log4j.message.MessageFactory#newMessage(java.lang.Object)
046     */
047    @Override
048    public Message newMessage(final Object message) {
049        return new ObjectMessage(message);
050    }
051
052    /*
053     * (non-Javadoc)
054     *
055     * @see org.apache.logging.log4j.message.MessageFactory#newMessage(java.lang.String)
056     */
057    @Override
058    public Message newMessage(final String message) {
059        return new SimpleMessage(message);
060    }
061
062    /**
063     * @since 2.6.1
064     */
065    @Override
066    public Message newMessage(final String message, final Object p0) {
067        return newMessage(message, new Object[] { p0 });
068    }
069
070    /**
071     * @since 2.6.1
072     */
073    @Override
074    public Message newMessage(final String message, final Object p0, final Object p1) {
075        return newMessage(message, new Object[] { p0, p1 });
076    }
077
078    /**
079     * @since 2.6.1
080     */
081    @Override
082    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2) {
083        return newMessage(message, new Object[] { p0, p1, p2 });
084    }
085
086    /**
087     * @since 2.6.1
088     */
089    @Override
090    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3) {
091        return newMessage(message, new Object[] { p0, p1, p2, p3 });
092    }
093
094    /**
095     * @since 2.6.1
096     */
097    @Override
098    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4) {
099        return newMessage(message, new Object[] { p0, p1, p2, p3, p4 });
100    }
101
102    /**
103     * @since 2.6.1
104     */
105    @Override
106    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5) {
107        return newMessage(message, new Object[] { p0, p1, p2, p3, p4, p5 });
108    }
109
110    /**
111     * @since 2.6.1
112     */
113    @Override
114    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5,
115            final Object p6) {
116        return newMessage(message, new Object[] { p0, p1, p2, p3, p4, p5, p6 });
117    }
118
119    /**
120     * @since 2.6.1
121     */
122    @Override
123    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5,
124            final Object p6, final Object p7) {
125        return newMessage(message, new Object[] { p0, p1, p2, p3, p4, p5, p6, p7 });
126    }
127
128    /**
129     * @since 2.6.1
130     */
131    @Override
132    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5,
133            final Object p6, final Object p7, final Object p8) {
134        return newMessage(message, new Object[] { p0, p1, p2, p3, p4, p5, p6, p7, p8 });
135    }
136
137    /**
138     * @since 2.6.1
139     */
140    @Override
141    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5,
142            final Object p6, final Object p7, final Object p8, final Object p9) {
143        return newMessage(message, new Object[] { p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 });
144    }
145
146}