| Quintiq file version 2.0 | 
| #parent: #root | 
| Method GenerateNVT (structured_Object data_i, Boolean deleteData_i) as owning NamedValueTree | 
| { | 
|   Description: | 
|   [* | 
|     Transform the data into the format that is implemented in the Channel Library and put in an a NamedValueTree. | 
|     (1) In some cases, we want to delete the input data, in others we wish to keep it | 
|   *] | 
|   TextBody: | 
|   [* | 
|     genericObject := null( Object ); | 
|     isDataManager := this.CommunicationChannelRoot().IsDataManager(); | 
|      | 
|     // Data will be null if the message is for notification only | 
|     dataSize := guard( data_i.Size(), 0 ); | 
|      | 
|     // If there is no data then use a Message, otherwise use a Batch. | 
|     // Using a Batch when there is not data results in an error when the QIntegrator is used. | 
|     nvt := null( NamedValueTree ); | 
|      | 
|     if( dataSize = 0 ) | 
|     { | 
|       nvt := LibInt_MessageAccessor::CreateEmptyMessage(); | 
|     } | 
|     else | 
|     { | 
|       nvt := LibInt_BatchAccessor::CreateEmptyBatch( dataSize ); | 
|      | 
|       //Fill each of the Children with the values of an object. | 
|       batchBody := LibInt_NvtAccessor::FirstChildNamed( nvt, nvt.Root(), 'Body' ); | 
|       idx := 0; | 
|      | 
|       traverse( batchBody.Children(), Elements, child ) | 
|       { | 
|         dataElement := data_i.Element( idx ); | 
|         if( not isDataManager ) | 
|         { | 
|           // Transform the data to the generic structure. | 
|           genericObject := this.DataTransformToGeneric( dataElement ); | 
|         } | 
|         else | 
|         { | 
|           // The data is already in the generic structure. | 
|           genericObject := dataElement; | 
|         } | 
|      | 
|         childBody := LibInt_NvtAccessor::FirstChildNamed( nvt, child, 'Body' ); | 
|      | 
|         // Put the object in the NVT. | 
|         NamedValueTreeIO::Export( genericObject, nvt, childBody, false ); | 
|      | 
|         if( not isDataManager ) | 
|         { | 
|           // The temporary created genericObject can be deleted again. | 
|           genericObject.Delete(); | 
|         } | 
|      | 
|         idx++; | 
|       } | 
|     } | 
|      | 
|     return &nvt; | 
|   *] | 
| } |