srcanaapps/depexplorer/com.nokia.s60tools.appdep/src/com/nokia/s60tools/appdep/core/model/AbstractFunctionData.java
changeset 0 a02c979e8dfd
equal deleted inserted replaced
-1:000000000000 0:a02c979e8dfd
       
     1 /*
       
     2 * Copyright (c) 2008 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 package com.nokia.s60tools.appdep.core.model;
       
    19 
       
    20 import java.util.regex.Pattern;
       
    21 
       
    22 import com.nokia.s60tools.appdep.exceptions.ZeroFunctionOrdinalException;
       
    23 import com.nokia.s60tools.appdep.resources.Messages;
       
    24 
       
    25 
       
    26 /**
       
    27  * Abstract base class for import and export function data.
       
    28  */
       
    29 public abstract class AbstractFunctionData {
       
    30 	
       
    31 	/**
       
    32 	 * The following character is used to separate class/namespace name from function name in raw cache data.
       
    33 	 */
       
    34 	private final static String FUNC_NAME_SEPARATOR = "::"; //$NON-NLS-1$
       
    35 	
       
    36 	/**
       
    37 	 * The following character is used to start parameter list in function name.
       
    38 	 */
       
    39 	private final static String FUNC_PARAM_LIST_START_CHAR = "("; //$NON-NLS-1$
       
    40 	
       
    41 	/**
       
    42 	 * Function ordinal (1..n when converted into integer).
       
    43 	 */
       
    44 	private final String functionOrdinal;
       
    45 	/**
       
    46 	 * Function name.
       
    47 	 */
       
    48 	protected String functionName;
       
    49 
       
    50 	/**
       
    51 	 * Constructor.
       
    52 	 * @param functionOrdinal Function ordinal (1..n when converted into integer).
       
    53 	 * @param functionName Function name.
       
    54 	 * @throws IllegalArgumentException 
       
    55 	 * @throws ZeroFunctionOrdinalException 
       
    56 	 */
       
    57 	public AbstractFunctionData(String functionOrdinal, String functionName) throws IllegalArgumentException, ZeroFunctionOrdinalException{
       
    58 		this.functionOrdinal = functionOrdinal;
       
    59 		this.functionName = functionName;
       
    60 		validateOrdinal();		
       
    61 	}
       
    62 
       
    63 	/**
       
    64 	 * Checks that ordinal can be converted into integer.
       
    65 	 * @throws ZeroFunctionOrdinalException 
       
    66 	 */
       
    67 	private void validateOrdinal() throws IllegalArgumentException, ZeroFunctionOrdinalException{
       
    68 		String validateErrMsg = Messages.getString("AbstractFunctionData.NotValidOrdinal_ErrMsg") + functionOrdinal; //$NON-NLS-1$
       
    69 		try {
       
    70 			int ordinal = getFunctionOrdinalAsInt();
       
    71 			// Ordinal should be positive value from 1..N
       
    72 			if(!(ordinal > 0)){
       
    73 				if(ordinal == 0){
       
    74 					// Zero ordinal functions are special cases handled by caller
       
    75 					throw new ZeroFunctionOrdinalException(functionName);
       
    76 				}
       
    77 				throw new IllegalArgumentException(validateErrMsg);				
       
    78 			}
       
    79 		} catch (NumberFormatException e) {
       
    80 			throw new IllegalArgumentException(validateErrMsg);
       
    81 		}		
       
    82 	}
       
    83 
       
    84 	/**
       
    85 	 * Returns function ordinal as int.
       
    86 	 * @return function ordinal as int.
       
    87 	 */
       
    88 	public int getFunctionOrdinalAsInt(){
       
    89 		return Integer.parseInt(functionOrdinal);
       
    90 	}
       
    91 
       
    92 	/**
       
    93 	 * Returns function ordinal as Integer.
       
    94 	 * @return function ordinal as Integer.
       
    95 	 */
       
    96 	public Integer getFunctionOrdinalAsInteger(){
       
    97 		return new Integer(getFunctionOrdinalAsInt());
       
    98 	}
       
    99 	
       
   100 	/**
       
   101 	 * Gets function ordinal. 
       
   102 	 * @return the functionOrdinal
       
   103 	 */
       
   104 	public String getFunctionOrdinal() {
       
   105 		return functionOrdinal;
       
   106 	}
       
   107 
       
   108 	/**
       
   109 	 * Gets function name.
       
   110 	 * @return the functionName
       
   111 	 */
       
   112 	public String getFunctionName() {
       
   113 		return functionName;
       
   114 	}
       
   115 	
       
   116 	/**
       
   117 	 * Extracts function's base name from the full name.
       
   118 	 * @return Function's base name without class or namespace name prefix and parameter list.
       
   119 	 */
       
   120 	public String getFunctionBaseName() {
       
   121 		// Separating component name prefix from function name and parameters
       
   122 		String[] splittedFuncName = functionName.split(Pattern.quote(FUNC_NAME_SEPARATOR));
       
   123 		// If there was component name prefix...
       
   124 		if(splittedFuncName.length == 2){
       
   125 			//  returning function base name without class/namespace name and without parameter list
       
   126 			// e.g RFs::PrivatePath(TDes16&) => PrivatePath			[efsrv.dll:27]
       
   127 			// q.g. std::terminate() => terminate					[drtrvct2_2.dll:1]
       
   128 			return splittedFuncName[1].split(Pattern.quote(FUNC_PARAM_LIST_START_CHAR))[0];
       
   129 		}
       
   130 		else{
       
   131 			// Otherwise returning just function name without parameter list
       
   132 			// e.g FileNamesIdentical(TDesC16 const&, TDesC16 const&) => FileNamesIdentical		[efsrv.dll:1]
       
   133 			// e.g operator delete(void*) => operator delete									[scppnwdl.dll:3]
       
   134 			// e.g __btod_div_common => __btod_div_common										[drtrvct2_2.dll:11]
       
   135 			return functionName.split(Pattern.quote(FUNC_PARAM_LIST_START_CHAR))[0];
       
   136 		}
       
   137 	}
       
   138 }