001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.studio.apacheds;
021
022
023 import java.util.HashMap;
024 import java.util.Map;
025
026 import org.apache.directory.studio.apacheds.model.Server;
027 import org.apache.directory.studio.apacheds.model.ServersHandler;
028 import org.eclipse.ui.console.ConsolePlugin;
029 import org.eclipse.ui.console.IConsole;
030
031
032 /**
033 * This class implements the consoles handler.
034 * <p>
035 *
036 * It is used to store all the consoles associated to servers.
037 *
038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
039 * @version $Rev$, $Date$
040 */
041 public class ConsolesHandler
042 {
043 /** The default instance */
044 private static ConsolesHandler instance;
045
046 /** The map of consoles identified by server ID */
047 private Map<String, LogMessageConsole> consolesMap;
048
049
050 /**
051 * Creates a new instance of ConsolesHandler.
052 */
053 private ConsolesHandler()
054 {
055 // Initialization of the map
056 consolesMap = new HashMap<String, LogMessageConsole>();
057 }
058
059
060 /**
061 * Gets the default consoles handler (singleton pattern).
062 *
063 * @return
064 * the default consoles handler
065 */
066 public static ConsolesHandler getDefault()
067 {
068 if ( instance == null )
069 {
070 instance = new ConsolesHandler();
071 }
072
073 return instance;
074 }
075
076
077 /**
078 * Gets the log message console associated with the if of the server.
079 *
080 * @param serverId
081 * the id of the server
082 * @return
083 * the associated log message console.
084 */
085 public LogMessageConsole getLogMessageConsole( String serverId )
086 {
087 if ( consolesMap.containsKey( serverId ) )
088 {
089 return consolesMap.get( serverId );
090 }
091 else
092 {
093 Server server = ServersHandler.getDefault().getServerById( serverId );
094
095 LogMessageConsole logMessageConsole = new LogMessageConsole( "Apache DS - " + server.getName() );
096
097 consolesMap.put( serverId, logMessageConsole );
098
099 ConsolePlugin.getDefault().getConsoleManager().addConsoles( new IConsole[]
100 { logMessageConsole } );
101
102 return logMessageConsole;
103 }
104 }
105 }