Source Code Cross Referenced for ModelLoader.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:         * [See end of file]
004:         */
005:
006:        package com.hp.hpl.jena.util;
007:
008:        import org.apache.commons.logging.*;
009:
010:        import com.hp.hpl.jena.rdf.model.*;
011:        import com.hp.hpl.jena.shared.*;
012:
013:        import com.hp.hpl.jena.db.*;
014:
015:        /** A set of static convenience methods for getting models
016:         *  The loader will guess the language/type of the model using
017:         *  {@link #guessLang(String) guessLang}
018:         *
019:         * @author Andy Seaborne
020:         * @version $Id: ModelLoader.java,v 1.28 2008/01/02 12:07:44 andy_seaborne Exp $
021:         */
022:
023:        public class ModelLoader {
024:            static Log log = LogFactory.getLog(ModelLoader.class);
025:
026:            /** @deprecated Use FileUtils.FileUtils.langXML */
027:            public static final String langXML = FileUtils.langXML;
028:
029:            /** @deprecated Use FileUtils.langXMLAbbrev */
030:            public static final String langXMLAbbrev = FileUtils.langXMLAbbrev;
031:
032:            /** @deprecated Use FileUtils.langNTriple */
033:            public static final String langNTriple = FileUtils.langNTriple;
034:
035:            /** @deprecated Use FileUtils.langN3 */
036:            public static final String langN3 = FileUtils.langN3;
037:            // Non-standard
038:            /** @deprecated Use FileUtils.langBDB */
039:            public static final String langBDB = FileUtils.langBDB;
040:            /** @deprecated Use FileUtils.langSQL */
041:            public static final String langSQL = FileUtils.langSQL;
042:
043:            /** Load a model
044:             *  @deprecated Use FileManager.get().loadModel(urlStr)
045:             * @param urlStr    The URL or file name of the model
046:             */
047:
048:            public static Model loadModel(String urlStr) {
049:                return loadModel(urlStr, null);
050:            }
051:
052:            /** Load a model or attached a persistent store (but not a database).
053:             *  @deprecated Use FileManager.get().loadModel(urlStr, lang)
054:             * @param urlStr	The URL or file name of the model
055:             * @param lang		The language of the data - if null, the system guesses
056:             */
057:
058:            public static Model loadModel(String urlStr, String lang) {
059:                try {
060:                    return FileManager.get().loadModel(urlStr, lang);
061:                } catch (JenaException ex) {
062:                    return null;
063:                }
064:            }
065:
066:            /** Load a model or attached a persistent store.
067:             *  Tries to guess syntax type.
068:             *  Database paramters only needed if its a database.
069:             *
070:             * @param urlStr		The URL or file name of the model
071:             * @param lang			The language of the data - if null, the system guesses
072:             * @param dbUser		Database user name (for RDB/JDBC)
073:             * @param dbPassword	Database password (for RDB/JDBC)
074:             * @param modelName     The name of the model 
075:             * @param dbType        Database type (e.g. MySQL)
076:             * @param driver        JDBC driver to load.
077:             * @return Model
078:             */
079:
080:            public static Model loadModel(String urlStr, String lang,
081:                    String dbUser, String dbPassword, String modelName,
082:                    String dbType, String driver) {
083:                // Wild guess at the language!
084:                if (lang == null)
085:                    lang = guessLang(urlStr);
086:
087:                if (lang == null)
088:                    lang = FileUtils.langXML;
089:
090:                if (lang.equals(FileUtils.langBDB)) {
091:                    // @@ temporarily not supported        	
092:                    LogFactory.getLog(ModelLoader.class).fatal(
093:                            "Failed to open Berkeley database");
094:                    return null;
095:                    /*
096:                     // URL had better be a file!
097:                     if ( basename != null )
098:                     urlStr = basename+File.separator+urlStr ;
099:
100:                     String dirBDB = getDirname(urlStr) ;
101:                     if ( dirBDB == null || dirBDB.length() == 0)
102:                     dirBDB = "." ;
103:                     urlStr = getBasename(urlStr) ;
104:
105:                     log.debug("BDB: file="+urlStr+", dir="+dirBDB+", basename="+basename) ;
106:
107:                     try {
108:                     Model model = new ModelBdb(new StoreBdbF(dirBDB, urlStr)) ;
109:                     return model ;
110:                     } catch (JenaException rdfEx)
111:                     {
112:                     log.severe("Failed to open Berkeley database", rdfEx) ;
113:                     System.exit(1) ;
114:                     }
115:                     */
116:                }
117:
118:                if (lang.equals(FileUtils.langSQL))
119:                    return connectToDB(urlStr, dbUser, dbPassword, modelName,
120:                            dbType, driver);
121:
122:                // Its a files.
123:                // Language is N3, RDF/XML or N-TRIPLE
124:                Model m = ModelFactory.createDefaultModel();
125:
126:                m.setReaderClassName(FileUtils.langXML,
127:                        com.hp.hpl.jena.rdf.arp.JenaReader.class.getName());
128:                m.setReaderClassName(FileUtils.langXMLAbbrev,
129:                        com.hp.hpl.jena.rdf.arp.JenaReader.class.getName());
130:
131:                // Default.
132:                //m.setReaderClassName(langNTriple, com.hp.hpl.jena.rdf.arp.NTriple.class.getName()) ;
133:
134:                try {
135:                    FileManager.get().readModel(m, urlStr, null, lang);
136:                } catch (JenaException rdfEx) {
137:                    log.warn("Error loading data source", rdfEx);
138:                    return null;
139:                }
140:                return m;
141:            }
142:
143:            /** Load a model from a file into a model.
144:             * @deprecated Use FileManager.get().readModel(model, urlStr) instead
145:             * @param model   Model to read into
146:             * @param urlStr  URL (or filename) to read from
147:             * @return Returns the model passed in.
148:             */
149:
150:            public static Model loadModel(Model model, String urlStr) {
151:                return loadModel(model, urlStr, null);
152:            }
153:
154:            /** Load a model from a file into a model.
155:             * @deprecated Use FileManager.get().readModel(model, urlStr, lang) instead
156:             * @param model   Model to read into
157:             * @param urlStr  URL (or filename) to read from
158:             * @param lang    Null mean guess based on the URI String
159:             * @return Returns the model passed in.
160:             */
161:
162:            public static Model loadModel(Model model, String urlStr,
163:                    String lang) {
164:                try {
165:                    return FileManager.get().readModel(model, urlStr, null,
166:                            lang);
167:                } catch (Exception e) {
168:                    LogFactory.getLog(ModelLoader.class).warn(
169:                            "No such data source: " + urlStr);
170:                    return null;
171:                }
172:            }
173:
174:            /**
175:             * Connect to a database.
176:             * @param urlStr
177:             * @param dbUser
178:             * @param dbPassword
179:             * @param dbType
180:             * @param driverName   Load this driver (if not null)
181:             * @return Model
182:             */
183:
184:            public static Model connectToDB(String urlStr, String dbUser,
185:                    String dbPassword, String modelName, String dbType,
186:                    String driverName) {
187:                // Fragment ID is the model name.
188:                try {
189:                    if (driverName != null)
190:                        Class.forName(driverName).newInstance();
191:                } catch (Exception ex) {
192:                }
193:
194:                try {
195:                    IDBConnection conn = ModelFactory
196:                            .createSimpleRDBConnection(urlStr, dbUser,
197:                                    dbPassword, dbType);
198:                    return ModelRDB.open(conn, modelName);
199:                } catch (JenaException rdfEx) {
200:                    LogFactory
201:                            .getLog(ModelLoader.class)
202:                            .error(
203:                                    "Failed to open SQL database: ModelLoader.connectToDB",
204:                                    rdfEx);
205:                    throw rdfEx;
206:                }
207:            }
208:
209:            /** Guess the language/type of model data. Updated by Chris, hived off the
210:             * model-suffix part to FileUtils as part of unifying it with similar code in FileGraph.
211:             * 
212:             * <ul>
213:             * <li> If the URI of the model starts jdbc: it is assumed to be an RDB model</li>
214:             * <li> If the URI ends ".rdf", it is assumed to be RDF/XML</li>
215:             * <li> If the URI end .nt, it is assumed to be N-Triples</li>
216:             * <li> If the URI end .bdb, it is assumed to be BerkeleyDB model [suppressed at present]</li>
217:             * </ul>
218:             * @deprecated Use FileUtils.guessLang
219:             * @param urlStr    URL to base the guess on
220:             * @param defaultLang Default guess
221:             * @return String   Guessed syntax - or the default supplied
222:             */
223:
224:            public static String guessLang(String urlStr, String defaultLang) {
225:                if (urlStr.startsWith("jdbc:") || urlStr.startsWith("JDBC:"))
226:                    return FileUtils.langSQL;
227:                else
228:                    return FileUtils.guessLang(urlStr, defaultLang);
229:            }
230:
231:            /** Guess the language/type of model data
232:             *  
233:             * 
234:             * <ul>
235:             * <li> If the URI of the model starts jdbc: it is assumed to be an RDB model</li>
236:             * <li> If the URI ends ".rdf", it is assumed to be RDF/XML</li>
237:             * <li> If the URI end .nt, it is assumed to be N-Triples</li>
238:             * <li> If the URI end .bdb, it is assumed to be BerkeleyDB model</li>
239:             * </ul>
240:             * @deprecated Use FileUtils.guessLang
241:             * @param urlStr    URL to base the guess on
242:             * @return String   Guessed syntax - null for no guess.
243:             */
244:
245:            public static String guessLang(String urlStr) {
246:                return FileUtils.guessLang(urlStr);
247:            }
248:        }
249:
250:        /*
251:         *  (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
252:         *  All rights reserved.
253:         *
254:         * Redistribution and use in source and binary forms, with or without
255:         * modification, are permitted provided that the following conditions
256:         * are met:
257:         * 1. Redistributions of source code must retain the above copyright
258:         *    notice, this list of conditions and the following disclaimer.
259:         * 2. Redistributions in binary form must reproduce the above copyright
260:         *    notice, this list of conditions and the following disclaimer in the
261:         *    documentation and/or other materials provided with the distribution.
262:         * 3. The name of the author may not be used to endorse or promote products
263:         *    derived from this software without specific prior written permission.
264:         *
265:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
266:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
267:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
268:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
269:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
270:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
271:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
272:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
273:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
274:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.