SaxonC 12.5
Saxon Processor library for C/C++, PHP and Python
Loading...
Searching...
No Matches
SaxonProcessor.h
1
2// Copyright (c) 2022 - 2023 Saxonica Limited.
3// This Source Code Form is subject to the terms of the Mozilla Public License,
4// v. 2.0. If a copy of the MPL was not distributed with this file, You can
5// obtain one at http://mozilla.org/MPL/2.0/. This Source Code Form is
6// "Incompatible With Secondary Licenses", as defined by the Mozilla Public
7// License, v. 2.0.
9
10#ifndef SAXON_PROCESSOR_H
11#define SAXON_PROCESSOR_H
12
13#if defined __linux__ || defined __APPLE__
14
15#include <dlfcn.h>
16#include <stdlib.h>
17#include <string>
18
19#define HANDLE void *
20#define LoadLibrary(x) dlopen(x, RTLD_LAZY)
21#define GetProcAddress(x, y) dlsym(x, y)
22#else
23#include <windows.h>
24#endif
25
26//#define DEBUG //remove
27//#define MEM_DEBUG //remove
28#define CVERSION "12.5.0"
29#define CVERSION_API_NO 1210
30
31#include <iostream>
32#include <map>
33#include <sstream>
34#include <stdexcept> // std::logic_error
35#include <string>
36#include <vector>
37
38#include "DocumentBuilder.h"
39#include "SaxonApiException.h"
40#include "SaxonCGlue.h"
41#include "SaxonCXPath.h"
42#include "SchemaValidator.h"
43#include "XPathProcessor.h"
44#include "XQueryProcessor.h"
45#include "Xslt30Processor.h"
46#include "XsltExecutable.h"
47//#include "com_saxonica_functions_extfn_PhpCall.h"
48//#include "com_saxonica_functions_extfn_PhpCall_PhpFunctionCall.h"
49//#define MEM_DEBUG
50#if defined MEM_DEBUG
51
52#include <algorithm>
53#include <cstdlib>
54#include <new>
55
56static std::vector<void *> myAlloc;
57
58void *newImpl(std::size_t sz, char const *file, int line);
59
60void *operator new(std::size_t sz, char const *file, int line);
61
62void *operator new[](std::size_t sz, char const *file, int line);
63
64void operator delete(void *ptr) noexcept;
65
66void operator delete(void *, std::size_t) noexcept;
67
68#endif
69
70class Xslt30Processor;
71
72class XQueryProcessor;
73
74class XPathProcessor;
75
76class SchemaValidator;
77
78class XdmValue;
79
80class XdmNode;
81
82class XdmItem;
83
84class XdmAtomicValue;
85
86class XdmFunctionItem;
87
88class XdmArray;
89
90class XdmMap;
91
92class XsltExecutable;
93
94class DocumentBuilder;
95
97
98typedef enum eXdmType {
99 XDM_VALUE = 0,
100 XDM_ATOMIC_VALUE = 1,
101 XDM_NODE = 2,
102 XDM_ARRAY = 3,
103 XDM_MAP = 4,
104 XDM_FUNCTION_ITEM = 5,
105 XDM_EMPTY = 6,
106 XDM_ITEM = 7,
107} XDM_TYPE;
108
109//==========================================
110
113
118
119 friend class DocumentBuilder;
120
121 friend class Xslt30Processor;
122
123 friend class XsltExecutable;
124
125 friend class XQueryProcessor;
126
127 friend class SchemaValidator;
128
129 friend class XPathProcessor;
130
131 friend class XdmValue;
132
133 friend class XdmAtomicValue;
134
135 friend class XdmFunctionItem;
136
137 friend class XdmNode;
138
139 friend class XdmMap;
140
141 friend class XdmArray;
142
143public:
145
151
153
158 SaxonProcessor(const char *configFile);
159
161
166 SaxonProcessor(bool l);
167
169
174
176
180 SaxonProcessor(const SaxonProcessor &other);
181
185
187
191 const char *getErrorMessage();
192
194
200
202
207
209
215
218
224
227
233
236
245 XdmAtomicValue *makeStringValue(std::string str,
246 const char *encoding = nullptr);
247
250
259 XdmAtomicValue *makeStringValue(const char *str,
260 const char *encoding = nullptr);
261
271
273
279
281
288
291
299
301
309
311
316 XdmAtomicValue *makeQNameValue(const char *str);
317
319
327 XdmAtomicValue *makeAtomicValue(const char *type, const char *value);
328
330
337 XdmArray *makeArray(const char **input, int length);
338
340
347 XdmArray *makeArray(short *input, int length);
348
350
357 XdmArray *makeArray(int *input, int length);
358
360
367 XdmArray *makeArray(long long *input, int length);
368
376 XdmArray *makeArray(bool *input, int length);
377
379
386 XdmArray *makeArray(XdmValue **values, int length);
387
389
396 XdmMap *makeMap(std::map<XdmAtomicValue *, XdmValue *> dataMap);
397
399
406 static XdmMap *makeMap2(std::map<std::string, XdmValue *> dataMap);
407
409
417 XdmMap *makeMap3(XdmAtomicValue **keys, XdmValue **values, int len);
418
420
430 const char *clarkNameToEQName(const char *name);
431
433
440 const char *EQNameToClarkName(const char *name);
441
443
447 const char *getStringValue(XdmItem *item);
448
451
462 XdmNode *parseXmlFromString(const char *source,
463 const char *encoding = nullptr,
464 SchemaValidator *validator = nullptr);
465
467
476 XdmNode *parseXmlFromFile(const char *source,
477 SchemaValidator *validator = nullptr);
478
480
489 XdmNode *parseXmlFromUri(const char *source,
490 SchemaValidator *validator = nullptr);
491
494
502 XdmValue *parseJsonFromString(const char *source,
503 const char *encoding = NULL);
504
506
514 XdmValue *parseJsonFromFile(const char *source);
515
517
522 int getNodeKind(int64_t obj);
523
525
531
533
538 bool exceptionOccurred();
539
542 void exceptionClear();
543
545 XdmValue **createXdmValueArray(int len) { return (new XdmValue *[len]); }
546
548
553 void deleteXdmValueArray(XdmValue **arr, int len);
554
557 return (new XdmAtomicValue *[len]);
558 }
559
561
566 void deleteXdmAtomicValueArray(XdmAtomicValue **arr, int len);
567
571 /*JNIEnv *env, jclass callingClass, jobject callingObject*/);
572
575 static void release();
576
578 static void attachCurrentThread();
579
581 static void detachCurrentThread();
582
584 void setcwd(const char *cwd);
585
587
591 const char *getcwd();
592
594
598 const char *getResourcesDirectory();
599
601 void setResourcesDirectory(const char *dir);
602
609 void setCatalog(const char *catalogFile);
610
617 void setCatalogFiles(const char **catalogFiles, int length);
618
620
628 void setConfigurationProperty(const char *name, const char *value);
629
632
634
638 const char *version();
639
641
647 /*void addNativeMethod(char *name, char *signature, void *fnPtr) {
648
649 JNINativeMethod method;
650 method.name = name;
651 method.signature = signature;
652 method.fnPtr = fnPtr;
653
654 nativeMethodVect.push_back(method);
655
656
657 }*/
658
660
669 /*bool registerCPPFunction(char *libName, JNINativeMethod *gMethods = nullptr)
670 { if (libName != nullptr) { setConfigurationProperty("extc", libName);
671
672 }
673
674 if (gMethods == nullptr && nativeMethodVect.size() == 0) {
675 return false;
676 } else {
677 if (gMethods == nullptr) {
678 //copy vector to gMethods
679 gMethods = new JNINativeMethod[nativeMethodVect.size()];
680 }
681 return registerNativeMethods(sxn_environ->env,
682 "com/saxonica/functions/extfn/CppCall$PhpFunctionCall", gMethods,
683 nativeMethodVect.size());
684
685
686 }
687 return false;
688 } */
689
691
698 /*static bool registerNativeMethods(JNIEnv *env, const char *className,
699 JNINativeMethod *gMethods, int numMethods) {
700 jclass clazz;
701 clazz = env->FindClass(className);
702 if (clazz == nullptr) {
703 std::cerr << "Native registration unable to find class " << className
704 << std::endl; return false;
705 }
706
707 if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
708 // std::cerr<<"RegisterNatives failed for "<< className<<std::endl;
709 return false;
710 }
711 return true;
712 } **/
713
716
721 // SaxonApiException *checkAndCreateException(jclass cppClass);
722
723 static int jvmCreatedCPP;
725 static sxnc_environment
728 std::string cwd;
732
736 static void deleteString(const char *data, char deleteFlag=0) {
737 if (data != nullptr && deleteFlag == 0) {
738 operator delete((char *)data);
739 data = nullptr;
740 }
741 }
742
743
745 void createHeapDump(bool live);
746
750 static void getInfo();
751
752 /*static JavaVM *jvm;*/
753
754protected:
755 // jclass xdmAtomicClass; /*!< The XdmAtomicValue instance */
756 // jclass versionClass; /*!< The Version instance */
757 // jclass procClass; /*!< The Saxon Processor instance */
758 // jclass saxonCAPIClass; /*!< The SaxonCAPI instance */
759 std::string cwdV;
760 // std::string resources_dir; /*!< current Saxon resources directory */
761 std::string versionStr;
762 std::map<std::string, XdmValue *>
765 std::map<std::string, std::string>
768 bool licensei;
771 int64_t procRef;
772
773 // JNINativeMethod *nativeMethods; /*!< native methods variable used in
774 // extension methods */ std::vector<JNINativeMethod> nativeMethodVect; /*!<
775 // Vector of native methods defined by user */
780private:
781 // void createException(const char *message = nullptr);
782
783 void initialize(bool l);
784
785 void applyConfigurationProperties();
786
787 // SaxonC method for internal use
788 static int64_t
789 createParameterJArray(std::map<std::string, XdmValue *> parameters,
790 std::map<std::string, std::string> properties,
791 int additions = 0);
792
793 static int64_t
794 createParameterJArray2(std::map<std::string, XdmValue *> parameters);
795
796 static int64_t createJArray(XdmValue **values, int length);
797
798 static XdmValue *makeXdmValueFromRef(int64_t valueRef);
799
800 static XdmItem *makeXdmItemFromRef(int64_t valueRef);
801
802 static const char *checkException();
803};
804
805//===============================================================================================
806
807#endif /* SAXON_PROCESSOR_H */
This C header file contains a number of factory functions for running SaxonC C/C++ APIs,...
SaxonCXPath.h provides the C API for XPath processing. This file contains a set of functions to compi...
Definition DocumentBuilder.h:35
Definition SaxonApiException.h:23
Definition SaxonProcessor.h:117
void setcwd(const char *cwd)
Set the current working directory.
Definition SaxonProcessor.cpp:701
XdmAtomicValue * makeStringValue(std::string str, const char *encoding=nullptr)
Definition SaxonProcessor.cpp:956
const char * getResourcesDirectory()
Get saxon resources directory.
Definition SaxonProcessor.cpp:709
void setCatalog(const char *catalogFile)
Definition SaxonProcessor.cpp:724
XdmNode * parseXmlFromFile(const char *source, SchemaValidator *validator=nullptr)
Parse a source document file and return it as an XdmNode.
Definition SaxonProcessor.cpp:853
XdmMap * makeMap3(XdmAtomicValue **keys, XdmValue **values, int len)
Make an XdmMap from an array of keys and values.
Definition SaxonProcessor.cpp:1254
static void detachCurrentThread()
Detach JVM from the current thread.
Definition SaxonProcessor.cpp:283
std::string cwdV
Definition SaxonProcessor.h:759
static void release()
Definition SaxonProcessor.cpp:910
XdmAtomicValue * makeAtomicValue(const char *type, const char *value)
Create an Xdm Atomic value from string representation.
Definition SaxonProcessor.cpp:1017
XdmNode * parseXmlFromUri(const char *source, SchemaValidator *validator=nullptr)
Parse a source document available by URI and return it as an XdmNode.
Definition SaxonProcessor.cpp:872
const char * getErrorMessage()
Get any error message thrown by the processor.
Definition SaxonProcessor.cpp:104
XdmValue * parseJsonFromString(const char *source, const char *encoding=NULL)
Definition SaxonProcessor.cpp:786
void setResourcesDirectory(const char *dir)
set saxon resources directory
Definition SaxonProcessor.cpp:713
static sxnc_environment * sxn_environ
Definition SaxonProcessor.h:726
static XdmMap * makeMap2(std::map< std::string, XdmValue * > dataMap)
Make an XdmMap whose argument is a map from the standard template library.
Definition SaxonProcessor.cpp:1215
void clearConfigurationProperties()
Clear configuration properties specific to the processor in use.
Definition SaxonProcessor.cpp:902
void exceptionClear()
Definition SaxonProcessor.cpp:111
XdmAtomicValue * makeBooleanValue(bool b)
Factory method: makes a XdmAtomicValue representing a boolean Value.
Definition SaxonProcessor.cpp:1002
SaxonProcessor()
A default constructor.
Definition SaxonProcessor.cpp:232
const char * getStringValue(XdmItem *item)
Get the string representation of the XdmValue.
Definition SaxonProcessor.cpp:1042
std::map< std::string, XdmValue * > parameters
Definition SaxonProcessor.h:763
XdmAtomicValue * makeQNameValue(const char *str)
Create an QName Xdm value from string representation in clark notation.
Definition SaxonProcessor.cpp:1010
SchemaValidator * newSchemaValidator()
Definition SaxonProcessor.cpp:681
const char * getcwd()
Get the current working directory.
Definition SaxonProcessor.cpp:707
const char * clarkNameToEQName(const char *name)
Convert clark name string to EQName notation.
Definition SaxonProcessor.cpp:1028
XdmAtomicValue * makeDoubleValue(double d)
Factory method. make an XdmAtomicValue from a primitive double value.
Definition SaxonProcessor.cpp:976
XdmAtomicValue * makeIntegerValue(int i)
Definition SaxonProcessor.cpp:966
XdmValue * parseJsonFromFile(const char *source)
Parse a source JSON file and return it as an XdmValue.
Definition SaxonProcessor.cpp:806
bool exceptionOccurred()
Checks for thrown exceptions.
Definition SaxonProcessor.cpp:81
const char * EQNameToClarkName(const char *name)
Convert EQName string to clark name notation.
Definition SaxonProcessor.cpp:1035
static SaxonApiException * checkForExceptionCPP()
Definition SaxonProcessor.cpp:125
void createHeapDump(bool live)
Internal method for diagnostics.
Definition SaxonProcessor.cpp:906
void setConfigurationProperty(const char *name, const char *value)
Set a configuration property specific to the processor in use.
Definition SaxonProcessor.cpp:894
void deleteXdmValueArray(XdmValue **arr, int len)
Utility method for Python API - internal use only.
Definition SaxonProcessor.cpp:933
void setCatalogFiles(const char **catalogFiles, int length)
Definition SaxonProcessor.cpp:751
XdmValue ** createXdmValueArray(int len)
Utility method for working with SaxonC on Python.
Definition SaxonProcessor.h:545
XdmAtomicValue ** createXdmAtomicValueArray(int len)
Utility method for working with SaxonC on Python.
Definition SaxonProcessor.h:556
XQueryProcessor * newXQueryProcessor()
Create an XQueryProcessor.
Definition SaxonProcessor.cpp:671
static void deleteString(const char *data, char deleteFlag=0)
Definition SaxonProcessor.h:736
const char * version()
Get the Saxon version.
Definition SaxonProcessor.cpp:692
static void getInfo()
Xslt30Processor * newXslt30Processor()
Create an Xslt30Processor.
Definition SaxonProcessor.cpp:665
std::string cwd
Definition SaxonProcessor.h:728
void deleteXdmAtomicValueArray(XdmAtomicValue **arr, int len)
Utility method for Python API - internal use only.
Definition SaxonProcessor.cpp:939
static void attachCurrentThread()
Attaches a current thread to the a Java VM.
Definition SaxonProcessor.cpp:270
std::string versionStr
Definition SaxonProcessor.h:761
XdmAtomicValue * makeLongValue(long l)
Definition SaxonProcessor.cpp:992
bool licensei
Definition SaxonProcessor.h:768
~SaxonProcessor()
Definition SaxonProcessor.cpp:330
std::map< std::string, std::string > configProperties
Definition SaxonProcessor.h:766
bool isSchemaAwareProcessor()
Test whether this processor is schema-aware.
Definition SaxonProcessor.cpp:353
SaxonProcessor & operator=(const SaxonProcessor &other)
The copy assignment= operator.
Definition SaxonProcessor.cpp:631
int getNodeKind(int64_t obj)
Get the kind of node.
Definition SaxonProcessor.cpp:846
SaxonApiException * exception
Definition SaxonProcessor.h:777
DocumentBuilder * newDocumentBuilder()
Create a DocumentBuilder.
Definition SaxonProcessor.cpp:655
XdmMap * makeMap(std::map< XdmAtomicValue *, XdmValue * > dataMap)
Make an XdmMap whose argument is a map from the standard template library.
Definition SaxonProcessor.cpp:1181
XdmArray * makeArray(const char **input, int length)
Make an XdmArray whose members are from string representation.
Definition SaxonProcessor.cpp:1158
static int jvmCreatedCPP
Add a native method.
Definition SaxonProcessor.h:723
XdmNode * parseXmlFromString(const char *source, const char *encoding=nullptr, SchemaValidator *validator=nullptr)
Definition SaxonProcessor.cpp:825
XPathProcessor * newXPathProcessor()
Definition SaxonProcessor.cpp:676
int64_t procRef
ObjectHandle reference to the underlying processor.
Definition SaxonProcessor.h:771
XdmAtomicValue * makeFloatValue(float f)
Factory method. make an XdmAtomicValue from a primitive float value.
Definition SaxonProcessor.cpp:985
Definition SchemaValidator.h:25
Definition XPathProcessor.h:63
Definition XQueryProcessor.h:24
Definition XdmArray.h:26
Definition XdmAtomicValue.h:26
Definition XdmFunctionItem.h:25
Definition XdmItem.h:30
Definition XdmMap.h:29
Definition XdmNode.h:56
Definition XdmValue.h:42
Definition Xslt30Processor.h:28
Definition XsltExecutable.h:29
Definition SaxonCGlue.h:79