Validate Library

To be able to link directly with Validate from a C++ application, the Validate Library (C++ API) can be used.

A very basic example program using the Validate Library looks like this:

#include <prolinga/Validate.hpp>

int main()
{
        /*Init */
        xmlDocPtr docReq, docRes;
        xmlNodePtr curReq, curRes;
        xmlBufferPtr bufRes;
        PlValidate val;

        /* Open Validate Environment */
        val.validateOpen("./prolingavalcfg.xml");

        /* Create Validate Command */
        docReq = xmlNewDoc((const xmlChar *)"1.0");
        docReq->children = xmlNewDocNode(docReq, NULL, (const xmlChar *)"ProLinga", NULL);
        curReq = xmlDocGetRootElement(docReq);
        curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Validate", (const xmlChar *)"");
        xmlNewProp (curReq, (const xmlChar *)"Version", (const xmlChar *)"1.0");
        curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Command", (const xmlChar *)"");
        xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)"Validate");
        xmlNewProp (curReq, (const xmlChar *)"Mode", (const xmlChar *)"Request");
        curReq = xmlNewTextChild (curReq, NULL, (const xmlChar *)"Object", (const xmlChar *)"");
        xmlNewProp (curReq, (const xmlChar *)"Application", (const xmlChar *)"MyOrder");
        xmlNewProp (curReq, (const xmlChar *)"Type", (const xmlChar *)"Logic");
        xmlNewProp (curReq, (const xmlChar *)"Name", (const xmlChar *)"RaiseStock");

        /* Process Validate Command */
        docRes = val.executeCommand(docReq);

        /* Print Response */
        bufRes = xmlBufferCreate();
        curRes = xmlDocGetRootElement(docRes);
        xmlNodeDump(bufRes, docRes, curRes, 0, 1);
        printf("%s\n", (char *)xmlBufferContent(bufRes));

        /* Close Validate Environment */
        val.validateClose();

        /* Free */
        xmlBufferFree(bufRes);
        xmlFreeDoc(docRes);
        xmlFreeDoc(docReq);

        /* Return */
        return 0;
}

When running this application, a connection is made to the Validate environment. When opening this connection an argument with the path and name of the validate configuration file can be passed as an argument. The system then knows details as in which directory it can find the Language Validation file etc. The configuration file has to be in a certain format, which is explained further on. The Validate Command is then presented to the Validate process engine and a response is returned. This response is printed to to stdout (screen). The connection to Validate is closed and the program exits.

After creating a connection using the openValidate class function, more than one VC can be executed without the need to close and open the Validate environment for every call. In fact performance wise this is the prefered method.

Note

The C API of the libxml2 toolkit has been used in this example, while it is probably better to use a C++ implementation of this toolkit as libxml++. Internal Validate code will be changed as the project progresses.

The validate environment has to access the application Repository. This Repository can either be accessed via the network connecting to the Repository Web Service or it can be accessed using a direct local path to the Repository.

To compile the program using the network Repository access, use the following command:

g++ validate_test.cpp -o validate_test `pkg-config --cflags --libs prolinga-validate`

ProLinga-Soap Library libprolingasoapclient has to be available for this option.

To compile the program using direct local path Repository access, use the following command:

g++ validate_test.cpp -o validate_test `pkg-config --cflags --libs prolinga-validate_nonet`

ProLinga-Validate Library libprolingavalidate_nonet has to be available for this option.

You may need to set the environment variable PKG_CONFIG_PATH to point to the directories where prolinga-validate.pc is located. This can be directory /usr/lib/pkgconfig or directory /usr/local/lib/pkgconfig on GNU/Linux for example.

ProLinga-Validate is built using various 3rd party open source packages. These packages need to be available at compile time for a sucessful result. See the dependencies and prerequisites section for more details.