SaxonC 13.1.0
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_API_NO 1210
29
30#include <iostream>
31#include <map>
32#include <sstream>
33#include <stdexcept> // std::logic_error
34#include <string>
35#include <vector>
36
37#include "saxonc_export.h"
38#include "saxonc/DocumentBuilder.h"
39#include "saxonc/SaxonApiException.h"
40#include "saxonc/SaxonCGlue.h"
41#include "saxonc/SaxonCXPath.h"
42#include "saxonc/SchemaValidator.h"
43#include "saxonc/XPathProcessor.h"
44#include "saxonc/XQueryProcessor.h"
45#include "saxonc/Xslt30Processor.h"
46#include "saxonc/UserFunctionHandler.h"
47#include "saxonc/XsltExecutable.h"
48
49
50//#define MEM_DEBUG
51#if defined MEM_DEBUG
52
53#include <algorithm>
54#include <cstdlib>
55#include <new>
56
57static std::vector<void *> myAlloc;
58
59void *newImpl(std::size_t sz, char const *file, int line);
60
61void *operator new(std::size_t sz, char const *file, int line);
62
63void *operator new[](std::size_t sz, char const *file, int line);
64
65void operator delete(void *ptr) noexcept;
66
67void operator delete(void *, std::size_t) noexcept;
68
69#endif
70
71class Xslt30Processor;
72
73class XQueryProcessor;
74
75class XPathProcessor;
76
77class SchemaValidator;
78
79class XsdCompiler;
80
81class XdmValue;
82
83class XdmNode;
84
85class XdmItem;
86
87class XdmAtomicValue;
88
89class XdmFunctionItem;
90
91class XdmArray;
92
93class XdmMap;
94
95class XsltExecutable;
96
97class DocumentBuilder;
98
100
101
102typedef enum eXdmType {
103 XDM_VALUE = 0,
104 XDM_ATOMIC_VALUE = 1,
105 XDM_NODE = 2,
106 XDM_ARRAY = 3,
107 XDM_MAP = 4,
108 XDM_FUNCTION_ITEM = 5,
109 XDM_EMPTY = 6,
110 XDM_ITEM = 7,
111} XDM_TYPE;
112
114 std::string ns;
115 std::string functionName;
116 XdmValue * (*func)(int, XdmValue **);
117 std::string returnTypeStr;
118 std::string arguments;
119 XdmValue * argumentTypes;
120 XdmValue * returnType;
121} ;
122
123
124
125//extern "C" void * c_nativeCall(char * functionName, void * proc, void * func, int useNativeTypes, int numOfArguments, void ** arguments);
126
127
128
129//==========================================
130
137class SAXONC_EXPORT SaxonProcessor {
138
139 friend class DocumentBuilder;
140
141 friend class Xslt30Processor;
142
143 friend class XsltExecutable;
144
145 friend class XQueryProcessor;
146
147 friend class SchemaValidator;
148
149 friend class XsdCompiler;
150
151 friend class XPathProcessor;
152
153 friend class XdmValue;
154
155 friend class XdmItem;
156
157 friend class XdmAtomicValue;
158
159 friend class XdmFunctionItem;
160
161 friend class XdmNode;
162
163 friend class XdmMap;
164
165 friend class XdmArray;
166
167public:
175
176
183 SaxonProcessor(const char *configFile);
184
191 SaxonProcessor(bool l);
192
198 SaxonProcessor &operator=(const SaxonProcessor &other);
199
204 SaxonProcessor(const SaxonProcessor &other);
205
210
217 DocumentBuilder *newDocumentBuilder();
218
225 Xslt30Processor *newXslt30Processor();
226
233 XQueryProcessor *newXQueryProcessor();
234
241 XPathProcessor *newXPathProcessor();
242
254 SchemaValidator *newSchemaValidator();
255
265 XsdCompiler *newXsdCompiler();
266
274 XdmAtomicValue *makeStringValue(std::string str,
275 const char *encoding = nullptr);
276
284 XdmAtomicValue *makeStringValue(const char *str,
285 const char *encoding = nullptr);
286
295 XdmAtomicValue *makeIntegerValue(int i);
296
302 XdmAtomicValue *makeDoubleValue(double d);
303
309 XdmAtomicValue *makeFloatValue(float f);
310
319 XdmAtomicValue *makeLongValue(long l);
320
326 XdmAtomicValue *makeBooleanValue(bool b);
327
333 XdmAtomicValue *makeQNameValue(const char *str);
334
342 XdmAtomicValue *makeAtomicValue(const char *type, const char *value);
343
351 XdmArray *makeArray(char **input, int length);
352
360 XdmArray *makeArray(short *input, int length);
361
369 XdmArray *makeArray(int *input, int length);
370
378 XdmArray *makeArray(long long *input, int length);
379
387 XdmArray *makeArray(bool *input, int length);
388
396 XdmArray *makeArray(XdmValue **values, int length);
397
398
399 static void * makeInternalArray(void **inputs, int length);
400
408 XdmMap *makeMap(std::map<XdmAtomicValue *, XdmValue *> dataMap);
409
417 static XdmMap *makeMap2(std::map<std::string, XdmValue *> dataMap);
418
427 XdmMap *makeMap3(XdmAtomicValue **keys, XdmValue **values, int len);
428
440 const char *clarkNameToEQName(const char *name);
441
449 const char *EQNameToClarkName(const char *name);
450
456 const char *getStringValue(XdmItem *item);
457
469 XdmNode *parseXmlFromString(const char *source,
470 const char *encoding = nullptr,
471 SchemaValidator *validator = nullptr);
472
482 XdmNode *parseXmlFromFile(const char *source,
483 SchemaValidator *validator = nullptr);
484
494 XdmNode *parseXmlFromUri(const char *source,
495 SchemaValidator *validator = nullptr);
496
505 XdmValue *parseJsonFromString(const char *source,
506 const char *encoding = NULL);
507
516 XdmValue *parseJsonFromFile(const char *source);
517
523 int getNodeKind(int64_t obj);
524
530 bool isSchemaAwareProcessor();
531
532
536 XdmValue **createXdmValueArray(int len) { return (new XdmValue *[len]); }
537
544 void deleteXdmValueArray(XdmValue **arr, int len);
545
550 return (new XdmAtomicValue *[len]);
551 }
552
559 void deleteXdmAtomicValueArray(XdmAtomicValue **arr, int len);
560
561
565 static const char * encodeString(const char * stringValue, const char * toCharSetName);
566
570 static void release();
571
575 static void attachCurrentThread();
576
580 static graal_isolatethread_t * getOrAttachCurrentThread(sxnc_environment * sxn);
581
585 static void detachCurrentThread();
586
590 static void attachCurrentThread(sxnc_environment * sxn);
591
595 static void detachCurrentThread(sxnc_environment * sxn);
596
601 void setcwd(const char *cwd);
602
607 const char *getcwd();
608
613 const char *getResourcesDirectory();
614
619 void setResourcesDirectory(const char *dir);
620
627 void setCatalog(const char *catalogFile);
628
635 void setCatalogFiles(const char **catalogFiles, int length);
636
645 void setConfigurationProperty(const char *name, const char *value);
646
650 void clearConfigurationProperties();
651
656 bool isLicensed();
657
665 const char * getSaxonEdition();
666
671 const char *version();
672
696 void registerUserFunction(const char * ns, XdmValue * (*func)(int, XdmValue **), const char * signatureJSON, bool useNativeTypes=false);
697
698 void registerUserFunctionWithProcessor(void * procPtr, const char * ns, void * func, const char * signatureJSON, bool useNativeTypes=false);
699
701
707 /*void addNativeMethod(char *name, char *signature, void *fnPtr) {
708
709 JNINativeMethod method;
710 method.name = name;
711 method.signature = signature;
712 method.fnPtr = fnPtr;
713
714 nativeMethodVect.push_back(method);
715
716
717 }*/
718
720
729 /*bool registerCPPFunction(char *libName, JNINativeMethod *gMethods = nullptr)
730 { if (libName != nullptr) { setConfigurationProperty("extc", libName);
731
732 }
733
734 if (gMethods == nullptr && nativeMethodVect.size() == 0) {
735 return false;
736 } else {
737 if (gMethods == nullptr) {
738 //copy vector to gMethods
739 gMethods = new JNINativeMethod[nativeMethodVect.size()];
740 }
741 return registerNativeMethods(sxn_environ->env,
742 "com/saxonica/functions/extfn/CppCall$PhpFunctionCall", gMethods,
743 nativeMethodVect.size());
744
745
746 }
747 return false;
748 } */
749
751
758 /*static bool registerNativeMethods(JNIEnv *env, const char *className,
759 JNINativeMethod *gMethods, int numMethods) {
760 jclass clazz;
761 clazz = env->FindClass(className);
762 if (clazz == nullptr) {
763 std::cerr << "Native registration unable to find class " << className
764 << std::endl; return false;
765 }
766
767 if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
768 // std::cerr<<"RegisterNatives failed for "<< className<<std::endl;
769 return false;
770 }
771 return true;
772 } **/
773
774 static int jvmCreatedCPP;
776 static sxnc_environment
779 std::string cwd;
785 static void deleteString(const char *data) {
786 if (data != nullptr) {
787 operator delete((char *)data);
788 data = nullptr;
789 }
790 }
791
795 static void createHeapDump(bool live);
796
797 static XdmItem *makeXdmItemFromRef(int64_t valueRef);
798
799 static XdmValue *makeXdmValueFromRef(int64_t valueRef);
800
801protected:
802
803
811 SaxonProcessor(int64_t procRef, bool license=false);
812
813 std::string cwdV;
814 // std::string resources_dir; /*!< Saxon resources directory */
815 std::string versionStr;
816 std::map<std::string, XdmValue *>
819 //std::map<std::string, std::string>
820 // configProperties; /*!< Map of properties used for the transformation as
821 // (string, string) pairs */
822 bool licensei;
825 int64_t procRef;
828private:
829 // void createException(const char *message = nullptr);
830
831 void initialize(bool l);
832
833 void applyConfigurationProperties();
834
835 // SaxonC method for internal use
836 static int64_t
837 createParameterJArray(std::map<std::string, XdmValue *> parameters,
838 std::map<std::string, std::string> properties,
839 int additions = 0);
840
841 static int64_t
842 createParameterJArray2(std::map<std::string, XdmValue *> parameters);
843
844 static int64_t createJArray(XdmValue **values, int length);
845
849 static void destroyHandle(int64_t handleRef);
850
854 static void getInfo();
855};
856
857//===============================================================================================
858
859#endif /* SAXON_PROCESSOR_H */
This C header file contains a number of factory functions for running SaxonC C/C++ APIs,...
EXTERN_SAXONC SAXONC_EXPORT const char * version(sxnc_environment *environi, sxnc_processor *proc)
Get the Saxon version.
Definition SaxonCProcessor.c:6
SAXONC_EXPORT void setCatalog(sxnc_environment *environi, sxnc_processor *proc, char *cwd, char *catalogFileName)
Set a catalog file to be used in Saxon.
Definition SaxonCProcessor.c:52
SAXONC_EXPORT void setCatalogFiles(sxnc_environment *environi, sxnc_processor *proc, char *cwd, char **catalogFileName, int length)
Set multiple catalog files to be used in Saxon.
Definition SaxonCProcessor.c:78
SAXONC_EXPORT void setConfigurationProperty(sxnc_environment *environi, sxnc_processor *proc, char *name, char *value)
Set a configuration property specific to the processor in use.
Definition SaxonCProcessor.c:38
SaxonCXPath.h provides the C API for XPath processing. This file contains a set of functions to compi...
SAXONC_EXPORT const char * getStringValue(sxnc_environment *environi, sxnc_value value)
Get the string value of the item.
Definition SaxonCXPath.c:240
A document builder holds properties controlling how a Saxon document tree should be built,...
Definition DocumentBuilder.h:35
SaxonApiException.
Definition SaxonApiException.h:25
The SaxonProcessor class acts as a factory for generating XQuery, XPath, Schema and XSLT compilers.
Definition SaxonProcessor.h:137
std::string cwdV
Definition SaxonProcessor.h:813
static sxnc_environment * sxn_environ
Definition SaxonProcessor.h:777
std::map< std::string, XdmValue * > parameters
Definition SaxonProcessor.h:817
XdmValue ** createXdmValueArray(int len)
Utility method for working with SaxonC on Python - internal use only.
Definition SaxonProcessor.h:536
XdmAtomicValue ** createXdmAtomicValueArray(int len)
Utility method for working with SaxonC on Python - internal use only.
Definition SaxonProcessor.h:549
std::string cwd
Definition SaxonProcessor.h:779
std::string versionStr
Definition SaxonProcessor.h:815
bool licensei
Definition SaxonProcessor.h:822
static void deleteString(const char *data)
Utility method required for the python and PHP extensions to delete a string created in the C++ code-...
Definition SaxonProcessor.h:785
static int jvmCreatedCPP
Add a native method.
Definition SaxonProcessor.h:774
int64_t procRef
Definition SaxonProcessor.h:825
Definition SchemaValidator.h:27
An XPathProcessor represents a factory to compile, load and execute XPath expressions.
Definition XPathProcessor.h:67
An XQueryProcessor represents a factory to compile, load and execute queries.
Definition XQueryProcessor.h:26
An array in the XDM data model.
Definition XdmArray.h:27
The class XdmAtomicValue represents an item in an XPath sequence that is an atomic value.
Definition XdmAtomicValue.h:27
The class XdmFunctionItem represents a function item.
Definition XdmFunctionItem.h:26
The class XdmItem represents an item in a sequence, as defined by the XDM data model.
Definition XdmItem.h:31
A map in the XDM data model.
Definition XdmMap.h:30
This class represents a node in the XDM data model.
Definition XdmNode.h:57
An XdmValue represents a value in the XDM data model.
Definition XdmValue.h:33
Definition XsdCompiler.h:49
An Xslt30Processor represents a factory to compile, load and execute stylesheets.
Definition Xslt30Processor.h:31
An XsltExecutable represents the compiled form of a stylesheet.
Definition XsltExecutable.h:33
Definition SaxonProcessor.h:113
sxnc_environment.
Definition SaxonCGlue.h:85