Source Code Cross Referenced for AbstractParser.java in  » Database-ORM » Speedo_1.4.5 » org » objectweb » speedo » generation » parser » 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 » Database ORM » Speedo_1.4.5 » org.objectweb.speedo.generation.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.speedo.generation.parser;
002:
003:        import java.io.File;
004:        import java.util.Iterator;
005:        import java.util.Properties;
006:
007:        import org.apache.tools.ant.types.DTDLocation;
008:        import org.objectweb.jorm.xml2mi.lib.SAXParserHelper;
009:        import org.objectweb.speedo.api.SpeedoException;
010:        import org.objectweb.speedo.api.SpeedoProperties;
011:        import org.objectweb.speedo.generation.lib.AbstractGeneratorComponent;
012:        import org.objectweb.speedo.lib.Personality;
013:        import org.objectweb.speedo.metadata.SpeedoClass;
014:        import org.objectweb.speedo.metadata.SpeedoPackage;
015:        import org.objectweb.speedo.metadata.SpeedoXMLDescriptor;
016:        import org.objectweb.util.monolog.api.BasicLevel;
017:        import org.w3c.dom.Document;
018:        import org.w3c.dom.Node;
019:        import org.xml.sax.SAXException;
020:
021:        public abstract class AbstractParser extends AbstractGeneratorComponent {
022:            public static String LOGGER_NAME = SpeedoProperties.LOGGER_NAME
023:                    + ".generation.parser.";
024:            SAXParserHelper parser;
025:            int parsedfiles;
026:
027:            abstract protected String getLoggerName();
028:
029:            public AbstractParser(Personality p) {
030:                super (p);
031:            }
032:
033:            /**
034:             * Create the XML file descriptor.
035:             * It throws an exception if the XML file doesn't follow the relevant dtd.
036:             * @param node root node of the descriptor which will be return.
037:             * @param o default descriptor to return.
038:             * @return descriptor.
039:             */
040:            abstract protected Object treatDocument(Node node, Object o)
041:                    throws SpeedoException;
042:
043:            /**
044:             * The parser instance is reused at each process method call
045:             */
046:
047:            // IMPLEMENTATION OF THE GeneratorComponent INTERFACE //
048:            //----------------------------------------------------//
049:            public boolean init() throws SpeedoException {
050:                logger = scp.loggerFactory.getLogger(LOGGER_NAME
051:                        + getLoggerName());
052:                logger.log(BasicLevel.DEBUG, "- " + getLoggerName()
053:                        + " XML descriptor Parsing -");
054:                if (scp.xml.isEmpty())
055:                    return false;
056:                Properties p = new Properties();
057:                for (Iterator iter = scp.dtdLocations.iterator(); iter
058:                        .hasNext();) {
059:                    DTDLocation element = (DTDLocation) iter.next();
060:                    p.setProperty(element.getPublicId(), element.getLocation());
061:                }
062:                try {
063:                    parser = new SAXParserHelper(p, logger, getClass()
064:                            .getClassLoader(), false);
065:                } catch (SAXException e) {
066:                    throw new SpeedoException(e);
067:                }
068:                parsedfiles = 0;
069:                return true;
070:            }
071:
072:            public void process() throws SpeedoException {
073:                if (scp.xml.isEmpty())
074:                    return;
075:                logger
076:                        .log(BasicLevel.DEBUG, scp.xml.size()
077:                                + " files to parse");
078:                for (Iterator it = scp.xml.iterator(); it.hasNext();) {
079:                    String xmlFileName = (String) it.next();
080:                    logger.log(BasicLevel.DEBUG, "Parse " + xmlFileName);
081:                    scp.getXmldescriptor().put(xmlFileName,
082:                            createObjectModel(xmlFileName));
083:                }
084:                parsedfiles += scp.xml.size();
085:            }
086:
087:            public String getTitle() {
088:                return "Loading " + getLoggerName() + " descriptor files...";
089:            }
090:
091:            public String getSummary() {
092:                return parsedfiles + " descriptor(s) parsed";
093:            }
094:
095:            // PRIVATE METHODS //
096:            //-----------------//
097:
098:            /**
099:             * This method constructs an object descriptor from a XML file.
100:             * It returns the new object descriptor.
101:             * If the file isn't well formed, a SpeedoXMLError is thrown.
102:             * @param xmlFile file name.
103:             * @return object descriptor for this file
104:             * @exception SpeedoException if the XML file doesn't follow the
105:             * relevant dtd.
106:             */
107:            private SpeedoXMLDescriptor createObjectModel(String xmlFile)
108:                    throws SpeedoException {
109:                try {
110:                    // parse the document
111:                    Document document = parser.parse(scp.xmlDir
112:                            + File.separator + xmlFile);
113:                    //create a descriptor for the document
114:                    SpeedoXMLDescriptor desc = new SpeedoXMLDescriptor(scp.smi);
115:                    desc.xmlFile = xmlFile;
116:                    //fill and return the file descriptor
117:                    return (SpeedoXMLDescriptor) treatDocument(document, desc);
118:                } catch (SpeedoException e) {
119:                    throw e;
120:                } catch (Exception e) {
121:                    String msg = "Error with the construction of file "
122:                            + scp.xmlDir + File.separator + xmlFile;
123:                    logger.log(BasicLevel.ERROR, msg);
124:                    throw new SpeedoException(msg, e);
125:                }
126:            }
127:
128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.