Source Code Cross Referenced for DigesterLoader.java in  » XML » digester » org » apache » commons » digester » xmlrules » 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 » XML » digester » org.apache.commons.digester.xmlrules 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* $Id: DigesterLoader.java 471661 2006-11-06 08:09:25Z skitching $
002:         *
003:         * Licensed to the Apache Software Foundation (ASF) under one or more
004:         * contributor license agreements.  See the NOTICE file distributed with
005:         * this work for additional information regarding copyright ownership.
006:         * The ASF licenses this file to You under the Apache License, Version 2.0
007:         * (the "License"); you may not use this file except in compliance with
008:         * the License.  You may obtain a copy of the License at
009:         * 
010:         *      http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        package org.apache.commons.digester.xmlrules;
020:
021:        import java.io.IOException;
022:        import java.io.InputStream;
023:        import java.io.Reader;
024:        import java.net.URL;
025:
026:        import org.apache.commons.digester.Digester;
027:        import org.apache.commons.digester.RuleSet;
028:
029:        import org.xml.sax.SAXException;
030:        import org.xml.sax.InputSource;
031:
032:        /**
033:         * This class manages the creation of Digester instances from XML digester
034:         * rules files.
035:         *
036:         * @since 1.2
037:         */
038:
039:        public class DigesterLoader {
040:
041:            /**
042:             * Creates a new digester and initializes it from the specified InputSource
043:             * @param rulesSource load the xml rules from this InputSource
044:             * @return a new Digester initialized with the rules
045:             */
046:            public static Digester createDigester(InputSource rulesSource) {
047:                RuleSet ruleSet = new FromXmlRuleSet(rulesSource);
048:                Digester digester = new Digester();
049:                digester.addRuleSet(ruleSet);
050:                return digester;
051:            }
052:
053:            /**
054:             * Creates a new digester and initializes it from the specified InputSource.
055:             * This constructor allows the digester to be used to load the rules to be specified.
056:             * This allows properties to be configured on the Digester instance before it is used.
057:             *
058:             * @param rulesSource load the xml rules from this InputSource
059:             * @param rulesDigester digester to load the specified XML file.
060:             * @return a new Digester initialized with the rules
061:             */
062:            public static Digester createDigester(InputSource rulesSource,
063:                    Digester rulesDigester) {
064:                RuleSet ruleSet = new FromXmlRuleSet(rulesSource, rulesDigester);
065:                Digester digester = new Digester();
066:                digester.addRuleSet(ruleSet);
067:                return digester;
068:            }
069:
070:            /**
071:             * Creates a new digester and initializes it from the specified XML file
072:             * @param rulesXml URL to the XML file defining the digester rules
073:             * @return a new Digester initialized with the rules
074:             */
075:            public static Digester createDigester(URL rulesXml) {
076:                RuleSet ruleSet = new FromXmlRuleSet(rulesXml);
077:                Digester digester = new Digester();
078:                digester.addRuleSet(ruleSet);
079:                return digester;
080:            }
081:
082:            /**
083:             * Creates a new digester and initializes it from the specified XML file.
084:             * This constructor allows specifing a rulesDigester to do the XML file
085:             * loading; thus no matter the XML files is packed into a jar, a war, or a
086:             * ear, the rulesDigester can always find the XML files with properly set
087:             * ClassLoader.
088:             *
089:             * @param rulesXml URL to the XML file defining the digester rules
090:             * @param rulesDigester digester to load the specified XML file.
091:             * @return a new Digester initialized with the rules
092:             */
093:            public static Digester createDigester(URL rulesXml,
094:                    Digester rulesDigester) {
095:                RuleSet ruleSet = new FromXmlRuleSet(rulesXml, rulesDigester);
096:                Digester digester = new Digester();
097:                digester.addRuleSet(ruleSet);
098:                return digester;
099:            }
100:
101:            /**
102:             * Given the digester rules XML file, a class loader, and an XML input file,
103:             * this method parses the input file into Java objects. The class loader
104:             * is used by the digester to create the Java objects.
105:             * @param digesterRules URL to the XML document defining the digester rules
106:             * @param classLoader the ClassLoader to register with the digester
107:             * @param fileURL URL to the XML file to parse into Java objects
108:             * @return an Object which is the root of the network of Java objects
109:             * created by digesting fileURL
110:             */
111:            public static Object load(URL digesterRules,
112:                    ClassLoader classLoader, URL fileURL) throws IOException,
113:                    SAXException, DigesterLoadingException {
114:                return load(digesterRules, classLoader, fileURL.openStream());
115:            }
116:
117:            /**
118:             * Given the digester rules XML file, a class loader, and an input stream,
119:             * this method parses the input into Java objects. The class loader
120:             * is used by the digester to create the Java objects.
121:             * @param digesterRules URL to the XML document defining the digester rules
122:             * @param classLoader the ClassLoader to register with the digester
123:             * @param input InputStream over the XML file to parse into Java objects
124:             * @return an Object which is the root of the network of Java objects
125:             * created by digesting fileURL
126:             */
127:            public static Object load(URL digesterRules,
128:                    ClassLoader classLoader, InputStream input)
129:                    throws IOException, SAXException, DigesterLoadingException {
130:                Digester digester = createDigester(digesterRules);
131:                digester.setClassLoader(classLoader);
132:                try {
133:                    return digester.parse(input);
134:                } catch (XmlLoadException ex) {
135:                    // This is a runtime exception that can be thrown by
136:                    // FromXmlRuleSet#addRuleInstances, which is called by the Digester
137:                    // before it parses the file.
138:                    throw new DigesterLoadingException(ex.getMessage(), ex);
139:                }
140:            }
141:
142:            /**
143:             * Given the digester rules XML file, a class loader, and an input stream,
144:             * this method parses the input into Java objects. The class loader
145:             * is used by the digester to create the Java objects.
146:             * @param digesterRules URL to the XML document defining the digester rules
147:             * @param classLoader the ClassLoader to register with the digester
148:             * @param reader Reader over the XML file to parse into Java objects
149:             * @return an Object which is the root of the network of Java objects
150:             * created by digesting fileURL
151:             */
152:            public static Object load(URL digesterRules,
153:                    ClassLoader classLoader, Reader reader) throws IOException,
154:                    SAXException, DigesterLoadingException {
155:                Digester digester = createDigester(digesterRules);
156:                digester.setClassLoader(classLoader);
157:                try {
158:                    return digester.parse(reader);
159:                } catch (XmlLoadException ex) {
160:                    // This is a runtime exception that can be thrown by
161:                    // FromXmlRuleSet#addRuleInstances, which is called by the Digester
162:                    // before it parses the file.
163:                    throw new DigesterLoadingException(ex.getMessage(), ex);
164:                }
165:            }
166:
167:            /**
168:             * Given the digester rules XML file, a class loader, and an XML input file,
169:             * this method parses the input file into Java objects. The class loader
170:             * is used by the digester to create the Java objects.
171:             * @param digesterRules URL to the XML document defining the digester rules
172:             * @param classLoader the ClassLoader to register with the digester
173:             * @param fileURL URL to the XML file to parse into Java objects
174:             * @param rootObject an Object to push onto the digester's stack, prior
175:             * to parsing the input
176:             * @return an Object which is the root of the network of Java objects.
177:             * Usually, this will be the same object as rootObject
178:             * created by digesting fileURL
179:             */
180:            public static Object load(URL digesterRules,
181:                    ClassLoader classLoader, URL fileURL, Object rootObject)
182:                    throws IOException, SAXException, DigesterLoadingException {
183:                return load(digesterRules, classLoader, fileURL.openStream(),
184:                        rootObject);
185:            }
186:
187:            /**
188:             * Given the digester rules XML file, a class loader, and an input stream,
189:             * this method parses the input into Java objects. The class loader
190:             * is used by the digester to create the Java objects.
191:             * @param digesterRules URL to the XML document defining the digester rules
192:             * @param classLoader the ClassLoader to register with the digester
193:             * @param input InputStream over the XML file to parse into Java objects
194:             * @param rootObject an Object to push onto the digester's stack, prior
195:             * to parsing the input
196:             * @return an Object which is the root of the network of Java objects
197:             * created by digesting fileURL
198:             */
199:            public static Object load(URL digesterRules,
200:                    ClassLoader classLoader, InputStream input,
201:                    Object rootObject) throws IOException, SAXException,
202:                    DigesterLoadingException {
203:                Digester digester = createDigester(digesterRules);
204:                digester.setClassLoader(classLoader);
205:                digester.push(rootObject);
206:                try {
207:                    return digester.parse(input);
208:                } catch (XmlLoadException ex) {
209:                    // This is a runtime exception that can be thrown by
210:                    // FromXmlRuleSet#addRuleInstances, which is called by the Digester
211:                    // before it parses the file.
212:                    throw new DigesterLoadingException(ex.getMessage(), ex);
213:                }
214:            }
215:
216:            /**
217:             * Given the digester rules XML file, a class loader, and an input stream,
218:             * this method parses the input into Java objects. The class loader
219:             * is used by the digester to create the Java objects.
220:             * @param digesterRules URL to the XML document defining the digester rules
221:             * @param classLoader the ClassLoader to register with the digester
222:             * @param input Reader over the XML file to parse into Java objects
223:             * @param rootObject an Object to push onto the digester's stack, prior
224:             * to parsing the input
225:             * @return an Object which is the root of the network of Java objects
226:             * created by digesting fileURL
227:             */
228:            public static Object load(URL digesterRules,
229:                    ClassLoader classLoader, Reader input, Object rootObject)
230:                    throws IOException, SAXException, DigesterLoadingException {
231:                Digester digester = createDigester(digesterRules);
232:                digester.setClassLoader(classLoader);
233:                digester.push(rootObject);
234:                try {
235:                    return digester.parse(input);
236:                } catch (XmlLoadException ex) {
237:                    // This is a runtime exception that can be thrown by
238:                    // FromXmlRuleSet#addRuleInstances, which is called by the Digester
239:                    // before it parses the file.
240:                    throw new DigesterLoadingException(ex.getMessage(), ex);
241:                }
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.