Created
May 31, 2016 14:06
-
-
Save ifedotov/52928a07270e5552a82275ecf7f8ce64 to your computer and use it in GitHub Desktop.
Parsing responses from eclipse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component name="result" | |
{ | |
/* | |
* | |
* PARSES RESPONSE FROM CONNECTION | |
* | |
* */ | |
//CALL parseResult() TO PARSE EACH ROW WITHING THE RETURNED TABLE | |
private function parseSubTable(connectionResult, fieldName) | |
{ | |
var local = StructNew(); | |
local.connectionResult = ARGUMENTS.connectionResult; | |
local.subTable = local.connectionResult.getSubTable(fieldName); | |
local.result = ArrayNew(1); | |
if(NOT isNull(local.subTable)) | |
{ | |
while(local.subTable.hasNext()) | |
{ | |
ArrayAppend(local.result, parseResult(local.subTable.getRowResult())); | |
} | |
} | |
return local.result; | |
} | |
//CALL parseResult() FOR EACH PROPERTY VALUE | |
private function parseSubMap(connectionResult, fieldName) | |
{ | |
var local = StructNew(); | |
local.result = StructNew(); | |
local.connectionResult = ARGUMENTS.connectionResult; | |
local.subMap = local.connectionResult.getSubMap(fieldName); | |
if(NOT isNull(local.subMap)) | |
{ | |
local.result = parseResult(local.subMap); | |
} | |
return local.result; | |
} | |
private function parseList(connectionResult, fieldName) | |
{ | |
var local = StructNew(); | |
local.result = ""; | |
local.connectionResult = ARGUMENTS.connectionResult; | |
local.list = local.connectionResult.getArray(fieldName); | |
return ArrayToList(local.list); | |
} | |
private function parseString(connectionResult, fieldName) | |
{ | |
var local = StructNew(); | |
local.connectionResult = ARGUMENTS.connectionResult; | |
return local.connectionResult.getString(ARGUMENTS.fieldName); | |
} | |
private function parseBool(connectionResult, fieldName) | |
{ | |
var local = StructNew(); | |
local.connectionResult = ARGUMENTS.connectionResult; | |
return local.connectionResult.getBool(ARGUMENTS.fieldName); | |
} | |
private function parseInt(connectionResult, fieldName) | |
{ | |
var local = StructNew(); | |
local.connectionResult = ARGUMENTS.connectionResult; | |
return val(local.connectionResult.getInt(ARGUMENTS.fieldName)); | |
} | |
private function parseValue(connectionResult, fieldName) | |
{ | |
var local = StructNew(); | |
local.result = StructNew(); | |
local.connectionResult = arguments.connectionResult; | |
if (local.connectionResult.isTable(arguments.fieldName)) | |
{ | |
local.result = parseSubTable(local.connectionResult, arguments.fieldName); | |
} | |
else if (local.connectionResult.isMap(arguments.fieldName)) | |
{ | |
local.result = parseSubMap(local.connectionResult, arguments.fieldName); | |
} | |
else if (local.connectionResult.isList(arguments.fieldName)) | |
{ | |
local.result = parseList(local.connectionResult, arguments.fieldName); | |
} | |
else | |
{ | |
local.result = parseString(local.connectionResult, arguments.fieldName); | |
} | |
return local.result; | |
} | |
public function parseResult(connectionResult) | |
{ | |
var local = StructNew(); | |
local.result = StructNew(); | |
local.connectionResult = ARGUMENTS.connectionResult; | |
for (local.fieldName in local.connectionResult.fieldNames()) | |
{ | |
try | |
{ | |
local.result[local.fieldName] = parseValue(local.connectionResult, local.fieldName); | |
} | |
catch (PARSING_PROBLEM e) | |
{ | |
rethrow; | |
} | |
catch (any e) | |
{ | |
try | |
{ | |
while(local.connectionResult.hasNext()) | |
{ | |
if(!StructKeyExists(local.result, local.fieldName)) | |
{ | |
local.result[local.fieldName] = []; | |
} | |
local.arrayResult = parseResult(local.connectionResult); | |
ArrayAppend(local.result[local.fieldName], local.arrayResult); | |
}; | |
} | |
catch (any e) | |
{ | |
throw(type = "PARSING_PROBLEM", Message = e.message); | |
} | |
} | |
} | |
return local.result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment