Source Code Cross Referenced for DOMASBuilderImpl.java in  » XML » xerces-2_9_1 » org » apache » xerces » parsers » 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.parsers 
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.parsers;
019:
020:        import java.util.Vector;
021:
022:        import org.apache.xerces.dom.ASModelImpl;
023:        import org.apache.xerces.dom3.as.ASModel;
024:        import org.apache.xerces.dom3.as.DOMASBuilder;
025:        import org.apache.xerces.dom3.as.DOMASException;
026:        import org.apache.xerces.impl.Constants;
027:        import org.apache.xerces.impl.xs.SchemaGrammar;
028:        import org.apache.xerces.impl.xs.XSGrammarBucket;
029:        import org.apache.xerces.util.SymbolTable;
030:        import org.apache.xerces.util.XMLGrammarPoolImpl;
031:        import org.apache.xerces.xni.XNIException;
032:        import org.apache.xerces.xni.grammars.Grammar;
033:        import org.apache.xerces.xni.grammars.XMLGrammarPool;
034:        import org.apache.xerces.xni.parser.XMLInputSource;
035:        import org.w3c.dom.ls.LSInput;
036:
037:        /**
038:         * This is Abstract Schema DOM Builder class. It extends the DOMParserImpl
039:         * class. Provides support for preparsing schemas.
040:         *
041:         * @deprecated
042:         * @author Pavani Mukthipudi, Sun Microsystems Inc.
043:         * @author Neil Graham, IBM
044:         * @version $Id: DOMASBuilderImpl.java 447239 2006-09-18 05:08:26Z mrglavas $
045:         *
046:         */
047:
048:        public class DOMASBuilderImpl extends DOMParserImpl implements 
049:                DOMASBuilder {
050:
051:            //
052:            // Constants
053:            //
054:
055:            // Feature ids
056:
057:            protected static final String SCHEMA_FULL_CHECKING = Constants.XERCES_FEATURE_PREFIX
058:                    + Constants.SCHEMA_FULL_CHECKING;
059:
060:            // Property ids
061:
062:            protected static final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX
063:                    + Constants.ERROR_REPORTER_PROPERTY;
064:
065:            protected static final String SYMBOL_TABLE = Constants.XERCES_PROPERTY_PREFIX
066:                    + Constants.SYMBOL_TABLE_PROPERTY;
067:
068:            protected static final String ENTITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX
069:                    + Constants.ENTITY_MANAGER_PROPERTY;
070:
071:            //
072:            // Data
073:            //
074:
075:            protected XSGrammarBucket fGrammarBucket;
076:
077:            protected ASModelImpl fAbstractSchema;
078:
079:            //
080:            // Constructors
081:            //
082:
083:            /**
084:             * Constructs a DOM Builder using the dtd/xml schema parser configuration.
085:             */
086:            public DOMASBuilderImpl() {
087:                super (new XMLGrammarCachingConfiguration());
088:            } // <init>
089:
090:            /**
091:             * Constructs a DOM Builder using the specified parser configuration.
092:             * We must demand that the configuration extend XMLGrammarCachingConfiguration to make
093:             * sure all relevant methods/features are available.
094:             */
095:            public DOMASBuilderImpl(XMLGrammarCachingConfiguration config) {
096:                super (config);
097:            } // <init>(XMLParserConfiguration)
098:
099:            /**
100:             * Constructs a DOM Builder using the specified symbol table.
101:             */
102:            public DOMASBuilderImpl(SymbolTable symbolTable) {
103:                super (new XMLGrammarCachingConfiguration(symbolTable));
104:            } // <init>(SymbolTable)
105:
106:            /**
107:             * Constructs a DOM Builder using the specified symbol table and
108:             * grammar pool.
109:             * The grammarPool implementation should extent the default
110:             * implementation; otherwise, correct functioning of this class may
111:             * not occur.
112:             */
113:            public DOMASBuilderImpl(SymbolTable symbolTable,
114:                    XMLGrammarPool grammarPool) {
115:                super (new XMLGrammarCachingConfiguration(symbolTable,
116:                        grammarPool));
117:            }
118:
119:            //
120:            // DOMASBuilder methods
121:            //
122:
123:            /**
124:             * Associate an <code>ASModel</code> with a document instance. This
125:             * <code>ASModel</code> will be used by the "
126:             * <code>validate-if-schema</code>" and "
127:             * <code>datatype-normalization</code>" options during the load of a new
128:             * <code>Document</code>.
129:             */
130:            public ASModel getAbstractSchema() {
131:                return fAbstractSchema;
132:            }
133:
134:            /**
135:             * Associate an <code>ASModel</code> with a document instance. This
136:             * <code>ASModel</code> will be used by the "
137:             * <code>validate-if-schema</code>" and "
138:             * <code>datatype-normalization</code>" options during the load of a new
139:             * <code>Document</code>.
140:             */
141:            public void setAbstractSchema(ASModel abstractSchema) {
142:
143:                // since the ASModel associated with this object is an attribute
144:                // according to the DOM IDL, we must obliterate anything
145:                // that was set before, rather than adding to it.
146:                // REVISIT:  so shouldn't we attempt to clear the
147:                // grammarPool before adding stuff to it?  - NG
148:                fAbstractSchema = (ASModelImpl) abstractSchema;
149:
150:                // make sure the GrammarPool is properly initialized.
151:                XMLGrammarPool grammarPool = (XMLGrammarPool) fConfiguration
152:                        .getProperty(StandardParserConfiguration.XMLGRAMMAR_POOL);
153:                // if there is no grammar pool, create one
154:                // REVISIT: ASBuilder should always create one.
155:                if (grammarPool == null) {
156:                    // something's not right in this situation...
157:                    grammarPool = new XMLGrammarPoolImpl();
158:                    fConfiguration.setProperty(
159:                            StandardParserConfiguration.XMLGRAMMAR_POOL,
160:                            grammarPool);
161:                }
162:                if (fAbstractSchema != null) {
163:                    initGrammarPool(fAbstractSchema, grammarPool);
164:                }
165:            }
166:
167:            /**
168:             * Parse a Abstract Schema from a location identified by an URI.
169:             *
170:             * @param uri The location of the Abstract Schema to be read.
171:             * @return The newly created <code>Abstract Schema</code>.
172:             * @exception DOMASException
173:             *   Exceptions raised by <code>parseASURI()</code> originate with the
174:             *   installed ErrorHandler, and thus depend on the implementation of
175:             *   the <code>DOMErrorHandler</code> interfaces. The default error
176:             *   handlers will raise a <code>DOMASException</code> if any form of
177:             *   Abstract Schema inconsistencies or warning occurs during the parse,
178:             *   but application defined errorHandlers are not required to do so.
179:             *   <br> WRONG_MIME_TYPE_ERR: Raised when <code>mimeTypeCheck</code> is
180:             *   <code>true</code> and the inputsource has an incorrect MIME Type.
181:             *   See attribute <code>mimeTypeCheck</code>.
182:             * @exception DOMSystemException
183:             *   Exceptions raised by <code>parseURI()</code> originate with the
184:             *   installed ErrorHandler, and thus depend on the implementation of
185:             *   the <code>DOMErrorHandler</code> interfaces. The default error
186:             *   handlers will raise a DOMSystemException if any form I/O or other
187:             *   system error occurs during the parse, but application defined error
188:             *   handlers are not required to do so.
189:             */
190:            public ASModel parseASURI(String uri) throws DOMASException,
191:                    Exception {
192:                XMLInputSource source = new XMLInputSource(null, uri, null);
193:                return parseASInputSource(source);
194:            }
195:
196:            /**
197:             * Parse a Abstract Schema from a location identified by an
198:             * <code>LSInput</code>.
199:             *
200:             * @param is The <code>LSInput</code> from which the source
201:             *   Abstract Schema is to be read.
202:             * @return The newly created <code>ASModel</code>.
203:             * @exception DOMASException
204:             *   Exceptions raised by <code>parseASURI()</code> originate with the
205:             *   installed ErrorHandler, and thus depend on the implementation of
206:             *   the <code>DOMErrorHandler</code> interfaces. The default error
207:             *   handlers will raise a <code>DOMASException</code> if any form of
208:             *   Abstract Schema inconsistencies or warning occurs during the parse,
209:             *   but application defined errorHandlers are not required to do so.
210:             *   <br> WRONG_MIME_TYPE_ERR: Raised when <code>mimeTypeCheck</code> is
211:             *   true and the inputsource has an incorrect MIME Type. See attribute
212:             *   <code>mimeTypeCheck</code>.
213:             * @exception DOMSystemException
214:             *   Exceptions raised by <code>parseURI()</code> originate with the
215:             *   installed ErrorHandler, and thus depend on the implementation of
216:             *   the <code>DOMErrorHandler</code> interfaces. The default error
217:             *   handlers will raise a DOMSystemException if any form I/O or other
218:             *   system error occurs during the parse, but application defined error
219:             *   handlers are not required to do so.
220:             */
221:            public ASModel parseASInputSource(LSInput is)
222:                    throws DOMASException, Exception {
223:
224:                // need to wrap the LSInput with an XMLInputSource
225:                XMLInputSource xis = this .dom2xmlInputSource(is);
226:                try {
227:                    return parseASInputSource(xis);
228:                } catch (XNIException e) {
229:                    Exception ex = e.getException();
230:                    throw ex;
231:                }
232:            }
233:
234:            ASModel parseASInputSource(XMLInputSource is) throws Exception {
235:
236:                if (fGrammarBucket == null) {
237:                    fGrammarBucket = new XSGrammarBucket();
238:                }
239:
240:                initGrammarBucket();
241:
242:                // actually do the parse:
243:                // save some casting
244:                XMLGrammarCachingConfiguration gramConfig = (XMLGrammarCachingConfiguration) fConfiguration;
245:                // ensure grammarPool doesn't absorb grammars while it's parsing
246:                gramConfig.lockGrammarPool();
247:                SchemaGrammar grammar = gramConfig.parseXMLSchema(is);
248:                gramConfig.unlockGrammarPool();
249:
250:                ASModelImpl newAsModel = null;
251:                if (grammar != null) {
252:                    newAsModel = new ASModelImpl();
253:                    fGrammarBucket.putGrammar(grammar, true);
254:                    addGrammars(newAsModel, fGrammarBucket);
255:                }
256:                return newAsModel;
257:            }
258:
259:            // put all the grammars we have access to in the GrammarBucket
260:            private void initGrammarBucket() {
261:                fGrammarBucket.reset();
262:                if (fAbstractSchema != null)
263:                    initGrammarBucketRecurse(fAbstractSchema);
264:            }
265:
266:            private void initGrammarBucketRecurse(ASModelImpl currModel) {
267:                if (currModel.getGrammar() != null) {
268:                    fGrammarBucket.putGrammar(currModel.getGrammar());
269:                }
270:                for (int i = 0; i < currModel.getInternalASModels().size(); i++) {
271:                    ASModelImpl nextModel = (ASModelImpl) (currModel
272:                            .getInternalASModels().elementAt(i));
273:                    initGrammarBucketRecurse(nextModel);
274:                }
275:            }
276:
277:            private void addGrammars(ASModelImpl model,
278:                    XSGrammarBucket grammarBucket) {
279:                SchemaGrammar[] grammarList = grammarBucket.getGrammars();
280:                for (int i = 0; i < grammarList.length; i++) {
281:                    ASModelImpl newModel = new ASModelImpl();
282:                    newModel.setGrammar(grammarList[i]);
283:                    model.addASModel(newModel);
284:                }
285:            } // addGrammars
286:
287:            private void initGrammarPool(ASModelImpl currModel,
288:                    XMLGrammarPool grammarPool) {
289:                // put all the grammars in fAbstractSchema into the grammar pool.
290:                // grammarPool must never be null!
291:                Grammar[] grammars = new Grammar[1];
292:                if ((grammars[0] = (Grammar) currModel.getGrammar()) != null) {
293:                    grammarPool
294:                            .cacheGrammars(grammars[0].getGrammarDescription()
295:                                    .getGrammarType(), grammars);
296:                }
297:                Vector modelStore = currModel.getInternalASModels();
298:                for (int i = 0; i < modelStore.size(); i++) {
299:                    initGrammarPool((ASModelImpl) modelStore.elementAt(i),
300:                            grammarPool);
301:                }
302:            }
303:        } // class DOMASBuilderImpl
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.