Permalink
Browse files

Make LinkInfo generic for type safety

  • Loading branch information...
1 parent 9a0d6fb commit 9d5b720ef091ae903ec2dc3a4f887cef4bf3989e @christav christav committed Dec 15, 2012
View
9 ...i/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java
@@ -88,12 +88,12 @@ public boolean hasLink(String rel) {
* rel of link to retrieve
* @return The link if found, null if not.
*/
- public LinkInfo getLink(String rel) {
+ public <U extends ODataEntity<?>> LinkInfo<U> getLink(String rel) {
for (Object child : entry.getEntryChildren()) {
LinkType link = LinkFromChild(child);
if (link != null && link.getRel().equals(rel)) {
- return new LinkInfo(link);
+ return new LinkInfo<U>(link);
}
}
return null;
@@ -106,15 +106,16 @@ public LinkInfo getLink(String rel) {
* name of the OData relationship
* @return the link if found, null if not.
*/
- public LinkInfo getRelationLink(String relationName) {
- return getLink(Constants.ODATA_DATA_NS + "/related/" + relationName);
+ public <U extends ODataEntity<?>> LinkInfo<U> getRelationLink(String relationName) {
+ return this.<U> getLink(Constants.ODATA_DATA_NS + "/related/" + relationName);
}
/**
* Return the links from this entry
*
* @return List of the links.
*/
+ @SuppressWarnings("rawtypes")
public List<LinkInfo> getLinks() {
ArrayList<LinkInfo> links = new ArrayList<LinkInfo>();
for (Object child : entry.getEntryChildren()) {
View
2 ...zure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicy.java
@@ -97,7 +97,7 @@ public Object getRequestContents() {
* the link
* @return the operation
*/
- public static EntityGetOperation<AccessPolicyInfo> get(LinkInfo link) {
+ public static EntityGetOperation<AccessPolicyInfo> get(LinkInfo<AccessPolicyInfo> link) {
return new DefaultGetOperation<AccessPolicyInfo>(link.getHref(), AccessPolicyInfo.class);
}
View
4 ...osoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java
@@ -171,7 +171,7 @@ public Creator setState(AssetState state) {
* the link
* @return the get operation
*/
- public static EntityGetOperation<AssetInfo> get(LinkInfo link) {
+ public static EntityGetOperation<AssetInfo> get(LinkInfo<AssetInfo> link) {
return new DefaultGetOperation<AssetInfo>(link.getHref(), AssetInfo.class);
}
@@ -204,7 +204,7 @@ public Creator setState(AssetState state) {
* Link to request assets from.
* @return The list operation.
*/
- public static DefaultListOperation<AssetInfo> list(LinkInfo link) {
+ public static DefaultListOperation<AssetInfo> list(LinkInfo<AssetInfo> link) {
return new DefaultListOperation<AssetInfo>(link.getHref(), new GenericType<ListResult<AssetInfo>>() {
});
}
View
2 ...t-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetFile.java
@@ -207,7 +207,7 @@ public static EntityActionOperation createFileInfos(String assetId) {
* Link to request AssetFiles from.
* @return The list operation.
*/
- public static DefaultListOperation<AssetFileInfo> list(LinkInfo link) {
+ public static DefaultListOperation<AssetFileInfo> list(LinkInfo<AssetFileInfo> link) {
return new DefaultListOperation<AssetFileInfo>(link.getHref(), new GenericType<ListResult<AssetFileInfo>>() {
});
}
View
17 ...t-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java
@@ -107,34 +107,35 @@ public AssetOption getOptions() {
*
* @return the link
*/
- public LinkInfo getAssetFilesLink() {
- return getRelationLink("Files");
+ public LinkInfo<AssetFileInfo> getAssetFilesLink() {
+ return this.<AssetFileInfo> getRelationLink("Files");
}
/**
* Get a link to the asset's content keys
*
* @return the link
*/
- public LinkInfo getContentKeysLink() {
- return getRelationLink("ContentKeys");
+ public LinkInfo<ContentKeyInfo> getContentKeysLink() {
+ return this.<ContentKeyInfo> getRelationLink("ContentKeys");
}
/**
* Get a link to the asset's locators
*
* @return the link
*/
- public LinkInfo getLocatorsLink() {
- return getRelationLink("Locators");
+ public LinkInfo<LocatorInfo> getLocatorsLink() {
+ return this.<LocatorInfo> getRelationLink("Locators");
}
/**
* Get a link to the asset's locators
*
* @return the link
*/
- public LinkInfo getParentAssetsLink() {
- return getRelationLink("ParentAssets");
+ public LinkInfo<AssetInfo> getParentAssetsLink() {
+ // TODO: NEEDS TESTS once we figure out how to create assets with parents
+ return this.<AssetInfo> getRelationLink("ParentAssets");
}
}
View
2 ...-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKey.java
@@ -211,7 +211,7 @@ public Creator setProtectionKeyType(ProtectionKeyType protectionKeyType) {
* Link to request content keys from.
* @return The list operation.
*/
- public static DefaultListOperation<ContentKeyInfo> list(LinkInfo link) {
+ public static DefaultListOperation<ContentKeyInfo> list(LinkInfo<ContentKeyInfo> link) {
return new DefaultListOperation<ContentKeyInfo>(link.getHref(), new GenericType<ListResult<ContentKeyInfo>>() {
});
}
View
12 ...oft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java
@@ -133,25 +133,25 @@ public String getTemplateId() {
*
* @return Link if found, null if not.
*/
- public LinkInfo getInputAssetsLink() {
- return getRelationLink("InputMediaAssets");
+ public LinkInfo<AssetInfo> getInputAssetsLink() {
+ return this.<AssetInfo> getRelationLink("InputMediaAssets");
}
/**
* Get a link which, when listed, will return the output assets for the job.
*
* @return Link if found, null if not.
*/
- public LinkInfo getOutputAssetsLink() {
- return getRelationLink("OutputMediaAssets");
+ public LinkInfo<AssetInfo> getOutputAssetsLink() {
+ return this.<AssetInfo> getRelationLink("OutputMediaAssets");
}
/**
* Gets the tasks link.
*
* @return the tasks link
*/
- public LinkInfo getTasksLink() {
- return getRelationLink("Tasks");
+ public LinkInfo<TaskInfo> getTasksLink() {
+ return this.<TaskInfo> getRelationLink("Tasks");
}
}
View
3 ...ft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LinkInfo.java
@@ -15,13 +15,14 @@
package com.microsoft.windowsazure.services.media.models;
+import com.microsoft.windowsazure.services.media.implementation.ODataEntity;
import com.microsoft.windowsazure.services.media.implementation.atom.LinkType;
/**
* Provides access to OData links
*
*/
-public class LinkInfo {
+public class LinkInfo<T extends ODataEntity<?>> {
private final LinkType rawLink;
/**
View
2 ...oft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Locator.java
@@ -218,7 +218,7 @@ public Creator setContentAccessComponent(String contentAccessComponent) {
* Link to request locators from.
* @return The list operation.
*/
- public static DefaultListOperation<LocatorInfo> list(LinkInfo link) {
+ public static DefaultListOperation<LocatorInfo> list(LinkInfo<LocatorInfo> link) {
return new DefaultListOperation<LocatorInfo>(link.getHref(), new GenericType<ListResult<LocatorInfo>>() {
});
}
View
8 ...azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorInfo.java
@@ -124,16 +124,16 @@ public String getContentAccessToken() {
*
* @return the link
*/
- public LinkInfo getAccessPolicyLink() {
- return getRelationLink("AccessPolicy");
+ public LinkInfo<AccessPolicyInfo> getAccessPolicyLink() {
+ return this.<AccessPolicyInfo> getRelationLink("AccessPolicy");
}
/**
* Return a link that gets this locator's asset
*
* @return the link
*/
- public LinkInfo getAssetLink() {
- return getRelationLink("Asset");
+ public LinkInfo<AssetInfo> getAssetLink() {
+ return this.<AssetInfo> getRelationLink("Asset");
}
}
View
2 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Task.java
@@ -80,7 +80,7 @@ public static CreateBatchOperation create(String mediaProcessorId, String taskBo
* link to tasks
* @return the list operation.
*/
- public static DefaultListOperation<TaskInfo> list(LinkInfo link) {
+ public static DefaultListOperation<TaskInfo> list(LinkInfo<TaskInfo> link) {
return new DefaultListOperation<TaskInfo>(link.getHref(), new GenericType<ListResult<TaskInfo>>() {
});
}
View
8 ...ft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java
@@ -217,16 +217,16 @@ public String getInitializationVector() {
*
* @return the link
*/
- public LinkInfo getInputAssetsLink() {
- return getRelationLink("InputMediaAssets");
+ public LinkInfo<AssetInfo> getInputAssetsLink() {
+ return this.<AssetInfo> getRelationLink("InputMediaAssets");
}
/**
* Gets link to the task's output assets
*
* @return the link
*/
- public LinkInfo getOutputAssetsLink() {
- return getRelationLink("OutputMediaAssets");
+ public LinkInfo<AssetInfo> getOutputAssetsLink() {
+ return this.<AssetInfo> getRelationLink("OutputMediaAssets");
}
}

0 comments on commit 9d5b720

Please sign in to comment.