KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * (c) Copyright 2003, 2004, Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  * [See end of file]
5  * $Id: Tutorial04.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.vocabulary.*;
11
12 /** Tutorial 4 - create a model and write it in XML form to standard out
13  *
14  * @author bwm - updated by Kers/Daniel
15  * @version Release='$Name: $' Revision='$Revision: 1.1 $' Date='$Date: 2005/03/12 13:52:28 $'
16  */

17 public class Tutorial04 extends Object JavaDoc {
18     
19     // some definitions
20
static String JavaDoc tutorialURI = "http://hostname/rdf/tutorial/";
21     static String JavaDoc briansName = "Brian McBride";
22     static String JavaDoc briansEmail1 = "brian_mcbride@hp.com";
23     static String JavaDoc briansEmail2 = "brian_mcbride@hpl.hp.com";
24     static String JavaDoc title = "An Introduction to RDF and the Jena API";
25     static String JavaDoc date = "23/01/2001";
26     
27     public static void main (String JavaDoc args[]) {
28     
29         // some definitions
30
String JavaDoc personURI = "http://somewhere/JohnSmith";
31         String JavaDoc givenName = "John";
32         String JavaDoc familyName = "Smith";
33         String JavaDoc fullName = givenName + " " + familyName;
34         // create an empty model
35
Model model = ModelFactory.createDefaultModel();
36
37         // create the resource
38
// and add the properties cascading style
39
Resource johnSmith
40           = model.createResource(personURI)
41                  .addProperty(VCARD.FN, fullName)
42                  .addProperty(VCARD.N,
43                               model.createResource()
44                                    .addProperty(VCARD.Given, givenName)
45                                    .addProperty(VCARD.Family, familyName));
46         
47         // now write the model in XML form to a file
48
model.write(System.out);
49     }
50 }
51
52 /*
53  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
54  * All rights reserved.
55  *
56  * Redistribution and use in source and binary forms, with or without
57  * modification, are permitted provided that the following conditions
58  * are met:
59  * 1. Redistributions of source code must retain the above copyright
60  * notice, this list of conditions and the following disclaimer.
61  * 2. Redistributions in binary form must reproduce the above copyright
62  * notice, this list of conditions and the following disclaimer in the
63  * documentation and/or other materials provided with the distribution.
64  * 3. The name of the author may not be used to endorse or promote products
65  * derived from this software without specific prior written permission.
66  *
67  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
68  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
69  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
70  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
71  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
72  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
73  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
74  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
75  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
76  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
77  */

78
Popular Tags