001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: IteratorFactory.java,v 1.14 2008/01/02 12:04:57 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.model.impl;
008:
009: import java.util.*;
010:
011: import com.hp.hpl.jena.rdf.model.*;
012: import com.hp.hpl.jena.util.iterator.*;
013:
014: import com.hp.hpl.jena.graph.*;
015:
016: /**
017: * @author jjc
018: * Builds Jena Iterators and other things (RDFNode and Statement)
019: * needed in a Model.
020: */
021: public final class IteratorFactory {
022:
023: private IteratorFactory() {
024: }
025:
026: /**
027: @deprecated use Model::asRDFNode( Node ) instead.
028: */
029: static public RDFNode asRDFNode(Node n, Model m) {
030: return m.asRDFNode(n);
031: }
032:
033: /**
034: @deprecated use Model::toStatement( Triple )
035: */
036: static public Statement asStatement(Triple t, ModelCom m) {
037: return StatementImpl.toStatement(t, m);
038: }
039:
040: /**
041: *
042: */
043: static public StmtIterator asStmtIterator(Iterator i,
044: final ModelCom m) {
045: return new StmtIteratorImpl(new Map1Iterator(new Map1() {
046: public Object map1(Object o) {
047: return m.asStatement((Triple) o);
048: }
049: }, i));
050: }
051:
052: /**
053: *
054: */
055: static public ResIterator asResIterator(Iterator i, final ModelCom m) {
056: return new ResIteratorImpl(new Map1Iterator(new Map1() {
057: public Object map1(Object o) {
058: return m.asRDFNode((Node) o);
059: }
060: }, i), null);
061: }
062:
063: /**
064: *
065: */
066: static public NodeIterator asRDFNodeIterator(Iterator i,
067: final ModelCom m) {
068: return new NodeIteratorImpl(new Map1Iterator(new Map1() {
069: public Object map1(Object o) {
070: return m.asRDFNode((Node) o);
071: }
072: }, i), null);
073: }
074:
075: static Resource asResource(Node n, ModelCom m) {
076: return asResource(n, Resource.class, m);
077:
078: }
079:
080: static Property asProperty(Node n, ModelCom m) {
081: return (Property) asResource(n, Property.class, m);
082: }
083:
084: static Literal asLiteral(Node n, ModelCom m) {
085: // return (Literal) m.getNodeAs( n, Literal.class );
086: return (Literal) m.getNodeAs(n, Literal.class);
087: }
088:
089: static Resource asResource(Node n, Class cl, ModelCom m) {
090: return (Resource) m.getNodeAs(n, cl);
091: }
092: }
093:
094: /*
095: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
096: All rights reserved.
097:
098: Redistribution and use in source and binary forms, with or without
099: modification, are permitted provided that the following conditions
100: are met:
101:
102: 1. Redistributions of source code must retain the above copyright
103: notice, this list of conditions and the following disclaimer.
104:
105: 2. Redistributions in binary form must reproduce the above copyright
106: notice, this list of conditions and the following disclaimer in the
107: documentation and/or other materials provided with the distribution.
108:
109: 3. The name of the author may not be used to endorse or promote products
110: derived from this software without specific prior written permission.
111:
112: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
113: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
114: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
115: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
116: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
117: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
118: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
119: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
120: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
121: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
122: */
|