Description
process XML document
Parameters
ihDocument | input | handle | x-document handle |
icClassName | input | character | business class shortname |
icOverrideAction | input | character | override action in XML document |
tXmlObjectsLoaded | output | temp-table | |
olSuccess | output | logical | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program1/bxmldaemonprocessor.p)
empty temp-table tXmlObjectsLoaded.
assign vcXSDFile = search("xml/":U + lc(icClassName) + ".xsd":U).
if vcXSDFile = ?
then do:
<M-34 run SetMessage
(input trim(#T-46'The XSD file for component $1 is not found.':255(9056)T-46#) (icMessage),
input icClassName (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-286':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BXmlDaemonProcessor>
assign oiReturnStatus = -3.
return.
end.
create dataset vhDS in widget-pool "non-persistent".
assign vhDS:name = "XmlDaemon"
vhDS:private-data = vcXSDFile
vcErrorFile = session:temp-dir + "xml-out.txt".
output to value(vcErrorFile).
/* Is this a partial or a full update ? */
vlIsPartialUpdate = ?.
create x-noderef vhClass in widget-pool "non-persistent".
create x-noderef vhTable in widget-pool "non-persistent".
create x-noderef vhField in widget-pool "non-persistent".
create x-noderef vhBuf in widget-pool "non-persistent".
ihDocument:get-child(vhClass,1).
do viCnt = 1 to vhClass:num-children:
vhClass:get-child(vhTable,viCnt).
if vhTable:name = "tContextInfo"
then do:
do vicnt2 = 1 to vhTable:num-children:
vhTable:get-child(vhField,viCnt2).
if vhField:name = "tlPartialUpdate"
and vhField:num-children = 1
then do:
vhField:get-child(vhBuf,1).
vlIsPartialUpdate = (vhBuf:node-value = "yes" or
vhBuf:node-value = "true").
end.
if vhField:name = "tcComment"
and vhField:num-children = 1
and vlIsPartialUpdate = ?
then do:
vhField:get-child(vhBuf,1).
vcCommentFromtContextInfo = vhBuf:node-value.
do viCnt1 = num-entries(vcCommentFromtContextInfo," ") to 1 by -1:
if entry(viCnt1,vcCommentFromtContextInfo," ") = "PartialUpdate=yes"
or entry(viCnt1,vcCommentFromtContextInfo," ") = "PartialUpdate=true"
then vlIsPartialUpdate = yes.
if entry(viCnt1,vcCommentFromtContextInfo," ") = "PartialUpdate=no"
or entry(viCnt1,vcCommentFromtContextInfo," ") = "PartialUpdate=false"
then vlIsPartialUpdate = no.
end.
end.
end.
leave.
end.
end.
if vlIsPartialUpdate = ?
then vlIsPartialUpdate = no.
delete object vhClass.
delete object vhTable.
delete object vhField.
delete object vhBuf.
if vlIsPartialUpdate
then do:
/* Make sure the structure is read from the XML schema file.
For partial update, force the initial values of all fields to be "unknown value" */
create dataset vhDSSchema in widget-pool "non-persistent".
vhDSSchema:read-xmlschema("file",vcXSDFile,?).
DO viCnt = 1 TO vhDSSchema:NUM-BUFFERS:
ASSIGN vhBuf = vhDSSchema:GET-BUFFER-HANDLE(viCnt).
CREATE TEMP-TABLE vhTable in widget-pool "non-persistent".
DO viCnt2 = 1 TO vhBuf:NUM-FIELDS:
ASSIGN vhField = vhBuf:BUFFER-FIELD(viCnt2).
vhTable:ADD-NEW-FIELD( vhField:NAME , vhField:DATA-TYPE , ? , vhField:FORMAT , "?" ).
END.
vhTable:TEMP-TABLE-PREPARE(vhBuf:NAME).
vhDS:ADD-BUFFER(vhTable:DEFAULT-BUFFER-HANDLE).
END.
DO viCnt = 1 TO vhDSSchema:NUM-RELATIONS:
ASSIGN vhRelation = vhDSSchema:GET-RELATION(viCnt).
vhDS:ADD-RELATION(vhDS:get-buffer-handle(vhRelation:PARENT-BUFFER:NAME),vhDS:get-buffer-handle(vhRelation:CHILD-BUFFER:NAME),"tc_Rowid,tc_ParentRowid").
END.
delete object vhDSSchema.
assign vhDSSchema = ?.
end.
else do:
/* Make sure the structure is read from the XML schema file.
For full update, accept the normal initial values of all fields */
vhDS:read-xmlschema("file",vcXSDFile,?).
end.
vhDS:read-xml("handle", ihDocument, "empty", ?, ?, ?, "LOOSE").
output close.
copy-lob from file vcErrorFile to vpErrors.
if valid-handle(vhDS) = no or
vhDS:num-buffers = 0 or
vpErrors > ""
then do:
<M-38 run SetMessage
(input trim(#T-47'Error while reading the XML document.':255(9057)T-47#) + chr(10) + vpErrors (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-287':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BXmlDaemonProcessor>
assign oiReturnStatus = -3.
return.
end.
assign vhTable = vhDS:get-buffer-handle("tContextInfo":U) no-error.
if not valid-handle(vhTable)
then do:
<M-39 run SetMessage
(input trim(#T-48'The XML did not contain the tContextInfo table.':255(9058)T-48#) (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-288':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BXmlDaemonProcessor>
assign oiReturnStatus = -3.
return.
end.
vhTable:find-unique("where true") no-error. /* table must contain one record */
if vhTable:available
then do:
assign vhField = vhTable:buffer-field("tcCompanyCode") no-error.
if valid-handle(vhField)
then assign vcCompanyCodeFromXML = vhTable::tcCompanyCode.
assign vhField = vhTable:buffer-field("tcActivityCode") no-error.
if valid-handle(vhField)
then assign vcActivityCodeFromXML = vhTable::tcActivityCode.
assign vhField = vhTable:buffer-field("tcCBFVersion") no-error.
if valid-handle(vhField)
then assign vcCbfVersion = vhTable::tcCBFVersion.
assign vhField = vhTable:buffer-field("tcAction") no-error.
if valid-handle(vhField)
then assign vcAction = vhTable::tcAction.
assign vcCommentFromtContextInfo = vhTable::tcComment no-error.
assign vhField = vhTable:buffer-field("tcPartialUpdateExceptionList") no-error.
if valid-handle(vhField)
then assign vcPartialUpdateExceptionList = vhTable::tcPartialUpdateExceptionList.
else do viCnt = num-entries(vcCommentFromtContextInfo, " ") to 1 by -1:
assign vcEntry = entry(viCnt, vcCommentFromtContextInfo, " ").
if vcEntry begins "PartialUpdateExceptionList="
then assign vcPartialUpdateExceptionList = replace(vcEntry, "PartialUpdateExceptionList=", "").
end.
end.
if vcCbfVersion <> "9.2":U
then do:
<M-44 run SetMessage
(input trim(#T-49'The XML file should be updated to use version 9.2.':255(9059)T-49#) (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-289':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BXmlDaemonProcessor>
assign oiReturnStatus = -3.
return.
end.
if icClassName <> "BStoredSearch"
then do:
<M-69 run SwitchSessionCy
(input vcCompanyCodeFromXML (icCompanyCode),
input 0 (iiCompanyId),
output viFcReturnSuper (oiReturnStatus)) in BXmlDaemonProcessor>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
/* Generic run of business method */
<M-40 run BusinessClassActions
(input lc(icClassName) (icClassShortname),
input 'START+OPEN' (icAction),
input no (ilSubtransaction),
input-output viOpenC (biClassOpenCount),
input-output vhdatabaseInst (bhClassInstanceHandle),
input-output vidatabaseId (biClassInstanceId),
input '' (icDraftReference),
input '' (icUserDefinedContext),
output viFcReturnSuper (oiReturnStatus)) in BXmlDaemonProcessor>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
if icOverrideAction <> ""
then assign vcAction = icOverrideAction.
run gipr_ClearSTables in vhdatabaseInst no-error.
if vcActivityCodeFromXML <> "" and
vcActivityCodeFromXML <> ?
then do:
<M-90 run SetPublicData
(input 'vcActivityCode' (icDataList),
input vcActivityCodeFromXML (icValueList),
output viFcReturnSuper (oiReturnStatus)) in database>
end.
<M-66 run PartialSetSTables
(input vhDS by-reference (izDatasetHandle),
input vlIsPartialUpdate (ilIsPartialUpdate),
output viLocalReturn (oiReturnStatus)) in database>
if viLocalReturn >= 0
then do:
create dataset vhDataset in widget-pool "non-persistent".
<M-11 run MaintainByDatasetWithOutput
(input vcAction (icAction),
input false (ilReturnDataset),
input vlIsPartialUpdate (ilPartialUpdate),
input vcPartialUpdateExceptionList (icPartialUpdateExceptionList),
output vpReturnPrime (opPrimaryKey),
output vpReturnRowid (opRowid),
output viReturnDraftInstance (oiDraftInstance),
output vcDummy (ocPrimaryKeyName),
output vhDataset by-reference (ozObjectRepresentation),
output viLocalReturn (oiReturnStatus)) in database>
delete object vhDataset.
assign vhDataset = ?.
end.
<M-29 run BusinessClassActions
(input lc(icClassName) (icClassShortname),
input if viReturnDraftInstance = 0 then 'CLOSE+STOP':U else 'CLOSE':U (icAction),
input no (ilSubtransaction),
input-output viOpenC (biClassOpenCount),
input-output vhdatabaseInst (bhClassInstanceHandle),
input-output vidatabaseId (biClassInstanceId),
input '' (icDraftReference),
input '' (icUserDefinedContext),
output viFcReturnSuper (oiReturnStatus)) in BXmlDaemonProcessor>
if viLocalReturn < 0
then do:
assign vlSuccess = no.
if not can-find(first tFcMessages)
then do:
run ConvertReturnStatus in {&TARGETPROCEDURE}
(input viLocalReturn,
output vcDummy).
<M-54 run SetMessage
(input vcDummy (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-229':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BXmlDaemonProcessor>
end.
end.
else do viFcCount1 = num-entries(vpReturnPrime, chr(4)) to 1 by -1:
create tXmlObjectsLoaded.
assign tXmlObjectsLoaded.tiObjectSeq = viFcCount1
tXmlObjectsLoaded.tcObjectPK = entry(viFcCount1, vpReturnPrime, chr(4))
tXmlObjectsLoaded.tiObjectReturnStatus = viLocalReturn
tXmlObjectsLoaded.tcObjectRowid = entry(viFcCount1, vpReturnRowid)
tXmlObjectsLoaded.tiObjectDraftId = viReturnDraftInstance.
end.
olSuccess = vlSuccess.
finally:
if vhDS <> ?
then delete object vhDS.
if vhDSSchema <> ?
then delete object vhDSSchema.
end finally.