genio 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,128 @@
1
+ <%
2
+ #
3
+ # Copyright 2013 PayPal Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ #
18
+ %>
19
+ /**
20
+ * Checks whether the node is empty space
21
+ */
22
+ private boolean isWhitespaceNode(Node n) {
23
+ if (n.getNodeType() == Node.TEXT_NODE) {
24
+ String val = n.getNodeValue();
25
+ return val.trim().length() == 0;
26
+ } else if (n.getNodeType() == Node.ELEMENT_NODE ) {
27
+ return (n.getChildNodes().getLength() == 0);
28
+ } else {
29
+ return false;
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Constructor using a Node parameter
35
+ */
36
+ public <%= classname %> (Node node) throws XPathExpressionException {
37
+ XPathFactory factory = XPathFactory.newInstance();
38
+ XPath xpath = factory.newXPath();
39
+ Node childNode = null;
40
+ NodeList nodeList = null;
41
+ <% type = data_type %>
42
+ <% while type %>
43
+ <% type.properties.each do |name , definition| %>
44
+ <% vname = validate_property_name(name) %>
45
+ <% if definition.array %>
46
+ nodeList = (NodeList) xpath.evaluate("<%= name %>", node, XPathConstants.NODESET);
47
+ if (nodeList != null && nodeList.getLength() > 0) {
48
+ for (int i = 0; i < nodeList.getLength(); i++) {
49
+ Node subNode = nodeList.item(i);
50
+ <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
51
+ <% if definition.enum %>
52
+ String value = subNode.getTextContent();
53
+ this.<%= vname %>.add(<%= validate_class_name(definition.type) %>.fromValue(value));
54
+ <% else %>
55
+ this.<%= vname %>.add(new <%= validate_class_name(definition.type) %>(subNode));
56
+ <% end %>
57
+ <% else %>
58
+ String value = subNode.getTextContent();
59
+ <% if find_basic_type(definition.type) == 'String' %>
60
+ this.<%= vname %>.add(value);
61
+ <% elsif find_basic_type(definition.type) == 'Integer' %>
62
+ this.<%= vname %>.add(Integer.valueOf(value));
63
+ <% elsif find_basic_type(definition.type) == 'Boolean' %>
64
+ this.<%= vname %>.add(Boolean.valueOf(value));
65
+ <% elsif find_basic_type(definition.type) == 'Double' %>
66
+ this.<%= vname %>.add(Double.valueOf(value));
67
+ <% elsif find_basic_type(definition.type) == 'Float' %>
68
+ this.<%= vname %>.add(Float.valueOf(value));
69
+ <% end %>
70
+ <% end %>
71
+ }
72
+ }
73
+ <% else %>
74
+ <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
75
+ <% if definition.enum %>
76
+ <% if definition.attribute %>
77
+ childNode = (Node) xpath.evaluate("@<%= name %>", node, XPathConstants.NODE);
78
+ if (childNode != null) {
79
+ this.<%= vname %> = <%= validate_class_name(definition.type) %>.fromValue(childNode.getNodeValue());
80
+ }
81
+ <% else %>
82
+ childNode = (Node) xpath.evaluate("<%= name %>", node, XPathConstants.NODE);
83
+ if (childNode != null && !isWhitespaceNode(childNode)) {
84
+ this.<%= vname %> = <%= validate_class_name(definition.type) %>.fromValue(childNode.getTextContent());
85
+ }
86
+ <% end %>
87
+ <% else %>
88
+ childNode = (Node) xpath.evaluate("<%= name %>", node, XPathConstants.NODE);
89
+ if (childNode != null && !isWhitespaceNode(childNode)) {
90
+ this.<%= vname %> = new <%= validate_class_name(definition.type) %>(childNode);
91
+ }
92
+ <% end %>
93
+ <% else %>
94
+ <% if definition.value == '1' %>
95
+ String value = node.getTextContent();
96
+ <% if find_basic_type(definition.type) == 'String' %>
97
+ this.<%= vname %> = value;
98
+ <% elsif find_basic_type(definition.type) == 'Integer' %>
99
+ this.<%= vname %> = Integer.valueOf(value);
100
+ <% elsif find_basic_type(definition.type) == 'Boolean' %>
101
+ this.<%= vname %> = Boolean.valueOf(value);
102
+ <% elsif find_basic_type(definition.type) == 'Double' %>
103
+ this.<%= vname %> = Double.valueOf(value);
104
+ <% elsif find_basic_type(definition.type) == 'Float' %>
105
+ this.<%= vname %> = Float.valueOf(value);
106
+ <% end %>
107
+ <% else %>
108
+ childNode = (Node) xpath.evaluate("<%= name %>", node, XPathConstants.NODE);
109
+ if (childNode != null && !isWhitespaceNode(childNode)) {
110
+ <% if find_basic_type(definition.type) == 'String' %>
111
+ this.<%= vname %> = childNode.getTextContent();
112
+ <% elsif find_basic_type(definition.type) == 'Integer' %>
113
+ this.<%= vname %> = Integer.valueOf(childNode.getTextContent());
114
+ <% elsif find_basic_type(definition.type) == 'Boolean' %>
115
+ this.<%= vname %> = Boolean.valueOf(childNode.getTextContent());
116
+ <% elsif find_basic_type(definition.type) == 'Double' %>
117
+ this.<%= vname %> = Double.valueOf(childNode.getTextContent());
118
+ <% elsif find_basic_type(definition.type) == 'Float' %>
119
+ this.<%= vname %> = Float.valueOf(childNode.getTextContent());
120
+ <% end %>
121
+ }
122
+ <% end %>
123
+ <% end %>
124
+ <% end %>
125
+ <% end %>
126
+ <% type = schema.data_types[type.extends] %>
127
+ <% end %>
128
+ }
@@ -0,0 +1,184 @@
1
+ <%
2
+ #
3
+ # Copyright 2013 PayPal Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ #
18
+ %>
19
+ <% if operation_input %>
20
+ public String ToXMLString()
21
+ {
22
+ return ToXMLString("<%= serialization_name.split(':').first %>", "<%= serialization_name.split(':').last %>");
23
+ }
24
+ <% end %>
25
+
26
+ /// <summary>
27
+ /// Serialize the object to XML String form
28
+ /// </summary>
29
+ public String ToXMLString(string prefix, string name)
30
+ {
31
+ StringBuilder sb = new StringBuilder();
32
+ if (name != null)
33
+ {
34
+ <% if contains_attribute(data_type) %>
35
+ if (prefix != null)
36
+ {
37
+ sb.Append("<").Append(prefix + ":").Append(name);
38
+ }
39
+ else
40
+ {
41
+ sb.Append("<").Append(name);
42
+ }
43
+ sb.Append(GetAttributeAsXml());
44
+ sb.Append(">");
45
+ <% else %>
46
+ if (prefix != null)
47
+ {
48
+ sb.Append("<").Append(prefix + ":").Append(name).Append(">");
49
+ }
50
+ else
51
+ {
52
+ sb.Append("<").Append(name).Append(">");
53
+ }
54
+ <% end %>
55
+ }
56
+ <% type = data_type %>
57
+ <% while type %>
58
+ <% type.properties.each do |name , definition| %>
59
+ <% if !definition.attribute %>
60
+ <% vname = validate_property_name(name, true) %>
61
+ if (this.<%= vname %> != null)
62
+ {
63
+ <% if definition.array %>
64
+ for (int i = 0; i < this.<%= vname %>.Count; i++)
65
+ {
66
+ <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
67
+ <% if definition.enum %>
68
+ sb.Append("<");
69
+ <% if should_qualify_name(definition.package, schema) %>
70
+ sb.Append("<%= definition.package %>:");
71
+ <% end %>
72
+ sb.Append("<%= name %>>").Append(SDKUtil.EscapeInvalidXmlCharsRegex(ReflectionEnumUtil.GetDescription(this.<%= vname %>[i]))).Append("</");
73
+ <% if should_qualify_name(definition.package, schema) %>
74
+ sb.Append("<%= definition.package %>:");
75
+ <% end %>
76
+ sb.Append("<%= name %>>");
77
+ <% else %>
78
+ <% if should_qualify_name(definition.package, schema) %>
79
+ sb.Append(this.<%= vname %>[i].ToXMLString("<%= definition.package %>","<%= name %>"));
80
+ <% else %>
81
+ sb.Append(this.<%= vname %>[i].ToXMLString(null,"<%= name %>"));
82
+ <% end %>
83
+ <% end %>
84
+ <% else %>
85
+ <% if definition.value == '1' %>
86
+ sb.Append(SDKUtil.EscapeInvalidXmlCharsRegex(<% if find_basic_type(definition.type) == 'double' %>Convert.ToString(Value[i], DefaultCulture)<% else %>Value[i]<% end %>));
87
+ <% else %>
88
+ sb.Append("<");
89
+ <% if should_qualify_name(definition.package, schema) %>
90
+ sb.Append("<%= definition.package %>:");
91
+ <% end %>
92
+ sb.Append("<%= name %>>").Append(SDKUtil.EscapeInvalidXmlCharsRegex(<% if find_basic_type(definition.type) == 'double' %>Convert.ToString(this.<%= vname %>[i], DefaultCulture)<% else %>this.<%= vname %>[i]<% end %>));
93
+ sb.Append("</");
94
+ <% if should_qualify_name(definition.package, schema) %>
95
+ sb.Append("<%= definition.package %>:");
96
+ <% end %>
97
+ sb.Append("<%= name %>>");
98
+ <% end %>
99
+ <% end %>
100
+ }
101
+ <% else %>
102
+ <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
103
+ <% if definition.enum %>
104
+ sb.Append("<");
105
+ <% if should_qualify_name(definition.package, schema) %>
106
+ sb.Append("<%= definition.package %>:");
107
+ <% end %>
108
+ sb.Append("<%= name %>>").Append(SDKUtil.EscapeInvalidXmlCharsRegex(ReflectionEnumUtil.GetDescription(this.<%= vname %>))).Append("</");
109
+ <% if should_qualify_name(definition.package, schema) %>
110
+ sb.Append("<%= definition.package %>:");
111
+ <% end %>
112
+ sb.Append("<%= name %>>");
113
+ <% else %>
114
+ <% if should_qualify_name(definition.package, schema) %>
115
+ sb.Append(this.<%= vname %>.ToXMLString("<%= definition.package %>","<%= name %>"));
116
+ <% else %>
117
+ sb.Append(this.<%= vname %>.ToXMLString(null, "<%= name %>"));
118
+ <% end %>
119
+ <% end %>
120
+ <% else %>
121
+ <% if definition.value == '1' %>
122
+ sb.Append(SDKUtil.EscapeInvalidXmlCharsRegex(<% if find_basic_type(definition.type) == 'double' %>Convert.ToString(Value, DefaultCulture)<% else %>Value<% end %>));
123
+ <% else %>
124
+ sb.Append("<");
125
+ <% if should_qualify_name(definition.package, schema) %>
126
+ sb.Append("<%= definition.package %>:");
127
+ <% end %>
128
+ sb.Append("<%= name %>>");
129
+ sb.Append(SDKUtil.EscapeInvalidXmlCharsRegex(<% if find_basic_type(definition.type) == 'double' %>Convert.ToString(this.<%= vname %>, DefaultCulture)<% else %>this.<%= vname %><% end %>));
130
+ sb.Append("</");
131
+ <% if should_qualify_name(definition.package, schema) %>
132
+ sb.Append("<%= definition.package %>:");
133
+ <% end %>
134
+ sb.Append("<%= name %>>");
135
+ <% end %>
136
+ <% end %>
137
+ <% end %>
138
+ }
139
+ <% end %>
140
+ <% end %>
141
+ <% type = schema.data_types[type.extends] %>
142
+ <% end %>
143
+ if (name != null)
144
+ {
145
+ if (prefix != null)
146
+ {
147
+ sb.Append("</").Append(prefix + ":").Append(name).Append(">");
148
+ }
149
+ else
150
+ {
151
+ sb.Append("</").Append(name).Append(">");
152
+ }
153
+ }
154
+ return sb.ToString();
155
+ }
156
+
157
+ <% if contains_attribute(data_type) %>
158
+
159
+ /// <summary>
160
+ /// Serializes attributes if any
161
+ /// </summary>
162
+ private String GetAttributeAsXml()
163
+ {
164
+ StringBuilder sb = new StringBuilder();
165
+ <% type = data_type %>
166
+ <% while type %>
167
+ <% type.properties.each do |name , definition| %>
168
+ <% if definition.attribute %>
169
+ <% vname = validate_property_name(name, true) %>
170
+ if (this.<%= vname %> != null)
171
+ {
172
+ <% if definition.enum %>
173
+ sb.Append(" <%= name %>=\"").Append(SDKUtil.EscapeInvalidXmlCharsRegex(ReflectionEnumUtil.GetDescription(this.<%= vname %>))).Append("\"");
174
+ <% else %>
175
+ sb.Append(" <%= name %>=\"").Append(SDKUtil.EscapeInvalidXmlCharsRegex(this.<%= vname %>)).Append("\"");
176
+ <% end %>
177
+ }
178
+ <% end %>
179
+ <% end %>
180
+ <% type = schema.data_types[type.extends] %>
181
+ <% end %>
182
+ return sb.ToString();
183
+ }
184
+ <% end %>
@@ -0,0 +1,170 @@
1
+ <%
2
+ #
3
+ # Copyright 2013 PayPal Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ #
18
+ %>
19
+ <% if operation_input %>
20
+ public String toXMLString() {
21
+ return toXMLString("<%= serialization_name.split(':').first %>", "<%= serialization_name.split(':').last %>");
22
+ }
23
+ <% end %>
24
+
25
+ /**
26
+ * Serialize the object to XML String form
27
+ * @param prefix
28
+ * Namespace prefix to use during serialization
29
+ * @param name
30
+ * Name used for serialization
31
+ */
32
+ public String toXMLString(String prefix, String name) {
33
+ StringBuilder sb = new StringBuilder();
34
+ if (name != null) {
35
+ <% if contains_attribute(data_type) %>
36
+ if (prefix != null) {
37
+ sb.append("<").append(prefix + ":").append(name);
38
+ } else {
39
+ sb.append("<").append(name);
40
+ }
41
+ sb.append(getAttributeAsXml());
42
+ sb.append(">");
43
+ <% else %>
44
+ if (prefix != null) {
45
+ sb.append("<").append(prefix + ":").append(name).append(">");
46
+ } else {
47
+ sb.append("<").append(name).append(">");
48
+ }
49
+ <% end %>
50
+ }
51
+ <% type = data_type %>
52
+ <% while type %>
53
+ <% type.properties.each do |name , definition| %>
54
+ <% if !definition.attribute %>
55
+ <% vname = validate_property_name(name) %>
56
+ if (this.<%= vname %> != null) {
57
+ <% if definition.array %>
58
+ for (int i=0; i < this.<%= vname %>.size(); i++) {
59
+ <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
60
+ <% if definition.enum %>
61
+ sb.append("<");
62
+ <% if should_qualify_name(definition.package, schema) %>
63
+ sb.append("<%= definition.package %>:");
64
+ <% end %>
65
+ sb.append("<%= name %>>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>.get(i).getValue())).append("</");
66
+ <% if should_qualify_name(definition.package, schema) %>
67
+ sb.append("<%= definition.package %>:");
68
+ <% end %>
69
+ sb.append("<%= name %>>");
70
+ <% else %>
71
+ <% if should_qualify_name(definition.package, schema) %>
72
+ sb.append(this.<%= vname %>.get(i).toXMLString("<%= definition.package %>","<%= name %>"));
73
+ <% else %>
74
+ sb.append(this.<%= vname %>.get(i).toXMLString(null,"<%= name %>"));
75
+ <% end %>
76
+ <% end %>
77
+ <% else %>
78
+ <% if definition.value == '1' %>
79
+ sb.append(SDKUtil.escapeInvalidXmlCharsRegex(value.get(i)));
80
+ <% else %>
81
+ sb.append("<");
82
+ <% if should_qualify_name(definition.package, schema) %>
83
+ sb.append("<%= definition.package %>:");
84
+ <% end %>
85
+ sb.append("<%= name %>>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>.get(i)));
86
+ sb.append("</");
87
+ <% if should_qualify_name(definition.package, schema) %>
88
+ sb.append("<%= definition.package %>:");
89
+ <% end %>
90
+ sb.append("<%= name %>>");
91
+ <% end %>
92
+ <% end %>
93
+ }
94
+ <% else %>
95
+ <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
96
+ <% if definition.enum %>
97
+ sb.append("<");
98
+ <% if should_qualify_name(definition.package, schema) %>
99
+ sb.append("<%= definition.package %>:");
100
+ <% end %>
101
+ sb.append("<%= name %>>").append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>.getValue())).append("</");
102
+ <% if should_qualify_name(definition.package, schema) %>
103
+ sb.append("<%= definition.package %>:");
104
+ <% end %>
105
+ sb.append("<%= name %>>");
106
+ <% else %>
107
+ <% if should_qualify_name(definition.package, schema) %>
108
+ sb.append(this.<%= vname %>.toXMLString("<%= definition.package %>","<%= name %>"));
109
+ <% else %>
110
+ sb.append(this.<%= vname %>.toXMLString(null, "<%= name %>"));
111
+ <% end %>
112
+ <% end %>
113
+ <% else %>
114
+ <% if definition.value == '1' %>
115
+ sb.append(SDKUtil.escapeInvalidXmlCharsRegex(value));
116
+ <% else %>
117
+ sb.append("<");
118
+ <% if should_qualify_name(definition.package, schema) %>
119
+ sb.append("<%= definition.package %>:");
120
+ <% end %>
121
+ sb.append("<%= name %>>");
122
+ sb.append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>));
123
+ sb.append("</");
124
+ <% if should_qualify_name(definition.package, schema) %>
125
+ sb.append("<%= definition.package %>:");
126
+ <% end %>
127
+ sb.append("<%= name %>>");
128
+ <% end %>
129
+ <% end %>
130
+ <% end %>
131
+ }
132
+ <% end %>
133
+ <% end %>
134
+ <% type = schema.data_types[type.extends] %>
135
+ <% end %>
136
+ if (name != null) {
137
+ if (prefix != null) {
138
+ sb.append("</").append(prefix + ":").append(name).append(">");
139
+ } else {
140
+ sb.append("</").append(name).append(">");
141
+ }
142
+ }
143
+ return sb.toString();
144
+ }
145
+
146
+ <% if contains_attribute(data_type) %>
147
+ /**
148
+ * Serializes attributes if any
149
+ */
150
+ private String getAttributeAsXml() {
151
+ StringBuilder sb = new StringBuilder();
152
+ <% type = data_type %>
153
+ <% while type %>
154
+ <% type.properties.each do |name , definition| %>
155
+ <% if definition.attribute %>
156
+ <% vname = validate_property_name(name) %>
157
+ if (this.<%= vname %> != null) {
158
+ <% if definition.enum %>
159
+ sb.append(" <%= name %>=\"").append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>.getValue())).append("\"");
160
+ <% else %>
161
+ sb.append(" <%= name %>=\"").append(SDKUtil.escapeInvalidXmlCharsRegex(this.<%= vname %>)).append("\"");
162
+ <% end %>
163
+ }
164
+ <% end %>
165
+ <% end %>
166
+ <% type = schema.data_types[type.extends] %>
167
+ <% end %>
168
+ return sb.toString();
169
+ }
170
+ <% end %>