diff -r 000000000000 -r a02c979e8dfd srcanaapps/apiquerytool/com.nokia.s60tools.apiquery/src/com/nokia/s60tools/apiquery/shared/datatypes/FieldMappingRules.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/srcanaapps/apiquerytool/com.nokia.s60tools.apiquery/src/com/nokia/s60tools/apiquery/shared/datatypes/FieldMappingRules.java Sat Jan 09 10:04:11 2010 +0530 @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +package com.nokia.s60tools.apiquery.shared.datatypes; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import com.nokia.s60tools.apiquery.shared.resources.Messages; + +/** + * Stores field mapping rules that can be used to + * map API detail field descriptions to XML + * and vice versa. + */ +public class FieldMappingRules { + + /** + * Storage for the mapping rules. + */ + Map ruleMap; + + /** + * Constructor + */ + public FieldMappingRules(){ + ruleMap = new HashMap(); + } + + /** + * Adds a new rule to the mapping rules. + * @param mapFromStr String to map from. + * @param mapToStr String to map into. + */ + public void addRule(String mapFromStr, String mapToStr){ + ruleMap.put(mapFromStr, mapToStr); + } + + /** + * Gets the string that was mapped into the given parameter string. + * @param keyStr Key string to ask mapped result for. + * @return Returns result string or throws IllegalArgumentException + * if no . + * @throws java.lang.IllegalArgumentException + * @see java.lang.IllegalArgumentException + */ + public String mapFrom(String keyStr){ + String resultStr = ruleMap.get(keyStr); + if(resultStr == null){ + throw new IllegalArgumentException(Messages.getString("FieldMappingRules.NoMappingRule_ErrMsg") + keyStr); //$NON-NLS-1$ + } + return resultStr; + } + + /** + * Returns key set that this field mapping rule instance + * has mapping rules for. + * @return Set of String key values. + */ + public Set getMapFromKeySet(){ + return ruleMap.keySet(); + } +}