Source Code Cross Referenced for XMLDescrReader.java in  » Web-Server » Jigsaw » org » w3c » tools » resources » serialization » xml » 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 » Web Server » Jigsaw » org.w3c.tools.resources.serialization.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // XMLDescrReader.java
002:        // $Id: XMLDescrReader.java,v 1.9 2007/04/04 12:22:10 ylafon Exp $
003:        // (c) COPYRIGHT MIT, INRIA and Keio, 1999.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:        package org.w3c.tools.resources.serialization.xml;
006:
007:        import java.io.IOException;
008:        import java.io.Reader;
009:
010:        import java.util.Vector;
011:        import java.util.Hashtable;
012:        import java.util.Stack;
013:
014:        import org.xml.sax.AttributeList;
015:        import org.xml.sax.HandlerBase;
016:        import org.xml.sax.InputSource;
017:        import org.xml.sax.Parser;
018:        import org.xml.sax.SAXException;
019:        import org.xml.sax.SAXParseException;
020:
021:        import org.w3c.tools.resources.Resource;
022:        import org.w3c.tools.resources.UnknownResource;
023:        import org.w3c.tools.resources.ResourceFrame;
024:        import org.w3c.tools.resources.Attribute;
025:        import org.w3c.tools.resources.SimpleAttribute;
026:        import org.w3c.tools.resources.ArrayAttribute;
027:        import org.w3c.tools.resources.serialization.SerializationException;
028:        import org.w3c.tools.resources.serialization.AttributeDescription;
029:        import org.w3c.tools.resources.serialization.ResourceDescription;
030:        import org.w3c.tools.resources.serialization.EmptyDescription;
031:
032:        /**
033:         * @version $Revision: 1.9 $
034:         * @author  Benoît Mahé (bmahe@w3.org)
035:         */
036:        public class XMLDescrReader extends HandlerBase implements  JigXML {
037:
038:            Parser parser = null;
039:            ResourceDescription resources[] = null;
040:
041:            Reader reader = null;
042:            Stack resourceSetStack = null;
043:            Stack resourceStack = null;
044:            Stack defsStack = null;
045:            Stack classes = null;
046:            Stack interfaces = null;
047:            Stack FAStack = null;
048:            Vector children = null;
049:            SimpleAttribute currentS = null;
050:            ArrayAttribute currentA = null;
051:            int length = -1;
052:            boolean isavalue = false;
053:            String array[] = null;
054:            int arrayidx = -1;
055:            StringBuffer characters = null;
056:            String charvalue = null;
057:
058:            public void startElement(String name, AttributeList attributes)
059:                    throws SAXException {
060:                endCharacters();
061:                String iname = name.intern();
062:                if (iname == iINHERIT_TAG) {
063:                    Vector vclasses = (Vector) classes.peek();
064:                    vclasses.addElement(attributes.getValue(CLASS_ATTR));
065:                } else if (iname == iIMPLEMENTS_TAG) {
066:                    Vector vinterfaces = (Vector) interfaces.peek();
067:                    vinterfaces.addElement(attributes.getValue(CLASS_ATTR));
068:                } else if (iname == iCHILDREN_TAG) {
069:                    length = Integer.parseInt(attributes.getValue(LENGTH_ATTR));
070:                    array = new String[length];
071:                    arrayidx = 0;
072:                } else if (iname == iDESCR_TAG) {
073:                    String resourceclass = attributes.getValue(CLASS_ATTR);
074:                    String identifier = attributes.getValue(NAME_ATTR);
075:                    if (identifier.equals(NULL))
076:                        identifier = null;
077:                    resourceStack.push(new EmptyDescription(resourceclass,
078:                            identifier));
079:
080:                } else if (iname == iRESOURCE_TAG) {
081:                    String resourceclass = attributes.getValue(CLASS_ATTR);
082:                    resourceStack.push(new ResourceDescription(resourceclass));
083:                    defsStack.push(new Vector(10));
084:                    Vector vcls = new Vector(8);
085:                    vcls.addElement(resourceclass);
086:                    classes.push(vcls);
087:                    interfaces.push(new Vector(8));
088:                } else if (iname == iATTRIBUTE_TAG) {
089:                    String attrclass = attributes.getValue(CLASS_ATTR);
090:                    try {
091:                        Class c = Class.forName(attrclass);
092:                        currentS = (SimpleAttribute) c.newInstance();
093:                        currentS.setName(attributes.getValue(NAME_ATTR));
094:                        currentS.setFlag(attributes.getValue(FLAG_ATTR));
095:                    } catch (Exception ex) {
096:                        ex.printStackTrace();
097:                        currentS = null;
098:                    }
099:                } else if (iname == iARRAY_TAG) {
100:                    String attrclass = attributes.getValue(CLASS_ATTR);
101:                    try {
102:                        Class c = Class.forName(attrclass);
103:                        currentA = (ArrayAttribute) c.newInstance();
104:                        currentA.setName(attributes.getValue(NAME_ATTR));
105:                        currentA.setFlag(attributes.getValue(FLAG_ATTR));
106:                        length = Integer.parseInt(attributes
107:                                .getValue(LENGTH_ATTR));
108:                        array = new String[length];
109:                        arrayidx = 0;
110:                    } catch (Exception ex) {
111:                        ex.printStackTrace();
112:                        currentA = null;
113:                    }
114:                } else if (iname == iRESARRAY_TAG) {
115:                    resourceSetStack.push(new Vector(10));
116:                    String attrclass = attributes.getValue(CLASS_ATTR);
117:                    try {
118:                        Class c = Class.forName(attrclass);
119:                        Attribute attr = (Attribute) c.newInstance();
120:                        attr.setName(attributes.getValue(NAME_ATTR));
121:                        FAStack.push(attr);
122:                    } catch (Exception ex) {
123:                        ex.printStackTrace();
124:                        throw new SAXException(
125:                                "Unable to create an instance of " + attrclass);
126:                    }
127:                } else if ((iname == iCHILD_TAG) || (iname == iVALUE_TAG)) {
128:                    isavalue = true;
129:                }
130:            }
131:
132:            public void endElement(String name) throws SAXException {
133:                endCharacters();
134:                String iname = name.intern();
135:                if (iname == iRESOURCE_TAG) {
136:                    ResourceDescription res = (ResourceDescription) resourceStack
137:                            .pop();
138:                    res.setAttributeDescriptions((Vector) defsStack.pop());
139:                    Vector vresources = (Vector) resourceSetStack.peek();
140:                    vresources.addElement(res);
141:                    Vector vclasses = (Vector) classes.pop();
142:                    res.setClassHierarchy(vclasses);
143:                    Vector vinterfaces = (Vector) interfaces.pop();
144:                    res.setInterfaces(vinterfaces);
145:                } else if (iname == iCHILDREN_TAG) {
146:                    ResourceDescription res = (ResourceDescription) resourceStack
147:                            .peek();
148:                    res.setChildren(array);
149:                } else if (iname == iDESCR_TAG) {
150:                    ResourceDescription res = (ResourceDescription) resourceStack
151:                            .pop();
152:                    Vector vresources = (Vector) resourceSetStack.peek();
153:                    vresources.addElement(res);
154:                } else if (iname == iATTRIBUTE_TAG) {
155:                    currentS = null;
156:                } else if (iname == iARRAY_TAG) {
157:                    AttributeDescription ad = new AttributeDescription(
158:                            currentA, currentA.unpickle(array));
159:                    Vector attrs = (Vector) defsStack.peek();
160:                    attrs.addElement(ad);
161:                    currentA = null;
162:                } else if (iname == iRESARRAY_TAG) {
163:                    Vector vframes = (Vector) resourceSetStack.pop();
164:                    ResourceDescription frames[] = new ResourceDescription[vframes
165:                            .size()];
166:                    vframes.copyInto(frames);
167:                    AttributeDescription ad = new AttributeDescription(
168:                            (Attribute) FAStack.pop(), frames);
169:                    Vector attrs = (Vector) defsStack.peek();
170:                    attrs.addElement(ad);
171:                } else if ((iname == iCHILD_TAG) || (iname == iVALUE_TAG)) {
172:                    isavalue = false;
173:                }
174:            }
175:
176:            public void startDocument() throws SAXException {
177:                defsStack = new Stack();
178:                classes = new Stack();
179:                interfaces = new Stack();
180:                FAStack = new Stack();
181:                resourceStack = new Stack();
182:                resourceSetStack = new Stack();
183:                resourceSetStack.push(new Vector(10));
184:            }
185:
186:            public void endDocument() throws SAXException {
187:                Vector vresources = (Vector) resourceSetStack.pop();
188:                resources = new ResourceDescription[vresources.size()];
189:                vresources.copyInto(resources);
190:                try {
191:                    reader.close();
192:                } catch (IOException ex) {
193:                    ex.printStackTrace();
194:                }
195:            }
196:
197:            public void characters(char ch[], int start, int length)
198:                    throws SAXException {
199:                if (charvalue == null) {
200:                    charvalue = new String(ch, start, length);
201:                } else if (length > 0) {
202:                    if (characters == null) {
203:                        characters = new StringBuffer(charvalue);
204:                    }
205:                    characters.append(ch, start, length);
206:                }
207:            }
208:
209:            private void endCharacters() {
210:                String value;
211:                if (charvalue == null) {
212:                    return;
213:                }
214:                if (characters == null) {
215:                    value = charvalue;
216:                } else {
217:                    value = characters.toString();
218:                }
219:                characters = null;
220:                charvalue = null;
221:                if (currentS != null) {
222:                    AttributeDescription ad = null;
223:                    if (value.equals(NULL))
224:                        ad = new AttributeDescription(currentS, null);
225:                    else
226:                        ad = new AttributeDescription(currentS, currentS
227:                                .unpickle(value));
228:                    Vector attrs = (Vector) defsStack.peek();
229:                    attrs.addElement(ad);
230:                } else if (isavalue) {
231:                    array[arrayidx++] = value;
232:                }
233:            }
234:
235:            public void warning(SAXParseException e) throws SAXException {
236:                System.out.println("WARNING in element " + e.getPublicId());
237:                System.out.println("Sys  : " + e.getSystemId());
238:                System.out.println("Line : " + e.getLineNumber());
239:                System.out.println("Col  : " + e.getColumnNumber());
240:                e.printStackTrace();
241:            }
242:
243:            public void error(SAXParseException e) throws SAXException {
244:                System.out.println("ERROR in element " + e.getPublicId());
245:                System.out.println("Sys  : " + e.getSystemId());
246:                System.out.println("Line : " + e.getLineNumber());
247:                System.out.println("Col  : " + e.getColumnNumber());
248:                e.printStackTrace();
249:            }
250:
251:            public void fatalError(SAXParseException e) throws SAXException {
252:                System.out.println("FATAL ERROR in element " + e.getPublicId());
253:                System.out.println("Sys  : " + e.getSystemId());
254:                System.out.println("Line : " + e.getLineNumber());
255:                System.out.println("Col  : " + e.getColumnNumber());
256:                e.printStackTrace();
257:            }
258:
259:            protected void parse() throws SAXException, IOException {
260:                try {
261:                    parser.setDocumentHandler(this );
262:                    parser.setErrorHandler(this );
263:                    parser.parse(new InputSource(reader));
264:                } catch (IOException ex) {
265:                    try {
266:                        reader.close();
267:                    } catch (IOException ioex) {
268:                    }
269:                    throw ex;
270:                } catch (SAXException sex) {
271:                    try {
272:                        reader.close();
273:                    } catch (IOException ioex) {
274:                    }
275:                    throw sex;
276:                }
277:            }
278:
279:            public ResourceDescription[] readResourceDescriptions()
280:                    throws IOException, SerializationException {
281:                try {
282:                    parse();
283:                } catch (SAXException ex) {
284:                    ex.printStackTrace();
285:                    return new ResourceDescription[0];
286:                }
287:
288:                return resources;
289:            }
290:
291:            public XMLDescrReader(Reader reader, Parser parser) {
292:                this.reader = reader;
293:                this.parser = parser;
294:            }
295:
296:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.