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,154 @@
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
+ <% service_imports(schema, service, package).each do |import| %>
20
+ using <%= import %>;
21
+ <% end %>
22
+ namespace <%= package %>
23
+ {
24
+ public class <%= validate_class_name(classname) %> : BasePayPalService
25
+ {
26
+
27
+ static <%= validate_class_name(classname) %>()
28
+ {
29
+ DefaultSOAPAPICallHandler.XMLNamespaceProvider = new XmlNamespacePrefixProvider();
30
+ }
31
+
32
+ /// <summary>
33
+ /// Service Version
34
+ /// </summary>
35
+ private const string ServiceVersion = "";
36
+
37
+ /// <summary>
38
+ /// Service Name
39
+ /// </summary>
40
+ private const string ServiceName = "<%= classname %>";
41
+
42
+ /// <summary>
43
+ /// SDK Name
44
+ /// </summary>
45
+ private const string SDKName = "";
46
+
47
+ /// <summary>
48
+ /// SDK Version
49
+ /// </summary>
50
+ private const string SDKVersion = "";
51
+
52
+ /// <summary>
53
+ /// Default constructor for loading configuration from *.Config file
54
+ /// </summary>
55
+ public <%= validate_class_name(classname) %>() : base()
56
+ {
57
+
58
+ }
59
+
60
+ /// <summary>
61
+ /// constructor for passing in a dynamic configuration object
62
+ /// </summary>
63
+ public <%= validate_class_name(classname) %>(Dictionary<string, string> config) : base(config)
64
+ {
65
+
66
+ }
67
+
68
+ <% service.operations.each do |name, definition| %>
69
+ <% methodname = validate_method_name(name) %>
70
+ <% argumentHash = get_wsdl_operation_arguments(definition) %>
71
+ /// <summary>
72
+ ///
73
+ /// </summary>
74
+ <% if argumentHash.size > 0 %>
75
+ <% argumentHash.each do |name, type| %>
76
+ /// <param name="<%= name %>"><%= type %> request argument</param>
77
+ <% end %>
78
+ <% end %>
79
+ /// <param name="apiContext">APIContext argument</param>
80
+ public <%= definition.response %> <%= methodname %>(<% if argumentHash.size > 0 %><%= argumentHash.map{|name, type| "#{type.camelcase} #{name}"}.join(", ") %><% end %>, APIContext apiContext)
81
+ {
82
+ if (apiContext == null)
83
+ {
84
+ throw new ArgumentNullException("APIContext is null");
85
+ }
86
+ if (apiContext.HTTPHeaders == null)
87
+ {
88
+ apiContext.HTTPHeaders = new Dictionary<string, string>();
89
+ }
90
+ <%
91
+ if definition.soapAction.blank?
92
+ soapAction = "\"\""
93
+ else
94
+ soapAction = definition.soapAction
95
+ end
96
+ %>
97
+ apiContext.HTTPHeaders.Add("SOAPAction", <%= soapAction.inspect %>);
98
+ DefaultSOAPAPICallHandler apiCallPreHandler = new DefaultSOAPAPICallHandler(<% if argumentHash.size > 0 %><%= argumentHash.map{|name, type| "#{name}"}.join(", ") %><% end %>, apiContext, this.config, "<%= name %>");
99
+ XmlDocument xmlDocument = new XmlDocument();
100
+ string response = Call(apiCallPreHandler);
101
+ xmlDocument.LoadXml(response);
102
+ <%= definition.response %> <%= validate_property_as_argument(definition.response) %> = null;
103
+ XmlNode xmlNode = xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='<%= definition.response_property.name %>']");
104
+ if (xmlNode != null)
105
+ {
106
+ <%= validate_property_as_argument(definition.response) %> = new <%= definition.response %>(xmlNode);
107
+ }
108
+ <% if definition.fault %>
109
+ else
110
+ {
111
+ xmlNode = xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='Fault']/*[local-name()='detail']/*[local-name()='<%= definition.fault %>']");
112
+ if (xmlNode != null)
113
+ {
114
+ <%= definition.fault_property.name %> faultMessage = new <%= definition.fault_property.name %>(xmlNode);
115
+ throw faultMessage;
116
+ }
117
+ else
118
+ {
119
+ throw new Exception("Unable to parse response, response = " + response);
120
+ }
121
+
122
+ }
123
+ <% end %>
124
+ return <%= validate_property_as_argument(definition.response) %>;
125
+ }
126
+
127
+
128
+ <% end %>
129
+
130
+ private class XmlNamespacePrefixProvider : DefaultSOAPAPICallHandler.XmlNamespaceProvider
131
+ {
132
+
133
+ /// <summary>
134
+ /// Namespace Dictionary instance
135
+ /// </summary>
136
+ private Dictionary<string, string> namespaceDictionary;
137
+
138
+ public XmlNamespacePrefixProvider()
139
+ {
140
+ namespaceDictionary = new Dictionary<string, string>();
141
+ <% schema.namespaces.each do |namespace, prefix| %>
142
+ <% if prefix != '' %>
143
+ namespaceDictionary.Add("<%= prefix %>", "<%= namespace %>");
144
+ <% end %>
145
+ <% end %>
146
+ }
147
+
148
+ public Dictionary<string, string> GetNamespaceDictionary()
149
+ {
150
+ return namespaceDictionary;
151
+ }
152
+ }
153
+ }
154
+ }
@@ -0,0 +1,145 @@
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
+ package <%= package %>;
20
+
21
+ <% service_imports(schema, service, package).each do |import| %>
22
+ import <%= import %>;
23
+ <% end %>
24
+
25
+ public class <%= validate_class_name(classname) %> extends BaseService {
26
+
27
+ static {
28
+ DefaultSOAPAPICallHandler.setXmlNamespaceProvider(new XmlNamespacePrefixProvider());
29
+ }
30
+
31
+ // Service Version
32
+ public static final String SERVICE_VERSION = "";
33
+
34
+ // Service Name
35
+ public static final String SERVICE_NAME = "<%= classname %>";
36
+
37
+ //SDK Name
38
+ private static final String SDK_NAME = "";
39
+
40
+ //SDK Version
41
+ private static final String SDK_VERSION = "";
42
+
43
+ /**
44
+ * Default <code><%= validate_class_name(classname) %></code> Constructor.
45
+ * Initializes the SDK system with the default configuration file named
46
+ * 'sdk_config.properties' found in the class-path
47
+ */
48
+ public <%= validate_class_name(classname) %>() {
49
+ super.initializeToDefault();
50
+ }
51
+
52
+ /**
53
+ * <code><%= validate_class_name(classname) %></code> that uses the supplied
54
+ * {@link Properties} to initialize the SDK system. For values that the
55
+ * properties should holdconsult the documentation.
56
+ * The initialization context is maintained only for
57
+ * this instance of the class. Service level configuration.
58
+ *
59
+ * @param properties
60
+ * {@link Properties} object
61
+ */
62
+ public <%= validate_class_name(classname) %>(Properties properties) {
63
+ super(properties);
64
+ }
65
+
66
+ /**
67
+ * <code><%= validate_class_name(classname) %></code> that uses the supplied
68
+ * {@link Map} to initialize the SDK system. For values that the
69
+ * configurationMap should hold consult the documentation.
70
+ * The initialization context is maintained only for
71
+ * this instance of the class. Service level configuration.
72
+ *
73
+ * @param configurationMap
74
+ * {@link Map} object
75
+ */
76
+ public <%= validate_class_name(classname) %>(Map<String, String> configurationMap) {
77
+ super(configurationMap);
78
+ }
79
+
80
+ <% service.operations.each do |name, definition| %>
81
+ <% methodname = validate_method_name(name) %>
82
+ <% argumentHash = get_wsdl_operation_arguments(definition) %>
83
+ public <%= definition.response %> <%= methodname %>(<% if argumentHash.size > 0 %><%= argumentHash.map{|name, type| "#{type.camelcase} #{name}"}.join(", ") %><% end %>, BaseAPIContext baseAPIContext) throws SAXException, IOException, ParserConfigurationException, InvalidResponseDataException, HttpErrorException, ClientActionRequiredException, InvalidCredentialException, MissingCredentialException, OAuthException, SSLConfigurationException, InterruptedException {
84
+ if (baseAPIContext == null) {
85
+ throw new IllegalArgumentException("BaseAPIContext is null");
86
+ }
87
+ if (baseAPIContext.getHTTPHeaders() == null) {
88
+ baseAPIContext.setHTTPHeaders(new HashMap<String, String>());
89
+ }
90
+ <%
91
+ if definition.soapAction.blank?
92
+ soapAction = "\"\""
93
+ else
94
+ soapAction = definition.soapAction
95
+ end
96
+ %>
97
+ baseAPIContext.getHTTPHeaders().put("SOAPAction", <%= soapAction.inspect %>);
98
+ APICallPreHandler apiCallPreHandler = new DefaultSOAPAPICallHandler(<% if argumentHash.size > 0 %><%= argumentHash.map{|name, type| "#{name}"}.join(", ") %><% end %>, baseAPIContext, this.configurationMap, "<%= name %>");
99
+ String response = call(apiCallPreHandler);
100
+ InputSource inStream = new InputSource();
101
+ inStream.setCharacterStream(new StringReader((String) response));
102
+ try {
103
+ Node node = (Node) XPathFactory.newInstance().newXPath().evaluate("Envelope/Body/<%= definition.response_property.name %>", DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inStream), XPathConstants.NODE);
104
+ return new <%= definition.response %>(node);
105
+ } catch (XPathExpressionException exe) {
106
+ <% if definition.fault %>
107
+ try {
108
+ inStream = new InputSource();
109
+ inStream.setCharacterStream(new StringReader((String) response));
110
+ Node node = (Node) XPathFactory.newInstance().newXPath().evaluate("Envelope/Body/Fault/detail/<%= definition.fault %>", DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inStream), XPathConstants.NODE);
111
+ <%= definition.fault_property.name %> faultException = new <%= definition.fault_property.name %>(node);
112
+ throw faultException;
113
+ } catch (XPathExpressionException e) {
114
+ throw new RuntimeException("Unable to parse response", e);
115
+ }
116
+ <% else %>
117
+ throw new RuntimeException("Unable to parse response", exe);
118
+ <% end %>
119
+ }
120
+ }
121
+
122
+ <% end %>
123
+
124
+ /**
125
+ * Implementation of DefaultSOAPAPICallHandler.XmlNamespaceProvider
126
+ */
127
+ private static class XmlNamespacePrefixProvider implements XmlNamespaceProvider {
128
+
129
+ private Map<String, String> namespaceMap;
130
+
131
+ public XmlNamespacePrefixProvider() {
132
+ namespaceMap = new HashMap<String, String>();
133
+ <% schema.namespaces.each do |namespace, prefix| %>
134
+ <% if prefix != '' %>
135
+ namespaceMap.put("<%= prefix %>", "<%= namespace %>");
136
+ <% end %>
137
+ <% end %>
138
+ }
139
+
140
+ public Map<String, String> getNamespaceMap() {
141
+ return namespaceMap;
142
+ }
143
+ }
144
+
145
+ }
@@ -0,0 +1,92 @@
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
+ <?php
20
+ namespace <%= package %>;
21
+
22
+ <% service_imports(schema, service, package).each do |import| %>
23
+ use <%= import %>;
24
+ <% end %>
25
+ /**
26
+ * AUTO GENERATED service wrapper class
27
+ */
28
+ class <%= classname %> extends PPBaseService {
29
+
30
+ private static $SERVICE_NAME = "<%= classname %>";
31
+ private static $SERVICE_VERSION = "";
32
+ private static $SDK_NAME = "";
33
+ private static $SDK_VERSION = "";
34
+
35
+ public function __construct() {
36
+ parent::__construct('<%= classname %>', 'SOAP');
37
+ }
38
+ <% service.operations.each do |name, definition| %>
39
+ <% methodname = validate_method_name(name) %>
40
+
41
+ /**
42
+ * <%= definition.description %>
43
+ * @param <%= get_namespace(schema.data_types[definition.request].package) %>\<%= definition.request %> $<%= valid_property_name(definition.request) %>
44
+ * @param PayPal\Common\PPApiContext $apiContext
45
+ * @return <%= get_namespace(schema.data_types[definition.response].package) %>\<%= definition.response %>
46
+ <% if definition.fault %>
47
+ * @throws <%= get_namespace(schema.data_types[definition.fault].package) %>\<%= definition.fault %>
48
+ <% end %>
49
+ */
50
+ <% argument_array = get_wsdl_operation_arguments(definition) %>
51
+ public function <%= methodname %>(<% if argument_array.size > 0 %> <%= argument_array.join(', ') %><% end %>, $apiContext) {
52
+
53
+ $apiContext->addHttpHeader("SOAPAction", '"<%= definition.soapAction || '""' %>"');
54
+
55
+ $handlers = array(
56
+ new \PayPal\Handler\GenericSoapHandler($this->xmlNamespacePrefixProvider()),
57
+ );
58
+ $resp = $this->call('<%= classname %>', '<%= methodname %>', <% if argument_array.size > 0 %> <%= argument_array.join(', ') %><% end %>, $apiContext, $handlers);
59
+
60
+ $ret = new <%= definition.response %>();
61
+ <% if definition.fault %>
62
+ try {
63
+ $ret->init(PPUtils::xmlToArray($resp));
64
+ } catch (PPTransformerException $ex) {
65
+ $fault = new <%= definition.fault%>();
66
+ $fault->init(PPUtils::xmlToArray($resp));
67
+ throw $fault;
68
+ }
69
+ <% else %>
70
+ $ret->init(PPUtils::xmlToArray($resp));
71
+ <% end %>
72
+ return $ret;
73
+ }
74
+
75
+ <% end %>
76
+
77
+
78
+ /**
79
+ * fucntion with namespaces and corresponding prefixes used in SOAP request serialization
80
+ */
81
+ public function xmlNamespacePrefixProvider(){
82
+
83
+ $namespace = "";
84
+ <% schema.namespaces.each do |namespace, prefix| %>
85
+ <% if prefix != '' %>
86
+ $namespace .= 'xmlns:<%= prefix %>="<%= namespace %>" ';
87
+ <% end %>
88
+ <% end %>
89
+
90
+ return $namespace;
91
+ }
92
+ }
@@ -0,0 +1,139 @@
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
+ /// <summary>
20
+ /// Checks whether the node is empty space
21
+ /// </summary>
22
+ public static bool IsWhiteSpaceNode(XmlNode n)
23
+ {
24
+ if (n.NodeType == XmlNodeType.Text)
25
+ {
26
+ string val = n.InnerText;
27
+ return (val.Trim().Length == 0);
28
+ }
29
+ else if (n.NodeType == XmlNodeType.Element)
30
+ {
31
+ return (n.ChildNodes.Count == 0);
32
+ }
33
+ else
34
+ {
35
+ return false;
36
+ }
37
+ }
38
+
39
+ /// <summary>
40
+ /// Constructor using XmlNode parameter
41
+ /// </summary>
42
+ public <%= classname %> (XmlNode xmlNode)
43
+ {
44
+ XmlNode ChildNode = null;
45
+ XmlNodeList ChildNodeList = null;
46
+ <% type = data_type %>
47
+ <% while type %>
48
+ <% type.properties.each do |name , definition| %>
49
+ <% vname = validate_property_name(name, true) %>
50
+ <% if definition.array %>
51
+ ChildNodeList = xmlNode.SelectNodes("*[local-name() = '<%= name %>']");
52
+ if (ChildNodeList != null && ChildNodeList.Count > 0)
53
+ {
54
+ for(int i = 0; i < ChildNodeList.Count; i++)
55
+ {
56
+ <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
57
+ <% if definition.enum %>
58
+ string value = ChildNodeList[i].InnerText;
59
+ this.<%= vname %>.Add((<%= validate_class_name(definition.type) %>)ReflectionEnumUtil.GetValue(value, typeof(<%= validate_class_name(definition.type) %>)));
60
+ <% else %>
61
+ XmlNode subNode = ChildNodeList.Item(i);
62
+ this.<%= vname %>.Add(new <%= validate_class_name(definition.type) %>(subNode));
63
+
64
+ <% end %>
65
+ <% else %>
66
+ string value = ChildNodeList[i].InnerText;
67
+ <% if find_basic_type(definition.type) == 'string' %>
68
+ this.<%= vname %>.Add(value);
69
+ <% elsif find_basic_type(definition.type) == 'int' %>
70
+ this.<%= vname %>.Add(System.Convert.ToInt32(value));
71
+ <% elsif find_basic_type(definition.type) == 'bool' %>
72
+ this.<%= vname %>.Add(System.Convert.ToBoolean(value));
73
+ <% elsif find_basic_type(definition.type) == 'double' %>
74
+ this.<%= vname %>.add(System.Convert.ToDouble(value));
75
+ <% elsif find_basic_type(definition.type) == 'float' %>
76
+ this.<%= vname %>.add(System.Convert.ToSingle(value));
77
+ <% end %>
78
+ <% end %>
79
+ }
80
+ }
81
+ <% else %> // array
82
+ <% if is_complex_type(definition.type, schema) || is_enum_type(definition.type, schema) %>
83
+ <% if definition.enum %>
84
+ <% if definition.attribute %>
85
+ ChildNode = xmlNode.SelectSingleNode("@*[local-name() = '<%= name %>']");
86
+ if (ChildNode != null)
87
+ {
88
+ this.<%= vname %> = (<%= validate_class_name(definition.type) %>)ReflectionEnumUtil.GetValue(ChildNode.Value, typeof(<%= validate_class_name(definition.type) %>));
89
+ }
90
+ <% else %> // attribute
91
+ ChildNode = xmlNode.SelectSingleNode("*[local-name() = '<%= name %>']");
92
+ if(ChildNode != null && !IsWhiteSpaceNode(ChildNode))
93
+ {
94
+ this.<%= vname %> = (<%= validate_class_name(definition.type) %>)ReflectionEnumUtil.GetValue(ChildNode.InnerText,typeof(<%= validate_class_name(definition.type) %>));
95
+ }
96
+ <% end %> // attribute
97
+ <% else %> // non-enum
98
+ ChildNode = xmlNode.SelectSingleNode("*[local-name() = '<%= name %>']");
99
+ if(ChildNode != null && !IsWhiteSpaceNode(ChildNode))
100
+ {
101
+ this.<%= vname %> = new <%= validate_class_name(definition.type) %>(ChildNode);
102
+ }
103
+ <% end %> // enum
104
+ <% else %> // complex
105
+ <% if definition.value == '1' %>
106
+ <% if find_basic_type(definition.type) == 'string' %>
107
+ this.<%= vname %> = xmlNode.InnerText;
108
+ <% elsif find_basic_type(definition.type) == 'int' %>
109
+ this.<%= vname %> = System.Convert.ToInt32(xmlNode.InnerText);
110
+ <% elsif find_basic_type(definition.type) == 'bool' %>
111
+ this.<%= vname %> = System.Convert.ToBoolean(xmlNode.InnerText);
112
+ <% elsif find_basic_type(definition.type) == 'double' %>
113
+ this.<%= vname %> = System.Convert.ToDouble(xmlNode.InnerText);
114
+ <% elsif find_basic_type(definition.type) == 'float' %>
115
+ this.<%= vname %> = System.Convert.ToSingle(xmlNode.InnerText);
116
+ <% end %>
117
+ <% else %> // value
118
+ ChildNode = xmlNode.SelectSingleNode("*[local-name() = '<%= name %>']");
119
+ if(ChildNode != null && !IsWhiteSpaceNode(ChildNode))
120
+ {
121
+ <% if find_basic_type(definition.type) == 'string' %>
122
+ this.<%= vname %> = ChildNode.InnerText;
123
+ <% elsif find_basic_type(definition.type) == 'int' %>
124
+ this.<%= vname %> = System.Convert.ToInt32(ChildNode.InnerText);
125
+ <% elsif find_basic_type(definition.type) == 'bool' %>
126
+ this.<%= vname %> = System.Convert.ToBoolean(ChildNode.InnerText);
127
+ <% elsif find_basic_type(definition.type) == 'double' %>
128
+ this.<%= vname %> = System.Convert.ToDouble(ChildNode.InnerText);
129
+ <% elsif find_basic_type(definition.type) == 'float' %>
130
+ this.<%= vname %> = System.Convert.ToSingle(ChildNode.InnerText);
131
+ <% end %>
132
+ }
133
+ <% end %> // value
134
+ <% end %> // complex
135
+ <% end %> // array
136
+ <% end %>
137
+ <% type = schema.data_types[type.extends] %>
138
+ <% end %>
139
+ }