1 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 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 Model model = ModelFactory.createDefaultModel(); 28 29 InputStream in = FileManager.get().open(inputFileName); 31 if (in == null) { 32 throw new IllegalArgumentException ( "File: " + inputFileName + " not found"); 33 } 34 35 model.read(new InputStreamReader(in), ""); 37 38 Resource vcard = model.getResource(johnSmithURI); 40 41 Resource name = (Resource) vcard.getRequiredProperty(VCARD.N) 43 .getObject(); 44 String fullName = vcard.getRequiredProperty(VCARD.FN) 46 .getString(); 47 vcard.addProperty(VCARD.NICKNAME, "Smithy") 49 .addProperty(VCARD.NICKNAME, "Adman"); 50 51 System.out.println("The nicknames of \"" + fullName + "\" are:"); 53 StmtIterator iter = vcard.listProperties(VCARD.NICKNAME); 55 while (iter.hasNext()) { 56 System.out.println(" " + iter.nextStatement().getObject() 57 .toString()); 58 } 59 } 60 } 61 62 88 | Popular Tags |