KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * (c) Copyright 2003, 2004, Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  * [See end of file]
5  * $Id: Tutorial06.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 /** Tutorial navigating a model
16  *
17  * @author bwm - updated by kers/Daniel
18  * @version Release='$Name: $' Revision='$Revision: 1.1 $' Date='$Date: 2005/03/12 13:52:28 $'
19  */

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

88
Popular Tags