Source Code Cross Referenced for XMLString.java in  » XML » xerces-2_9_1 » org » apache » xerces » xni » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML » xerces 2_9_1 » org.apache.xerces.xni 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.xerces.xni;
019:
020:        /**
021:         * This class is used as a structure to pass text contained in the underlying
022:         * character buffer of the scanner. The offset and length fields allow the
023:         * buffer to be re-used without creating new character arrays.
024:         * <p>
025:         * <strong>Note:</strong> Methods that are passed an XMLString structure
026:         * should consider the contents read-only and not make any modifications
027:         * to the contents of the buffer. The method receiving this structure
028:         * should also not modify the offset and length if this structure (or
029:         * the values of this structure) are passed to another method.
030:         * <p>
031:         * <strong>Note:</strong> Methods that are passed an XMLString structure
032:         * are required to copy the information out of the buffer if it is to be
033:         * saved for use beyond the scope of the method. The contents of the 
034:         * structure are volatile and the contents of the character buffer cannot
035:         * be assured once the method that is passed this structure returns.
036:         * Therefore, methods passed this structure should not save any reference
037:         * to the structure or the character array contained in the structure.
038:         *
039:         * @author Eric Ye, IBM
040:         * @author Andy Clark, IBM
041:         *
042:         * @version $Id: XMLString.java 447247 2006-09-18 05:23:52Z mrglavas $
043:         */
044:        public class XMLString {
045:
046:            //
047:            // Data
048:            //
049:
050:            /** The character array. */
051:            public char[] ch;
052:
053:            /** The offset into the character array. */
054:            public int offset;
055:
056:            /** The length of characters from the offset. */
057:            public int length;
058:
059:            //
060:            // Constructors
061:            //
062:
063:            /** Default constructor. */
064:            public XMLString() {
065:            } // <init>()
066:
067:            /**
068:             * Constructs an XMLString structure preset with the specified
069:             * values.
070:             * 
071:             * @param ch     The character array.
072:             * @param offset The offset into the character array.
073:             * @param length The length of characters from the offset.
074:             */
075:            public XMLString(char[] ch, int offset, int length) {
076:                setValues(ch, offset, length);
077:            } // <init>(char[],int,int)
078:
079:            /**
080:             * Constructs an XMLString structure with copies of the values in
081:             * the given structure.
082:             * <p>
083:             * <strong>Note:</strong> This does not copy the character array;
084:             * only the reference to the array is copied.
085:             *
086:             * @param string The XMLString to copy.
087:             */
088:            public XMLString(XMLString string) {
089:                setValues(string);
090:            } // <init>(XMLString)
091:
092:            //
093:            // Public methods
094:            //
095:
096:            /**
097:             * Initializes the contents of the XMLString structure with the
098:             * specified values.
099:             * 
100:             * @param ch     The character array.
101:             * @param offset The offset into the character array.
102:             * @param length The length of characters from the offset.
103:             */
104:            public void setValues(char[] ch, int offset, int length) {
105:                this .ch = ch;
106:                this .offset = offset;
107:                this .length = length;
108:            } // setValues(char[],int,int)
109:
110:            /**
111:             * Initializes the contents of the XMLString structure with copies
112:             * of the given string structure.
113:             * <p>
114:             * <strong>Note:</strong> This does not copy the character array;
115:             * only the reference to the array is copied.
116:             * 
117:             * @param s
118:             */
119:            public void setValues(XMLString s) {
120:                setValues(s.ch, s.offset, s.length);
121:            } // setValues(XMLString)
122:
123:            /** Resets all of the values to their defaults. */
124:            public void clear() {
125:                this .ch = null;
126:                this .offset = 0;
127:                this .length = -1;
128:            } // clear()
129:
130:            /**
131:             * Returns true if the contents of this XMLString structure and
132:             * the specified array are equal.
133:             * 
134:             * @param ch     The character array.
135:             * @param offset The offset into the character array.
136:             * @param length The length of characters from the offset.
137:             */
138:            public boolean equals(char[] ch, int offset, int length) {
139:                if (ch == null) {
140:                    return false;
141:                }
142:                if (this .length != length) {
143:                    return false;
144:                }
145:
146:                for (int i = 0; i < length; i++) {
147:                    if (this .ch[this .offset + i] != ch[offset + i]) {
148:                        return false;
149:                    }
150:                }
151:                return true;
152:            } // equals(char[],int,int):boolean
153:
154:            /**
155:             * Returns true if the contents of this XMLString structure and
156:             * the specified string are equal.
157:             * 
158:             * @param s The string to compare.
159:             */
160:            public boolean equals(String s) {
161:                if (s == null) {
162:                    return false;
163:                }
164:                if (length != s.length()) {
165:                    return false;
166:                }
167:
168:                // is this faster than call s.toCharArray first and compare the 
169:                // two arrays directly, which will possibly involve creating a
170:                // new char array object.
171:                for (int i = 0; i < length; i++) {
172:                    if (ch[offset + i] != s.charAt(i)) {
173:                        return false;
174:                    }
175:                }
176:
177:                return true;
178:            } // equals(String):boolean
179:
180:            //
181:            // Object methods
182:            //
183:
184:            /** Returns a string representation of this object. */
185:            public String toString() {
186:                return length > 0 ? new String(ch, offset, length) : "";
187:            } // toString():String
188:
189:        } // class XMLString
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.