All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dragome.forms.bindings.client.command.SendToBuilderImpl Maven / Gradle / Ivy

There is a newer version: 0.96-beta4
Show newest version
package com.dragome.forms.bindings.client.command;

import com.dragome.forms.bindings.client.binding.Disposable;
import com.dragome.forms.bindings.client.channel.Channel;
import com.dragome.forms.bindings.client.channel.Destination;
import com.dragome.forms.bindings.client.channel.Publisher;
import com.dragome.forms.bindings.client.value.ValueTarget;

/**
* Created by IntelliJ IDEA.
* User: andrew
* Date: Mar 6, 2010
* Time: 1:01:25 PM
* To change this template use File | Settings | File Templates.
*/
public class SendToBuilderImpl implements SendToBuilder
{
	private Channel trigger;
	private T value;

	SendToBuilderImpl(Channel trigger, T value)
	{
		this.trigger= trigger;
		this.value= value;
	}

	public Disposable to(final Destination destination)
	{
		if (destination == null)
		{
			throw new NullPointerException("destination is null");
		}
		return trigger.sendTo(new Destination()
		{
			public void receive(Object ignore)
			{
				destination.receive(value);
			}
		});
	}

	public Disposable to(final Publisher destination)
	{
		if (destination == null)
		{
			throw new NullPointerException("destination is null");
		}

		return trigger.sendTo(new Destination()
		{
			public void receive(Object ignore)
			{
				destination.publish(value);
			}
		});
	}

	public Disposable to(final ValueTarget destination)
	{
		if (destination == null)
		{
			throw new NullPointerException("destination is null");
		}

		return trigger.sendTo(new Destination()
		{
			public void receive(Object ignore)
			{
				destination.setValue(value);
			}
		});
	}

	public Disposable to(final ParameterisedCommand destination)
	{
		if (destination == null)
		{
			throw new NullPointerException("destination is null");
		}

		return trigger.sendTo(new Destination()
		{
			public void receive(Object ignore)
			{
				destination.execute(value);
			}
		});
	}
}