Package com.hp.jena.ymris.yast

Source Code of com.hp.jena.ymris.yast.YAll

/*
  (c) Copyright 2009 Hewlett-Packard Development Company, LP
  All rights reserved.
*/

package com.hp.jena.ymris.yast;

import java.util.*;

import com.hp.hpl.jena.datatypes.RDFDatatype;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.impl.LiteralLabel;
import com.hp.hpl.jena.shared.PrefixMapping;
import com.hp.jena.ymris.deploy.local.BindingSink;

public class YAll implements ExpandsPrefixMapping<YAll>
    {
    protected final Terms premise;
    protected final Terms conclusion;
    protected final YVar id;
   
    public YAll( YVar id, Terms premise, Terms conclusion )
        {
        this.id = id;
        this.premise = premise;
        this.conclusion = conclusion;
        }
   
    @Override public YAll expand( PrefixMapping pm )
        { return new YAll( id, premise.expand( pm ), conclusion.expand( pm ) ); }
   
    public BindingSink translate( TranslationContext c, final BindingSink sink )
        {
        final int size = c.bindingSize();
        List<YTriple> triples = this.premise.triples;
        final int offset = c.varOffset( id );
        BindingSink select = new BindingSink()
            {
            protected final Set<Node> elements = new HashSet<Node>();
           
            @Override public void finish()
                {
                Node [] item = new Node[size];
                item[offset] = encodeSetAsLiteral( elements );
                sink.consume( item );
                }
           
            private Node encodeSetAsLiteral( Set<Node> elements )
                {
                RDFDatatype dt = new FakeSetLiteralType();              
                LiteralLabel ll = new LiteralLabel( elements, "", dt );
                return Node.createLiteral( ll );
                }

            @Override public void consume( Node[] item )
                { elements.add( item[offset] ); }
            };
        return triples.isEmpty() ? RuleBody.once( c, sink ) : RuleBody.join( c, triples, select );
        }
    }

/*
    (c) Copyright 2009 Hewlett-Packard Development Company, LP
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    3. The name of the author may not be used to endorse or promote products
       derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
TOP

Related Classes of com.hp.jena.ymris.yast.YAll

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.