Access keysTop, Summary,
Class properties,
Class methodsDataMapper
| Kind of class: |
class |
| Inherits from: |
none |
| Classpath: |
data.DataMapper |
| File last modified: |
Monday, 06 November 2006, 08:09:08 |
import org.asapframework.data.array.ArrayEnumerator;
import org.asapframework.data.KeyValue;
import org.asapframework.data.KeyValueList;
import org.asapframework.util.StringUtilsSplit;
import org.asapframework.util.StringUtilsTrim;
import data.IMappable;
/**
Maps key-value pairs to an object.
How {@link AppController} uses this: values (retrieved from data lines from projectdata.txt) are set to 'key' properties of {@link ProjectData} objects.
*/
class data.DataMapper {
private static var ITEM_DELIMITER:String = ","; /**< Property delimiter. */
private static var KEY_VALUE_DELIMITER:String = "="; /**< Key-value pair delimiter. */
public static function map (inDataString:String, inMappableObject:IMappable) {
var components:Array = StringUtilsSplit.splitAndPreserveQuotes(inDataString, ITEM_DELIMITER);
var kvList:KeyValueList = parsePropertyComponents(components);
var e:ArrayEnumerator = new ArrayEnumerator(kvList.getArray());
var kv:KeyValue = null;
while (kv = e.getNextObject()) {
inMappableObject.map(kv.key, kv.value);
}
}
/**
Transforms the values in the property components array ({@code key=value} pairs) to KeyValueList key-values. The delimiter character is {@link #KEY_VALUE_DELIMITER}.
*/
private static function parsePropertyComponents (inComponents:Array) : KeyValueList {
var list:KeyValueList = new KeyValueList();
var i:Number, ilen:Number = inComponents.length;
for (i=0; i<ilen; ++i) {
var keyValue:Array = StringUtilsSplit.splitAndPreserveQuotes(inComponents[i], KEY_VALUE_DELIMITER);
var key:String = trimQuotes(keyValue[0]);
var value:String = trimQuotes(keyValue[1]);
list.addValueForKey(value, key);
}
return list;
}
/**
Removes quote characters at both ends of a string.
@param inString : String to convert
*/
private static function trimQuotes (inString:String) : String {
var text:String = StringUtilsTrim.leftTrimForChars(inString, StringUtilsTrim.QUOTE_CHAR);
return StringUtilsTrim.rightTrimForChars(text, StringUtilsTrim.QUOTE_CHAR);
}
}
Maps key-value pairs to an object.
How
controllers.AppController uses this: values (retrieved from data lines from projectdata.txt) are set to 'key' properties of
ProjectData objects.
Class properties
ITEM_DELIMITER
static private ITEM_DELIMITER:String = ","
(read,write)
Property delimiter.
KEY_VALUE_DELIMITER
static private KEY_VALUE_DELIMITER:String = "="
(read,write)
Key-value pair delimiter.
Class methods
map
static function map (
inDataString:String,
inMappableObject:IMappable)
parsePropertyComponents
static private function parsePropertyComponents (
inComponents:Array) : KeyValueList
Transforms the values in the property components array (
key=value pairs) to KeyValueList key-values. The delimiter character is
KEY_VALUE_DELIMITER.
trimQuotes
static private function trimQuotes (
inString:String) : String
Removes quote characters at both ends of a string.
Parameters:
inString:
String to convert