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


001:        /*
002:         * The contents of this file are subject to the terms
003:         * of the Common Development and Distribution License
004:         * (the "License").  You may not use this file except
005:         * in compliance with the License.
006:         * 
007:         * You can obtain a copy of the license at
008:         * https://jwsdp.dev.java.net/CDDLv1.0.html
009:         * See the License for the specific language governing
010:         * permissions and limitations under the License.
011:         * 
012:         * When distributing Covered Code, include this CDDL
013:         * HEADER in each file and include the License file at
014:         * https://jwsdp.dev.java.net/CDDLv1.0.html  If applicable,
015:         * add the following below this CDDL HEADER, with the
016:         * fields enclosed by brackets "[]" replaced with your
017:         * own identifying information: Portions Copyright [yyyy]
018:         * [name of copyright owner]
019:         */
020:        package com.sun.xml.stream.buffer;
021:
022:        import org.xml.sax.Attributes;
023:
024:        /**
025:         * Class for holding attributes.
026:         *
027:         * Since it implements {@link Attributes}, this class follows the SAX convention
028:         * of using "" instead of null.
029:         */
030:        @SuppressWarnings({"PointlessArithmeticExpression"})
031:        public final class AttributesHolder implements  Attributes {
032:            protected static final int DEFAULT_CAPACITY = 8;
033:            protected static final int ITEM_SIZE = 1 << 3;
034:
035:            protected static final int PREFIX = 0;
036:            protected static final int URI = 1;
037:            protected static final int LOCAL_NAME = 2;
038:            protected static final int QNAME = 3;
039:            protected static final int TYPE = 4;
040:            protected static final int VALUE = 5;
041:
042:            protected int _attributeCount;
043:
044:            protected String[] _strings;
045:
046:            public AttributesHolder() {
047:                _strings = new String[DEFAULT_CAPACITY * ITEM_SIZE];
048:            }
049:
050:            public final int getLength() {
051:                return _attributeCount;
052:            }
053:
054:            public final String getPrefix(int index) {
055:                return (index >= 0 && index < _attributeCount) ? _strings[(index << 3)
056:                        + PREFIX]
057:                        : null;
058:            }
059:
060:            public final String getLocalName(int index) {
061:                return (index >= 0 && index < _attributeCount) ? _strings[(index << 3)
062:                        + LOCAL_NAME]
063:                        : null;
064:            }
065:
066:            public final String getQName(int index) {
067:                return (index >= 0 && index < _attributeCount) ? _strings[(index << 3)
068:                        + QNAME]
069:                        : null;
070:            }
071:
072:            public final String getType(int index) {
073:                return (index >= 0 && index < _attributeCount) ? _strings[(index << 3)
074:                        + TYPE]
075:                        : null;
076:            }
077:
078:            public final String getURI(int index) {
079:                return (index >= 0 && index < _attributeCount) ? _strings[(index << 3)
080:                        + URI]
081:                        : null;
082:            }
083:
084:            public final String getValue(int index) {
085:                return (index >= 0 && index < _attributeCount) ? _strings[(index << 3)
086:                        + VALUE]
087:                        : null;
088:            }
089:
090:            public final int getIndex(String qName) {
091:                for (int i = 0; i < _attributeCount; i++) {
092:                    if (qName.equals(_strings[(i << 3) + QNAME])) {
093:                        return i;
094:                    }
095:                }
096:                return -1;
097:            }
098:
099:            public final String getType(String qName) {
100:                final int i = (getIndex(qName) << 3) + TYPE;
101:                return (i >= 0) ? _strings[i] : null;
102:            }
103:
104:            public final String getValue(String qName) {
105:                final int i = (getIndex(qName) << 3) + VALUE;
106:                return (i >= 0) ? _strings[i] : null;
107:            }
108:
109:            public final int getIndex(String uri, String localName) {
110:                for (int i = 0; i < _attributeCount; i++) {
111:                    if (localName.equals(_strings[(i << 3) + LOCAL_NAME])
112:                            && uri.equals(_strings[(i << 3) + URI])) {
113:                        return i;
114:                    }
115:                }
116:                return -1;
117:            }
118:
119:            public final String getType(String uri, String localName) {
120:                final int i = (getIndex(uri, localName) << 3) + TYPE;
121:                return (i >= 0) ? _strings[i] : null;
122:            }
123:
124:            public final String getValue(String uri, String localName) {
125:                final int i = (getIndex(uri, localName) << 3) + VALUE;
126:                return (i >= 0) ? _strings[i] : null;
127:            }
128:
129:            public final void clear() {
130:                if (_attributeCount > 0) {
131:                    for (int i = 0; i < _attributeCount; i++) {
132:                        _strings[(i << 3) + VALUE] = null;
133:                    }
134:                    _attributeCount = 0;
135:                }
136:            }
137:
138:            /**
139:             * Add an attribute using a qualified name that contains the 
140:             * prefix and local name.
141:             *
142:             * @param uri
143:             *      This can be empty but not null, just like everywhere else in SAX.
144:             */
145:            public final void addAttributeWithQName(String uri,
146:                    String localName, String qName, String type, String value) {
147:                final int i = _attributeCount << 3;
148:                if (i == _strings.length) {
149:                    resize(i);
150:                }
151:
152:                _strings[i + PREFIX] = null;
153:                _strings[i + URI] = uri;
154:                _strings[i + LOCAL_NAME] = localName;
155:                _strings[i + QNAME] = qName;
156:                _strings[i + TYPE] = type;
157:                _strings[i + VALUE] = value;
158:
159:                _attributeCount++;
160:            }
161:
162:            /**
163:             * Add an attribute using a prefix.
164:             *
165:             * @param prefix
166:             *      This can be empty but not null, just like everywhere else in SAX.
167:             * @param uri
168:             *      This can be empty but not null, just like everywhere else in SAX.
169:             */
170:            public final void addAttributeWithPrefix(String prefix, String uri,
171:                    String localName, String type, String value) {
172:                final int i = _attributeCount << 3;
173:                if (i == _strings.length) {
174:                    resize(i);
175:                }
176:
177:                _strings[i + PREFIX] = prefix;
178:                _strings[i + URI] = uri;
179:                _strings[i + LOCAL_NAME] = localName;
180:                _strings[i + QNAME] = null;
181:                _strings[i + TYPE] = type;
182:                _strings[i + VALUE] = value;
183:
184:                _attributeCount++;
185:            }
186:
187:            private void resize(int length) {
188:                final int newLength = length * 2;
189:                final String[] strings = new String[newLength];
190:                System.arraycopy(_strings, 0, strings, 0, length);
191:                _strings = strings;
192:            }
193:
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.