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


001:        package org.ontoware.rdfreactor.generator;
002:
003:        import java.io.File;
004:
005:        import org.apache.commons.logging.Log;
006:        import org.apache.commons.logging.LogFactory;
007:        import org.ontoware.rdf2go.Reasoning;
008:        import org.ontoware.rdf2go.model.Model;
009:        import org.ontoware.rdfreactor.generator.java.JModel;
010:
011:        /**
012:         * <b>CodeGenerator</b> is more of a 'model generator'
013:         * 
014:         * The main() and generate() methods should be used from external users to start
015:         * the generation of a Java class model representing a given RDFS/OWL schema
016:         * file.
017:         * 
018:         * @author voelkel
019:         * 
020:         */
021:        public class CodeGenerator {
022:
023:            public static final String GENERATOR_VERSION = "$Id: CodeGenerator.java 1046 2008-01-26 14:38:26Z max.at.xam.de $";
024:
025:            private static Log log = LogFactory.getLog(CodeGenerator.class);
026:
027:            public static final String SEMANTICS_RDFS = "rdfs";
028:
029:            public static final String SEMANTICS_OWL = "owl";
030:
031:            public static final String SEMANTICS_RDFS_AND_OWL = "rdfs+owl";
032:
033:            /**
034:             * Generate a Java class model from the given RDFS/OWL schema file
035:             * 
036:             * @param args
037:             *            schemafilename, outdir, packagename, (RDFS|OWL)
038:             * @throws Exception
039:             */
040:            public static void main(String[] args) throws Exception {
041:                generate(args[0], args[1], args[2], args[3], true, true, "");
042:            }
043:
044:            /**
045:             * TODO read from configuration file and respect in template This is already
046:             * used in the veloctiy template
047:             */
048:            @SuppressWarnings("unused")
049:            private static boolean readOnly = false;
050:
051:            /**
052:             * @deprecated Use {@link #generate(String,String,String,Reasoning,boolean)} instead
053:             */
054:            public static void generate(String schemafilename, String outdir,
055:                    String packagename, Reasoning semantics,
056:                    boolean skipbuiltins, boolean alwaysWriteToModel)
057:                    throws Exception {
058:                generate(schemafilename, outdir, packagename, semantics,
059:                        skipbuiltins);
060:            }
061:
062:            public static void generate(String schemafilename, String outdir,
063:                    String packagename, Reasoning semantics,
064:                    boolean skipbuiltins) throws Exception {
065:                generate(schemafilename, outdir, packagename, semantics,
066:                        skipbuiltins, "");
067:            }
068:
069:            /**
070:             * Generate a Java class model from the given RDFS/OWL schema file
071:             * 
072:             * @param schemafilename
073:             *            a path to an rdf or owl file in N3, NT or XML syntax. File
074:             *            extension determines parsing.
075:             * @param outdir-
076:             *            e.g './src' or './gen-src'
077:             * @param packagename -
078:             *            e.g. 'org.ontoware.myname.reactor'
079:             * @param semantics -
080:             *            'rdfs', 'owl' or 'rdfs+owl' (experimental)
081:             * @param skipbuiltins
082:             *            if false, internal helper classes are re-generated. This is
083:             *            usually not needed.
084:             * @param alwaysWriteToModel
085:             *            if false, public contructors allow for the choice
086:             * @throws Exception
087:             * @deprecated Use {@link #generate(String,String,String,Reasoning,boolean,String)} instead
088:             */
089:            public static void generate(String schemafilename, String outdir,
090:                    String packagename, Reasoning semantics,
091:                    boolean skipbuiltins, boolean alwaysWriteToModel,
092:                    String methodnamePrefix) throws Exception {
093:                generate(schemafilename, outdir, packagename, semantics,
094:                        skipbuiltins, methodnamePrefix);
095:            }
096:
097:            /**
098:             * Generate a Java class model from the given RDFS/OWL schema file
099:             * 
100:             * @param schemafilename
101:             *            a path to an rdf or owl file in N3, NT or XML syntax. File
102:             *            extension determines parsing.
103:             * @param packagename -
104:             *            e.g. 'org.ontoware.myname.reactor'
105:             * @param semantics -
106:             *            'rdfs', 'owl' or 'rdfs+owl' (experimental)
107:             * @param skipbuiltins
108:             *            if false, internal helper classes are re-generated. This is
109:             *            usually not needed.
110:             * @param outdir-
111:             *            e.g './src' or './gen-src'
112:             * @throws Exception
113:             */
114:            public static void generate(String schemafilename, String outdir,
115:                    String packagename, Reasoning semantics,
116:                    boolean skipbuiltins, String methodnamePrefix)
117:                    throws Exception {
118:
119:                // first step
120:                Model schemaDataModel = loadSchemaDataModel(schemafilename);
121:                File outDir = new File(outdir);
122:
123:                generate(schemaDataModel, outDir, packagename, semantics,
124:                        skipbuiltins, methodnamePrefix);
125:            }
126:
127:            public static void generate(String schemafilename, String outdir,
128:                    String packagename, String semantics, boolean skipbuiltins,
129:                    boolean alwaysWriteToModel, String methodnamePrefix)
130:                    throws Exception {
131:
132:                Reasoning reasoning;
133:
134:                if (semantics.equalsIgnoreCase(SEMANTICS_RDFS))
135:                    reasoning = Reasoning.rdfs;
136:                else if (semantics.equalsIgnoreCase(SEMANTICS_OWL))
137:                    reasoning = Reasoning.owl;
138:                else if (semantics.equalsIgnoreCase(SEMANTICS_RDFS_AND_OWL))
139:                    reasoning = Reasoning.rdfsAndOwl;
140:                else
141:                    throw new RuntimeException("Unknown semantics: '"
142:                            + semantics + "'");
143:
144:                generate(schemafilename, outdir, packagename, reasoning,
145:                        skipbuiltins, methodnamePrefix);
146:            }
147:
148:            /**
149:             * 
150:             * @param modelWithSchemaData
151:             *            a Model in which the ontology to generate Java classes form is
152:             *            loaded
153:             * @param outDir
154:             * @param packagename
155:             * @param semantics
156:             * @param skipbuiltins
157:             * @param alwaysWriteToModel
158:             * @param methodnamePrefix
159:             * @throws Exception
160:             * @deprecated Use {@link #generate(Model,File,String,Reasoning,boolean,String)} instead
161:             */
162:            public static void generate(Model modelWithSchemaData, File outDir,
163:                    String packagename, Reasoning semantics,
164:                    boolean skipbuiltins, boolean alwaysWriteToModel,
165:                    String methodnamePrefix) throws Exception {
166:                generate(modelWithSchemaData, outDir, packagename, semantics,
167:                        skipbuiltins, methodnamePrefix);
168:            }
169:
170:            /**
171:             * 
172:             * @param modelWithSchemaData
173:             *            a Model in which the ontology to generate Java classes form is
174:             *            loaded
175:             * @param outDir
176:             * @param packagename
177:             * @param semantics
178:             * @param skipbuiltins
179:             * @param methodnamePrefix
180:             * @throws Exception
181:             */
182:            public static void generate(Model modelWithSchemaData, File outDir,
183:                    String packagename, Reasoning semantics,
184:                    boolean skipbuiltins, String methodnamePrefix)
185:                    throws Exception {
186:
187:                log.info("using semantics: " + semantics);
188:                // different semantics mean different ways to create the internal model
189:                JModel jm;
190:
191:                // second step
192:                if (semantics == Reasoning.rdfs) {
193:                    log.info("MODEL generating RDFS into "
194:                            + outDir.getAbsolutePath() + " ...");
195:                    jm = ModelGenerator.createFromRDFS_Schema(
196:                            modelWithSchemaData, packagename, skipbuiltins);
197:                } else if (semantics == Reasoning.owl) {
198:                    log.info("generating OWL into " + outDir.getAbsolutePath()
199:                            + " ...");
200:                    jm = ModelGenerator.createFromOWL(modelWithSchemaData,
201:                            packagename, skipbuiltins);
202:                } else if (semantics == Reasoning.rdfsAndOwl) {
203:                    log.info("MODEL generating RDFS+OWL mix semantics into "
204:                            + outDir.getAbsolutePath() + " ...");
205:                    jm = ModelGenerator.createFromRDFS_AND_OWL(
206:                            modelWithSchemaData, packagename, skipbuiltins);
207:                } else
208:                    throw new RuntimeException(
209:                            "Can't handle the semantics of '" + semantics + "'");
210:
211:                // third and final step
212:                log.info("write using sourceCodeWriter");
213:                SourceCodeWriter.write(jm, outDir,
214:                        SourceCodeWriter.TEMPLATE_CLASS, methodnamePrefix);
215:            }
216:
217:            /**
218:             * load & deanonymize a schema file into a Jena RDF model
219:             * 
220:             * @param schemafilename
221:             * @return Jena RDF Model loaded from given filename
222:             * @throws Exception
223:             */
224:            public static Model loadSchemaDataModel(String schemafilename)
225:                    throws Exception {
226:                File schemaFile = new File(schemafilename);
227:                log.info("loading from " + schemaFile.getCanonicalPath());
228:                Model schemaDataModel = ModelReaderUtils.read(schemafilename);
229:                return schemaDataModel;
230:
231:            }
232:
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.