com.dragome.forms.bindings.client.channel.DefaultChannel 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.channel;
import com.dragome.forms.bindings.client.binding.Disposable;
import com.dragome.forms.bindings.client.command.ParameterisedCommand;
import com.dragome.forms.bindings.client.function.Function;
import com.dragome.forms.bindings.client.util.SubscriptionList;
import com.dragome.forms.bindings.client.value.ValueTarget;
import com.dragome.model.interfaces.HasValue;
/**
* Created by IntelliJ IDEA.
* User: andrew
* Date: Feb 23, 2010
* Time: 2:32:52 PM
* To change this template use File | Settings | File Templates.
*/
public class DefaultChannel extends SubscriptionList> implements Channel
{
public void publish(final T value)
{
visitSubscribers(new Visitor>()
{
public void visit(Destination super T> subscriber)
{
subscriber.receive(value);
}
});
}
public Publisher getFormattedPublisher(final Function function)
{
if (function == null)
{
throw new NullPointerException("function is null");
}
return new Publisher()
{
public void publish(S value)
{
DefaultChannel.this.publish(function.compute(value));
}
};
}
public Destination asFormattedDestination(final Function function)
{
if (function == null)
{
throw new NullPointerException("function is null");
}
return new Destination()
{
public void receive(S value)
{
publish(function.compute(value));
}
};
}
public Destination asDestination()
{
return new Destination()
{
public void receive(T value)
{
publish(value);
}
};
}
public Disposable sendTo(Destination super T> destination)
{
if (destination == null)
{
throw new NullPointerException("destination is null");
}
return subscribe(destination);
}
public Disposable sendTo(final Publisher super T> publisher)
{
return sendTo(new Destination()
{
public void receive(T value)
{
publisher.publish(value);
}
});
}
public Disposable sendTo(final ValueTarget super T> destination)
{
return sendTo(new Destination()
{
public void receive(T value)
{
destination.setValue(value);
}
});
}
public Disposable sendTo(final HasValue super T> destination)
{
return sendTo(new Destination()
{
public void receive(T value)
{
destination.setValue(value);
}
});
}
public Disposable sendTo(final ParameterisedCommand super T> destination)
{
return sendTo(new Destination()
{
public void receive(T value)
{
destination.execute(value);
}
});
}
}