KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > impl > RDFReaderFImpl


1 /*
2  * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $Id: RDFReaderFImpl.java,v 1.12 2005/02/21 12:14:50 andy_seaborne Exp $
28  */

29
30 package com.hp.hpl.jena.rdf.model.impl;
31
32 import com.hp.hpl.jena.*;
33 import com.hp.hpl.jena.rdf.model.*;
34 import com.hp.hpl.jena.shared.*;
35 import java.util.Properties JavaDoc;
36 import com.hp.hpl.jena.JenaRuntime ;
37
38 /**
39  *
40  * @author bwm
41  * @version $Revision: 1.12 $ $Date: 2005/02/21 12:14:50 $
42  */

43 public class RDFReaderFImpl extends Object JavaDoc implements RDFReaderF {
44
45     protected static Properties JavaDoc langToClassName = null;
46
47     // predefined languages - these should probably go in a properties file
48

49     protected static final String JavaDoc LANGS[] = { "RDF/XML",
50                                               "RDF/XML-ABBREV",
51                                               "N-TRIPLE",
52                                               "N-TRIPLES",
53                                               "N3",
54                                               "TURTLE"};
55     // default readers for each language
56

57     protected static final String JavaDoc DEFAULTREADERS[] = {
58         "com.hp.hpl.jena.rdf.arp.JenaReader",
59         "com.hp.hpl.jena.rdf.arp.JenaReader",
60         Jena.PATH + ".rdf.model.impl.NTripleReader",
61         Jena.PATH + ".rdf.model.impl.NTripleReader",
62         "com.hp.hpl.jena.n3.N3JenaReader",
63         "com.hp.hpl.jena.n3.TurtleJenaReader"
64     };
65
66     protected static final String JavaDoc DEFAULTLANG = LANGS[0];
67
68     protected static final String JavaDoc PROPNAMEBASE = Jena.PATH + ".reader.";
69
70     static { // static initializer - set default readers
71
langToClassName = new Properties JavaDoc();
72         for (int i = 0; i<LANGS.length; i++) {
73             langToClassName.setProperty(
74                                LANGS[i],
75                                JenaRuntime.getSystemProperty(PROPNAMEBASE + LANGS[i],
76                                                   DEFAULTREADERS[i]));
77         }
78     }
79
80
81     /** Creates new RDFReaderFImpl */
82     public RDFReaderFImpl() {
83     }
84
85     public RDFReader getReader() {
86         return getReader(DEFAULTLANG);
87     }
88
89     public RDFReader getReader(String JavaDoc lang) {
90
91         // setup default language
92
if (lang==null || lang.equals("")) {
93             lang = LANGS[0];
94         }
95
96         String JavaDoc className = langToClassName.getProperty(lang);
97         if (className == null || className.equals("")) {
98             throw new NoReaderForLangException( lang );
99         }
100         try {
101           return (RDFReader) Class.forName(className)
102                                   .newInstance();
103         } catch (Exception JavaDoc e) {
104             throw new JenaException(e);
105         }
106     }
107
108     public String JavaDoc setReaderClassName( String JavaDoc lang,String JavaDoc className ) {
109         return setBaseReaderClassName( lang, className );
110     }
111     
112     public static String JavaDoc setBaseReaderClassName( String JavaDoc lang, String JavaDoc className ) {
113         String JavaDoc oldClassName = langToClassName.getProperty(lang);
114         langToClassName.setProperty(lang, className);
115         return oldClassName;
116     }
117 }
118
Popular Tags