/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.geronimo.gshell.ansi;

import org.apache.geronimo.gshell.i18n.MessageSource;

/**
 * Message source implementation which supports automatic ANSI color rendering.
 *
 * @version $Rev$ $Date$
 */
public class RenderMessageSource
    extends MessageSource
{
    private final Renderer renderer = new Renderer();

    public RenderMessageSource(final String[] names) {
        super(names);
    }

    public RenderMessageSource(final String name) {
        super(name);
    }

    public RenderMessageSource(final Class[] types) {
        super(types);
    }

    public RenderMessageSource(final Class type) {
        super(type);
    }

    public String getMessage(final String code) {
        final String msg = super.getMessage(code);

        if (Renderer.test(msg)) {
            return renderer.render(msg);
        }

        return msg;
    }
}

@@ -924,22 +924,15 @@
 rce 
-implementation
+adapter
  whi
@@ -1048,14 +1048,17 @@
     
-extend
+implement
 s Me
@@ -1135,86 +1135,173 @@
    p
-ublic RenderMessageSource(final String%5B%5D names) %7B%0A        super(names)
+rivate final MessageSource source;%0A%0A    public RenderMessageSource(final MessageSource source) %7B%0A        assert source != null;%0A%0A        this.source = source
 ;%0A    %7D%0A
 %0A   
@@ -1288,32 +1288,36 @@
 = source;%0A    %7D%0A
+    
 %0A    public Rend
@@ -1312,34 +1312,32 @@
  public 
-RenderMessageSourc
+String getMessag
 e(final 
@@ -1343,19 +1343,19 @@
  String 
-nam
+cod
 e) %7B%0A   
@@ -1363,236 +1363,212 @@
     
-super(nam
+String msg = source.getMessage(cod
 e);%0A
+%0A
     
-%7D%0A%0A
     
-public RenderMessageSource(final Class%5B%5D types) %7B%0A        super(types);%0A    %7D%0A%0A    public RenderMessageSource(final Class type) %7B%0A        super(type);%0A    %7D%0A%0A    public String getMessage(final String code
+if (Renderer.test(msg)) %7B%0A            return renderer.render(msg);%0A        %7D%0A%0A        return msg;%0A    %7D%0A%0A    public String format(String code, Object... args
 ) %7B%0A
@@ -1575,22 +1575,16 @@
         
-final 
 String m
@@ -1593,28 +1593,31 @@
  = s
-uper.getMessage(code
+ource.format(code, args
 );%0A%0A

Make the render msg wrap instead of extend