com.windowsazure.messaging.WindowsTemplateRegistration Maven / Gradle / Ivy
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
package com.windowsazure.messaging;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
/**
* Class representing a registration for template notifications for devices using WNS.
*/
public class WindowsTemplateRegistration extends WindowsRegistration {
private static final String WNS_TEMPLATE_REGISTRATION1 = "";
private static final String WNS_TEMPLATE_REGISTRATION2 = "";
private static final String WNS_TEMPLATE_REGISTRATION3 = " ";
private static final String WNS_TEMPLATE_REGISTRATION5 = " ";
private String bodyTemplate;
private Map headers = new HashMap();
public WindowsTemplateRegistration() {
}
public WindowsTemplateRegistration(URI channelUri, String bodyTemplate,
Map headers) {
super(channelUri);
this.bodyTemplate = bodyTemplate;
this.headers = headers;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result
+ ((bodyTemplate == null) ? 0 : bodyTemplate.hashCode());
result = prime * result + ((headers == null) ? 0 : headers.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
WindowsTemplateRegistration other = (WindowsTemplateRegistration) obj;
if (bodyTemplate == null) {
if (other.bodyTemplate != null)
return false;
} else if (!bodyTemplate.equals(other.bodyTemplate))
return false;
if (headers == null) {
if (other.headers != null)
return false;
} else if (!headers.equals(other.headers))
return false;
return true;
}
public WindowsTemplateRegistration(URI channelUri,
String bodyTemplate) {
super(channelUri);
this.bodyTemplate = bodyTemplate;
}
public String getBodyTemplate() {
return bodyTemplate;
}
public void setBodyTemplate(String bodyTemplate) {
this.bodyTemplate = bodyTemplate;
}
public Map getHeaders() {
return headers;
}
public void addHeader(String name, String value) {
headers.put(name, value);
}
@Override
public String getXml() {
return WNS_TEMPLATE_REGISTRATION1 +
getTagsXml() +
WNS_TEMPLATE_REGISTRATION2 +
channelUri.toString() +
WNS_TEMPLATE_REGISTRATION3 +
bodyTemplate +
WNS_TEMPLATE_REGISTRATION4 +
getHeadersXml() +
WNS_TEMPLATE_REGISTRATION5;
}
private String getHeadersXml() {
StringBuilder buf = new StringBuilder();
if (!headers.isEmpty()) {
buf.append("");
for (String key : headers.keySet()) {
buf.append("");
buf.append(key).append(" ");
buf.append(headers.get(key)).append(" ");
}
}
buf.append(" ");
return buf.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy