001    /*
002     * Copyright (C) 2010 Evgeny Mandrikov
003     *
004     * Sonar-IDE is free software; you can redistribute it and/or
005     * modify it under the terms of the GNU Lesser General Public
006     * License as published by the Free Software Foundation; either
007     * version 3 of the License, or (at your option) any later version.
008     *
009     * Sonar-IDE is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012     * Lesser General Public License for more details.
013     *
014     * You should have received a copy of the GNU Lesser General Public
015     * License along with Sonar-IDE; if not, write to the Free Software
016     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
017     */
018    
019    package org.sonar.ide.ui;
020    
021    /**
022     * @author Jérémie Lagarde
023     */
024    public class ConsoleManager {
025    
026      private static ConsoleManager instance = null;
027      private final static ISonarConsole SILENT_CONOLE = new SilentSonarConole();
028      private ISonarConsole console;
029    
030      protected ConsoleManager() {
031        instance = this;
032      }
033    
034      public static ISonarConsole getConsole() {
035        if (instance == null) {
036          return SILENT_CONOLE;
037        }
038        return instance.create();
039      }
040    
041      protected ISonarConsole create() {
042        if (console == null) {
043          console = new DefaultConsole();
044        }
045        return console;
046      }
047    
048      static private class SilentSonarConole implements ISonarConsole {
049    
050        public void logError(String error) {
051        }
052    
053        public void logRequest(String request) {
054        }
055    
056        public void logResponse(String response) {
057        }
058    
059        public void logError(String error, Throwable ex) {
060        }
061    
062      }
063    }