~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to prj/apx/src/app/apx-nrqst.als

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ---------------------------------------------------------------------------
2
 
# - apx-nrqst                                                               -
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.                  -
7
 
# -                                                                         -
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
 
# ---------------------------------------------------------------------------
16
 
 
17
 
# ----------------------------------------------------------------------------
18
 
# - global section                                                           -
19
 
# ----------------------------------------------------------------------------
20
 
 
21
 
# the request node class
22
 
const afnix:apx:request (class)
23
 
 
24
 
# ----------------------------------------------------------------------------
25
 
# - public section                                                          -
26
 
# ----------------------------------------------------------------------------
27
 
 
28
 
# the request tag name
29
 
const AFNIX:APX:XML-RQST-NAME "apx:request"
30
 
 
31
 
# ----------------------------------------------------------------------------
32
 
# - private section                                                          -
33
 
# ----------------------------------------------------------------------------
34
 
 
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"
38
 
 
39
 
# the request command/argument attribute name
40
 
const AFNIX:APX:XML-RNAM-ATTR "name"
41
 
const AFNIX:APX:XML-RVAL-ATTR "value"
42
 
 
43
 
# ----------------------------------------------------------------------------
44
 
# - initial section                                                          -
45
 
# ----------------------------------------------------------------------------
46
 
 
47
 
# initialize the apx request node
48
 
 
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)
52
 
}
53
 
 
54
 
# ----------------------------------------------------------------------------
55
 
# - method section                                                          -
56
 
# ----------------------------------------------------------------------------
57
 
 
58
 
# add a command value in the request node
59
 
# @param value the command value to set
60
 
 
61
 
trans afnix:apx:request:set-command (value) {
62
 
  # get the head node
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"
67
 
  }
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
72
 
  head:add-child rcmd
73
 
}
74
 
 
75
 
# get the request command node
76
 
 
77
 
trans afnix:apx:request:get-command-node nil {
78
 
  # get the head node
79
 
  const head (this:get-head-node)
80
 
  # get the command node
81
 
  head:lookup-child AFNIX:APX:XML-RCMD-NAME
82
 
}
83
 
 
84
 
# get the request command value
85
 
 
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
91
 
}
92
 
 
93
 
# add a command agument in the request node
94
 
# @param value the argument value to add
95
 
 
96
 
trans afnix:apx:request:add-argument-value (value) {
97
 
  # get the head node
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
103
 
  head:add-child rarg
104
 
}
105
 
 
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
109
 
 
110
 
trans afnix:apx:request:add-argument-name-value (name value) {
111
 
  # get the head node
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"
116
 
  }
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
122
 
  head:add-child rarg
123
 
}
124
 
 
125
 
# add an argument list
126
 
# @param argl the argument list to add
127
 
 
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
132
 
  for (attr) (argl) {
133
 
    trans name (attr:get-name)
134
 
    trans pval (attr:get-value)
135
 
    this:add-argument-name-value name pval
136
 
  }
137
 
}
138
 
 
139
 
# get the request arguments nodes
140
 
 
141
 
trans afnix:apx:request:get-argument-node-vector nil {
142
 
  # get the head node
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
146
 
}
147
 
 
148
 
# get the request argument values
149
 
 
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
154
 
  const argv (Vector)
155
 
  # loop in each node
156
 
  for (node) (xvec) {
157
 
    argv:append (node:get-attribute-value AFNIX:APX:XML-RVAL-ATTR)
158
 
  }
159
 
  # here is the result
160
 
  eval argv
161
 
}
162
 
 
163
 
# get the request argument value by name
164
 
# @param name the argument name
165
 
 
166
 
trans afnix:apx:request:get-argument-name-value (name) {
167
 
  # get the argument nodes vector
168
 
  const xvec (this:get-argument-node-vector)
169
 
  # loop in each node
170
 
  for (node) (xvec) {
171
 
    if (node:attribute-p AFNIX:APX:XML-RNAM-ATTR name) {
172
 
      return (node:get-attribute-value AFNIX:APX:XML-RVAL-ATTR)
173
 
    }
174
 
  }
175
 
  # not found
176
 
  throw "apx-error" (+ "invalid argument name " name)
177
 
}
178
 
 
179
 
# get the request argument list
180
 
 
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
185
 
  const argl (Plist)
186
 
  # loop in each node
187
 
  for (node) (xvec) {
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
194
 
      argl:set name pval
195
 
    }
196
 
  }
197
 
  # here is the result
198
 
  eval argl
199
 
}