1
# ---------------------------------------------------------------------------
3
# - afnix:apx request node class module -
4
# ---------------------------------------------------------------------------
5
# - This program is free software; you can redistribute it and/or modify -
6
# - it provided that this copyright notice is kept intact. -
8
# - This program is distributed in the hope that it will be useful, but -
9
# - without any warranty; without even the implied warranty of -
10
# - merchantability or fitness for a particular purpose. In no event shall -
11
# - the copyright holder be liable for any direct, indirect, incidental or -
12
# - special damages arising in any way out of the use of this software. -
13
# ---------------------------------------------------------------------------
14
# - copyright (c) 1999-2007 amaury darsch -
15
# ---------------------------------------------------------------------------
17
# ----------------------------------------------------------------------------
19
# ----------------------------------------------------------------------------
21
# the request node class
22
const afnix:apx:request (class)
24
# ----------------------------------------------------------------------------
26
# ----------------------------------------------------------------------------
28
# the request tag name
29
const AFNIX:APX:XML-RQST-NAME "apx:request"
31
# ----------------------------------------------------------------------------
33
# ----------------------------------------------------------------------------
35
# the request command/argument tag name
36
const AFNIX:APX:XML-RCMD-NAME "apx:cmd"
37
const AFNIX:APX:XML-RARG-NAME "apx:arg"
39
# the request command/argument attribute name
40
const AFNIX:APX:XML-RNAM-ATTR "name"
41
const AFNIX:APX:XML-RVAL-ATTR "value"
43
# ----------------------------------------------------------------------------
45
# ----------------------------------------------------------------------------
47
# initialize the apx request node
49
trans afnix:apx:request:preset nil {
50
# set the base message object
51
trans this:super (afnix:apx:mesg AFNIX:APX:XML-RQST-NAME)
54
# ----------------------------------------------------------------------------
56
# ----------------------------------------------------------------------------
58
# add a command value in the request node
59
# @param value the command value to set
61
trans afnix:apx:request:set-command (value) {
63
const head (this:get-head-node)
64
# check if the command node exists
65
if (head:child-p AFNIX:APX:XML-RCMD-NAME) {
66
throw "apx-error" "command already exists in request node"
68
# create a command tag
69
const rcmd (afnix:xml:XmlTag AFNIX:APX:XML-RCMD-NAME)
70
rcmd:set-attribute AFNIX:APX:XML-RNAM-ATTR value
71
# add the node to the head
75
# get the request command node
77
trans afnix:apx:request:get-command-node nil {
79
const head (this:get-head-node)
80
# get the command node
81
head:lookup-child AFNIX:APX:XML-RCMD-NAME
84
# get the request command value
86
trans afnix:apx:request:get-command-value nil {
87
# get the command node
88
const rcmd (this:get-command-node)
89
# get the command attribute value
90
rcmd:get-attribute-value AFNIX:APX:XML-RNAM-ATTR
93
# add a command agument in the request node
94
# @param value the argument value to add
96
trans afnix:apx:request:add-argument-value (value) {
98
const head (this:get-head-node)
99
# create a argument tag
100
const rarg (afnix:xml:XmlTag AFNIX:APX:XML-RARG-NAME)
101
rarg:set-attribute AFNIX:APX:XML-RVAL-ATTR value
102
# add the node to the head
106
# add a command agument in the request node by name and value
107
# @param name the argument name to add
108
# @param value the argument value to add
110
trans afnix:apx:request:add-argument-name-value (name value) {
112
const head (this:get-head-node)
113
# check if the argument node exists
114
if (head:child-p AFNIX:APX:XML-RARG-NAME AFNIX:APX:XML-RNAM-ATTR name) {
115
throw "apx-error" "argument already exists in request node"
117
# create a argument tag
118
const rarg (afnix:xml:XmlTag AFNIX:APX:XML-RARG-NAME)
119
rarg:set-attribute AFNIX:APX:XML-RNAM-ATTR name
120
rarg:set-attribute AFNIX:APX:XML-RVAL-ATTR value
121
# add the node to the head
125
# add an argument list
126
# @param argl the argument list to add
128
trans afnix:apx:request:add-argument-list (argl) {
129
# make sure we have a property list
130
assert true (plist-p argl)
131
# loop in the attribute list
133
trans name (attr:get-name)
134
trans pval (attr:get-value)
135
this:add-argument-name-value name pval
139
# get the request arguments nodes
141
trans afnix:apx:request:get-argument-node-vector nil {
143
const head (this:get-head-node)
144
# select the argument nodes
145
afnix:apx:select-children-by-name head AFNIX:APX:XML-RARG-NAME
148
# get the request argument values
150
trans afnix:apx:request:get-argument-vector nil {
151
# get the argument nodes vector
152
const xvec (this:get-argument-node-vector)
153
# create a result list
157
argv:append (node:get-attribute-value AFNIX:APX:XML-RVAL-ATTR)
163
# get the request argument value by name
164
# @param name the argument name
166
trans afnix:apx:request:get-argument-name-value (name) {
167
# get the argument nodes vector
168
const xvec (this:get-argument-node-vector)
171
if (node:attribute-p AFNIX:APX:XML-RNAM-ATTR name) {
172
return (node:get-attribute-value AFNIX:APX:XML-RVAL-ATTR)
176
throw "apx-error" (+ "invalid argument name " name)
179
# get the request argument list
181
trans afnix:apx:request:get-argument-list nil {
182
# get the argument nodes vector
183
const xvec (this:get-argument-node-vector)
184
# create a result list
188
# check for a name attribute
189
if (node:attribute-p AFNIX:APX:XML-RNAM-ATTR) {
190
# get the name/value attribute
191
trans name (node:get-attribute-value AFNIX:APX:XML-RNAM-ATTR)
192
trans pval (node:get-attribute-value AFNIX:APX:XML-RVAL-ATTR)
193
# add the pair in the result list