|
1 /* |
|
2 * Copyright (c) 2007 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.apiquery.shared.datatypes; |
|
19 |
|
20 import java.util.HashMap; |
|
21 import java.util.Map; |
|
22 import java.util.Set; |
|
23 |
|
24 import com.nokia.s60tools.apiquery.shared.resources.Messages; |
|
25 |
|
26 /** |
|
27 * Stores field mapping rules that can be used to |
|
28 * map API detail field descriptions to XML |
|
29 * and vice versa. |
|
30 */ |
|
31 public class FieldMappingRules { |
|
32 |
|
33 /** |
|
34 * Storage for the mapping rules. |
|
35 */ |
|
36 Map <String, String> ruleMap; |
|
37 |
|
38 /** |
|
39 * Constructor |
|
40 */ |
|
41 public FieldMappingRules(){ |
|
42 ruleMap = new HashMap<String, String>(); |
|
43 } |
|
44 |
|
45 /** |
|
46 * Adds a new rule to the mapping rules. |
|
47 * @param mapFromStr String to map from. |
|
48 * @param mapToStr String to map into. |
|
49 */ |
|
50 public void addRule(String mapFromStr, String mapToStr){ |
|
51 ruleMap.put(mapFromStr, mapToStr); |
|
52 } |
|
53 |
|
54 /** |
|
55 * Gets the string that was mapped into the given parameter string. |
|
56 * @param keyStr Key string to ask mapped result for. |
|
57 * @return Returns result string or throws <code>IllegalArgumentException</code> |
|
58 * if no . |
|
59 * @throws java.lang.IllegalArgumentException |
|
60 * @see java.lang.IllegalArgumentException |
|
61 */ |
|
62 public String mapFrom(String keyStr){ |
|
63 String resultStr = ruleMap.get(keyStr); |
|
64 if(resultStr == null){ |
|
65 throw new IllegalArgumentException(Messages.getString("FieldMappingRules.NoMappingRule_ErrMsg") + keyStr); //$NON-NLS-1$ |
|
66 } |
|
67 return resultStr; |
|
68 } |
|
69 |
|
70 /** |
|
71 * Returns key set that this field mapping rule instance |
|
72 * has mapping rules for. |
|
73 * @return Set of String key values. |
|
74 */ |
|
75 public Set<String> getMapFromKeySet(){ |
|
76 return ruleMap.keySet(); |
|
77 } |
|
78 } |