Source Code Cross Referenced for SAXDocumentParser.java in  » 6.0-JDK-Modules-com.sun » fastinfoset » com » sun » xml » fastinfoset » sax » 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 » 6.0 JDK Modules com.sun » fastinfoset » com.sun.xml.fastinfoset.sax 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Fast Infoset ver. 0.1 software ("Software")
0003:         *
0004:         * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
0005:         *
0006:         * Software is licensed under the Apache License, Version 2.0 (the "License");
0007:         * you may not use this file except in compliance with the License. You may
0008:         * obtain a copy of the License at:
0009:         *
0010:         *        http://www.apache.org/licenses/LICENSE-2.0
0011:         *
0012:         *    Unless required by applicable law or agreed to in writing, software
0013:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
0014:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
0015:         * License for the specific language governing permissions and limitations.
0016:         *
0017:         *    Sun supports and benefits from the global community of open source
0018:         * developers, and thanks the community for its important contributions and
0019:         * open standards-based technology, which Sun has adopted into many of its
0020:         * products.
0021:         *
0022:         *    Please note that portions of Software may be provided with notices and
0023:         * open source licenses from such communities and third parties that govern the
0024:         * use of those portions, and any licenses granted hereunder do not alter any
0025:         * rights and obligations you may have under such open source licenses,
0026:         * however, the disclaimer of warranty and limitation of liability provisions
0027:         * in this License will apply to all Software in this distribution.
0028:         *
0029:         *    You acknowledge that the Software is not designed, licensed or intended
0030:         * for use in the design, construction, operation or maintenance of any nuclear
0031:         * facility.
0032:         *
0033:         * Apache License
0034:         * Version 2.0, January 2004
0035:         * http://www.apache.org/licenses/
0036:         *
0037:         */
0038:
0039:        package com.sun.xml.fastinfoset.sax;
0040:
0041:        import com.sun.xml.fastinfoset.Decoder;
0042:        import com.sun.xml.fastinfoset.DecoderStateTables;
0043:        import com.sun.xml.fastinfoset.EncodingConstants;
0044:        import com.sun.xml.fastinfoset.QualifiedName;
0045:        import com.sun.xml.fastinfoset.algorithm.BuiltInEncodingAlgorithmFactory;
0046:        import com.sun.xml.fastinfoset.algorithm.BuiltInEncodingAlgorithmState;
0047:        import org.jvnet.fastinfoset.sax.EncodingAlgorithmContentHandler;
0048:        import org.jvnet.fastinfoset.sax.FastInfosetReader;
0049:        import org.jvnet.fastinfoset.sax.PrimitiveTypeContentHandler;
0050:        import com.sun.xml.fastinfoset.util.CharArray;
0051:        import com.sun.xml.fastinfoset.util.CharArrayString;
0052:        import java.io.IOException;
0053:        import java.io.InputStream;
0054:        import java.net.URL;
0055:        import java.util.Map;
0056:        import org.jvnet.fastinfoset.EncodingAlgorithm;
0057:        import org.jvnet.fastinfoset.EncodingAlgorithmException;
0058:        import org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
0059:        import org.jvnet.fastinfoset.FastInfosetException;
0060:        import org.xml.sax.ContentHandler;
0061:        import org.xml.sax.DTDHandler;
0062:        import org.xml.sax.EntityResolver;
0063:        import org.xml.sax.ErrorHandler;
0064:        import org.xml.sax.InputSource;
0065:        import org.xml.sax.SAXException;
0066:        import org.xml.sax.SAXNotRecognizedException;
0067:        import org.xml.sax.SAXNotSupportedException;
0068:        import org.xml.sax.SAXParseException;
0069:        import org.xml.sax.ext.LexicalHandler;
0070:        import org.xml.sax.helpers.DefaultHandler;
0071:        import com.sun.xml.fastinfoset.CommonResourceBundle;
0072:        import org.xml.sax.ext.DeclHandler;
0073:
0074:        /**
0075:         * The Fast Infoset SAX parser.
0076:         * <p>
0077:         * Instantiate this parser to parse a fast infoset document in accordance 
0078:         * with the SAX API.
0079:         * 
0080:         * <p>
0081:         * More than one fast infoset document may be decoded from the 
0082:         * {@link java.io.InputStream}.
0083:         */
0084:        public class SAXDocumentParser extends Decoder implements 
0085:                FastInfosetReader {
0086:
0087:            /*
0088:             * Empty lexical handler used by default to report
0089:             * lexical-based events
0090:             */
0091:            private static final class LexicalHandlerImpl implements 
0092:                    LexicalHandler {
0093:                public void comment(char[] ch, int start, int end) {
0094:                }
0095:
0096:                public void startDTD(String name, String publicId,
0097:                        String systemId) {
0098:                }
0099:
0100:                public void endDTD() {
0101:                }
0102:
0103:                public void startEntity(String name) {
0104:                }
0105:
0106:                public void endEntity(String name) {
0107:                }
0108:
0109:                public void startCDATA() {
0110:                }
0111:
0112:                public void endCDATA() {
0113:                }
0114:            };
0115:
0116:            /*
0117:             * Empty DTD declaration handler used by default to report
0118:             * DTD declaration-based events
0119:             */
0120:            private static final class DeclHandlerImpl implements  DeclHandler {
0121:                public void elementDecl(String name, String model)
0122:                        throws SAXException {
0123:                }
0124:
0125:                public void attributeDecl(String eName, String aName,
0126:                        String type, String mode, String value)
0127:                        throws SAXException {
0128:                }
0129:
0130:                public void internalEntityDecl(String name, String value)
0131:                        throws SAXException {
0132:                }
0133:
0134:                public void externalEntityDecl(String name, String publicId,
0135:                        String systemId) throws SAXException {
0136:                }
0137:            }
0138:
0139:            /**
0140:             * SAX Namespace attributes features
0141:             */
0142:            protected boolean _namespacePrefixesFeature = false;
0143:
0144:            /**
0145:             * Reference to entity resolver.
0146:             */
0147:            protected EntityResolver _entityResolver;
0148:
0149:            /**
0150:             * Reference to dtd handler.
0151:             */
0152:            protected DTDHandler _dtdHandler;
0153:
0154:            /**
0155:             * Reference to content handler.
0156:             */
0157:            protected ContentHandler _contentHandler;
0158:
0159:            /**
0160:             * Reference to error handler.
0161:             */
0162:            protected ErrorHandler _errorHandler;
0163:
0164:            /**
0165:             * Reference to lexical handler.
0166:             */
0167:            protected LexicalHandler _lexicalHandler;
0168:
0169:            /**
0170:             * Reference to DTD declaration handler.
0171:             */
0172:            protected DeclHandler _declHandler;
0173:
0174:            protected EncodingAlgorithmContentHandler _algorithmHandler;
0175:
0176:            protected PrimitiveTypeContentHandler _primitiveHandler;
0177:
0178:            protected BuiltInEncodingAlgorithmState builtInAlgorithmState = new BuiltInEncodingAlgorithmState();
0179:
0180:            protected AttributesHolder _attributes;
0181:
0182:            protected int[] _namespacePrefixes = new int[16];
0183:
0184:            protected int _namespacePrefixesIndex;
0185:
0186:            protected boolean _clearAttributes = false;
0187:
0188:            /** Creates a new instance of DocumetParser2 */
0189:            public SAXDocumentParser() {
0190:                DefaultHandler handler = new DefaultHandler();
0191:                _attributes = new AttributesHolder(
0192:                        _registeredEncodingAlgorithms);
0193:
0194:                _entityResolver = handler;
0195:                _dtdHandler = handler;
0196:                _contentHandler = handler;
0197:                _errorHandler = handler;
0198:                _lexicalHandler = new LexicalHandlerImpl();
0199:                _declHandler = new DeclHandlerImpl();
0200:            }
0201:
0202:            protected void resetOnError() {
0203:                _clearAttributes = false;
0204:                _attributes.clear();
0205:                _namespacePrefixesIndex = 0;
0206:
0207:                if (_v != null) {
0208:                    _v.prefix.clearCompletely();
0209:                }
0210:                _duplicateAttributeVerifier.clear();
0211:            }
0212:
0213:            // XMLReader interface
0214:
0215:            public boolean getFeature(String name)
0216:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0217:                if (name.equals(Features.NAMESPACES_FEATURE)) {
0218:                    return true;
0219:                } else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) {
0220:                    return _namespacePrefixesFeature;
0221:                } else if (name.equals(Features.STRING_INTERNING_FEATURE)
0222:                        || name
0223:                                .equals(FastInfosetReader.STRING_INTERNING_PROPERTY)) {
0224:                    return getStringInterning();
0225:                } else {
0226:                    throw new SAXNotRecognizedException(CommonResourceBundle
0227:                            .getInstance().getString(
0228:                                    "message.featureNotSupported")
0229:                            + name);
0230:                }
0231:            }
0232:
0233:            public void setFeature(String name, boolean value)
0234:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0235:                if (name.equals(Features.NAMESPACES_FEATURE)) {
0236:                    if (value == false) {
0237:                        throw new SAXNotSupportedException(name + ":" + value);
0238:                    }
0239:                } else if (name.equals(Features.NAMESPACE_PREFIXES_FEATURE)) {
0240:                    _namespacePrefixesFeature = value;
0241:                } else if (name.equals(Features.STRING_INTERNING_FEATURE)
0242:                        || name
0243:                                .equals(FastInfosetReader.STRING_INTERNING_PROPERTY)) {
0244:                    setStringInterning(value);
0245:                } else {
0246:                    throw new SAXNotRecognizedException(CommonResourceBundle
0247:                            .getInstance().getString(
0248:                                    "message.featureNotSupported")
0249:                            + name);
0250:                }
0251:            }
0252:
0253:            public Object getProperty(String name)
0254:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0255:                if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
0256:                    return getLexicalHandler();
0257:                } else if (name
0258:                        .equals(Properties.DTD_DECLARATION_HANDLER_PROPERTY)) {
0259:                    return getDeclHandler();
0260:                } else if (name
0261:                        .equals(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY)) {
0262:                    return getExternalVocabularies();
0263:                } else if (name
0264:                        .equals(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY)) {
0265:                    return getRegisteredEncodingAlgorithms();
0266:                } else if (name
0267:                        .equals(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY)) {
0268:                    return getEncodingAlgorithmContentHandler();
0269:                } else if (name
0270:                        .equals(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY)) {
0271:                    return getPrimitiveTypeContentHandler();
0272:                } else {
0273:                    throw new SAXNotRecognizedException(CommonResourceBundle
0274:                            .getInstance().getString(
0275:                                    "message.propertyNotRecognized",
0276:                                    new Object[] { name }));
0277:                }
0278:            }
0279:
0280:            public void setProperty(String name, Object value)
0281:                    throws SAXNotRecognizedException, SAXNotSupportedException {
0282:                if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
0283:                    if (value instanceof  LexicalHandler) {
0284:                        setLexicalHandler((LexicalHandler) value);
0285:                    } else {
0286:                        throw new SAXNotSupportedException(
0287:                                Properties.LEXICAL_HANDLER_PROPERTY);
0288:                    }
0289:                } else if (name
0290:                        .equals(Properties.DTD_DECLARATION_HANDLER_PROPERTY)) {
0291:                    if (value instanceof  DeclHandler) {
0292:                        setDeclHandler((DeclHandler) value);
0293:                    } else {
0294:                        throw new SAXNotSupportedException(
0295:                                Properties.LEXICAL_HANDLER_PROPERTY);
0296:                    }
0297:                } else if (name
0298:                        .equals(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY)) {
0299:                    if (value instanceof  Map) {
0300:                        setExternalVocabularies((Map) value);
0301:                    } else {
0302:                        throw new SAXNotSupportedException(
0303:                                FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY);
0304:                    }
0305:                } else if (name
0306:                        .equals(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY)) {
0307:                    if (value instanceof  Map) {
0308:                        setRegisteredEncodingAlgorithms((Map) value);
0309:                    } else {
0310:                        throw new SAXNotSupportedException(
0311:                                FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY);
0312:                    }
0313:                } else if (name
0314:                        .equals(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY)) {
0315:                    if (value instanceof  EncodingAlgorithmContentHandler) {
0316:                        setEncodingAlgorithmContentHandler((EncodingAlgorithmContentHandler) value);
0317:                    } else {
0318:                        throw new SAXNotSupportedException(
0319:                                FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY);
0320:                    }
0321:                } else if (name
0322:                        .equals(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY)) {
0323:                    if (value instanceof  PrimitiveTypeContentHandler) {
0324:                        setPrimitiveTypeContentHandler((PrimitiveTypeContentHandler) value);
0325:                    } else {
0326:                        throw new SAXNotSupportedException(
0327:                                FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY);
0328:                    }
0329:                } else if (name.equals(FastInfosetReader.BUFFER_SIZE_PROPERTY)) {
0330:                    if (value instanceof  Integer) {
0331:                        setBufferSize(((Integer) value).intValue());
0332:                    } else {
0333:                        throw new SAXNotSupportedException(
0334:                                FastInfosetReader.BUFFER_SIZE_PROPERTY);
0335:                    }
0336:                } else {
0337:                    throw new SAXNotRecognizedException(CommonResourceBundle
0338:                            .getInstance().getString(
0339:                                    "message.propertyNotRecognized",
0340:                                    new Object[] { name }));
0341:                }
0342:            }
0343:
0344:            public void setEntityResolver(EntityResolver resolver) {
0345:                _entityResolver = resolver;
0346:            }
0347:
0348:            public EntityResolver getEntityResolver() {
0349:                return _entityResolver;
0350:            }
0351:
0352:            public void setDTDHandler(DTDHandler handler) {
0353:                _dtdHandler = handler;
0354:            }
0355:
0356:            public DTDHandler getDTDHandler() {
0357:                return _dtdHandler;
0358:            }
0359:
0360:            public void setContentHandler(ContentHandler handler) {
0361:                _contentHandler = handler;
0362:            }
0363:
0364:            public ContentHandler getContentHandler() {
0365:                return _contentHandler;
0366:            }
0367:
0368:            public void setErrorHandler(ErrorHandler handler) {
0369:                _errorHandler = handler;
0370:            }
0371:
0372:            public ErrorHandler getErrorHandler() {
0373:                return _errorHandler;
0374:            }
0375:
0376:            public void parse(InputSource input) throws IOException,
0377:                    SAXException {
0378:                try {
0379:                    InputStream s = input.getByteStream();
0380:                    if (s == null) {
0381:                        String systemId = input.getSystemId();
0382:                        if (systemId == null) {
0383:                            throw new SAXException(CommonResourceBundle
0384:                                    .getInstance().getString(
0385:                                            "message.inputSource"));
0386:                        }
0387:                        parse(systemId);
0388:                    } else {
0389:                        parse(s);
0390:                    }
0391:                } catch (FastInfosetException e) {
0392:                    e.printStackTrace();
0393:                    throw new SAXException(e);
0394:                }
0395:            }
0396:
0397:            public void parse(String systemId) throws IOException, SAXException {
0398:                try {
0399:                    systemId = SystemIdResolver.getAbsoluteURI(systemId);
0400:                    parse(new URL(systemId).openStream());
0401:                } catch (FastInfosetException e) {
0402:                    e.printStackTrace();
0403:                    throw new SAXException(e);
0404:                }
0405:            }
0406:
0407:            // FastInfosetReader
0408:
0409:            public final void parse(InputStream s) throws IOException,
0410:                    FastInfosetException, SAXException {
0411:                setInputStream(s);
0412:                parse();
0413:            }
0414:
0415:            public void setLexicalHandler(LexicalHandler handler) {
0416:                _lexicalHandler = handler;
0417:            }
0418:
0419:            public LexicalHandler getLexicalHandler() {
0420:                return _lexicalHandler;
0421:            }
0422:
0423:            public void setDeclHandler(DeclHandler handler) {
0424:                _declHandler = handler;
0425:            }
0426:
0427:            public DeclHandler getDeclHandler() {
0428:                return _declHandler;
0429:            }
0430:
0431:            public void setEncodingAlgorithmContentHandler(
0432:                    EncodingAlgorithmContentHandler handler) {
0433:                _algorithmHandler = handler;
0434:            }
0435:
0436:            public EncodingAlgorithmContentHandler getEncodingAlgorithmContentHandler() {
0437:                return _algorithmHandler;
0438:            }
0439:
0440:            public void setPrimitiveTypeContentHandler(
0441:                    PrimitiveTypeContentHandler handler) {
0442:                _primitiveHandler = handler;
0443:            }
0444:
0445:            public PrimitiveTypeContentHandler getPrimitiveTypeContentHandler() {
0446:                return _primitiveHandler;
0447:            }
0448:
0449:            public final void parse() throws FastInfosetException, IOException {
0450:                if (_octetBuffer.length < _bufferSize) {
0451:                    _octetBuffer = new byte[_bufferSize];
0452:                }
0453:
0454:                try {
0455:                    reset();
0456:                    decodeHeader();
0457:                    if (_parseFragments)
0458:                        processDIIFragment();
0459:                    else
0460:                        processDII();
0461:                } catch (RuntimeException e) {
0462:                    try {
0463:                        _errorHandler.fatalError(new SAXParseException(e
0464:                                .getClass().getName(), null, e));
0465:                    } catch (Exception ee) {
0466:                    }
0467:                    resetOnError();
0468:                    // Wrap runtime exception
0469:                    throw new FastInfosetException(e);
0470:                } catch (FastInfosetException e) {
0471:                    try {
0472:                        _errorHandler.fatalError(new SAXParseException(e
0473:                                .getClass().getName(), null, e));
0474:                    } catch (Exception ee) {
0475:                    }
0476:                    resetOnError();
0477:                    throw e;
0478:                } catch (IOException e) {
0479:                    try {
0480:                        _errorHandler.fatalError(new SAXParseException(e
0481:                                .getClass().getName(), null, e));
0482:                    } catch (Exception ee) {
0483:                    }
0484:                    resetOnError();
0485:                    throw e;
0486:                }
0487:            }
0488:
0489:            protected final void processDII() throws FastInfosetException,
0490:                    IOException {
0491:                try {
0492:                    _contentHandler.startDocument();
0493:                } catch (SAXException e) {
0494:                    throw new FastInfosetException("processDII", e);
0495:                }
0496:
0497:                _b = read();
0498:                if (_b > 0) {
0499:                    processDIIOptionalProperties();
0500:                }
0501:
0502:                // Decode one Document Type II, Comment IIs, PI IIs and one EII
0503:                boolean firstElementHasOccured = false;
0504:                boolean documentTypeDeclarationOccured = false;
0505:                while (!_terminate || !firstElementHasOccured) {
0506:                    _b = read();
0507:                    switch (DecoderStateTables.DII[_b]) {
0508:                    case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL:
0509:                        processEII(_elementNameTable._array[_b], false);
0510:                        firstElementHasOccured = true;
0511:                        break;
0512:                    case DecoderStateTables.EII_AIIS_INDEX_SMALL:
0513:                        processEII(
0514:                                _elementNameTable._array[_b
0515:                                        & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK],
0516:                                true);
0517:                        firstElementHasOccured = true;
0518:                        break;
0519:                    case DecoderStateTables.EII_INDEX_MEDIUM:
0520:                        processEII(
0521:                                decodeEIIIndexMedium(),
0522:                                (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
0523:                        firstElementHasOccured = true;
0524:                        break;
0525:                    case DecoderStateTables.EII_INDEX_LARGE:
0526:                        processEII(
0527:                                decodeEIIIndexLarge(),
0528:                                (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
0529:                        firstElementHasOccured = true;
0530:                        break;
0531:                    case DecoderStateTables.EII_LITERAL: {
0532:                        final QualifiedName qn = decodeLiteralQualifiedName(
0533:                                _b
0534:                                        & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
0535:                                _elementNameTable.getNext());
0536:                        _elementNameTable.add(qn);
0537:                        processEII(
0538:                                qn,
0539:                                (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
0540:                        firstElementHasOccured = true;
0541:                        break;
0542:                    }
0543:                    case DecoderStateTables.EII_NAMESPACES:
0544:                        processEIIWithNamespaces();
0545:                        firstElementHasOccured = true;
0546:                        break;
0547:                    case DecoderStateTables.DOCUMENT_TYPE_DECLARATION_II: {
0548:                        if (documentTypeDeclarationOccured) {
0549:                            throw new FastInfosetException(CommonResourceBundle
0550:                                    .getInstance().getString(
0551:                                            "message.secondOccurenceOfDTDII"));
0552:                        }
0553:                        documentTypeDeclarationOccured = true;
0554:
0555:                        String system_identifier = ((_b & EncodingConstants.DOCUMENT_TYPE_SYSTEM_IDENTIFIER_FLAG) > 0) ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI)
0556:                                : "";
0557:                        String public_identifier = ((_b & EncodingConstants.DOCUMENT_TYPE_PUBLIC_IDENTIFIER_FLAG) > 0) ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI)
0558:                                : "";
0559:
0560:                        _b = read();
0561:                        while (_b == EncodingConstants.PROCESSING_INSTRUCTION) {
0562:                            switch (decodeNonIdentifyingStringOnFirstBit()) {
0563:                            case NISTRING_STRING:
0564:                                if (_addToTable) {
0565:                                    _v.otherString.add(new CharArray(
0566:                                            _charBuffer, 0, _charBufferLength,
0567:                                            true));
0568:                                }
0569:                                break;
0570:                            case NISTRING_ENCODING_ALGORITHM:
0571:                                throw new FastInfosetException(
0572:                                        CommonResourceBundle
0573:                                                .getInstance()
0574:                                                .getString(
0575:                                                        "message.processingIIWithEncodingAlgorithm"));
0576:                            case NISTRING_INDEX:
0577:                                break;
0578:                            case NISTRING_EMPTY_STRING:
0579:                                break;
0580:                            }
0581:                            _b = read();
0582:                        }
0583:                        if ((_b & EncodingConstants.TERMINATOR) != EncodingConstants.TERMINATOR) {
0584:                            throw new FastInfosetException(
0585:                                    CommonResourceBundle
0586:                                            .getInstance()
0587:                                            .getString(
0588:                                                    "message.processingInstructionIIsNotTerminatedCorrectly"));
0589:                        }
0590:                        if (_b == EncodingConstants.DOUBLE_TERMINATOR) {
0591:                            _terminate = true;
0592:                        }
0593:
0594:                        if (_notations != null)
0595:                            _notations.clear();
0596:                        if (_unparsedEntities != null)
0597:                            _unparsedEntities.clear();
0598:                        /*
0599:                         * TODO
0600:                         * Report All events associated with DTD, PIs, notations etc
0601:                         */
0602:                        break;
0603:                    }
0604:                    case DecoderStateTables.COMMENT_II:
0605:                        processCommentII();
0606:                        break;
0607:                    case DecoderStateTables.PROCESSING_INSTRUCTION_II:
0608:                        processProcessingII();
0609:                        break;
0610:                    case DecoderStateTables.TERMINATOR_DOUBLE:
0611:                        _doubleTerminate = true;
0612:                    case DecoderStateTables.TERMINATOR_SINGLE:
0613:                        _terminate = true;
0614:                        break;
0615:                    default:
0616:                        throw new FastInfosetException(CommonResourceBundle
0617:                                .getInstance().getString(
0618:                                        "message.IllegalStateDecodingDII"));
0619:                    }
0620:                }
0621:
0622:                // Decode any remaining Comment IIs, PI IIs
0623:                while (!_terminate) {
0624:                    _b = read();
0625:                    switch (DecoderStateTables.DII[_b]) {
0626:                    case DecoderStateTables.COMMENT_II:
0627:                        processCommentII();
0628:                        break;
0629:                    case DecoderStateTables.PROCESSING_INSTRUCTION_II:
0630:                        processProcessingII();
0631:                        break;
0632:                    case DecoderStateTables.TERMINATOR_DOUBLE:
0633:                        _doubleTerminate = true;
0634:                    case DecoderStateTables.TERMINATOR_SINGLE:
0635:                        _terminate = true;
0636:                        break;
0637:                    default:
0638:                        throw new FastInfosetException(CommonResourceBundle
0639:                                .getInstance().getString(
0640:                                        "message.IllegalStateDecodingDII"));
0641:                    }
0642:                }
0643:
0644:                try {
0645:                    _contentHandler.endDocument();
0646:                } catch (SAXException e) {
0647:                    throw new FastInfosetException("processDII", e);
0648:                }
0649:            }
0650:
0651:            protected final void processDIIFragment()
0652:                    throws FastInfosetException, IOException {
0653:                try {
0654:                    _contentHandler.startDocument();
0655:                } catch (SAXException e) {
0656:                    throw new FastInfosetException("processDII", e);
0657:                }
0658:
0659:                _b = read();
0660:                if (_b > 0) {
0661:                    processDIIOptionalProperties();
0662:                }
0663:
0664:                while (!_terminate) {
0665:                    _b = read();
0666:                    switch (DecoderStateTables.EII[_b]) {
0667:                    case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL:
0668:                        processEII(_elementNameTable._array[_b], false);
0669:                        break;
0670:                    case DecoderStateTables.EII_AIIS_INDEX_SMALL:
0671:                        processEII(
0672:                                _elementNameTable._array[_b
0673:                                        & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK],
0674:                                true);
0675:                        break;
0676:                    case DecoderStateTables.EII_INDEX_MEDIUM:
0677:                        processEII(
0678:                                decodeEIIIndexMedium(),
0679:                                (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
0680:                        break;
0681:                    case DecoderStateTables.EII_INDEX_LARGE:
0682:                        processEII(
0683:                                decodeEIIIndexLarge(),
0684:                                (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
0685:                        break;
0686:                    case DecoderStateTables.EII_LITERAL: {
0687:                        final QualifiedName qn = decodeLiteralQualifiedName(
0688:                                _b
0689:                                        & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
0690:                                _elementNameTable.getNext());
0691:                        _elementNameTable.add(qn);
0692:                        processEII(
0693:                                qn,
0694:                                (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
0695:                        break;
0696:                    }
0697:                    case DecoderStateTables.EII_NAMESPACES:
0698:                        processEIIWithNamespaces();
0699:                        break;
0700:                    case DecoderStateTables.CII_UTF8_SMALL_LENGTH:
0701:                        _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) + 1;
0702:                        processUtf8CharacterString();
0703:                        break;
0704:                    case DecoderStateTables.CII_UTF8_MEDIUM_LENGTH:
0705:                        _octetBufferLength = read()
0706:                                + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT;
0707:                        processUtf8CharacterString();
0708:                        break;
0709:                    case DecoderStateTables.CII_UTF8_LARGE_LENGTH:
0710:                        _octetBufferLength = ((read() << 24) | (read() << 16)
0711:                                | (read() << 8) | read())
0712:                                + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT;
0713:                        processUtf8CharacterString();
0714:                        break;
0715:                    case DecoderStateTables.CII_UTF16_SMALL_LENGTH:
0716:                        _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) + 1;
0717:                        decodeUtf16StringAsCharBuffer();
0718:                        if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
0719:                            _characterContentChunkTable.add(_charBuffer,
0720:                                    _charBufferLength);
0721:                        }
0722:
0723:                        try {
0724:                            _contentHandler.characters(_charBuffer, 0,
0725:                                    _charBufferLength);
0726:                        } catch (SAXException e) {
0727:                            throw new FastInfosetException("processCII", e);
0728:                        }
0729:                        break;
0730:                    case DecoderStateTables.CII_UTF16_MEDIUM_LENGTH:
0731:                        _octetBufferLength = read()
0732:                                + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT;
0733:                        decodeUtf16StringAsCharBuffer();
0734:                        if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
0735:                            _characterContentChunkTable.add(_charBuffer,
0736:                                    _charBufferLength);
0737:                        }
0738:
0739:                        try {
0740:                            _contentHandler.characters(_charBuffer, 0,
0741:                                    _charBufferLength);
0742:                        } catch (SAXException e) {
0743:                            throw new FastInfosetException("processCII", e);
0744:                        }
0745:                        break;
0746:                    case DecoderStateTables.CII_UTF16_LARGE_LENGTH:
0747:                        _octetBufferLength = ((read() << 24) | (read() << 16)
0748:                                | (read() << 8) | read())
0749:                                + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT;
0750:                        decodeUtf16StringAsCharBuffer();
0751:                        if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
0752:                            _characterContentChunkTable.add(_charBuffer,
0753:                                    _charBufferLength);
0754:                        }
0755:
0756:                        try {
0757:                            _contentHandler.characters(_charBuffer, 0,
0758:                                    _charBufferLength);
0759:                        } catch (SAXException e) {
0760:                            throw new FastInfosetException("processCII", e);
0761:                        }
0762:                        break;
0763:                    case DecoderStateTables.CII_RA: {
0764:                        final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0;
0765:
0766:                        // Decode resitricted alphabet integer
0767:                        _identifier = (_b & 0x02) << 6;
0768:                        _b = read();
0769:                        _identifier |= (_b & 0xFC) >> 2;
0770:
0771:                        decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b);
0772:
0773:                        decodeRestrictedAlphabetAsCharBuffer();
0774:
0775:                        if (addToTable) {
0776:                            _characterContentChunkTable.add(_charBuffer,
0777:                                    _charBufferLength);
0778:                        }
0779:
0780:                        try {
0781:                            _contentHandler.characters(_charBuffer, 0,
0782:                                    _charBufferLength);
0783:                        } catch (SAXException e) {
0784:                            throw new FastInfosetException("processCII", e);
0785:                        }
0786:                        break;
0787:                    }
0788:                    case DecoderStateTables.CII_EA: {
0789:                        if ((_b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
0790:                            throw new EncodingAlgorithmException(
0791:                                    CommonResourceBundle
0792:                                            .getInstance()
0793:                                            .getString(
0794:                                                    "message.addToTableNotSupported"));
0795:                        }
0796:
0797:                        // Decode encoding algorithm integer
0798:                        _identifier = (_b & 0x02) << 6;
0799:                        _b = read();
0800:                        _identifier |= (_b & 0xFC) >> 2;
0801:
0802:                        decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b);
0803:
0804:                        processCIIEncodingAlgorithm();
0805:                        break;
0806:                    }
0807:                    case DecoderStateTables.CII_INDEX_SMALL: {
0808:                        final int index = _b
0809:                                & EncodingConstants.INTEGER_4TH_BIT_SMALL_MASK;
0810:                        try {
0811:                            _contentHandler.characters(
0812:                                    _characterContentChunkTable._array,
0813:                                    _characterContentChunkTable._offset[index],
0814:                                    _characterContentChunkTable._length[index]);
0815:                        } catch (SAXException e) {
0816:                            throw new FastInfosetException("processCII", e);
0817:                        }
0818:                        break;
0819:                    }
0820:                    case DecoderStateTables.CII_INDEX_MEDIUM: {
0821:                        final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_MEDIUM_MASK) << 8) | read())
0822:                                + EncodingConstants.INTEGER_4TH_BIT_SMALL_LIMIT;
0823:                        try {
0824:                            _contentHandler.characters(
0825:                                    _characterContentChunkTable._array,
0826:                                    _characterContentChunkTable._offset[index],
0827:                                    _characterContentChunkTable._length[index]);
0828:                        } catch (SAXException e) {
0829:                            throw new FastInfosetException("processCII", e);
0830:                        }
0831:                        break;
0832:                    }
0833:                    case DecoderStateTables.CII_INDEX_LARGE: {
0834:                        final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_LARGE_MASK) << 16)
0835:                                | (read() << 8) | read())
0836:                                + EncodingConstants.INTEGER_4TH_BIT_MEDIUM_LIMIT;
0837:
0838:                        try {
0839:                            _contentHandler.characters(
0840:                                    _characterContentChunkTable._array,
0841:                                    _characterContentChunkTable._offset[index],
0842:                                    _characterContentChunkTable._length[index]);
0843:                        } catch (SAXException e) {
0844:                            throw new FastInfosetException("processCII", e);
0845:                        }
0846:                        break;
0847:                    }
0848:                    case DecoderStateTables.CII_INDEX_LARGE_LARGE: {
0849:                        final int index = ((read() << 16) | (read() << 8) | read())
0850:                                + EncodingConstants.INTEGER_4TH_BIT_LARGE_LIMIT;
0851:
0852:                        try {
0853:                            _contentHandler.characters(
0854:                                    _characterContentChunkTable._array,
0855:                                    _characterContentChunkTable._offset[index],
0856:                                    _characterContentChunkTable._length[index]);
0857:                        } catch (SAXException e) {
0858:                            throw new FastInfosetException("processCII", e);
0859:                        }
0860:                        break;
0861:                    }
0862:                    case DecoderStateTables.COMMENT_II:
0863:                        processCommentII();
0864:                        break;
0865:                    case DecoderStateTables.PROCESSING_INSTRUCTION_II:
0866:                        processProcessingII();
0867:                        break;
0868:                    case DecoderStateTables.UNEXPANDED_ENTITY_REFERENCE_II: {
0869:                        String entity_reference_name = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName);
0870:
0871:                        String system_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG) > 0) ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI)
0872:                                : "";
0873:                        String public_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG) > 0) ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI)
0874:                                : "";
0875:
0876:                        try {
0877:                            /*
0878:                             * TODO
0879:                             * Need to verify if the skippedEntity method:
0880:                             * http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/ContentHandler.html#skippedEntity(java.lang.String)
0881:                             * is the correct method to call. It appears so but a more extensive
0882:                             * check is necessary.
0883:                             */
0884:                            _contentHandler
0885:                                    .skippedEntity(entity_reference_name);
0886:                        } catch (SAXException e) {
0887:                            throw new FastInfosetException(
0888:                                    "processUnexpandedEntityReferenceII", e);
0889:                        }
0890:                        break;
0891:                    }
0892:                    case DecoderStateTables.TERMINATOR_DOUBLE:
0893:                        _doubleTerminate = true;
0894:                    case DecoderStateTables.TERMINATOR_SINGLE:
0895:                        _terminate = true;
0896:                        break;
0897:                    default:
0898:                        throw new FastInfosetException(CommonResourceBundle
0899:                                .getInstance().getString(
0900:                                        "message.IllegalStateDecodingEII"));
0901:                    }
0902:                }
0903:
0904:                try {
0905:                    _contentHandler.endDocument();
0906:                } catch (SAXException e) {
0907:                    throw new FastInfosetException("processDII", e);
0908:                }
0909:            }
0910:
0911:            protected final void processDIIOptionalProperties()
0912:                    throws FastInfosetException, IOException {
0913:                // Optimize for the most common case
0914:                if (_b == EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) {
0915:                    decodeInitialVocabulary();
0916:                    return;
0917:                }
0918:
0919:                if ((_b & EncodingConstants.DOCUMENT_ADDITIONAL_DATA_FLAG) > 0) {
0920:                    decodeAdditionalData();
0921:                    /*
0922:                     * TODO
0923:                     * how to report the additional data?
0924:                     */
0925:                }
0926:
0927:                if ((_b & EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) > 0) {
0928:                    decodeInitialVocabulary();
0929:                }
0930:
0931:                if ((_b & EncodingConstants.DOCUMENT_NOTATIONS_FLAG) > 0) {
0932:                    decodeNotations();
0933:                    /*
0934:                        try {
0935:                            _dtdHandler.notationDecl(name, public_identifier, system_identifier);
0936:                        } catch (SAXException e) {
0937:                            throw new IOException("NotationsDeclarationII");
0938:                        }
0939:                     */
0940:                }
0941:
0942:                if ((_b & EncodingConstants.DOCUMENT_UNPARSED_ENTITIES_FLAG) > 0) {
0943:                    decodeUnparsedEntities();
0944:                    /*
0945:                        try {
0946:                            _dtdHandler.unparsedEntityDecl(name, public_identifier, system_identifier, notation_name);
0947:                        } catch (SAXException e) {
0948:                            throw new IOException("UnparsedEntitiesII");
0949:                        }
0950:                     */
0951:                }
0952:
0953:                if ((_b & EncodingConstants.DOCUMENT_CHARACTER_ENCODING_SCHEME) > 0) {
0954:                    String characterEncodingScheme = decodeCharacterEncodingScheme();
0955:                    /*
0956:                     * TODO
0957:                     * how to report the character encoding scheme?
0958:                     */
0959:                }
0960:
0961:                if ((_b & EncodingConstants.DOCUMENT_STANDALONE_FLAG) > 0) {
0962:                    boolean standalone = (read() > 0) ? true : false;
0963:                    /*
0964:                     * TODO
0965:                     * how to report the standalone flag?
0966:                     */
0967:                }
0968:
0969:                if ((_b & EncodingConstants.DOCUMENT_VERSION_FLAG) > 0) {
0970:                    decodeVersion();
0971:                    /*
0972:                     * TODO
0973:                     * how to report the standalone flag?
0974:                     */
0975:                }
0976:            }
0977:
0978:            protected final void processEII(QualifiedName name,
0979:                    boolean hasAttributes) throws FastInfosetException,
0980:                    IOException {
0981:                if (_prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) {
0982:                    throw new FastInfosetException(CommonResourceBundle
0983:                            .getInstance().getString(
0984:                                    "message.qNameOfEIINotInScope"));
0985:                }
0986:
0987:                if (hasAttributes) {
0988:                    processAIIs();
0989:                }
0990:
0991:                try {
0992:                    _contentHandler.startElement(name.namespaceName,
0993:                            name.localName, name.qName, _attributes);
0994:                } catch (SAXException e) {
0995:                    e.printStackTrace();
0996:                    throw new FastInfosetException("processEII", e);
0997:                }
0998:
0999:                if (_clearAttributes) {
1000:                    _attributes.clear();
1001:                    _clearAttributes = false;
1002:                }
1003:
1004:                while (!_terminate) {
1005:                    _b = read();
1006:                    switch (DecoderStateTables.EII[_b]) {
1007:                    case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL:
1008:                        processEII(_elementNameTable._array[_b], false);
1009:                        break;
1010:                    case DecoderStateTables.EII_AIIS_INDEX_SMALL:
1011:                        processEII(
1012:                                _elementNameTable._array[_b
1013:                                        & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK],
1014:                                true);
1015:                        break;
1016:                    case DecoderStateTables.EII_INDEX_MEDIUM:
1017:                        processEII(
1018:                                decodeEIIIndexMedium(),
1019:                                (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
1020:                        break;
1021:                    case DecoderStateTables.EII_INDEX_LARGE:
1022:                        processEII(
1023:                                decodeEIIIndexLarge(),
1024:                                (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
1025:                        break;
1026:                    case DecoderStateTables.EII_LITERAL: {
1027:                        final QualifiedName qn = decodeLiteralQualifiedName(
1028:                                _b
1029:                                        & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
1030:                                _elementNameTable.getNext());
1031:                        _elementNameTable.add(qn);
1032:                        processEII(
1033:                                qn,
1034:                                (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
1035:                        break;
1036:                    }
1037:                    case DecoderStateTables.EII_NAMESPACES:
1038:                        processEIIWithNamespaces();
1039:                        break;
1040:                    case DecoderStateTables.CII_UTF8_SMALL_LENGTH:
1041:                        _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) + 1;
1042:                        processUtf8CharacterString();
1043:                        break;
1044:                    case DecoderStateTables.CII_UTF8_MEDIUM_LENGTH:
1045:                        _octetBufferLength = read()
1046:                                + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT;
1047:                        processUtf8CharacterString();
1048:                        break;
1049:                    case DecoderStateTables.CII_UTF8_LARGE_LENGTH:
1050:                        _octetBufferLength = ((read() << 24) | (read() << 16)
1051:                                | (read() << 8) | read())
1052:                                + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT;
1053:                        processUtf8CharacterString();
1054:                        break;
1055:                    case DecoderStateTables.CII_UTF16_SMALL_LENGTH:
1056:                        _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) + 1;
1057:                        decodeUtf16StringAsCharBuffer();
1058:                        if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
1059:                            _characterContentChunkTable.add(_charBuffer,
1060:                                    _charBufferLength);
1061:                        }
1062:
1063:                        try {
1064:                            _contentHandler.characters(_charBuffer, 0,
1065:                                    _charBufferLength);
1066:                        } catch (SAXException e) {
1067:                            throw new FastInfosetException("processCII", e);
1068:                        }
1069:                        break;
1070:                    case DecoderStateTables.CII_UTF16_MEDIUM_LENGTH:
1071:                        _octetBufferLength = read()
1072:                                + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT;
1073:                        decodeUtf16StringAsCharBuffer();
1074:                        if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
1075:                            _characterContentChunkTable.add(_charBuffer,
1076:                                    _charBufferLength);
1077:                        }
1078:
1079:                        try {
1080:                            _contentHandler.characters(_charBuffer, 0,
1081:                                    _charBufferLength);
1082:                        } catch (SAXException e) {
1083:                            throw new FastInfosetException("processCII", e);
1084:                        }
1085:                        break;
1086:                    case DecoderStateTables.CII_UTF16_LARGE_LENGTH:
1087:                        _octetBufferLength = ((read() << 24) | (read() << 16)
1088:                                | (read() << 8) | read())
1089:                                + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT;
1090:                        decodeUtf16StringAsCharBuffer();
1091:                        if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
1092:                            _characterContentChunkTable.add(_charBuffer,
1093:                                    _charBufferLength);
1094:                        }
1095:
1096:                        try {
1097:                            _contentHandler.characters(_charBuffer, 0,
1098:                                    _charBufferLength);
1099:                        } catch (SAXException e) {
1100:                            throw new FastInfosetException("processCII", e);
1101:                        }
1102:                        break;
1103:                    case DecoderStateTables.CII_RA: {
1104:                        final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0;
1105:
1106:                        // Decode resitricted alphabet integer
1107:                        _identifier = (_b & 0x02) << 6;
1108:                        _b = read();
1109:                        _identifier |= (_b & 0xFC) >> 2;
1110:
1111:                        decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b);
1112:
1113:                        decodeRestrictedAlphabetAsCharBuffer();
1114:
1115:                        if (addToTable) {
1116:                            _characterContentChunkTable.add(_charBuffer,
1117:                                    _charBufferLength);
1118:                        }
1119:
1120:                        try {
1121:                            _contentHandler.characters(_charBuffer, 0,
1122:                                    _charBufferLength);
1123:                        } catch (SAXException e) {
1124:                            throw new FastInfosetException("processCII", e);
1125:                        }
1126:                        break;
1127:                    }
1128:                    case DecoderStateTables.CII_EA: {
1129:                        if ((_b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
1130:                            throw new EncodingAlgorithmException(
1131:                                    CommonResourceBundle
1132:                                            .getInstance()
1133:                                            .getString(
1134:                                                    "message.addToTableNotSupported"));
1135:                        }
1136:
1137:                        // Decode encoding algorithm integer
1138:                        _identifier = (_b & 0x02) << 6;
1139:                        _b = read();
1140:                        _identifier |= (_b & 0xFC) >> 2;
1141:
1142:                        decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b);
1143:
1144:                        processCIIEncodingAlgorithm();
1145:                        break;
1146:                    }
1147:                    case DecoderStateTables.CII_INDEX_SMALL: {
1148:                        final int index = _b
1149:                                & EncodingConstants.INTEGER_4TH_BIT_SMALL_MASK;
1150:                        try {
1151:                            _contentHandler.characters(
1152:                                    _characterContentChunkTable._array,
1153:                                    _characterContentChunkTable._offset[index],
1154:                                    _characterContentChunkTable._length[index]);
1155:                        } catch (SAXException e) {
1156:                            throw new FastInfosetException("processCII", e);
1157:                        }
1158:                        break;
1159:                    }
1160:                    case DecoderStateTables.CII_INDEX_MEDIUM: {
1161:                        final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_MEDIUM_MASK) << 8) | read())
1162:                                + EncodingConstants.INTEGER_4TH_BIT_SMALL_LIMIT;
1163:                        try {
1164:                            _contentHandler.characters(
1165:                                    _characterContentChunkTable._array,
1166:                                    _characterContentChunkTable._offset[index],
1167:                                    _characterContentChunkTable._length[index]);
1168:                        } catch (SAXException e) {
1169:                            throw new FastInfosetException("processCII", e);
1170:                        }
1171:                        break;
1172:                    }
1173:                    case DecoderStateTables.CII_INDEX_LARGE: {
1174:                        final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_LARGE_MASK) << 16)
1175:                                | (read() << 8) | read())
1176:                                + EncodingConstants.INTEGER_4TH_BIT_MEDIUM_LIMIT;
1177:
1178:                        try {
1179:                            _contentHandler.characters(
1180:                                    _characterContentChunkTable._array,
1181:                                    _characterContentChunkTable._offset[index],
1182:                                    _characterContentChunkTable._length[index]);
1183:                        } catch (SAXException e) {
1184:                            throw new FastInfosetException("processCII", e);
1185:                        }
1186:                        break;
1187:                    }
1188:                    case DecoderStateTables.CII_INDEX_LARGE_LARGE: {
1189:                        final int index = ((read() << 16) | (read() << 8) | read())
1190:                                + EncodingConstants.INTEGER_4TH_BIT_LARGE_LIMIT;
1191:
1192:                        try {
1193:                            _contentHandler.characters(
1194:                                    _characterContentChunkTable._array,
1195:                                    _characterContentChunkTable._offset[index],
1196:                                    _characterContentChunkTable._length[index]);
1197:                        } catch (SAXException e) {
1198:                            throw new FastInfosetException("processCII", e);
1199:                        }
1200:                        break;
1201:                    }
1202:                    case DecoderStateTables.COMMENT_II:
1203:                        processCommentII();
1204:                        break;
1205:                    case DecoderStateTables.PROCESSING_INSTRUCTION_II:
1206:                        processProcessingII();
1207:                        break;
1208:                    case DecoderStateTables.UNEXPANDED_ENTITY_REFERENCE_II: {
1209:                        String entity_reference_name = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName);
1210:
1211:                        String system_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG) > 0) ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI)
1212:                                : "";
1213:                        String public_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG) > 0) ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI)
1214:                                : "";
1215:
1216:                        try {
1217:                            /*
1218:                             * TODO
1219:                             * Need to verify if the skippedEntity method:
1220:                             * http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/ContentHandler.html#skippedEntity(java.lang.String)
1221:                             * is the correct method to call. It appears so but a more extensive
1222:                             * check is necessary.
1223:                             */
1224:                            _contentHandler
1225:                                    .skippedEntity(entity_reference_name);
1226:                        } catch (SAXException e) {
1227:                            throw new FastInfosetException(
1228:                                    "processUnexpandedEntityReferenceII", e);
1229:                        }
1230:                        break;
1231:                    }
1232:                    case DecoderStateTables.TERMINATOR_DOUBLE:
1233:                        _doubleTerminate = true;
1234:                    case DecoderStateTables.TERMINATOR_SINGLE:
1235:                        _terminate = true;
1236:                        break;
1237:                    default:
1238:                        throw new FastInfosetException(CommonResourceBundle
1239:                                .getInstance().getString(
1240:                                        "message.IllegalStateDecodingEII"));
1241:                    }
1242:                }
1243:
1244:                _terminate = _doubleTerminate;
1245:                _doubleTerminate = false;
1246:
1247:                try {
1248:                    _contentHandler.endElement(name.namespaceName,
1249:                            name.localName, name.qName);
1250:                } catch (SAXException e) {
1251:                    throw new FastInfosetException("processEII", e);
1252:                }
1253:            }
1254:
1255:            private final void processUtf8CharacterString()
1256:                    throws FastInfosetException, IOException {
1257:                if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
1258:                    _characterContentChunkTable.ensureSize(_octetBufferLength);
1259:                    final int charactersOffset = _characterContentChunkTable._arrayIndex;
1260:                    decodeUtf8StringAsCharBuffer(
1261:                            _characterContentChunkTable._array,
1262:                            charactersOffset);
1263:                    _characterContentChunkTable.add(_charBufferLength);
1264:                    try {
1265:                        _contentHandler.characters(
1266:                                _characterContentChunkTable._array,
1267:                                charactersOffset, _charBufferLength);
1268:                    } catch (SAXException e) {
1269:                        throw new FastInfosetException("processCII", e);
1270:                    }
1271:                } else {
1272:                    decodeUtf8StringAsCharBuffer();
1273:                    try {
1274:                        _contentHandler.characters(_charBuffer, 0,
1275:                                _charBufferLength);
1276:                    } catch (SAXException e) {
1277:                        throw new FastInfosetException("processCII", e);
1278:                    }
1279:                }
1280:            }
1281:
1282:            protected final void processEIIWithNamespaces()
1283:                    throws FastInfosetException, IOException {
1284:                final boolean hasAttributes = (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0;
1285:
1286:                _clearAttributes = (_namespacePrefixesFeature) ? true : false;
1287:
1288:                if (++_prefixTable._declarationId == Integer.MAX_VALUE) {
1289:                    _prefixTable.clearDeclarationIds();
1290:                }
1291:
1292:                String prefix = "", namespaceName = "";
1293:                final int start = _namespacePrefixesIndex;
1294:                int b = read();
1295:                while ((b & EncodingConstants.NAMESPACE_ATTRIBUTE_MASK) == EncodingConstants.NAMESPACE_ATTRIBUTE) {
1296:                    if (_namespacePrefixesIndex == _namespacePrefixes.length) {
1297:                        final int[] namespaceAIIs = new int[_namespacePrefixesIndex * 3 / 2 + 1];
1298:                        System.arraycopy(_namespacePrefixes, 0, namespaceAIIs,
1299:                                0, _namespacePrefixesIndex);
1300:                        _namespacePrefixes = namespaceAIIs;
1301:                    }
1302:
1303:                    switch (b
1304:                            & EncodingConstants.NAMESPACE_ATTRIBUTE_PREFIX_NAME_MASK) {
1305:                    // no prefix, no namespace
1306:                    // Undeclaration of default namespace
1307:                    case 0:
1308:                        prefix = namespaceName = "";
1309:                        _namespaceNameIndex = _prefixIndex = _namespacePrefixes[_namespacePrefixesIndex++] = -1;
1310:                        break;
1311:                    // no prefix, namespace
1312:                    // Declaration of default namespace
1313:                    case 1:
1314:                        prefix = "";
1315:                        namespaceName = decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(false);
1316:
1317:                        _prefixIndex = _namespacePrefixes[_namespacePrefixesIndex++] = -1;
1318:                        break;
1319:                    // prefix, no namespace
1320:                    // Undeclaration of namespace
1321:                    case 2:
1322:                        prefix = decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(false);
1323:                        namespaceName = "";
1324:
1325:                        _namespaceNameIndex = -1;
1326:                        _namespacePrefixes[_namespacePrefixesIndex++] = _prefixIndex;
1327:                        break;
1328:                    // prefix, namespace
1329:                    // Declaration of prefixed namespace 
1330:                    case 3:
1331:                        prefix = decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(true);
1332:                        namespaceName = decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(true);
1333:
1334:                        _namespacePrefixes[_namespacePrefixesIndex++] = _prefixIndex;
1335:                        break;
1336:                    }
1337:
1338:                    _prefixTable.pushScope(_prefixIndex, _namespaceNameIndex);
1339:
1340:                    if (_namespacePrefixesFeature) {
1341:                        // Add the namespace delcaration as an attribute
1342:                        if (prefix != "") {
1343:                            _attributes.addAttribute(new QualifiedName(
1344:                                    EncodingConstants.XMLNS_NAMESPACE_PREFIX,
1345:                                    EncodingConstants.XMLNS_NAMESPACE_NAME,
1346:                                    prefix), namespaceName);
1347:                        } else {
1348:                            _attributes
1349:                                    .addAttribute(
1350:                                            EncodingConstants.DEFAULT_NAMESPACE_DECLARATION,
1351:                                            namespaceName);
1352:                        }
1353:                    }
1354:
1355:                    try {
1356:                        _contentHandler.startPrefixMapping(prefix,
1357:                                namespaceName);
1358:                    } catch (SAXException e) {
1359:                        throw new IOException("processStartNamespaceAII");
1360:                    }
1361:
1362:                    b = read();
1363:                }
1364:                if (b != EncodingConstants.TERMINATOR) {
1365:                    throw new IOException(
1366:                            CommonResourceBundle
1367:                                    .getInstance()
1368:                                    .getString(
1369:                                            "message.EIInamespaceNameNotTerminatedCorrectly"));
1370:                }
1371:                final int end = _namespacePrefixesIndex;
1372:
1373:                _b = read();
1374:                switch (DecoderStateTables.EII[_b]) {
1375:                case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL:
1376:                    processEII(_elementNameTable._array[_b], hasAttributes);
1377:                    break;
1378:                case DecoderStateTables.EII_INDEX_MEDIUM:
1379:                    processEII(decodeEIIIndexMedium(), hasAttributes);
1380:                    break;
1381:                case DecoderStateTables.EII_INDEX_LARGE:
1382:                    processEII(decodeEIIIndexLarge(), hasAttributes);
1383:                    break;
1384:                case DecoderStateTables.EII_LITERAL: {
1385:                    final QualifiedName qn = decodeLiteralQualifiedName(
1386:                            _b
1387:                                    & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
1388:                            _elementNameTable.getNext());
1389:                    _elementNameTable.add(qn);
1390:                    processEII(qn, hasAttributes);
1391:                    break;
1392:                }
1393:                default:
1394:                    throw new IOException(CommonResourceBundle.getInstance()
1395:                            .getString(
1396:                                    "message.IllegalStateDecodingEIIAfterAIIs"));
1397:                }
1398:
1399:                try {
1400:                    for (int i = end - 1; i >= start; i--) {
1401:                        final int prefixIndex = _namespacePrefixes[i];
1402:                        _prefixTable.popScope(prefixIndex);
1403:                        prefix = (prefixIndex > 0) ? _prefixTable
1404:                                .get(prefixIndex - 1)
1405:                                : (prefixIndex == -1) ? ""
1406:                                        : EncodingConstants.XML_NAMESPACE_PREFIX;
1407:                        _contentHandler.endPrefixMapping(prefix);
1408:                    }
1409:                    _namespacePrefixesIndex = start;
1410:                } catch (SAXException e) {
1411:                    throw new IOException("processStartNamespaceAII");
1412:                }
1413:            }
1414:
1415:            protected final void processAIIs() throws FastInfosetException,
1416:                    IOException {
1417:                QualifiedName name;
1418:                int b;
1419:                String value;
1420:
1421:                _clearAttributes = true;
1422:
1423:                if (++_duplicateAttributeVerifier._currentIteration == Integer.MAX_VALUE) {
1424:                    _duplicateAttributeVerifier.clear();
1425:                }
1426:
1427:                do {
1428:                    // AII qualified name
1429:                    b = read();
1430:                    switch (DecoderStateTables.AII[b]) {
1431:                    case DecoderStateTables.AII_INDEX_SMALL:
1432:                        name = _attributeNameTable._array[b];
1433:                        break;
1434:                    case DecoderStateTables.AII_INDEX_MEDIUM: {
1435:                        final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read())
1436:                                + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT;
1437:                        name = _attributeNameTable._array[i];
1438:                        break;
1439:                    }
1440:                    case DecoderStateTables.AII_INDEX_LARGE: {
1441:                        final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16)
1442:                                | (read() << 8) | read())
1443:                                + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT;
1444:                        name = _attributeNameTable._array[i];
1445:                        break;
1446:                    }
1447:                    case DecoderStateTables.AII_LITERAL:
1448:                        name = decodeLiteralQualifiedName(
1449:                                b
1450:                                        & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
1451:                                _attributeNameTable.getNext());
1452:                        name
1453:                                .createAttributeValues(_duplicateAttributeVerifier.MAP_SIZE);
1454:                        _attributeNameTable.add(name);
1455:                        break;
1456:                    case DecoderStateTables.AII_TERMINATOR_DOUBLE:
1457:                        _doubleTerminate = true;
1458:                    case DecoderStateTables.AII_TERMINATOR_SINGLE:
1459:                        _terminate = true;
1460:                        // AIIs have finished break out of loop
1461:                        continue;
1462:                    default:
1463:                        throw new IOException(CommonResourceBundle
1464:                                .getInstance()
1465:                                .getString("message.decodingAIIs"));
1466:                    }
1467:
1468:                    if (name.prefixIndex > 0
1469:                            && _prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) {
1470:                        throw new FastInfosetException(CommonResourceBundle
1471:                                .getInstance().getString(
1472:                                        "message.AIIqNameNotInScope"));
1473:                    }
1474:
1475:                    _duplicateAttributeVerifier.checkForDuplicateAttribute(
1476:                            name.attributeHash, name.attributeId);
1477:
1478:                    // [normalized value] of AII
1479:
1480:                    b = read();
1481:                    switch (DecoderStateTables.NISTRING[b]) {
1482:                    case DecoderStateTables.NISTRING_UTF8_SMALL_LENGTH:
1483:                        _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1;
1484:                        value = decodeUtf8StringAsString();
1485:                        if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
1486:                            _attributeValueTable.add(value);
1487:                        }
1488:
1489:                        _attributes.addAttribute(name, value);
1490:                        break;
1491:                    case DecoderStateTables.NISTRING_UTF8_MEDIUM_LENGTH:
1492:                        _octetBufferLength = read()
1493:                                + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT;
1494:                        value = decodeUtf8StringAsString();
1495:                        if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
1496:                            _attributeValueTable.add(value);
1497:                        }
1498:
1499:                        _attributes.addAttribute(name, value);
1500:                        break;
1501:                    case DecoderStateTables.NISTRING_UTF8_LARGE_LENGTH:
1502:                        _octetBufferLength = ((read() << 24) | (read() << 16)
1503:                                | (read() << 8) | read())
1504:                                + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT;
1505:                        value = decodeUtf8StringAsString();
1506:                        if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
1507:                            _attributeValueTable.add(value);
1508:                        }
1509:
1510:                        _attributes.addAttribute(name, value);
1511:                        break;
1512:                    case DecoderStateTables.NISTRING_UTF16_SMALL_LENGTH:
1513:                        _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1;
1514:                        value = decodeUtf16StringAsString();
1515:                        if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
1516:                            _attributeValueTable.add(value);
1517:                        }
1518:
1519:                        _attributes.addAttribute(name, value);
1520:                        break;
1521:                    case DecoderStateTables.NISTRING_UTF16_MEDIUM_LENGTH:
1522:                        _octetBufferLength = read()
1523:                                + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT;
1524:                        value = decodeUtf16StringAsString();
1525:                        if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
1526:                            _attributeValueTable.add(value);
1527:                        }
1528:
1529:                        _attributes.addAttribute(name, value);
1530:                        break;
1531:                    case DecoderStateTables.NISTRING_UTF16_LARGE_LENGTH:
1532:                        _octetBufferLength = ((read() << 24) | (read() << 16)
1533:                                | (read() << 8) | read())
1534:                                + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT;
1535:                        value = decodeUtf16StringAsString();
1536:                        if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
1537:                            _attributeValueTable.add(value);
1538:                        }
1539:
1540:                        _attributes.addAttribute(name, value);
1541:                        break;
1542:                    case DecoderStateTables.NISTRING_RA: {
1543:                        final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
1544:                        // Decode resitricted alphabet integer
1545:                        _identifier = (b & 0x0F) << 4;
1546:                        b = read();
1547:                        _identifier |= (b & 0xF0) >> 4;
1548:
1549:                        decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b);
1550:
1551:                        value = decodeRestrictedAlphabetAsString();
1552:                        if (addToTable) {
1553:                            _attributeValueTable.add(value);
1554:                        }
1555:
1556:                        _attributes.addAttribute(name, value);
1557:                        break;
1558:                    }
1559:                    case DecoderStateTables.NISTRING_EA: {
1560:                        if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) {
1561:                            throw new EncodingAlgorithmException(
1562:                                    CommonResourceBundle
1563:                                            .getInstance()
1564:                                            .getString(
1565:                                                    "message.addToTableNotSupported"));
1566:                        }
1567:
1568:                        _identifier = (b & 0x0F) << 4;
1569:                        b = read();
1570:                        _identifier |= (b & 0xF0) >> 4;
1571:
1572:                        decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b);
1573:
1574:                        processAIIEncodingAlgorithm(name);
1575:                        break;
1576:                    }
1577:                    case DecoderStateTables.NISTRING_INDEX_SMALL:
1578:                        _attributes
1579:                                .addAttribute(
1580:                                        name,
1581:                                        _attributeValueTable._array[b
1582:                                                & EncodingConstants.INTEGER_2ND_BIT_SMALL_MASK]);
1583:                        break;
1584:                    case DecoderStateTables.NISTRING_INDEX_MEDIUM: {
1585:                        final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read())
1586:                                + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT;
1587:
1588:                        _attributes.addAttribute(name,
1589:                                _attributeValueTable._array[index]);
1590:                        break;
1591:                    }
1592:                    case DecoderStateTables.NISTRING_INDEX_LARGE: {
1593:                        final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16)
1594:                                | (read() << 8) | read())
1595:                                + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT;
1596:
1597:                        _attributes.addAttribute(name,
1598:                                _attributeValueTable._array[index]);
1599:                        break;
1600:                    }
1601:                    case DecoderStateTables.NISTRING_EMPTY:
1602:                        _attributes.addAttribute(name, "");
1603:                        break;
1604:                    default:
1605:                        throw new IOException(CommonResourceBundle
1606:                                .getInstance().getString(
1607:                                        "message.decodingAIIValue"));
1608:                    }
1609:
1610:                } while (!_terminate);
1611:
1612:                // Reset duplication attribute verfifier
1613:                _duplicateAttributeVerifier._poolCurrent = _duplicateAttributeVerifier._poolHead;
1614:
1615:                _terminate = _doubleTerminate;
1616:                _doubleTerminate = false;
1617:            }
1618:
1619:            protected final void processCommentII()
1620:                    throws FastInfosetException, IOException {
1621:                switch (decodeNonIdentifyingStringOnFirstBit()) {
1622:                case NISTRING_STRING:
1623:                    if (_addToTable) {
1624:                        _v.otherString.add(new CharArray(_charBuffer, 0,
1625:                                _charBufferLength, true));
1626:                    }
1627:
1628:                    try {
1629:                        _lexicalHandler.comment(_charBuffer, 0,
1630:                                _charBufferLength);
1631:                    } catch (SAXException e) {
1632:                        throw new FastInfosetException("processCommentII", e);
1633:                    }
1634:                    break;
1635:                case NISTRING_ENCODING_ALGORITHM:
1636:                    throw new IOException(
1637:                            CommonResourceBundle.getInstance().getString(
1638:                                    "message.commentIIAlgorithmNotSupported"));
1639:                case NISTRING_INDEX:
1640:                    final CharArray ca = _v.otherString.get(_integer);
1641:
1642:                    try {
1643:                        _lexicalHandler.comment(ca.ch, ca.start, ca.length);
1644:                    } catch (SAXException e) {
1645:                        throw new FastInfosetException("processCommentII", e);
1646:                    }
1647:                    break;
1648:                case NISTRING_EMPTY_STRING:
1649:                    try {
1650:                        _lexicalHandler.comment(_charBuffer, 0, 0);
1651:                    } catch (SAXException e) {
1652:                        throw new FastInfosetException("processCommentII", e);
1653:                    }
1654:                    break;
1655:                }
1656:            }
1657:
1658:            protected final void processProcessingII()
1659:                    throws FastInfosetException, IOException {
1660:                final String target = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName);
1661:
1662:                switch (decodeNonIdentifyingStringOnFirstBit()) {
1663:                case NISTRING_STRING:
1664:                    final String data = new String(_charBuffer, 0,
1665:                            _charBufferLength);
1666:                    if (_addToTable) {
1667:                        _v.otherString.add(new CharArrayString(data));
1668:                    }
1669:                    try {
1670:                        _contentHandler.processingInstruction(target, data);
1671:                    } catch (SAXException e) {
1672:                        throw new FastInfosetException("processProcessingII", e);
1673:                    }
1674:                    break;
1675:                case NISTRING_ENCODING_ALGORITHM:
1676:                    throw new IOException(
1677:                            CommonResourceBundle
1678:                                    .getInstance()
1679:                                    .getString(
1680:                                            "message.processingIIWithEncodingAlgorithm"));
1681:                case NISTRING_INDEX:
1682:                    try {
1683:                        _contentHandler.processingInstruction(target,
1684:                                _v.otherString.get(_integer).toString());
1685:                    } catch (SAXException e) {
1686:                        throw new FastInfosetException("processProcessingII", e);
1687:                    }
1688:                    break;
1689:                case NISTRING_EMPTY_STRING:
1690:                    try {
1691:                        _contentHandler.processingInstruction(target, "");
1692:                    } catch (SAXException e) {
1693:                        throw new FastInfosetException("processProcessingII", e);
1694:                    }
1695:                    break;
1696:                }
1697:            }
1698:
1699:            protected final void processCIIEncodingAlgorithm()
1700:                    throws FastInfosetException, IOException {
1701:                if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
1702:                    if (_primitiveHandler != null) {
1703:                        processCIIBuiltInEncodingAlgorithmAsPrimitive();
1704:                    } else if (_algorithmHandler != null) {
1705:                        Object array = processBuiltInEncodingAlgorithmAsObject();
1706:
1707:                        try {
1708:                            _algorithmHandler.object(null, _identifier, array);
1709:                        } catch (SAXException e) {
1710:                            throw new FastInfosetException(e);
1711:                        }
1712:                    } else {
1713:                        StringBuffer buffer = new StringBuffer();
1714:                        processBuiltInEncodingAlgorithmAsCharacters(buffer);
1715:
1716:                        try {
1717:                            _contentHandler.characters(buffer.toString()
1718:                                    .toCharArray(), 0, buffer.length());
1719:                        } catch (SAXException e) {
1720:                            throw new FastInfosetException(e);
1721:                        }
1722:                    }
1723:                } else if (_identifier == EncodingAlgorithmIndexes.CDATA) {
1724:                    // Set back buffer position to start of encoded string
1725:                    _octetBufferOffset -= _octetBufferLength;
1726:                    decodeUtf8StringIntoCharBuffer();
1727:
1728:                    try {
1729:                        _lexicalHandler.startCDATA();
1730:                        _contentHandler.characters(_charBuffer, 0,
1731:                                _charBufferLength);
1732:                        _lexicalHandler.endCDATA();
1733:                    } catch (SAXException e) {
1734:                        throw new FastInfosetException(e);
1735:                    }
1736:                } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START
1737:                        && _algorithmHandler != null) {
1738:                    final String URI = _v.encodingAlgorithm
1739:                            .get(_identifier
1740:                                    - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
1741:                    if (URI == null) {
1742:                        throw new EncodingAlgorithmException(
1743:                                CommonResourceBundle.getInstance().getString(
1744:                                        "message.URINotPresent",
1745:                                        new Object[] { Integer
1746:                                                .valueOf(_identifier) }));
1747:                    }
1748:
1749:                    final EncodingAlgorithm ea = (EncodingAlgorithm) _registeredEncodingAlgorithms
1750:                            .get(URI);
1751:                    if (ea != null) {
1752:                        final Object data = ea.decodeFromBytes(_octetBuffer,
1753:                                _octetBufferStart, _octetBufferLength);
1754:                        try {
1755:                            _algorithmHandler.object(URI, _identifier, data);
1756:                        } catch (SAXException e) {
1757:                            throw new FastInfosetException(e);
1758:                        }
1759:                    } else {
1760:                        try {
1761:                            _algorithmHandler.octets(URI, _identifier,
1762:                                    _octetBuffer, _octetBufferStart,
1763:                                    _octetBufferLength);
1764:                        } catch (SAXException e) {
1765:                            throw new FastInfosetException(e);
1766:                        }
1767:                    }
1768:                } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
1769:                    // TODO should have property to ignore
1770:                    throw new EncodingAlgorithmException(CommonResourceBundle
1771:                            .getInstance().getString(
1772:                                    "message.algorithmDataCannotBeReported"));
1773:                } else {
1774:                    // Reserved built-in algorithms for future use
1775:                    // TODO should use sax property to decide if event will be
1776:                    // reported, allows for support through handler if required.
1777:                    throw new EncodingAlgorithmException(CommonResourceBundle
1778:                            .getInstance().getString(
1779:                                    "message.identifiers10to31Reserved"));
1780:                }
1781:            }
1782:
1783:            protected final void processCIIBuiltInEncodingAlgorithmAsPrimitive()
1784:                    throws FastInfosetException, IOException {
1785:                try {
1786:                    int length;
1787:                    switch (_identifier) {
1788:                    case EncodingAlgorithmIndexes.HEXADECIMAL:
1789:                    case EncodingAlgorithmIndexes.BASE64:
1790:                        _primitiveHandler.bytes(_octetBuffer,
1791:                                _octetBufferStart, _octetBufferLength);
1792:                        break;
1793:                    case EncodingAlgorithmIndexes.SHORT:
1794:                        length = BuiltInEncodingAlgorithmFactory.shortEncodingAlgorithm
1795:                                .getPrimtiveLengthFromOctetLength(_octetBufferLength);
1796:                        if (length > builtInAlgorithmState.shortArray.length) {
1797:                            final short[] array = new short[length * 3 / 2 + 1];
1798:                            System.arraycopy(builtInAlgorithmState.shortArray,
1799:                                    0, array, 0,
1800:                                    builtInAlgorithmState.shortArray.length);
1801:                            builtInAlgorithmState.shortArray = array;
1802:                        }
1803:
1804:                        BuiltInEncodingAlgorithmFactory.shortEncodingAlgorithm
1805:                                .decodeFromBytesToShortArray(
1806:                                        builtInAlgorithmState.shortArray, 0,
1807:                                        _octetBuffer, _octetBufferStart,
1808:                                        _octetBufferLength);
1809:                        _primitiveHandler.shorts(
1810:                                builtInAlgorithmState.shortArray, 0, length);
1811:                        break;
1812:                    case EncodingAlgorithmIndexes.INT:
1813:                        length = BuiltInEncodingAlgorithmFactory.intEncodingAlgorithm
1814:                                .getPrimtiveLengthFromOctetLength(_octetBufferLength);
1815:                        if (length > builtInAlgorithmState.intArray.length) {
1816:                            final int[] array = new int[length * 3 / 2 + 1];
1817:                            System.arraycopy(builtInAlgorithmState.intArray, 0,
1818:                                    array, 0,
1819:                                    builtInAlgorithmState.intArray.length);
1820:                            builtInAlgorithmState.intArray = array;
1821:                        }
1822:
1823:                        BuiltInEncodingAlgorithmFactory.intEncodingAlgorithm
1824:                                .decodeFromBytesToIntArray(
1825:                                        builtInAlgorithmState.intArray, 0,
1826:                                        _octetBuffer, _octetBufferStart,
1827:                                        _octetBufferLength);
1828:                        _primitiveHandler.ints(builtInAlgorithmState.intArray,
1829:                                0, length);
1830:                        break;
1831:                    case EncodingAlgorithmIndexes.LONG:
1832:                        length = BuiltInEncodingAlgorithmFactory.longEncodingAlgorithm
1833:                                .getPrimtiveLengthFromOctetLength(_octetBufferLength);
1834:                        if (length > builtInAlgorithmState.longArray.length) {
1835:                            final long[] array = new long[length * 3 / 2 + 1];
1836:                            System.arraycopy(builtInAlgorithmState.longArray,
1837:                                    0, array, 0,
1838:                                    builtInAlgorithmState.longArray.length);
1839:                            builtInAlgorithmState.longArray = array;
1840:                        }
1841:
1842:                        BuiltInEncodingAlgorithmFactory.longEncodingAlgorithm
1843:                                .decodeFromBytesToLongArray(
1844:                                        builtInAlgorithmState.longArray, 0,
1845:                                        _octetBuffer, _octetBufferStart,
1846:                                        _octetBufferLength);
1847:                        _primitiveHandler.longs(
1848:                                builtInAlgorithmState.longArray, 0, length);
1849:                        break;
1850:                    case EncodingAlgorithmIndexes.BOOLEAN:
1851:                        length = BuiltInEncodingAlgorithmFactory.booleanEncodingAlgorithm
1852:                                .getPrimtiveLengthFromOctetLength(
1853:                                        _octetBufferLength,
1854:                                        _octetBuffer[_octetBufferStart] & 0xFF);
1855:                        if (length > builtInAlgorithmState.booleanArray.length) {
1856:                            final boolean[] array = new boolean[length * 3 / 2 + 1];
1857:                            System.arraycopy(
1858:                                    builtInAlgorithmState.booleanArray, 0,
1859:                                    array, 0,
1860:                                    builtInAlgorithmState.booleanArray.length);
1861:                            builtInAlgorithmState.booleanArray = array;
1862:                        }
1863:
1864:                        BuiltInEncodingAlgorithmFactory.booleanEncodingAlgorithm
1865:                                .decodeFromBytesToBooleanArray(
1866:                                        builtInAlgorithmState.booleanArray, 0,
1867:                                        length, _octetBuffer,
1868:                                        _octetBufferStart, _octetBufferLength);
1869:                        _primitiveHandler.booleans(
1870:                                builtInAlgorithmState.booleanArray, 0, length);
1871:                        break;
1872:                    case EncodingAlgorithmIndexes.FLOAT:
1873:                        length = BuiltInEncodingAlgorithmFactory.floatEncodingAlgorithm
1874:                                .getPrimtiveLengthFromOctetLength(_octetBufferLength);
1875:                        if (length > builtInAlgorithmState.floatArray.length) {
1876:                            final float[] array = new float[length * 3 / 2 + 1];
1877:                            System.arraycopy(builtInAlgorithmState.floatArray,
1878:                                    0, array, 0,
1879:                                    builtInAlgorithmState.floatArray.length);
1880:                            builtInAlgorithmState.floatArray = array;
1881:                        }
1882:
1883:                        BuiltInEncodingAlgorithmFactory.floatEncodingAlgorithm
1884:                                .decodeFromBytesToFloatArray(
1885:                                        builtInAlgorithmState.floatArray, 0,
1886:                                        _octetBuffer, _octetBufferStart,
1887:                                        _octetBufferLength);
1888:                        _primitiveHandler.floats(
1889:                                builtInAlgorithmState.floatArray, 0, length);
1890:                        break;
1891:                    case EncodingAlgorithmIndexes.DOUBLE:
1892:                        length = BuiltInEncodingAlgorithmFactory.doubleEncodingAlgorithm
1893:                                .getPrimtiveLengthFromOctetLength(_octetBufferLength);
1894:                        if (length > builtInAlgorithmState.doubleArray.length) {
1895:                            final double[] array = new double[length * 3 / 2 + 1];
1896:                            System.arraycopy(builtInAlgorithmState.doubleArray,
1897:                                    0, array, 0,
1898:                                    builtInAlgorithmState.doubleArray.length);
1899:                            builtInAlgorithmState.doubleArray = array;
1900:                        }
1901:
1902:                        BuiltInEncodingAlgorithmFactory.doubleEncodingAlgorithm
1903:                                .decodeFromBytesToDoubleArray(
1904:                                        builtInAlgorithmState.doubleArray, 0,
1905:                                        _octetBuffer, _octetBufferStart,
1906:                                        _octetBufferLength);
1907:                        _primitiveHandler.doubles(
1908:                                builtInAlgorithmState.doubleArray, 0, length);
1909:                        break;
1910:                    case EncodingAlgorithmIndexes.UUID:
1911:                        length = BuiltInEncodingAlgorithmFactory.uuidEncodingAlgorithm
1912:                                .getPrimtiveLengthFromOctetLength(_octetBufferLength);
1913:                        if (length > builtInAlgorithmState.longArray.length) {
1914:                            final long[] array = new long[length * 3 / 2 + 1];
1915:                            System.arraycopy(builtInAlgorithmState.longArray,
1916:                                    0, array, 0,
1917:                                    builtInAlgorithmState.longArray.length);
1918:                            builtInAlgorithmState.longArray = array;
1919:                        }
1920:
1921:                        BuiltInEncodingAlgorithmFactory.uuidEncodingAlgorithm
1922:                                .decodeFromBytesToLongArray(
1923:                                        builtInAlgorithmState.longArray, 0,
1924:                                        _octetBuffer, _octetBufferStart,
1925:                                        _octetBufferLength);
1926:                        _primitiveHandler.uuids(
1927:                                builtInAlgorithmState.longArray, 0, length);
1928:                        break;
1929:                    case EncodingAlgorithmIndexes.CDATA:
1930:                        throw new UnsupportedOperationException("CDATA");
1931:                    default:
1932:                        throw new FastInfosetException(CommonResourceBundle
1933:                                .getInstance().getString(
1934:                                        "message.unsupportedAlgorithm",
1935:                                        new Object[] { Integer
1936:                                                .valueOf(_identifier) }));
1937:                    }
1938:                } catch (SAXException e) {
1939:                    throw new FastInfosetException(e);
1940:                }
1941:            }
1942:
1943:            protected final void processAIIEncodingAlgorithm(QualifiedName name)
1944:                    throws FastInfosetException, IOException {
1945:                if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
1946:                    if (_primitiveHandler != null || _algorithmHandler != null) {
1947:                        Object data = processBuiltInEncodingAlgorithmAsObject();
1948:                        _attributes.addAttributeWithAlgorithmData(name, null,
1949:                                _identifier, data);
1950:                    } else {
1951:                        StringBuffer buffer = new StringBuffer();
1952:                        processBuiltInEncodingAlgorithmAsCharacters(buffer);
1953:                        _attributes.addAttribute(name, buffer.toString());
1954:                    }
1955:                } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START
1956:                        && _algorithmHandler != null) {
1957:                    final String URI = _v.encodingAlgorithm
1958:                            .get(_identifier
1959:                                    - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
1960:                    if (URI == null) {
1961:                        throw new EncodingAlgorithmException(
1962:                                CommonResourceBundle.getInstance().getString(
1963:                                        "message.URINotPresent",
1964:                                        new Object[] { Integer
1965:                                                .valueOf(_identifier) }));
1966:                    }
1967:
1968:                    final EncodingAlgorithm ea = (EncodingAlgorithm) _registeredEncodingAlgorithms
1969:                            .get(URI);
1970:                    if (ea != null) {
1971:                        final Object data = ea.decodeFromBytes(_octetBuffer,
1972:                                _octetBufferStart, _octetBufferLength);
1973:                        _attributes.addAttributeWithAlgorithmData(name, URI,
1974:                                _identifier, data);
1975:                    } else {
1976:                        final byte[] data = new byte[_octetBufferLength];
1977:                        System.arraycopy(_octetBuffer, _octetBufferStart, data,
1978:                                0, _octetBufferLength);
1979:                        _attributes.addAttributeWithAlgorithmData(name, URI,
1980:                                _identifier, data);
1981:                    }
1982:                } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
1983:                    // TODO should have property to ignore
1984:                    throw new EncodingAlgorithmException(CommonResourceBundle
1985:                            .getInstance().getString(
1986:                                    "message.algorithmDataCannotBeReported"));
1987:                } else if (_identifier == EncodingAlgorithmIndexes.CDATA) {
1988:                    throw new EncodingAlgorithmException(CommonResourceBundle
1989:                            .getInstance().getString(
1990:                                    "message.CDATAAlgorithmNotSupported"));
1991:                } else {
1992:                    // Reserved built-in algorithms for future use
1993:                    // TODO should use sax property to decide if event will be
1994:                    // reported, allows for support through handler if required.
1995:                    throw new EncodingAlgorithmException(CommonResourceBundle
1996:                            .getInstance().getString(
1997:                                    "message.identifiers10to31Reserved"));
1998:                }
1999:            }
2000:
2001:            protected final void processBuiltInEncodingAlgorithmAsCharacters(
2002:                    StringBuffer buffer) throws FastInfosetException,
2003:                    IOException {
2004:                // TODO not very efficient, need to reuse buffers
2005:                Object array = BuiltInEncodingAlgorithmFactory.table[_identifier]
2006:                        .decodeFromBytes(_octetBuffer, _octetBufferStart,
2007:                                _octetBufferLength);
2008:
2009:                BuiltInEncodingAlgorithmFactory.table[_identifier]
2010:                        .convertToCharacters(array, buffer);
2011:            }
2012:
2013:            protected final Object processBuiltInEncodingAlgorithmAsObject()
2014:                    throws FastInfosetException, IOException {
2015:                return BuiltInEncodingAlgorithmFactory.table[_identifier]
2016:                        .decodeFromBytes(_octetBuffer, _octetBufferStart,
2017:                                _octetBufferLength);
2018:            }
2019:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.