Skip to content

Commit 5b5bf17

Browse files
committed
Removed deprecated methods from Java. Fixed indentation.
Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
1 parent 7402afe commit 5b5bf17

6 files changed

Lines changed: 72 additions & 206 deletions

File tree

ocaml/sdk-gen/java/autogen/xen-api/src/main/java/com/xensource/xenapi/Connection.java

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,6 @@ public Connection(JsonRpcClient jsonRpcClient) {
6868
this.client = jsonRpcClient;
6969
}
7070

71-
/**
72-
* Creates a connection to a particular server using a given url. This object can then be passed
73-
* in to any other API calls.
74-
* <p>
75-
* Note this constructor does NOT call Session.loginWithPassword; the programmer is responsible for calling it,
76-
* passing the Connection as a parameter. No attempt to connect to the server is made until login is called.
77-
* <p>
78-
* When this constructor is used, a call to dispose() will do nothing. The programmer is responsible for manually
79-
* logging out the Session.
80-
*
81-
* @param httpClient The HttpClient used to make calls, this will be used by the underlying {@link #client} for handling requests
82-
* @param url The URL of the server to connect to. Should be of the form http(s)://host-url/jsonrpc or http(s)://host-url.
83-
* @param requestTimeout The reply timeout for JSON-RPC calls in seconds
84-
* @deprecated This constructor is deprecated. To set the {@code requestTimeout} please {@link #setRequestTimeout(int)}. You may also use the {@link com.xensource.xenapi.JsonRpcClient#setRequestTimeout(int)}
85-
* method of this object's {@link #client}. This option is only advisable if you are managing your own {@link com.xensource.xenapi.JsonRpcClient} as the underlying
86-
* {@link #client} for this object.
87-
*/
88-
@Deprecated
89-
public Connection(CloseableHttpClient httpClient, URL url, int requestTimeout) {
90-
this.client = new JsonRpcClient(httpClient, url);
91-
this.client.setRequestTimeout(requestTimeout);
92-
}
93-
9471
/**
9572
* Creates a connection to a particular server using a given url. This object can then be passed
9673
* in to any other API calls.
@@ -110,31 +87,6 @@ public Connection(URL url) {
11087
this.client = new JsonRpcClient(url);
11188
}
11289

113-
/**
114-
* Creates a connection to a particular server using a given url. This object can then be passed
115-
* in to any other API calls.
116-
* <p>
117-
* Note this constructor does NOT call Session.loginWithPassword; the programmer is responsible for calling it,
118-
* passing the Connection as a parameter. No attempt to connect to the server is made until login is called.
119-
* <p>
120-
* When this constructor is used, a call to dispose() will do nothing. The programmer is responsible for manually
121-
* logging out the Session.
122-
*
123-
* @param url The URL of the server to connect to. Should be of the form http(s)://host-url/jsonrpc or http(s)://host-url.
124-
* @param requestTimeout The reply timeout for JSON-RPC calls in seconds
125-
* @param connectionTimeout The connection timeout for JSON-RPC calls in seconds
126-
* @deprecated This constructor is deprecated. To set {@code requestTimeout} or {@code connectionTimeout} please use {@link #setRequestTimeout(int)} or {@link #setConnectionTimeout(int)} respectively.
127-
* You may also use the {@link com.xensource.xenapi.JsonRpcClient#setRequestTimeout(int)} method of this object's {@link #client}.
128-
* This option is only advisable if you are managing your own {@link com.xensource.xenapi.JsonRpcClient} as the underlying
129-
* {@link #client} for this object.
130-
*/
131-
@Deprecated
132-
public Connection(URL url, int requestTimeout, int connectionTimeout) {
133-
this.client = new JsonRpcClient(url);
134-
this.client.setRequestTimeout(requestTimeout);
135-
this.client.setConnectionTimeout(connectionTimeout);
136-
}
137-
13890
/**
13991
* Creates a connection to a particular server using a given url. This object can then be passed
14092
* in to any other API calls.
@@ -159,36 +111,6 @@ public Connection(URL url, String sessionReference) {
159111
this.sessionReference = sessionReference;
160112
}
161113

162-
/**
163-
* Creates a connection to a particular server using a given url. This object can then be passed
164-
* in to any other API calls.
165-
* <p>
166-
* Note this constructor does NOT call Session.loginWithPassword; the programmer is responsible for calling it,
167-
* passing the Connection as a parameter. No attempt to connect to the server is made until login is called.
168-
* <p>
169-
* When this constructor is used, a call to dispose() will do nothing. The programmer is responsible for manually
170-
* logging out the Session.
171-
*
172-
* @param url The URL of the server to connect to. Should be of the form http(s)://host-url/jsonrpc or http(s)://host-url.
173-
* @param sessionReference A reference to a logged-in Session. Any method calls on this Connection will use it.
174-
* This constructor does not call Session.loginWithPassword, and dispose() on the resulting
175-
* Connection object does not call Session.logout. The programmer is responsible for
176-
* ensuring the Session is logged in and out correctly.
177-
* @param requestTimeout The reply timeout for JSON-RPC calls in seconds
178-
* @param connectionTimeout The connection timeout for JSON-RPC calls in seconds
179-
* @deprecated This constructor is deprecated. To set {@code requestTimeout} or {@code connectionTimeout} please use {@link #setRequestTimeout(int)} or {@link #setConnectionTimeout(int)} respectively.
180-
* You may also use the {@link com.xensource.xenapi.JsonRpcClient#setRequestTimeout(int)} method of this object's {@link #client}.
181-
* This option is only advisable if you are managing your own {@link com.xensource.xenapi.JsonRpcClient} as the underlying
182-
* {@link #client} for this object.
183-
*/
184-
@Deprecated
185-
public Connection(URL url, String sessionReference, int requestTimeout, int connectionTimeout) {
186-
this.client = new JsonRpcClient(url);
187-
this.client.setRequestTimeout(requestTimeout);
188-
this.client.setConnectionTimeout(connectionTimeout);
189-
this.sessionReference = sessionReference;
190-
}
191-
192114
/**
193115
* Set the timeout in seconds for every request made by this object's {@link #client}.
194116
* If not set the value defaults to {@value JsonRpcClient#DEFAULT_REQUEST_TIMEOUT}.

ocaml/sdk-gen/java/autogen/xen-api/src/main/java/com/xensource/xenapi/CustomDateDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class CustomDateDeserializer extends StdDeserializer<Date> {
4949
/**
5050
* Array of {@link SimpleDateFormat} objects representing the date formats
5151
* used in xen-api responses.
52-
* <br />
52+
* <br>
5353
* RFC-3339 date formats can be returned in either Zulu or time zone agnostic.
5454
* This list is not an exhaustive list of formats supported by RFC-3339, rather
5555
* a set of formats that will enable the deserialization of xen-api dates.

ocaml/sdk-gen/java/autogen/xen-api/src/main/java/com/xensource/xenapi/JsonRpcClient.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,14 @@
5353

5454
/**
5555
* Provides a JSON-RPC v2.0 client for making remote procedure calls to xapi's backend URL.
56-
* <br />
56+
* <br>
5757
* This class enables the communication to the JSON-RPC backend. The client utilizes the HttpClient class for
5858
* sending HTTP POST requests with JSON payloads and the ObjectMapper class from the Jackson library for
5959
* serialization and deserialization of JSON data.
60-
* <br />
60+
* <br>
6161
* The client can be customised by passing it as a parameter to corresponding constructor, enabling custom
6262
* handling of requests.
63-
* <br />
64-
* <br />
63+
* <br>
6564
* By default, the timeout for requests is set to {@value #DEFAULT_REQUEST_TIMEOUT}. The default timeout for connecting to the
6665
* JSON-RPC backend is set to {@value #DEFAULT_CONNECTION_TIMEOUT} seconds. The maximum number of concurrent connections handled
6766
* by the underlying {@link PoolingHttpClientConnectionManager} is {@value #MAX_CONCURRENT_CONNECTIONS}.

ocaml/sdk-gen/java/main.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,6 @@ let get_types_json types =
501501
("name", `String type_string)
502502
; ("class_name", `String class_name)
503503
; ("method_name", `String method_name)
504-
; ( "suppress_unchecked_warning"
505-
, `Bool
506-
( match t with
507-
| Map _ | Record _ | Option (Record _) | Option (Map _) ->
508-
true
509-
| _ ->
510-
false
511-
)
512-
)
513504
; ( "generate_reference_task_result_func"
514505
, `Bool generate_reference_task_result_func
515506
)

ocaml/sdk-gen/java/templates/Class.mustache

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ public class {{class_name}} extends XenAPIObject {
6161
protected final String ref;
6262

6363
/**
64-
* For internal use only.
64+
* Creates an object from a given XenAPI reference (OpaqueRef)
65+
* @param ref The OpaqueRef from which to create the object.
6566
*/
66-
{{{class_name}}}(String ref) {
67+
public {{{class_name}}}(String ref) {
6768
this.ref = ref;
6869
}
6970

@@ -79,21 +80,17 @@ public class {{class_name}} extends XenAPIObject {
7980
* If obj is a {{{class_name}}}, compares XenAPI references for equality.
8081
*/
8182
@Override
82-
public boolean equals(Object obj)
83-
{
84-
if (obj instanceof {{{class_name}}})
85-
{
83+
public boolean equals(Object obj) {
84+
if (obj instanceof {{{class_name}}}) {
8685
{{{class_name}}} other = ({{{class_name}}}) obj;
8786
return other.ref.equals(this.ref);
88-
} else
89-
{
87+
} else {
9088
return false;
9189
}
9290
}
9391

9492
@Override
95-
public int hashCode()
96-
{
93+
public int hashCode() {
9794
return ref.hashCode();
9895
}
9996

ocaml/sdk-gen/java/templates/Types.mustache

Lines changed: 61 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -40,84 +40,77 @@ import java.util.regex.Pattern;
4040
*/
4141
public class Types
4242
{
43-
/**
44-
* Interface for all Record classes
45-
*/
46-
public interface Record
47-
{
48-
/**
49-
* Convert a Record to a Map
50-
*/
51-
Map<String, Object> toMap();
52-
}
53-
/**
54-
* Base class for all XenAPI Exceptions
55-
*/
56-
public static class XenAPIException extends IOException {
57-
public final String shortDescription;
58-
public final String[] errorDescription;
59-
XenAPIException(String shortDescription)
60-
{
61-
this.shortDescription = shortDescription;
62-
this.errorDescription = null;
63-
}
64-
XenAPIException(String[] errorDescription)
65-
{
66-
this.errorDescription = errorDescription;
67-
if (errorDescription.length > 0)
68-
{
69-
shortDescription = errorDescription[0];
70-
} else
71-
{
72-
shortDescription = "";
73-
}
74-
}
75-
public String toString()
76-
{
77-
if (errorDescription == null)
78-
{
79-
return shortDescription;
80-
} else if (errorDescription.length == 0)
81-
{
82-
return "";
83-
}
43+
/**
44+
* Interface for all Record classes
45+
*/
46+
public interface Record
47+
{
48+
/**
49+
* Convert a Record to a Map
50+
*/
51+
Map<String, Object> toMap();
52+
}
53+
/**
54+
* Base class for all XenAPI Exceptions
55+
*/
56+
public static class XenAPIException extends IOException {
57+
public final String shortDescription;
58+
public final String[] errorDescription;
59+
60+
XenAPIException(String shortDescription) {
61+
this.shortDescription = shortDescription;
62+
this.errorDescription = null;
63+
}
64+
65+
XenAPIException(String[] errorDescription) {
66+
this.errorDescription = errorDescription;
67+
if (errorDescription.length > 0) {
68+
shortDescription = errorDescription[0];
69+
} else {
70+
shortDescription = "";
71+
}
72+
}
73+
74+
public String toString() {
75+
if (errorDescription == null) {
76+
return shortDescription;
77+
} else if (errorDescription.length == 0) {
78+
return "";
79+
}
80+
8481
StringBuilder sb = new StringBuilder();
85-
for (int i = 0; i < errorDescription.length - 1; i++)
86-
{
82+
for (int i = 0; i < errorDescription.length - 1; i++) {
8783
sb.append(errorDescription[i]);
8884
}
8985
sb.append(errorDescription[errorDescription.length - 1]);
9086
return sb.toString();
9187
}
9288
}
9389

94-
/**
95-
* Thrown if the response from the server contains an invalid status.
96-
*/
97-
public static class BadServerResponse extends XenAPIException
98-
{
99-
public BadServerResponse(JsonRpcResponseError responseError)
100-
{
101-
super(String.valueOf(responseError));
102-
}
103-
}
90+
/**
91+
* Thrown if the response from the server contains an invalid status.
92+
*/
93+
public static class BadServerResponse extends XenAPIException {
94+
public BadServerResponse(JsonRpcResponseError responseError) {
95+
super(String.valueOf(responseError));
96+
}
97+
}
10498

105-
/**
106-
* Checks the provided server response was successful. If the call
107-
* failed, throws a XenAPIException. If the server
108-
* returned an invalid response, throws a BadServerResponse.
109-
* Otherwise, returns the server response as passed in.
110-
*/
111-
public static void checkError(JsonRpcResponseError response) throws XenAPIException, BadServerResponse
112-
{
99+
/**
100+
* Checks the provided server response was successful. If the call
101+
* failed, throws a XenAPIException. If the server
102+
* returned an invalid response, throws a BadServerResponse.
103+
* Otherwise, returns the server response as passed in.
104+
*/
105+
public static void checkError(JsonRpcResponseError response) throws XenAPIException, BadServerResponse {
113106
var errorData = response.data;
114-
if(errorData.length == 0){
107+
if(errorData.length == 0) {
115108
throw new BadServerResponse(response);
116109
}
117110
var errorName = response.message;
118111

119112
{{#errors}}
120-
if (errorName.equals("{{{name}}}")){
113+
if (errorName.equals("{{{name}}}")) {
121114
{{#err_params}}
122115
String p{{{index}}} = errorData.length > {{{index}}} ? errorData[{{{index}}}] : "";
123116
{{/err_params}}
@@ -180,50 +173,26 @@ public class Types
180173
/**
181174
* Create a new BadAsyncResult
182175
*/
183-
public BadAsyncResult(String result)
184-
{
176+
public BadAsyncResult(String result) {
185177
super(result);
186178
this.result = result;
187179
}
188180
}
189181

190-
{{#types}}
191-
/**
192-
* Converts an {@link Object} to a {@link {{{name}}}} object.
193-
* <br />
194-
* This method takes an {@link Object} as input and attempts to convert it into a {@link {{{name}}}} object.
195-
* If the input object is null, the method returns null. Otherwise, it creates a new {@link {{{name}}}}
196-
* object using the input object's {@link String} representation.
197-
* <br />
198-
* @param object The {@link Object} to be converted to a {@link {{{name}}}} object.
199-
* @return A {@link {{{name}}}} object created from the input {@link Object}'s {@link String} representation,
200-
* or null if the input object is null.
201-
* @deprecated this method will not be publicly exposed in future releases of this package.
202-
*/
203-
@Deprecated{{#suppress_unchecked_warning}}
204-
@SuppressWarnings("unchecked"){{/suppress_unchecked_warning}}
205-
public static {{{name}}} {{{method_name}}}(Object object) {
206-
if (object == null) {
207-
return null;
208-
}
209-
{{{method_body}}}
210-
}
211-
212-
{{/types}}
213-
214182
{{#types}}{{#generate_reference_task_result_func}}
215183
/**
216184
* Attempt to convert the {@link Task}'s result to a {@link {{{name}}}} object.
217185
* Will return null if the method cannot fetch a valid value from the {@link Task} object.
218186
* @param task The task from which to fetch the result.
219187
* @param connection The connection
220188
* @return the instantiated object if a valid value was found, null otherwise.
221-
* @throws BadServerResponse Thrown if the response from the server contains an invalid status.
189+
* @throws BadServerResponse if the response from the server contains an invalid status.
222190
* @throws XenAPIException if the call failed.
223-
* @throws IOException if an error occurs during a send or receive. This includes cases where a payload is invalid JSON.
191+
* @throws IOException if an error occurs during send or receive. This includes cases where a payload is invalid JSON.
224192
*/
225193
public static {{class_name}} to{{class_name}}(Task task, Connection connection) throws IOException {
226-
return Types.to{{class_name}}(parseResult(task.getResult(connection)));
194+
String result = parseResult(task.getResult(connection));
195+
return result == null || result.isEmpty() ? null : new {{class_name}}(result);
227196
}
228197

229198
{{/generate_reference_task_result_func}}
@@ -238,16 +207,4 @@ public class Types
238207

239208
return matcher.group(1);
240209
}
241-
242-
public static EventBatch toEventBatch(Object object) {
243-
if (object == null) {
244-
return null;
245-
}
246-
Map map = (Map) object;
247-
EventBatch batch = new EventBatch();
248-
batch.token = toString(map.get("token"));
249-
batch.validRefCounts = map.get("valid_ref_counts");
250-
batch.events = toSetOfEventRecord(map.get("events"));
251-
return batch;
252-
}
253210
}

0 commit comments

Comments
 (0)