forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotation parser refactor (Azure#193)
* Rename classes in RestProxy, inline populateMatrix() function * Working on proxy details classes * Rearrange v2 RestProxy classes and add tests * Fix checkstyle errors * Pass checkstyle. Extract HttpClient and SerializerAdapter from RestClient for RestProxy * Updates based on pull request reviews
- Loading branch information
1 parent
08e7fda
commit 856a8f6
Showing
18 changed files
with
1,106 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
client-runtime/src/main/java/com/microsoft/rest/v2/EncodedParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.rest.v2; | ||
|
||
/** | ||
* An EncodedParameter is the result of encoding a query parameter or header name/value pair for a | ||
* HTTP request. It contains the query parameter or header name, plus the query parameter's value or | ||
* header's value. | ||
*/ | ||
class EncodedParameter { | ||
private final String name; | ||
private final String encodedValue; | ||
|
||
/** | ||
* Create a new EncodedParameter using the provided parameter name and encoded value. | ||
* @param name The name of the new parameter. | ||
* @param encodedValue The encoded value of the new parameter. | ||
*/ | ||
EncodedParameter(String name, String encodedValue) { | ||
this.name = name; | ||
this.encodedValue = encodedValue; | ||
} | ||
|
||
/** | ||
* Get this parameter's name. | ||
* @return The name of this parameter. | ||
*/ | ||
public String name() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Get the encoded value for this parameter. | ||
* @return The encoded value for this parameter. | ||
*/ | ||
public String encodedValue() { | ||
return encodedValue; | ||
} | ||
|
||
/** | ||
* Get whether or not this value equals the provided rhs value. | ||
* @param rhs The value to compare against this value. | ||
* @return Whether or not this value equals the provided rhs value. | ||
*/ | ||
@Override | ||
public boolean equals(Object rhs) { | ||
return rhs instanceof EncodedParameter ? equals((EncodedParameter) rhs) : false; | ||
} | ||
|
||
/** | ||
* Get whether or not this value equals the provided rhs value. | ||
* @param rhs The value to compare against this value. | ||
* @return Whether or not this value equals the provided rhs value. | ||
*/ | ||
public boolean equals(EncodedParameter rhs) { | ||
return rhs != null | ||
&& name.equals(rhs.name) | ||
&& encodedValue.equals(rhs.encodedValue); | ||
} | ||
|
||
/** | ||
* Get the unique hash code for this value. | ||
* @return The unique hash code for this value. | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
return name.hashCode() ^ encodedValue.hashCode(); | ||
} | ||
} |
277 changes: 119 additions & 158 deletions
277
client-runtime/src/main/java/com/microsoft/rest/v2/RestProxy.java
Large diffs are not rendered by default.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
client-runtime/src/main/java/com/microsoft/rest/v2/Substitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.rest.v2; | ||
|
||
/** | ||
* A Substitution is a value that can be used to replace placeholder values in a URL. Placeholders | ||
* look like: "http://{host}.com/{fileName}.html", where "{host}" and "{fileName}" are the | ||
* placeholders. | ||
*/ | ||
class Substitution { | ||
private final String urlParameterName; | ||
private final int methodParameterIndex; | ||
private final boolean shouldEncode; | ||
|
||
/** | ||
* Create a new Substitution. | ||
* @param urlParameterName The name that is used between curly quotes as a placeholder in the | ||
* target URL. | ||
* @param methodParameterIndex The index of the parameter in the original interface method where | ||
* the value for the placeholder is. | ||
* @param shouldEncode Whether or not the value from the method's argument should be encoded | ||
* when the substitution is taking place. | ||
*/ | ||
Substitution(String urlParameterName, int methodParameterIndex, boolean shouldEncode) { | ||
this.urlParameterName = urlParameterName; | ||
this.methodParameterIndex = methodParameterIndex; | ||
this.shouldEncode = shouldEncode; | ||
} | ||
|
||
/** | ||
* Get the placeholder's name. | ||
* @return The name of the placeholder. | ||
*/ | ||
public String urlParameterName() { | ||
return urlParameterName; | ||
} | ||
|
||
/** | ||
* Get the index of the method parameter where the replacement value is. | ||
* @return The index of the method parameter where the replacement value is. | ||
*/ | ||
public int methodParameterIndex() { | ||
return methodParameterIndex; | ||
} | ||
|
||
/** | ||
* Get whether or not the replacement value from the method argument needs to be encoded when the | ||
* substitution is taking place. | ||
* @return Whether or not the replacement value from the method argument needs to be encoded | ||
* when the substitution is taking place. | ||
*/ | ||
public boolean shouldEncode() { | ||
return shouldEncode; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
client-runtime/src/main/java/com/microsoft/rest/v2/SwaggerInterfaceProxyDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.rest.v2; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Details that are associated with an interface that is generated from a Swagger specification. | ||
* This is generally used by a proxy implementation of the Swagger interface. | ||
*/ | ||
class SwaggerInterfaceProxyDetails { | ||
private final Map<String, SwaggerMethodProxyDetails> methodDetails = new HashMap<>(); | ||
|
||
/** | ||
* Create and return a SwaggerMethodProxyDetails object that is associated with the provided | ||
* methodName. If a SwaggerMethodProxyDetails object is already associated with the provided | ||
* methodName, then the existing object will be returned. | ||
* @param methodName The name of the method. | ||
* @return The SwaggerMethodProxyDetails object that is associated with the provided methodName. | ||
*/ | ||
public SwaggerMethodProxyDetails getMethodProxyDetails(String methodName) { | ||
SwaggerMethodProxyDetails result = methodDetails.get(methodName); | ||
if (result == null) { | ||
result = new SwaggerMethodProxyDetails(); | ||
methodDetails.put(methodName, result); | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.