com.dragome.forms.bindings.client.command.AbstractEvents Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dragome-form-bindings Show documentation
Show all versions of dragome-form-bindings Show documentation
Dragome SDK module: form bindings
package com.dragome.forms.bindings.client.command;
import com.dragome.forms.bindings.client.binding.Disposable;
import com.dragome.forms.bindings.client.channel.DefaultChannel;
import com.dragome.forms.bindings.client.channel.Destination;
import com.dragome.forms.bindings.client.util.SubscriptionList;
import com.dragome.forms.bindings.extra.user.client.Command;
/**
* Created by IntelliJ IDEA.
* User: andrew
* Date: Apr 1, 2010
* Time: 1:38:00 PM
* To change this template use File | Settings | File Templates.
*/
public abstract class AbstractEvents implements Events
{
private SubscriptionList callbacks= new SubscriptionList();
private DefaultChannel startChannel= new DefaultChannel();
private DefaultChannel finishedChannel= new DefaultChannel();
protected AbstractEvents()
{
}
protected void fireStart()
{
startChannel.publish(null);
visitSubscribers(new SubscriptionList.Visitor()
{
public void visit(LifeCycleCallback subscriber)
{
subscriber.onStart();
}
});
}
protected void fireFinish()
{
finishedChannel.publish(null);
visitSubscribers(new SubscriptionList.Visitor()
{
public void visit(LifeCycleCallback subscriber)
{
subscriber.onFinish();
}
});
}
protected void visitSubscribers(SubscriptionList.Visitor visitor)
{
if (visitor == null)
{
throw new NullPointerException("visitor is null");
}
callbacks.visitSubscribers(visitor);
}
public Disposable onStartInvoke(final Command command)
{
if (command == null)
{
throw new NullPointerException("command is null");
}
return startChannel.sendTo(new Destination()
{
public void receive(Void value)
{
command.execute();
}
});
}
public SendToBuilder onStartSend(final T value)
{
return new SendToBuilderImpl(startChannel, value);
}
public Disposable onFinishInvoke(final Command command)
{
if (command == null)
{
throw new NullPointerException("command is null");
}
return finishedChannel.sendTo(new Destination()
{
public void receive(Void value)
{
command.execute();
}
});
}
public Disposable sendAllEventsTo(LifeCycleCallback callback)
{
if (callback == null)
{
throw new NullPointerException("callback is null");
}
return callbacks.subscribe(callback);
}
public SendToBuilder onFinishSend(final T value)
{
return new SendToBuilderImpl(finishedChannel, value);
}
}