KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jena > examples > rdf > Tutorial08


1 /*
2  * (c) Copyright 2003, 2004, Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  * [See end of file]
5  * $Id: Tutorial08.java,v 1.1 2005/03/12 13:52:28 andy_seaborne Exp $
6  */

7 package jena.examples.rdf ;
8
9 import com.hp.hpl.jena.rdf.model.*;
10 import com.hp.hpl.jena.util.FileManager;
11 import com.hp.hpl.jena.vocabulary.*;
12
13 import java.io.*;
14
15
16 /** Tutorial 8 - demonstrate Selector methods
17  *
18  * @author bwm - updated by kers/Daniel
19  * @version Release='$Name: $' Revision='$Revision: 1.1 $' Date='$Date: 2005/03/12 13:52:28 $'
20  */

21 public class Tutorial08 extends Object JavaDoc {
22     
23     static final String JavaDoc inputFileName = "vc-db-1.rdf";
24     
25     public static void main (String JavaDoc args[]) {
26         // create an empty model
27
Model model = ModelFactory.createDefaultModel();
28        
29         // use the FileManager to find the input file
30
InputStream in = FileManager.get().open(inputFileName);
31         if (in == null) {
32             throw new IllegalArgumentException JavaDoc( "File: " + inputFileName + " not found");
33         }
34         
35         // read the RDF/XML file
36
model.read( in, "" );
37         
38         // select all the resources with a VCARD.FN property
39
// whose value ends with "Smith"
40
StmtIterator iter = model.listStatements(
41             new
42                 SimpleSelector(null, VCARD.FN, (RDFNode) null) {
43                     public boolean selects(Statement s) {
44                             return s.getString().endsWith("Smith");
45                     }
46                 });
47         if (iter.hasNext()) {
48             System.out.println("The database contains vcards for:");
49             while (iter.hasNext()) {
50                 System.out.println(" " + iter.nextStatement()
51                                               .getString());
52             }
53         } else {
54             System.out.println("No Smith's were found in the database");
55         }
56     }
57 }
58
59 /*
60  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
61  * All rights reserved.
62  *
63  * Redistribution and use in source and binary forms, with or without
64  * modification, are permitted provided that the following conditions
65  * are met:
66  * 1. Redistributions of source code must retain the above copyright
67  * notice, this list of conditions and the following disclaimer.
68  * 2. Redistributions in binary form must reproduce the above copyright
69  * notice, this list of conditions and the following disclaimer in the
70  * documentation and/or other materials provided with the distribution.
71  * 3. The name of the author may not be used to endorse or promote products
72  * derived from this software without specific prior written permission.
73  *
74  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
75  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
77  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
78  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
79  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
80  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
81  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
83  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84  */

85
Popular Tags