Source Code Cross Referenced for XSLoaderImpl.java in  » XML » xerces-2_9_1 » org » apache » xerces » impl » xs » 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 » xerces 2_9_1 » org.apache.xerces.impl.xs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.xerces.impl.xs;
019:
020:        import org.apache.xerces.impl.xs.XMLSchemaLoader;
021:        import org.apache.xerces.impl.xs.util.XSGrammarPool;
022:        import org.apache.xerces.xni.grammars.Grammar;
023:        import org.apache.xerces.xni.grammars.XMLGrammarDescription;
024:        import org.apache.xerces.xni.grammars.XSGrammar;
025:        import org.apache.xerces.xni.parser.XMLInputSource;
026:        import org.apache.xerces.xs.LSInputList;
027:        import org.apache.xerces.xs.StringList;
028:        import org.apache.xerces.xs.XSConstants;
029:        import org.apache.xerces.xs.XSLoader;
030:        import org.apache.xerces.xs.XSModel;
031:        import org.apache.xerces.xs.XSNamedMap;
032:        import org.apache.xerces.xs.XSObjectList;
033:        import org.apache.xerces.xs.XSTypeDefinition;
034:        import org.w3c.dom.DOMConfiguration;
035:        import org.w3c.dom.DOMException;
036:        import org.w3c.dom.DOMStringList;
037:        import org.w3c.dom.ls.LSInput;
038:
039:        /**
040:         * <p>An implementation of XSLoader which wraps XMLSchemaLoader.</p>
041:         * 
042:         * @xerces.internal
043:         * 
044:         * @author Michael Glavassevich, IBM
045:         * 
046:         * @version $Id: XSLoaderImpl.java 449487 2006-09-24 21:11:28Z mrglavas $
047:         */
048:        public final class XSLoaderImpl implements  XSLoader, DOMConfiguration {
049:
050:            /**
051:             * Grammar pool. Need this to prevent us from
052:             * getting two grammars from the same namespace.
053:             */
054:            private final XSGrammarPool fGrammarPool = new XSGrammarMerger();
055:
056:            /** Schema loader. **/
057:            private final XMLSchemaLoader fSchemaLoader = new XMLSchemaLoader();
058:
059:            /**
060:             * No-args constructor.
061:             */
062:            public XSLoaderImpl() {
063:                fSchemaLoader.setProperty(XMLSchemaLoader.XMLGRAMMAR_POOL,
064:                        fGrammarPool);
065:            }
066:
067:            /**
068:             *  The configuration of a document. It maintains a table of recognized 
069:             * parameters. Using the configuration, it is possible to change the 
070:             * behavior of the load methods. The configuration may support the 
071:             * setting of and the retrieval of the following non-boolean parameters 
072:             * defined on the <code>DOMConfiguration</code> interface: 
073:             * <code>error-handler</code> (<code>DOMErrorHandler</code>) and 
074:             * <code>resource-resolver</code> (<code>LSResourceResolver</code>). 
075:             * <br> The following list of boolean parameters is defined: 
076:             * <dl>
077:             * <dt>
078:             * <code>"validate"</code></dt>
079:             * <dd>
080:             * <dl>
081:             * <dt><code>true</code></dt>
082:             * <dd>[required] (default) Validate an XML 
083:             * Schema during loading. If validation errors are found, the error 
084:             * handler is notified. </dd>
085:             * <dt><code>false</code></dt>
086:             * <dd>[optional] Do not 
087:             * report errors during the loading of an XML Schema document. </dd>
088:             * </dl></dd>
089:             * </dl>
090:             */
091:            public DOMConfiguration getConfig() {
092:                return this ;
093:            }
094:
095:            /**
096:             * Parses the content of XML Schema documents specified as the list of URI 
097:             * references. If the URI contains a fragment identifier, the behavior 
098:             * is not defined by this specification. 
099:             * @param uriList The list of URI locations.
100:             * @return An XSModel representing the schema documents.
101:             */
102:            public XSModel loadURIList(StringList uriList) {
103:                int length = uriList.getLength();
104:                if (length == 0) {
105:                    return null;
106:                }
107:                try {
108:                    fGrammarPool.clear();
109:                    for (int i = 0; i < length; ++i) {
110:                        fSchemaLoader.loadGrammar(new XMLInputSource(null,
111:                                uriList.item(i), null));
112:                    }
113:                    return fGrammarPool.toXSModel();
114:                } catch (Exception e) {
115:                    fSchemaLoader.reportDOMFatalError(e);
116:                    return null;
117:                }
118:            }
119:
120:            /**
121:             *  Parses the content of XML Schema documents specified as a list of 
122:             * <code>LSInput</code>s. 
123:             * @param is  The list of <code>LSInput</code>s from which the XML 
124:             *   Schema documents are to be read. 
125:             * @return An XSModel representing the schema documents.
126:             */
127:            public XSModel loadInputList(LSInputList is) {
128:                final int length = is.getLength();
129:                if (length == 0) {
130:                    return null;
131:                }
132:                try {
133:                    fGrammarPool.clear();
134:                    for (int i = 0; i < length; ++i) {
135:                        fSchemaLoader.loadGrammar(fSchemaLoader
136:                                .dom2xmlInputSource(is.item(i)));
137:                    }
138:                    return fGrammarPool.toXSModel();
139:                } catch (Exception e) {
140:                    fSchemaLoader.reportDOMFatalError(e);
141:                    return null;
142:                }
143:            }
144:
145:            /**
146:             * Parse an XML Schema document from a location identified by a URI 
147:             * reference. If the URI contains a fragment identifier, the behavior is 
148:             * not defined by this specification. 
149:             * @param uri The location of the XML Schema document to be read.
150:             * @return An XSModel representing this schema.
151:             */
152:            public XSModel loadURI(String uri) {
153:                try {
154:                    fGrammarPool.clear();
155:                    return ((XSGrammar) fSchemaLoader
156:                            .loadGrammar(new XMLInputSource(null, uri, null)))
157:                            .toXSModel();
158:                } catch (Exception e) {
159:                    fSchemaLoader.reportDOMFatalError(e);
160:                    return null;
161:                }
162:            }
163:
164:            /**
165:             *  Parse an XML Schema document from a resource identified by a 
166:             * <code>LSInput</code> . 
167:             * @param is  The <code>LSInput</code> from which the source 
168:             *   document is to be read. 
169:             * @return An XSModel representing this schema.
170:             */
171:            public XSModel load(LSInput is) {
172:                try {
173:                    fGrammarPool.clear();
174:                    return ((XSGrammar) fSchemaLoader.loadGrammar(fSchemaLoader
175:                            .dom2xmlInputSource(is))).toXSModel();
176:                } catch (Exception e) {
177:                    fSchemaLoader.reportDOMFatalError(e);
178:                    return null;
179:                }
180:            }
181:
182:            /* (non-Javadoc)
183:             * @see org.apache.xerces.dom3.DOMConfiguration#setParameter(java.lang.String, java.lang.Object)
184:             */
185:            public void setParameter(String name, Object value)
186:                    throws DOMException {
187:                fSchemaLoader.setParameter(name, value);
188:            }
189:
190:            /* (non-Javadoc)
191:             * @see org.apache.xerces.dom3.DOMConfiguration#getParameter(java.lang.String)
192:             */
193:            public Object getParameter(String name) throws DOMException {
194:                return fSchemaLoader.getParameter(name);
195:            }
196:
197:            /* (non-Javadoc)
198:             * @see org.apache.xerces.dom3.DOMConfiguration#canSetParameter(java.lang.String, java.lang.Object)
199:             */
200:            public boolean canSetParameter(String name, Object value) {
201:                return fSchemaLoader.canSetParameter(name, value);
202:            }
203:
204:            /* (non-Javadoc)
205:             * @see org.apache.xerces.dom3.DOMConfiguration#getParameterNames()
206:             */
207:            public DOMStringList getParameterNames() {
208:                return fSchemaLoader.getParameterNames();
209:            }
210:
211:            /** 
212:             * Grammar pool which merges grammars from the same namespace into one. This eliminates
213:             * duplicate named components. It doesn't ensure that the grammar is consistent, however
214:             * this no worse than than the behaviour of XMLSchemaLoader alone when used as an XSLoader.
215:             */
216:            private static final class XSGrammarMerger extends XSGrammarPool {
217:
218:                public XSGrammarMerger() {
219:                }
220:
221:                public void putGrammar(Grammar grammar) {
222:                    SchemaGrammar cachedGrammar = toSchemaGrammar(super 
223:                            .getGrammar(grammar.getGrammarDescription()));
224:                    if (cachedGrammar != null) {
225:                        SchemaGrammar newGrammar = toSchemaGrammar(grammar);
226:                        if (newGrammar != null) {
227:                            mergeSchemaGrammars(cachedGrammar, newGrammar);
228:                        }
229:                    } else {
230:                        super .putGrammar(grammar);
231:                    }
232:                }
233:
234:                private SchemaGrammar toSchemaGrammar(Grammar grammar) {
235:                    return (grammar instanceof  SchemaGrammar) ? (SchemaGrammar) grammar
236:                            : null;
237:                }
238:
239:                private void mergeSchemaGrammars(SchemaGrammar cachedGrammar,
240:                        SchemaGrammar newGrammar) {
241:
242:                    /** Add new top-level element declarations. **/
243:                    XSNamedMap map = newGrammar
244:                            .getComponents(XSConstants.ELEMENT_DECLARATION);
245:                    int length = map.getLength();
246:                    for (int i = 0; i < length; ++i) {
247:                        XSElementDecl decl = (XSElementDecl) map.item(i);
248:                        if (cachedGrammar.getGlobalElementDecl(decl.getName()) == null) {
249:                            cachedGrammar.addGlobalElementDecl(decl);
250:                        }
251:                    }
252:
253:                    /** Add new top-level attribute declarations. **/
254:                    map = newGrammar
255:                            .getComponents(XSConstants.ATTRIBUTE_DECLARATION);
256:                    length = map.getLength();
257:                    for (int i = 0; i < length; ++i) {
258:                        XSAttributeDecl decl = (XSAttributeDecl) map.item(i);
259:                        if (cachedGrammar
260:                                .getGlobalAttributeDecl(decl.getName()) == null) {
261:                            cachedGrammar.addGlobalAttributeDecl(decl);
262:                        }
263:                    }
264:
265:                    /** Add new top-level type definitions. **/
266:                    map = newGrammar.getComponents(XSConstants.TYPE_DEFINITION);
267:                    length = map.getLength();
268:                    for (int i = 0; i < length; ++i) {
269:                        XSTypeDefinition decl = (XSTypeDefinition) map.item(i);
270:                        if (cachedGrammar.getGlobalTypeDecl(decl.getName()) == null) {
271:                            cachedGrammar.addGlobalTypeDecl(decl);
272:                        }
273:                    }
274:
275:                    /** Add new top-level attribute group definitions. **/
276:                    map = newGrammar.getComponents(XSConstants.ATTRIBUTE_GROUP);
277:                    length = map.getLength();
278:                    for (int i = 0; i < length; ++i) {
279:                        XSAttributeGroupDecl decl = (XSAttributeGroupDecl) map
280:                                .item(i);
281:                        if (cachedGrammar.getGlobalAttributeGroupDecl(decl
282:                                .getName()) == null) {
283:                            cachedGrammar.addGlobalAttributeGroupDecl(decl);
284:                        }
285:                    }
286:
287:                    /** Add new top-level model group definitions. **/
288:                    map = newGrammar.getComponents(XSConstants.MODEL_GROUP);
289:                    length = map.getLength();
290:                    for (int i = 0; i < length; ++i) {
291:                        XSGroupDecl decl = (XSGroupDecl) map.item(i);
292:                        if (cachedGrammar.getGlobalGroupDecl(decl.getName()) == null) {
293:                            cachedGrammar.addGlobalGroupDecl(decl);
294:                        }
295:                    }
296:
297:                    /** Add new top-level notation declarations. **/
298:                    map = newGrammar
299:                            .getComponents(XSConstants.NOTATION_DECLARATION);
300:                    length = map.getLength();
301:                    for (int i = 0; i < length; ++i) {
302:                        XSNotationDecl decl = (XSNotationDecl) map.item(i);
303:                        if (cachedGrammar.getGlobalNotationDecl(decl.getName()) == null) {
304:                            cachedGrammar.addGlobalNotationDecl(decl);
305:                        }
306:                    }
307:
308:                    /** 
309:                     * Add all annotations. Since these components are not named it's
310:                     * possible we'll add duplicate components. There isn't much we can
311:                     * do. It's no worse than XMLSchemaLoader when used as an XSLoader.
312:                     */
313:                    XSObjectList annotations = newGrammar.getAnnotations();
314:                    length = annotations.getLength();
315:                    for (int i = 0; i < length; ++i) {
316:                        cachedGrammar
317:                                .addAnnotation((XSAnnotationImpl) annotations
318:                                        .item(i));
319:                    }
320:
321:                }
322:
323:                public boolean containsGrammar(XMLGrammarDescription desc) {
324:                    return false;
325:                }
326:
327:                public Grammar getGrammar(XMLGrammarDescription desc) {
328:                    return null;
329:                }
330:
331:                public Grammar retrieveGrammar(XMLGrammarDescription desc) {
332:                    return null;
333:                }
334:
335:                public Grammar[] retrieveInitialGrammarSet(String grammarType) {
336:                    return new Grammar[0];
337:                }
338:            }
339:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.