Source Code Cross Referenced for DemoHandler.java in  » Database-ORM » castor » dtx » 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 » castor » dtx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // dtx.DemoHandler -- public domain example, borrowed from the SAX package.
002:        // just put into the dtx package to make it easier to run.
003:
004:        // original notice:
005:
006:        // SAX event handler for demos.
007:        // No warranty; no copyright -- use this as you will.
008:
009:        package dtx;
010:
011:        import org.xml.sax.InputSource;
012:        import org.xml.sax.Locator;
013:        import org.xml.sax.AttributeList;
014:        import org.xml.sax.EntityResolver;
015:        import org.xml.sax.DTDHandler;
016:        import org.xml.sax.DocumentHandler;
017:        import org.xml.sax.ErrorHandler;
018:        import org.xml.sax.SAXParseException;
019:
020:        /**
021:         * Event handler class for SAX demos.
022:         *
023:         * <p>This handler simply reports all of the events that it receives.
024:         * It is useful for testing and comparing SAX implementations, and
025:         * for teaching or learning about SAX.  This is also a demonstration
026:         * of how one class can implement all four handler interfaces.</p>
027:         *
028:         * @see org.xml.sax.EntityResolver
029:         * @see org.xml.sax.DTDHandler
030:         * @see org.xml.sax.DocumentHandler
031:         * @see org.xml.sax.ErrorHandler
032:         */
033:        public class DemoHandler implements  EntityResolver, DTDHandler,
034:                DocumentHandler, ErrorHandler {
035:
036:            //////////////////////////////////////////////////////////////////////
037:            // Implementation of org.xml.sax.EntityResolver
038:            //////////////////////////////////////////////////////////////////////
039:
040:            /**
041:             * Display requests for entity resolution.
042:             *
043:             * <p>The SAX parser will invoke this method to give the application
044:             * a chance to resolve entities.  This implementation always
045:             * returns null, so that the parser will resolve the entity
046:             * itself.</p>
047:             *
048:             * @see org.xml.sax.EntityResolver#resolveEntity
049:             */
050:            public InputSource resolveEntity(String publicId, String systemId) {
051:                System.out.print("Resolve entity:");
052:                if (publicId != null) {
053:                    System.out.print(" publicId=\"" + publicId + '"');
054:                }
055:                System.out.println(" systemId=\"" + systemId + '"');
056:
057:                return null;
058:            }
059:
060:            //////////////////////////////////////////////////////////////////////
061:            // Implementation of org.xml.sax.DTDHandler
062:            //////////////////////////////////////////////////////////////////////
063:
064:            /**
065:             * Display notation declarations as they are reported.
066:             *
067:             * @see org.xml.sax.DTDHandler#notationDecl
068:             */
069:            public void notationDecl(String name, String publicId,
070:                    String systemId) {
071:                System.out.print("Notation declaration: " + name);
072:                if (publicId != null) {
073:                    System.out.print(" publicId=\"" + publicId + '"');
074:                }
075:                if (systemId != null) {
076:                    System.out.print(" systemId=\"" + systemId + '"');
077:                }
078:                System.out.print('\n');
079:            }
080:
081:            /**
082:             * Display unparsed entity declarations as they are reported.
083:             *
084:             * @see org.xml.sax.DTDHandler#unparsedEntityDecl
085:             */
086:            public void unparsedEntityDecl(String name, String publicId,
087:                    String systemId, String notationName) {
088:                System.out.print("Unparsed Entity Declaration: " + name);
089:                if (publicId != null) {
090:                    System.out.print(" publicId=\"" + publicId + '"');
091:                }
092:                if (systemId != null) {
093:                    System.out.print(" systemId=\"" + systemId + '"');
094:                }
095:                System.out.println(" notationName=\"" + notationName + '"');
096:            }
097:
098:            //////////////////////////////////////////////////////////////////////
099:            // Implementation of org.xml.sax.DocumentHandler
100:            //////////////////////////////////////////////////////////////////////
101:
102:            /**
103:             * Print a message when the parser provides a locator.
104:             *
105:             * <p>Not all SAX parsers will provide a locator object.</p>
106:             *
107:             * @see org.xml.sax.DocumentHandler#setDocumentLocator
108:             */
109:            public void setDocumentLocator(Locator locator) {
110:                System.out.println("Document locator supplied.");
111:            }
112:
113:            /**
114:             * Print a message at the start of the document.
115:             *
116:             * @see org.xml.sax.DocumentHandler#startDocument
117:             */
118:            public void startDocument() {
119:                System.out.println("Start document");
120:            }
121:
122:            /**
123:             * Print a message for the end of the document.
124:             *
125:             * @see org.xml.sax.DocumentHandler#endDocument
126:             */
127:            public void endDocument() {
128:                System.out.println("End document");
129:            }
130:
131:            /**
132:             * Print a message for the start of an element.
133:             *
134:             * <p>Display all attributes on separate lines, indented.</p>
135:             *
136:             * @see org.xml.sax.DocumentHandler#startElement
137:             */
138:            public void startElement(String name, AttributeList attributes) {
139:                System.out.println("Start element: " + name);
140:                for (int i = 0; i < attributes.getLength(); i++) {
141:                    System.out.println("  Attribute: " + attributes.getName(i)
142:                            + ' ' + attributes.getType(i) + " \""
143:                            + attributes.getValue(i) + '"');
144:                }
145:            }
146:
147:            /**
148:             * Print a message for the end of an element.
149:             *
150:             * @see org.xml.sax.DocumentHandler#endElement
151:             */
152:            public void endElement(String name) {
153:                System.out.println("End element: " + name);
154:            }
155:
156:            /**
157:             * Print a message for character data.
158:             *
159:             * @see org.xml.sax.DocumentHandler#characters
160:             */
161:            public void characters(char ch[], int start, int length) {
162:                System.out.print("Characters: ");
163:                display(ch, start, length);
164:            }
165:
166:            /**
167:             * Print a message for ignorable whitespace.
168:             *
169:             * @see org.xml.sax.DocumentHandler#ignorableWhitespace
170:             */
171:            public void ignorableWhitespace(char ch[], int start, int length) {
172:                System.out.print("Ignorable Whitespace: ");
173:                display(ch, start, length);
174:            }
175:
176:            /**
177:             * Print a message for a processing instruction.
178:             *
179:             * @see org.xml.sax.DocumentHandler#processingInstruction
180:             */
181:            public void processingInstruction(String target, String data) {
182:                System.out.println("Processing instruction: " + target + ' '
183:                        + data);
184:            }
185:
186:            //////////////////////////////////////////////////////////////////////
187:            // Implementation of org.xml.sax.ErrorHandler
188:            //////////////////////////////////////////////////////////////////////
189:
190:            /**
191:             * Report all warnings, and continue parsing.
192:             *
193:             * @see org.xml.sax.ErrorHandler#warning
194:             */
195:            public void warning(SAXParseException exception) {
196:                System.out.println("Warning: " + exception.getMessage() + " ("
197:                        + exception.getSystemId() + ':'
198:                        + exception.getLineNumber() + ','
199:                        + exception.getColumnNumber() + ')');
200:            }
201:
202:            /**
203:             * Report all recoverable errors, and try to continue parsing.
204:             *
205:             * @see org.xml.sax.ErrorHandler#error
206:             */
207:            public void error(SAXParseException exception) {
208:                System.out.println("Recoverable Error: "
209:                        + exception.getMessage() + " ("
210:                        + exception.getSystemId() + ':'
211:                        + exception.getLineNumber() + ','
212:                        + exception.getColumnNumber() + ')');
213:            }
214:
215:            /**
216:             * Report all fatal errors, and try to continue parsing.
217:             *
218:             * <p>Note: results are no longer reliable once a fatal error has
219:             * been reported.</p>
220:             *
221:             * @see org.xml.sax.ErrorHandler#fatalError
222:             */
223:            public void fatalError(SAXParseException exception) {
224:                System.out.println("Fatal Error: " + exception.getMessage()
225:                        + " (" + exception.getSystemId() + ':'
226:                        + exception.getLineNumber() + ','
227:                        + exception.getColumnNumber() + ')');
228:            }
229:
230:            //////////////////////////////////////////////////////////////////////
231:            // Utility routines.
232:            //////////////////////////////////////////////////////////////////////
233:
234:            /**
235:             * Display text, escaping some characters.
236:             */
237:            private static void display(char ch[], int start, int length) {
238:                for (int i = start; i < start + length; i++) {
239:                    switch (ch[i]) {
240:                    case '\n':
241:                        System.out.print("\\n");
242:                        break;
243:                    case '\t':
244:                        System.out.print("\\t");
245:                        break;
246:                    default:
247:                        System.out.print(ch[i]);
248:                        break;
249:                    }
250:                }
251:                System.out.print("\n");
252:            }
253:
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.