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.log4j;
018
019import org.apache.log4j.or.ObjectRenderer;
020import org.apache.logging.log4j.message.Message;
021
022/**
023 * Implements object rendering for Log4j 1.x compatibility.
024 */
025public class RenderedMessage implements Message {
026
027    private final ObjectRenderer renderer;
028    private final Object object;
029    private String rendered = null;
030
031    public RenderedMessage(ObjectRenderer renderer, Object object) {
032        this.renderer = renderer;
033        this.object = object;
034    }
035
036
037    @Override
038    public String getFormattedMessage() {
039        if (rendered == null) {
040            rendered = renderer.doRender(object);
041        }
042
043        return rendered;
044    }
045
046    @Override
047    public String getFormat() {
048        return getFormattedMessage();
049    }
050
051    @Override
052    public Object[] getParameters() {
053        return null;
054    }
055
056    @Override
057    public Throwable getThrowable() {
058        return null;
059    }
060}