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.spi; 018 019import java.util.Objects; 020 021import org.apache.logging.log4j.message.Message; 022import org.apache.logging.log4j.message.MessageFactory; 023import org.apache.logging.log4j.message.MessageFactory2; 024import org.apache.logging.log4j.message.SimpleMessage; 025 026/** 027 * Adapts a legacy MessageFactory to the new MessageFactory2 interface. 028 * 029 * @since 2.6 030 */ 031public class MessageFactory2Adapter implements MessageFactory2 { 032 private final MessageFactory wrapped; 033 034 public MessageFactory2Adapter(final MessageFactory wrapped) { 035 this.wrapped = Objects.requireNonNull(wrapped); 036 } 037 038 public MessageFactory getOriginal() { 039 return wrapped; 040 } 041 042 @Override 043 public Message newMessage(final CharSequence charSequence) { 044 return new SimpleMessage(charSequence); 045 } 046 047 @Override 048 public Message newMessage(final String message, final Object p0) { 049 return wrapped.newMessage(message, p0); 050 } 051 052 @Override 053 public Message newMessage(final String message, final Object p0, final Object p1) { 054 return wrapped.newMessage(message, p0, p1); 055 } 056 057 @Override 058 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2) { 059 return wrapped.newMessage(message, p0, p1, p2); 060 } 061 062 @Override 063 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, 064 final Object p3) { 065 return wrapped.newMessage(message, p0, p1, p2, p3); 066 } 067 068 @Override 069 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, 070 final Object p4) { 071 return wrapped.newMessage(message, p0, p1, p2, p3, p4); 072 } 073 074 @Override 075 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, 076 final Object p4, final Object p5) { 077 return wrapped.newMessage(message, p0, p1, p2, p3, p4, p5); 078 } 079 080 @Override 081 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, 082 final Object p4, final Object p5, final Object p6) { 083 return wrapped.newMessage(message, p0, p1, p2, p3, p4, p5, p6); 084 } 085 086 @Override 087 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, 088 final Object p4, final Object p5, final Object p6, final Object p7) { 089 return wrapped.newMessage(message, p0, p1, p2, p3, p4, p5, p6, p7); 090 } 091 092 @Override 093 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, 094 final Object p4, final Object p5, final Object p6, final Object p7, final Object p8) { 095 return wrapped.newMessage(message, p0, p1, p2, p3, p4, p5, p6, p7, p8); 096 } 097 098 @Override 099 public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3, 100 final Object p4, final Object p5, final Object p6, final Object p7, final Object p8, final Object p9) { 101 return wrapped.newMessage(message, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); 102 } 103 104 @Override 105 public Message newMessage(final Object message) { 106 return wrapped.newMessage(message); 107 } 108 109 @Override 110 public Message newMessage(final String message) { 111 return wrapped.newMessage(message); 112 } 113 114 @Override 115 public Message newMessage(final String message, final Object... params) { 116 return wrapped.newMessage(message, params); 117 } 118}