DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
XmlFunctionProvider.cs
Go to the documentation of this file.
1 using System;
2 
4 using Deveel.Data.Routines;
5 using Deveel.Data.Sql;
6 using Deveel.Data.Sql.Fluid;
7 
8 
9 namespace Deveel.Data.Xml {
10  public sealed class XmlFunctionProvider : FunctionProvider {
11  public override string SchemaName {
12  get { return SystemSchema.Name; }
13  }
14 
15  protected override ObjectName NormalizeName(ObjectName functionName) {
16  if (functionName.Parent == null)
17  functionName = new ObjectName(new ObjectName(SchemaName), functionName.Name);
18 
19  return base.NormalizeName(functionName);
20  }
21 
22  private static InvokeResult Simple(InvokeContext context, Func<DataObject[], DataObject> func) {
23  var args = context.EvaluatedArguments;
24  var funcResult = func(args);
25  return context.Result(funcResult);
26  }
27 
28  protected override void OnInit() {
29  Register(config => config.Named("to_xml")
30  .WithStringParameter("s")
31  .WhenExecute(context => Simple(context, args => XmlFunctions.XmlType(args[0])))
32  .ReturnsType(XmlNodeType.XmlType));
33 
34  Register(config => config.Named("appendchildxml")
35  .WithXmlParameter("obj")
36  .WithStringParameter("xpath")
37  .WithXmlParameter("value")
38  .WhenExecute(context => Simple(context, args => XmlFunctions.AppendChild(args[0], args[1], args[2])))
39  .ReturnsXmlType());
40 
41  Register(config => config.Named("extract")
42  .WithXmlParameter("node")
43  .WithStringParameter("xpath")
44  .WhenExecute(context => Simple(context, args => XmlFunctions.Extract(args[0], args[1])))
45  .ReturnsXmlType());
46 
47  Register(config => config.Named("extractvalue")
48  .WithXmlParameter("node")
49  .WithStringParameter("xpath")
50  .WhenExecute(context => Simple(context, args => XmlFunctions.ExtractValue(args[0], args[1])))
51  .ReturnsType(Function.DynamicType));
52 
53  Register(config => config.Named("existsxml")
54  .WithXmlParameter("node")
55  .WithStringParameter("xpath")
56  .WhenExecute(context => Simple(context, args => XmlFunctions.Exists(args[0], args[1])))
57  .ReturnsXmlType());
58 
59  Register(config => config.Named("insertbeforexml")
60  .WithXmlParameter("node")
61  .WithStringParameter("xpath")
62  .WithXmlParameter("value")
63  .WhenExecute(context => Simple(context, args => XmlFunctions.InsertBefore(args[0], args[1], args[2])))
64  .ReturnsXmlType());
65 
66  Register(config => config.Named("insertchildxml")
67  .WithXmlParameter("node")
68  .WithStringParameter("xpath")
69  .WithXmlParameter("child")
70  .WithXmlParameter("value")
71  .WhenExecute(context => Simple(context, args => XmlFunctions.InsertChild(args[0], args[1], args[2], args[3])))
72  .ReturnsXmlType());
73 
74  Register(config => config.Named("updatexml")
75  .WithXmlParameter("node")
76  .WithStringParameter("xpath")
77  .WithDynamicParameter("value")
78  .WhenExecute(context => Simple(context, args => XmlFunctions.Update(args[0], args[1], args[2])))
79  .ReturnsXmlType());
80  }
81  }
82 }
static DataObject InsertChild(DataObject obj, DataObject xpath, DataObject child, DataObject value)
static DataObject Extract(DataObject obj, DataObject xpath)
static DataObject InsertBefore(DataObject obj, DataObject xpath, DataObject value)
static readonly SqlType DynamicType
A special SqlType that is used to mark an argument of a function as dynamic.
Definition: Function.cs:39
A system routine that returns a value at the end of its execution.
Definition: Function.cs:31
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static DataObject ExtractValue(DataObject obj, DataObject xpath)
static DataObject Exists(DataObject obj, DataObject xpath)
static DataObject XmlType(DataObject obj)
Definition: XmlFunctions.cs:29
Represents the result of the execution of a routine.
Definition: InvokeResult.cs:25
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
override ObjectName NormalizeName(ObjectName functionName)
Provides utilities and properties for handling the SYSTEN schema of a database.
Definition: SystemSchema.cs:37
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
InvokeResult Result(DataObject value)
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
const string Name
The name of the system schema that contains tables referring to system information.
static InvokeResult Simple(InvokeContext context, Func< DataObject[], DataObject > func)
static SqlXmlNode Update(SqlXmlNode node, string xpath, DataObject value)
static DataObject AppendChild(DataObject obj, DataObject xpath, DataObject value)