KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > ModelExtract


1 /*
2       (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3       [See end of file]
4       $Id: ModelExtract.java,v 1.3 2005/02/21 12:14:08 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.rdf.model;
8
9 import com.hp.hpl.jena.graph.Graph;
10 import com.hp.hpl.jena.graph.GraphExtract;
11 import com.hp.hpl.jena.graph.TripleBoundary;
12
13 /**
14      ModelExtract - a wrapper for GraphExtract, allowing rooted sub-models to be
15      extracted from other models with some boundary condition.
16     @author hedgehog
17 */

18 public class ModelExtract
19     {
20     /**
21          The statement boundary used to bound the extraction.
22     */

23     protected StatementBoundary boundary;
24     
25     /**
26          Initialise this ModelExtract with a boundary condition.
27     */

28     public ModelExtract( StatementBoundary b )
29         { boundary = b; }
30     
31     /**
32          Answer the rooted sub-model.
33     */

34     public Model extract( Resource r, Model s )
35         { return extractInto( ModelFactory.createDefaultModel(), r, s ); }
36     
37     /**
38          Answer <code>model</code> after updating it with the sub-graph of
39          <code>s</code> rooted at <code>r</code>, bounded by this instances
40          <code>boundary</code>.
41     */

42     public Model extractInto( Model model, Resource r, Model s )
43         { TripleBoundary tb = boundary.asTripleBoundary( s );
44         Graph g = getGraphExtract( tb ) .extractInto( model.getGraph(), r.asNode(), s.getGraph() );
45         return ModelFactory.createModelForGraph( g ); }
46     
47     /**
48          Answer a GraphExtract initialised with <code>tb</code>; extension point
49          for sub-classes (specifically TestModelExtract's mocks).
50     */

51     protected GraphExtract getGraphExtract( TripleBoundary tb )
52         { return new GraphExtract( tb ); }
53     }
54
55 /*
56     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
57     All rights reserved.
58     
59     Redistribution and use in source and binary forms, with or without
60     modification, are permitted provided that the following conditions
61     are met:
62     
63     1. Redistributions of source code must retain the above copyright
64        notice, this list of conditions and the following disclaimer.
65     
66     2. Redistributions in binary form must reproduce the above copyright
67        notice, this list of conditions and the following disclaimer in the
68        documentation and/or other materials provided with the distribution.
69     
70     3. The name of the author may not be used to endorse or promote products
71        derived from this software without specific prior written permission.
72     
73     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
74     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
75     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
76     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
77     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
78     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
79     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
80     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83 */
Popular Tags