0
|
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.Collection;
|
|
21 |
import java.util.HashMap;
|
|
22 |
import java.util.Map;
|
|
23 |
import java.util.NoSuchElementException;
|
|
24 |
|
|
25 |
import com.nokia.s60tools.appdep.exceptions.InvalidModelDataException;
|
|
26 |
import com.nokia.s60tools.appdep.resources.Messages;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Model class instance representing data that is available via symbols cache data file.
|
|
30 |
*/
|
|
31 |
public class SymbolsCache {
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Map that can be used to get cached library by using
|
|
35 |
* library base name as key.
|
|
36 |
*/
|
|
37 |
private Map<String, LibPropertiesData> libraryPropertiesMap;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Constructor.
|
|
41 |
*/
|
|
42 |
public SymbolsCache(){
|
|
43 |
libraryPropertiesMap = new HashMap<String, LibPropertiesData>();
|
|
44 |
}
|
|
45 |
|
|
46 |
/**
|
|
47 |
* Adds given library properties data into model.
|
|
48 |
* @param libPropData Library properties data to be added.
|
|
49 |
* @throws InvalidModelDataException
|
|
50 |
*/
|
|
51 |
public void addLibPropertiesData(LibPropertiesData libPropData) throws InvalidModelDataException{
|
|
52 |
String libBaseName = libPropData.getLibraryBaseName().toLowerCase();
|
|
53 |
if(libraryPropertiesMap.get(libBaseName) != null){
|
|
54 |
throw new InvalidModelDataException(Messages.getString("SymbolsCache.SymbolHasDublicateDefinition_Err_Msg")); //$NON-NLS-1$
|
|
55 |
}
|
|
56 |
libraryPropertiesMap.put(libBaseName, libPropData);
|
|
57 |
}
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Returns all library properties of the cache file.
|
|
61 |
* The collection is not ordered.
|
|
62 |
* @return All library properties of the cache file.
|
|
63 |
*/
|
|
64 |
public Collection<LibPropertiesData> getAllLibraryProperties() {
|
|
65 |
return libraryPropertiesMap.values();
|
|
66 |
}
|
|
67 |
|
|
68 |
/**
|
|
69 |
* Gets component properties data object for given component.
|
|
70 |
* @param libBaseName Base name of the library to get properties data object for.
|
|
71 |
* @return Component properties data object for given component or <code>null</code> if component is not in cache.
|
|
72 |
*/
|
|
73 |
public LibPropertiesData getLibPropertiesData(String libBaseName){
|
|
74 |
return libraryPropertiesMap.get(libBaseName);
|
|
75 |
}
|
|
76 |
|
|
77 |
/**
|
|
78 |
* Returns file name without file extension.
|
|
79 |
* @param fileNameStr File name to be remove extension from.
|
|
80 |
* @return Return file name without an extension, or file
|
|
81 |
* name itself, if file did not have any extension.
|
|
82 |
*/
|
|
83 |
public static String removeFileExtension(String fileNameStr){
|
|
84 |
int extIndex = fileNameStr.lastIndexOf("."); //$NON-NLS-1$
|
|
85 |
if(extIndex != -1){
|
|
86 |
return fileNameStr.substring(0, extIndex);
|
|
87 |
}
|
|
88 |
else{
|
|
89 |
return fileNameStr;
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Gets exported functions for the given component name.
|
|
95 |
* @param componentNameWithExtension Component name with an extension.
|
|
96 |
* @return Exported functions for the given component name.
|
|
97 |
*/
|
|
98 |
public Collection<ExportFunctionData> getExportedFunctionsForComponent(String componentNameWithExtension) {
|
|
99 |
String libraryBaseName = removeFileExtension(componentNameWithExtension);
|
|
100 |
LibPropertiesData libPropData = libraryPropertiesMap.get(libraryBaseName);
|
|
101 |
if(libPropData == null){
|
|
102 |
throw new NoSuchElementException(Messages.getString("SymbolsCache.ComponentNotFoundFromCache_ErrMsg") + ": '" + libraryBaseName + "'."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
103 |
}
|
|
104 |
return libPropData.getExportedFunctions();
|
|
105 |
}
|
|
106 |
|
|
107 |
}
|