frameworkplugins/com.nokia.s60tools.util/src/com/nokia/s60tools/util/console/AbstractProductSpecificConsole.java
changeset 0 61163b28edca
equal deleted inserted replaced
-1:000000000000 0:61163b28edca
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17  
       
    18  
       
    19 package com.nokia.s60tools.util.console;
       
    20 
       
    21 import org.eclipse.jface.resource.ImageDescriptor;
       
    22 
       
    23 /**
       
    24  * Declares abstract product-specific console
       
    25  * that can be subclassed and configured with
       
    26  * product name and product-specific image
       
    27  * descriptor for the console.
       
    28  * 
       
    29  * Product specific console logging utility class
       
    30  * could be implemented, for instance, as a singleton
       
    31  * class that that extends this class and provides 
       
    32  * implementations for the abstract methods.<br><br>
       
    33  * 
       
    34  * In the following is given an example of such implementation:
       
    35  * 
       
    36  * <code>
       
    37  * <pre>
       
    38  * 
       
    39  * public class MyProductConsole extends AbstractProductSpecificConsole {
       
    40  * 	
       
    41  *     static private MyProductConsole instance = null;
       
    42  *     // Product information may be stored in some common place and just
       
    43  *     // initializing information in here order to use it in the methods.
       
    44  *     static final private String PRODUCT_CONSOLE_NAME = "MyProduct Console";
       
    45  *     static final private String PRODUCT_IMAGE_KEY = "MY_PROD_CONSOLE_IMG"
       
    46  * 	
       
    47  * 	static public MyProductConsole getInstance(){
       
    48  * 	    if(instance == null ){
       
    49  * 		instance = new MyProductConsole();
       
    50  * 	    }
       
    51  * 	    return instance;
       
    52  * 	}
       
    53  * 	
       
    54  *     private MyProductConsole(){		
       
    55  *     }
       
    56  * 			
       
    57  *     protected String getProductConsoleName() {
       
    58  * 	return PRODUCT_CONSOLE_NAME;
       
    59  *     }
       
    60  * 
       
    61  *     protected ImageDescriptor getProductConsoleImageDescriptor() {
       
    62  * 	// Product-specific images are probably stored into plugin-specific image registry
       
    63  * 	return MyProductPlugin.getDefault().getImageRegistry().getDescriptor(PRODUCT_IMAGE_KEY);
       
    64  *     }
       
    65  * 
       
    66  * }
       
    67  * 
       
    68   * </pre>
       
    69  * </code>
       
    70  *  
       
    71  */
       
    72 public abstract class AbstractProductSpecificConsole implements IConsolePrintUtility{
       
    73 	
       
    74 	/* (non-Javadoc)
       
    75 	 * @see com.nokia.s60tools.util.console.IConsolePrintUtility#println(java.lang.String)
       
    76 	 */
       
    77 	public void println(String message){
       
    78 		ConsoleWindowUtility.println(getProductConsoleName(), getProductConsoleImageDescriptor(), message);
       
    79 	}
       
    80 
       
    81 	/* (non-Javadoc)
       
    82 	 * @see com.nokia.s60tools.util.console.IConsolePrintUtility#println(java.lang.String, int)
       
    83 	 */
       
    84 	public void println(String message, int messageType){
       
    85 		ConsoleWindowUtility.println(getProductConsoleName(), getProductConsoleImageDescriptor(), message, messageType);
       
    86 	}
       
    87 	
       
    88 	/**
       
    89 	 * Prints given exception's stack trace element array contents to console as error message.
       
    90 	 * @param e exception for which stack trace is to be printed into the console
       
    91 	 */
       
    92 	public void printStackTrace(Exception e) {
       
    93 		
       
    94 		if(e == null){
       
    95 			return;
       
    96 		}
       
    97 		StackTraceElement[] stackTrace = e.getStackTrace();
       
    98 		
       
    99 		for (int i = 0; i < stackTrace.length; i++) {
       
   100 			StackTraceElement stackTraceElement = stackTrace[i];
       
   101 			String traceString = stackTraceElement.toString();
       
   102 			println(traceString, IConsolePrintUtility.MSG_ERROR);
       
   103 		}
       
   104 	}		
       
   105 
       
   106 	/**
       
   107 	 * Returns the name of the console used for a concrete product.
       
   108 	 * @return Console name string.
       
   109 	 */
       
   110 	protected abstract String getProductConsoleName(); 
       
   111 	
       
   112 	/**
       
   113 	 * Returns the image descriptor of the console used for a concrete product.
       
   114 	 * @return Console's image descriptor.
       
   115 	 */
       
   116 	protected abstract ImageDescriptor getProductConsoleImageDescriptor(); 
       
   117 }