Source Code Cross Referenced for ModelFactoryImpl.java in  » Search-Engine » semweb4j » org » ontoware » rdf2go » impl » jena24 » 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 » Search Engine » semweb4j » org.ontoware.rdf2go.impl.jena24 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.ontoware.rdf2go.impl.jena24;
002:
003:        import java.util.Properties;
004:
005:        import org.ontoware.rdf2go.ModelFactory;
006:        import org.ontoware.rdf2go.Reasoning;
007:        import org.ontoware.rdf2go.exception.ModelRuntimeException;
008:        import org.ontoware.rdf2go.impl.AbstractModelFactory;
009:        import org.ontoware.rdf2go.model.Model;
010:        import org.ontoware.rdf2go.model.ModelSet;
011:        import org.ontoware.rdf2go.model.node.URI;
012:
013:        import com.hp.hpl.jena.db.DBConnection;
014:        import com.hp.hpl.jena.db.IDBConnection;
015:        import com.hp.hpl.jena.ontology.OntModelSpec;
016:        import com.hp.hpl.jena.rdf.model.ModelMaker;
017:
018:        public class ModelFactoryImpl extends AbstractModelFactory implements 
019:                ModelFactory {
020:
021:            public static final String BACKEND = "back-end";
022:
023:            public static final String MEMORY = "memory";
024:
025:            public static final String DATABASE = "database";
026:
027:            public static final String SQL_DRIVERNAME = "sql_drivername";
028:
029:            public static final String DB_TYPE = "db_type";
030:
031:            public static final String DB_CONNECT_STRING = "db_connect_string";
032:
033:            public static final String DB_USER = "db_user";
034:
035:            public static final String DB_PASSWD = "db_passwd";
036:
037:            public static final String FILE = "file";
038:
039:            public static final String FILENAME = "filename";
040:
041:            public Model createModel(Properties p) throws ModelRuntimeException {
042:                com.hp.hpl.jena.rdf.model.Model model;
043:
044:                String backend = p.getProperty(BACKEND);
045:
046:                // default to in-memory model
047:                if (backend == null)
048:                    backend = MEMORY;
049:
050:                Reasoning reasoning = AbstractModelFactory.getReasoning(p);
051:
052:                if (backend == null || backend.equalsIgnoreCase(MEMORY)) {
053:                    model = com.hp.hpl.jena.rdf.model.ModelFactory
054:                            .createDefaultModel();
055:                    assert model != null;
056:                } else if (backend.equalsIgnoreCase(DATABASE)) {
057:                    String sql_drivername = p.getProperty(SQL_DRIVERNAME);
058:                    String db_type = p.getProperty(DB_TYPE);
059:                    String connect_string = p.getProperty(DB_CONNECT_STRING);
060:                    String user = p.getProperty(DB_USER);
061:                    String password = p.getProperty(DB_PASSWD);
062:
063:                    if (sql_drivername == null)
064:                        throw new RuntimeException(
065:                                "Please specify a sql_drivername in your property file!");
066:                    if (db_type == null)
067:                        throw new RuntimeException(
068:                                "Please specify a db_type in your property file!");
069:                    if (connect_string == null)
070:                        throw new RuntimeException(
071:                                "Please specify a connect_string in your property file!");
072:                    if (user == null)
073:                        throw new RuntimeException(
074:                                "Please specify a db_user in your property file!");
075:                    if (password == null)
076:                        throw new RuntimeException(
077:                                "Please specify a db_passwd in your property file!");
078:
079:                    ModelMaker maker;
080:                    try {
081:                        maker = getDBModelMaker(sql_drivername, connect_string,
082:                                user, password, db_type);
083:                    } catch (Exception e) {
084:                        throw new ModelRuntimeException(e);
085:                    }
086:
087:                    model = maker.createDefaultModel();
088:
089:                } else if (backend.equalsIgnoreCase(FILE)) {
090:                    String filename = p.getProperty(FILENAME);
091:                    if (filename == null) {
092:                        throw new RuntimeException(
093:                                "Please specify a filename in your property file!");
094:                    }
095:                    ModelMaker maker = getFileModelMaker(filename);
096:                    model = maker.createDefaultModel();
097:                } else
098:                    throw new IllegalArgumentException(
099:                            "Illegal back-end type: " + backend);
100:
101:                // reasoning
102:
103:                switch (reasoning) {
104:                case rdfsAndOwl:
105:                case owl:
106:                    com.hp.hpl.jena.rdf.model.Model owlModel = (com.hp.hpl.jena.rdf.model.Model) com.hp.hpl.jena.rdf.model.ModelFactory
107:                            .createOntologyModel(
108:                                    OntModelSpec.OWL_DL_MEM_RDFS_INF, model);
109:                    return new ModelImplJena24(owlModel);
110:                case rdfs:
111:                    com.hp.hpl.jena.rdf.model.Model rdfsModel = (com.hp.hpl.jena.rdf.model.Model) com.hp.hpl.jena.rdf.model.ModelFactory
112:                            .createRDFSModel(model);
113:                    return new ModelImplJena24(rdfsModel);
114:                default:
115:                    return new ModelImplJena24(model);
116:                }
117:
118:            }
119:
120:            public Model createModel(URI contextURI)
121:                    throws ModelRuntimeException {
122:                com.hp.hpl.jena.rdf.model.Model model = com.hp.hpl.jena.rdf.model.ModelFactory
123:                        .createDefaultModel();
124:                return new ModelImplJena24(contextURI, model);
125:            }
126:
127:            private ModelMaker getDBModelMaker(String SQLDriver,
128:                    String DB_connectString, String user, String password,
129:                    String db_type) throws Exception {
130:                Class.forName(SQLDriver);
131:                IDBConnection conn = new DBConnection(DB_connectString, user,
132:                        password, db_type);
133:                return com.hp.hpl.jena.rdf.model.ModelFactory
134:                        .createModelRDBMaker(conn);
135:            }
136:
137:            private ModelMaker getFileModelMaker(String filename) {
138:                return com.hp.hpl.jena.rdf.model.ModelFactory
139:                        .createFileModelMaker(filename);
140:            }
141:
142:            public ModelSet createModelSet(Properties p)
143:                    throws ModelRuntimeException {
144:                // TODO not available in Jena, TODO: implement using NG4J
145:                throw new UnsupportedOperationException(
146:                        "not available in Jena, TODO: implement using NG4J");
147:            }
148:
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.