Source Code Cross Referenced for ReaderDepthState.java in  » XML » xstream-1.3 » com » thoughtworks » xstream » io » binary » 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 » xstream 1.3 » com.thoughtworks.xstream.io.binary 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2006 Joe Walnes.
003:         * Copyright (C) 2006, 2007 XStream Committers.
004:         * All rights reserved.
005:         *
006:         * The software in this package is published under the terms of the BSD
007:         * style license a copy of which has been included with this distribution in
008:         * the LICENSE.txt file.
009:         * 
010:         * Created on 04. June 2006 by Joe Walnes
011:         */
012:        package com.thoughtworks.xstream.io.binary;
013:
014:        import java.util.List;
015:        import java.util.ArrayList;
016:        import java.util.Iterator;
017:        import java.util.Collections;
018:
019:        /**
020:         * Maintains the state of a pull reader at various states in the document depth.
021:         *
022:         * Used by the {@link BinaryStreamReader}
023:         *
024:         * @author Joe Walnes
025:         * @since 1.2
026:         */
027:        class ReaderDepthState {
028:
029:            private static final String EMPTY_STRING = "";
030:
031:            private static class State {
032:                String name;
033:                String value;
034:                List attributes;
035:                boolean hasMoreChildren;
036:                State parent;
037:            }
038:
039:            private static class Attribute {
040:                String name;
041:                String value;
042:            }
043:
044:            private State current;
045:
046:            public void push() {
047:                State newState = new State();
048:                newState.parent = current;
049:                current = newState;
050:            }
051:
052:            public void pop() {
053:                current = current.parent;
054:            }
055:
056:            public String getName() {
057:                return current.name;
058:            }
059:
060:            public void setName(String name) {
061:                current.name = name;
062:            }
063:
064:            public String getValue() {
065:                return current.value == null ? EMPTY_STRING : current.value;
066:            }
067:
068:            public void setValue(String value) {
069:                current.value = value;
070:            }
071:
072:            public boolean hasMoreChildren() {
073:                return current.hasMoreChildren;
074:            }
075:
076:            public void setHasMoreChildren(boolean hasMoreChildren) {
077:                current.hasMoreChildren = hasMoreChildren;
078:            }
079:
080:            public void addAttribute(String name, String value) {
081:                Attribute attribute = new Attribute();
082:                attribute.name = name;
083:                attribute.value = value;
084:                if (current.attributes == null) {
085:                    current.attributes = new ArrayList();
086:                }
087:                current.attributes.add(attribute);
088:            }
089:
090:            public String getAttribute(String name) {
091:                if (current.attributes == null) {
092:                    return null;
093:                } else {
094:                    // For short maps, it's faster to iterate then do a hashlookup.
095:                    for (Iterator iterator = current.attributes.iterator(); iterator
096:                            .hasNext();) {
097:                        Attribute attribute = (Attribute) iterator.next();
098:                        if (attribute.name.equals(name)) {
099:                            return attribute.value;
100:                        }
101:                    }
102:                    return null;
103:                }
104:            }
105:
106:            public String getAttribute(int index) {
107:                if (current.attributes == null) {
108:                    return null;
109:                } else {
110:                    Attribute attribute = (Attribute) current.attributes
111:                            .get(index);
112:                    return attribute.value;
113:                }
114:            }
115:
116:            public String getAttributeName(int index) {
117:                if (current.attributes == null) {
118:                    return null;
119:                } else {
120:                    Attribute attribute = (Attribute) current.attributes
121:                            .get(index);
122:                    return attribute.name;
123:                }
124:            }
125:
126:            public int getAttributeCount() {
127:                return current.attributes == null ? 0 : current.attributes
128:                        .size();
129:            }
130:
131:            public Iterator getAttributeNames() {
132:                if (current.attributes == null) {
133:                    return Collections.EMPTY_SET.iterator();
134:                } else {
135:                    final Iterator attributeIterator = current.attributes
136:                            .iterator();
137:                    return new Iterator() {
138:                        public boolean hasNext() {
139:                            return attributeIterator.hasNext();
140:                        }
141:
142:                        public Object next() {
143:                            Attribute attribute = (Attribute) attributeIterator
144:                                    .next();
145:                            return attribute.name;
146:                        }
147:
148:                        public void remove() {
149:                            throw new UnsupportedOperationException();
150:                        }
151:                    };
152:                }
153:            }
154:
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.