// Path: src/main/java/org/whispercomm/c2dm4j/Message.java
// public interface Message {
// 
// 	/**
// 	 * Gets the identifier for the client to whom the message will be sent.
// 	 * 
// 	 * @return the registration id of the client.
// 	 */
// 	public String getRegistrationId();
// 
// 	/**
// 	 * Gets the collapse key for the message. The collapse key is used to
// 	 * collapse similar messages queued by the C2DM server when a device is
// 	 * offline. Only the last message will be delivered when the device
// 	 * reconnects.
// 	 * 
// 	 * @return the collapse key
// 	 */
// 	public String getCollapseKey();
// 
// 	/**
// 	 * Returns the key-value pairs that will be delivered to the client.
// 	 * 
// 	 * @return the key-value pair payload data
// 	 */
// 	public Map<String, String> getData();
// 
// 	/**
// 	 * Indicates if message delivery should wait until the device is active.
// 	 * active. If false, the device will be woken up to receive the message.
// 	 * 
// 	 * @return {@code true} if message delivery should wait until the device is
// 	 *         active; {@code false} if it should be delivered immediately
// 	 */
// 	public boolean delayWhileIdle();
// 
// }
// 
// Path: src/main/java/org/whispercomm/c2dm4j/auth/AuthToken.java
// public class AuthToken {
// 
// 	private final String token;
// 
// 	/**
// 	 * Constructs a new immutable authentication token.
// 	 * 
// 	 * @param token
// 	 *            the token material.
// 	 */
// 	public AuthToken(String token) {
// 		if (token == null)
// 			throw new IllegalArgumentException(
// 					"Argument 'token' may not be null.");
// 
// 		this.token = token;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return token;
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		final int prime = 31;
// 		int result = 1;
// 		result = prime * result + ((token == null) ? 0 : token.hashCode());
// 		return result;
// 	}
// 
// 	@Override
// 	public boolean equals(Object obj) {
// 		if (this == obj)
// 			return true;
// 		if (obj == null)
// 			return false;
// 		if (getClass() != obj.getClass())
// 			return false;
// 		AuthToken other = (AuthToken) obj;
// 		if (token == null) {
// 			if (other.token != null)
// 				return false;
// 		} else if (!token.equals(other.token))
// 			return false;
// 		return true;
// 	}
// 
// }


import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.whispercomm.c2dm4j.Message;
import org.whispercomm.c2dm4j.auth.AuthToken;
/*
 * Copyright 2012 The Regents of the University of Michigan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.whispercomm.c2dm4j.impl;



/**
 * Encapsulates an HTTP POST request to the C2DM service. This class is
 * responsible for constructing the request from a {@link Message} instance.
 * 
 * @author David R. Bild
 * 
 */
class C2dmHttpPost extends HttpPost {

	private static final String REGISTRATION_ID = "registration_id";
	private static final String COLLAPSE_ID = "collapse_key";
	private static final String DELAY_WHILE_IDLE = "delay_while_idle";
	private static final String DATA_KEY_PREFIX = "data.";

	/**
	 * Constructs a new POST requests for the specified message, authentication
	 * token, and endpoint.
	 * 
	 * @param message
	 *            the message to be placed into the request body
	 * @param token
	 *            the authentication token for the request
	 * @param uri
	 *            the remote endpoint for the request
	 */
	public C2dmHttpPost(Message message, AuthToken token, URI uri) {
		super(uri);
		initAuthToken(token);
		initPostEntity(message);
	}

	private void initAuthToken(AuthToken token) {
		this.setHeader("Authorization",
				String.format("GoogleLogin auth=%s", token));
	}

// Path: src/main/java/org/whispercomm/c2dm4j/Message.java
// public interface Message {
// 
// 	/**
// 	 * Gets the identifier for the client to whom the message will be sent.
// 	 * 
// 	 * @return the registration id of the client.
// 	 */
// 	public String getRegistrationId();
// 
// 	/**
// 	 * Gets the collapse key for the message. The collapse key is used to
// 	 * collapse similar messages queued by the C2DM server when a device is
// 	 * offline. Only the last message will be delivered when the device
// 	 * reconnects.
// 	 * 
// 	 * @return the collapse key
// 	 */
// 	public String getCollapseKey();
// 
// 	/**
// 	 * Returns the key-value pairs that will be delivered to the client.
// 	 * 
// 	 * @return the key-value pair payload data
// 	 */
// 	public Map<String, String> getData();
// 
// 	/**
// 	 * Indicates if message delivery should wait until the device is active.
// 	 * active. If false, the device will be woken up to receive the message.
// 	 * 
// 	 * @return {@code true} if message delivery should wait until the device is
// 	 *         active; {@code false} if it should be delivered immediately
// 	 */
// 	public boolean delayWhileIdle();
// 
// }
// 
// Path: src/main/java/org/whispercomm/c2dm4j/auth/AuthToken.java
// public class AuthToken {
// 
// 	private final String token;
// 
// 	/**
// 	 * Constructs a new immutable authentication token.
// 	 * 
// 	 * @param token
// 	 *            the token material.
// 	 */
// 	public AuthToken(String token) {
// 		if (token == null)
// 			throw new IllegalArgumentException(
// 					"Argument 'token' may not be null.");
// 
// 		this.token = token;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return token;
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		final int prime = 31;
// 		int result = 1;
// 		result = prime * result + ((token == null) ? 0 : token.hashCode());
// 		return result;
// 	}
// 
// 	@Override
// 	public boolean equals(Object obj) {
// 		if (this == obj)
// 			return true;
// 		if (obj == null)
// 			return false;
// 		if (getClass() != obj.getClass())
// 			return false;
// 		AuthToken other = (AuthToken) obj;
// 		if (token == null) {
// 			if (other.token != null)
// 				return false;
// 		} else if (!token.equals(other.token))
// 			return false;
// 		return true;
// 	}
// 
// }


// Path: src/main/java/org/whispercomm/c2dm4j/impl/C2dmHttpPost.java
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.whispercomm.c2dm4j.Message;
import org.whispercomm.c2dm4j.auth.AuthToken;

/*
 * Copyright 2012 The Regents of the University of Michigan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.whispercomm.c2dm4j.impl;



/**
 * Encapsulates an HTTP POST request to the C2DM service. This class is
 * responsible for constructing the request from a {@link Message} instance.
 * 
 * @author David R. Bild
 * 
 */
class C2dmHttpPost extends HttpPost {

	private static final String REGISTRATION_ID = "registration_id";
	private static final String COLLAPSE_ID = "collapse_key";
	private static final String DELAY_WHILE_IDLE = "delay_while_idle";
	private static final String DATA_KEY_PREFIX = "data.";

	/**
	 * Constructs a new POST requests for the specified message, authentication
	 * token, and endpoint.
	 * 
	 * @param message
	 *            the message to be placed into the request body
	 * @param token
	 *            the authentication token for the request
	 * @param uri
	 *            the remote endpoint for the request
	 */
	public C2dmHttpPost(Message message, AuthToken token, URI uri) {
		super(uri);
		initAuthToken(token);
		initPostEntity(message);
	}

	private void initAuthToken(AuthToken token) {
		this.setHeader("Authorization",
				String.format("GoogleLogin auth=%s", token));
	}

	private void initPostEntity(Message message) {