01: /*
02: * (c) Copyright 2003, 2004, Hewlett-Packard Development Company, LP
03: * All rights reserved.
04: * [See end of file]
05: * $Id: Tutorial06.java,v 1.3 2005/10/06 17:49:05 andy_seaborne Exp $
06: */
07: package jena.examples.rdf;
08:
09: 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: /** Tutorial navigating a model
16: *
17: * @author bwm - updated by kers/Daniel
18: * @version Release='$Name: $' Revision='$Revision: 1.3 $' Date='$Date: 2005/10/06 17:49:05 $'
19: */
20: public class Tutorial06 extends Object {
21:
22: static final String inputFileName = "vc-db-1.rdf";
23: static final String johnSmithURI = "http://somewhere/JohnSmith/";
24:
25: public static void main(String 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("File: " + inputFileName
33: + " not found");
34: }
35:
36: // read the RDF/XML file
37: model.read(new InputStreamReader(in), "");
38:
39: // retrieve the Adam Smith vcard resource from the model
40: Resource vcard = model.getResource(johnSmithURI);
41:
42: // retrieve the value of the N property
43: Resource name = (Resource) vcard.getRequiredProperty(VCARD.N)
44: .getObject();
45: // retrieve the given name property
46: String fullName = vcard.getRequiredProperty(VCARD.FN)
47: .getString();
48: // add two nick name properties to vcard
49: vcard.addProperty(VCARD.NICKNAME, "Smithy").addProperty(
50: VCARD.NICKNAME, "Adman");
51:
52: // set up the output
53: System.out
54: .println("The nicknames of \"" + fullName + "\" are:");
55: // list the nicknames
56: StmtIterator iter = vcard.listProperties(VCARD.NICKNAME);
57: while (iter.hasNext()) {
58: System.out.println(" "
59: + iter.nextStatement().getObject().toString());
60: }
61: }
62: }
63:
64: /*
65: * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
66: * All rights reserved.
67: *
68: * Redistribution and use in source and binary forms, with or without
69: * modification, are permitted provided that the following conditions
70: * are met:
71: * 1. Redistributions of source code must retain the above copyright
72: * notice, this list of conditions and the following disclaimer.
73: * 2. Redistributions in binary form must reproduce the above copyright
74: * notice, this list of conditions and the following disclaimer in the
75: * documentation and/or other materials provided with the distribution.
76: * 3. The name of the author may not be used to endorse or promote products
77: * derived from this software without specific prior written permission.
78: *
79: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
80: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
81: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
82: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
83: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
84: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
85: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
86: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
87: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
88: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
89: */
|