Source Code Cross Referenced for XmlProcessorProperties.java in  » Code-Analyzer » Spoon » spoon » support » processing » 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 » Code Analyzer » Spoon » spoon.support.processing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Spoon - http://spoon.gforge.inria.fr/
003:         * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
004:         *
005:         * This software is governed by the CeCILL-C License under French law and
006:         * abiding by the rules of distribution of free software. You can use, modify
007:         * and/or redistribute the software under the terms of the CeCILL-C license as
008:         * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
009:         *
010:         * This program is distributed in the hope that it will be useful, but WITHOUT
011:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012:         * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
013:         *
014:         * The fact that you are presently reading this means that you have had
015:         * knowledge of the CeCILL-C license and that you accept its terms.
016:         */
017:
018:        package spoon.support.processing;
019:
020:        import java.io.IOException;
021:        import java.io.InputStream;
022:        import java.util.ArrayList;
023:        import java.util.Collection;
024:        import java.util.Map;
025:        import java.util.TreeMap;
026:        import java.util.Map.Entry;
027:
028:        import org.xml.sax.Attributes;
029:        import org.xml.sax.InputSource;
030:        import org.xml.sax.SAXException;
031:        import org.xml.sax.XMLReader;
032:        import org.xml.sax.helpers.DefaultHandler;
033:        import org.xml.sax.helpers.XMLReaderFactory;
034:
035:        import spoon.processing.ProcessorProperties;
036:        import spoon.reflect.Factory;
037:
038:        /**
039:         * This class defines a processor properties accessor that parses an XML
040:         * description of the properties.
041:         */
042:        public class XmlProcessorProperties implements  ProcessorProperties {
043:
044:            /**
045:             * Defines the tag handler of an XML Spoon property file.
046:             */
047:            public class Loader extends DefaultHandler {
048:                boolean isValue = false;
049:
050:                String name;
051:
052:                Object value;
053:
054:                /**
055:                 * Handdles a tag content.
056:                 */
057:                @SuppressWarnings("unchecked")
058:                @Override
059:                public void characters(char[] ch, int start, int length)
060:                        throws SAXException {
061:                    if (isValue) {
062:                        if ((value == null) || !(value instanceof  Collection)) {
063:                            value = new ArrayList<Object>();
064:                        }
065:                        ((Collection<Object>) value).add(new String(ch, start,
066:                                length));
067:                    }
068:                }
069:
070:                /**
071:                 * Handdles a tag end.
072:                 */
073:                @Override
074:                public void endElement(String uri, String localName,
075:                        String qName) throws SAXException {
076:                    if (localName.equals("property")) {
077:                        props.put(name, value);
078:                        value = null;
079:                    } else if (localName.equals("value")) {
080:                        isValue = false;
081:                    }
082:                }
083:
084:                /**
085:                 * Handdles a tag start.
086:                 */
087:                @Override
088:                public void startElement(String uri, String localName,
089:                        String qName, Attributes attributes)
090:                        throws SAXException {
091:                    if (localName.equals("property")) {
092:                        name = attributes.getValue("name");
093:                        if (attributes.getValue("value") != null) {
094:                            value = attributes.getValue("value");
095:                        }
096:                    } else if (localName.equals("value")) {
097:                        isValue = true;
098:                    }
099:                }
100:            }
101:
102:            Factory factory;
103:
104:            String processorName;
105:
106:            private Map<String, Object> props = new TreeMap<String, Object>();
107:
108:            public XmlProcessorProperties(Factory factory, String processorName) {
109:                this .processorName = processorName;
110:                this .factory = factory;
111:            }
112:
113:            public XmlProcessorProperties(Factory factory,
114:                    String processorName, InputStream stream)
115:                    throws IOException, SAXException {
116:                this .processorName = processorName;
117:                this .factory = factory;
118:                load(stream);
119:            }
120:
121:            public void addProperty(String name, Object value) {
122:                props.put(name, value);
123:            }
124:
125:            @SuppressWarnings("unchecked")
126:            public <T> T get(Class<T> type, String name) {
127:                if (!props.containsKey(name)) {
128:                    return null;
129:                }
130:                if (type.isArray()) {
131:                    return (T) factory.convertArray(type.getComponentType(),
132:                            (Collection<Object>) props.get(name));
133:                }
134:                return factory.convert(type, props.get(name));
135:            }
136:
137:            public String getProcessorName() {
138:                return processorName;
139:            }
140:
141:            private void load(InputStream stream) throws IOException,
142:                    SAXException {
143:                if (stream == null) {
144:                    return;
145:                }
146:                XMLReader xr;
147:                xr = XMLReaderFactory.createXMLReader();
148:                Loader handler = new Loader();
149:                xr.setContentHandler(handler);
150:                xr.parse(new InputSource(stream));
151:            }
152:
153:            @Override
154:            public String toString() {
155:                StringBuffer buf = new StringBuffer();
156:                buf.append("Properties : \n");
157:
158:                for (Entry<String, Object> ent : props.entrySet()) {
159:                    buf.append(ent.getKey());
160:                    for (int i = ent.getKey().length(); i < 15; i++) {
161:                        buf.append(" ");
162:                    }
163:                    buf.append(": " + ent.getValue() + "\n");
164:                }
165:                return buf.toString();
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.