/*
(c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
All rights reserved.
$Id$
*/
/*
(c) Copyright 2008 Hewlett-Packard Development Company, LP
All rights reserved.
$Id$
*/
package com.hp.jena.rules.retelike.impl;
import com.hp.jena.graph.*;
import com.hp.jena.rules.retelike.impl.scratch.Entries;
import com.hp.jena.ymris.util.Consumer;
/**
A Binder is a triple-consumer that consumes triples with respect to a
TripleTerm and sends the resulting bindings along to a bindings consumer.
@author kers
*/
public class Binder implements Consumer<Triple>
{
protected final Consumer<Entries> consumer;
protected final TripleTerm tripleTerm;
public Binder( TripleTerm tripleTerm, Consumer<Entries> consumer )
{
this.consumer = consumer;
this.tripleTerm = tripleTerm;
}
public Binder( Consumer<Entries> consumer )
{ this( null, consumer ); }
public void consume( Triple triple )
{
Entries bound = new Entries();
if (tripleTerm.bind( triple, bound )) consumer.consume( bound );
}
public TripleTerm boundTerm()
{ return tripleTerm; }
public void start()
{ consumer.start(); }
public void finish()
{ consumer.finish(); }
}
/*
(c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
All rights reserved.
$Id$
*/