Source Code Cross Referenced for Node.java in  » Cache » shiftone-cache » org » shiftone » cache » config » 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
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » shiftone cache » org.shiftone.cache.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.shiftone.cache.config;
002:
003:        import org.shiftone.cache.ConfigurationException;
004:        import org.shiftone.cache.util.Log;
005:
006:        import java.io.PrintStream;
007:        import java.util.Collection;
008:        import java.util.HashMap;
009:        import java.util.Iterator;
010:        import java.util.Map;
011:
012:        /**
013:         * @version $Revision: 1.5 $
014:         * @author <a href="mailto:jeff@shiftone.org">Jeff Drost</a>
015:         */
016:        public class Node {
017:
018:            private static final Log LOG = new Log(Node.class);
019:            private Map children = new HashMap();
020:            private String key = null;
021:            private String value = null;
022:
023:            /**
024:             * Constructor StackNode
025:             */
026:            public Node(String key, String value) {
027:                this .value = value;
028:                this .key = key;
029:            }
030:
031:            /**
032:             * Method getKey
033:             */
034:            public String getKey() {
035:                return key;
036:            }
037:
038:            /**
039:             * Method getValue
040:             */
041:            public String getValue() {
042:                return value;
043:            }
044:
045:            /**
046:             * Method getChildren
047:             */
048:            public Collection getChildren() {
049:                return children.values();
050:            }
051:
052:            public boolean hasNode(String key) {
053:                return getNode(key) != null;
054:            }
055:
056:            public Node getRequiredNode(String key)
057:                    throws ConfigurationException {
058:
059:                Node node = getNode(key);
060:
061:                if (node == null) {
062:                    throw new ConfigurationException("node not found : " + key);
063:                }
064:
065:                return node;
066:            }
067:
068:            public Node getNode(String key) {
069:                return getNodeInternal(PropertiesTree.tokenize(key), 0);
070:            }
071:
072:            /**
073:             * Method getNode
074:             */
075:            private Node getNodeInternal(String[] keyParts, int partIndex) {
076:
077:                if (keyParts.length == partIndex) {
078:                    return this ;
079:                } else {
080:                    String part = keyParts[partIndex];
081:                    Node nextChild = (Node) children.get(part);
082:
083:                    if (nextChild == null) {
084:                        LOG.debug("node not found : "
085:                                + fullKey(keyParts, partIndex));
086:
087:                        return null;
088:                    }
089:
090:                    return nextChild.getNodeInternal(keyParts, partIndex + 1);
091:                }
092:            }
093:
094:            /**
095:             * Method fullKey
096:             */
097:            private String fullKey(String[] keyParts, int partIndex) {
098:
099:                String fullKey = keyParts[0];
100:
101:                for (int i = 1; i < partIndex; i++) {
102:                    fullKey += ("." + keyParts[i]);
103:                }
104:
105:                return fullKey;
106:            }
107:
108:            /**
109:             * Method createNode
110:             */
111:            public void createNode(String key, String value) {
112:                createNode(PropertiesTree.tokenize(key, "."), 0, value);
113:            }
114:
115:            /**
116:             * Method createNode
117:             */
118:            private void createNode(String[] keyParts, int partIndex,
119:                    String value) {
120:
121:                if (keyParts.length == partIndex) {
122:                    this .value = value;
123:                } else {
124:                    Node nextChild = null;
125:                    String part = keyParts[partIndex];
126:
127:                    if (children.containsKey(part)) {
128:                        nextChild = (Node) children.get(part);
129:                    } else {
130:                        nextChild = new Node(part, null);
131:
132:                        children.put(part, nextChild);
133:                    }
134:
135:                    nextChild.createNode(keyParts, partIndex + 1, value);
136:                }
137:            }
138:
139:            public void print() {
140:                print(System.out, 0);
141:            }
142:
143:            /**
144:             * Method print
145:             */
146:            private void print(PrintStream out, int indentLevel) {
147:
148:                Collection children = getChildren();
149:
150:                if (children.size() == 0) {
151:                    out.println(bufferString(indentLevel, '\t') + "<"
152:                            + getKey() + " value=\"" + getValue() + "\"/>");
153:                } else {
154:                    out.println(bufferString(indentLevel, '\t') + "<"
155:                            + getKey() + " value=\"" + getValue() + "\">");
156:
157:                    Iterator i = children.iterator();
158:
159:                    while (i.hasNext()) {
160:                        ((Node) i.next()).print(out, indentLevel + 1);
161:                    }
162:
163:                    out.println(bufferString(indentLevel, '\t') + "</"
164:                            + getKey() + ">");
165:                }
166:            }
167:
168:            private static String bufferString(int indentLevel, char c) {
169:
170:                StringBuffer sb = new StringBuffer(indentLevel);
171:
172:                for (int i = 0; i < indentLevel; i++) {
173:                    sb.append(c);
174:                }
175:
176:                return sb.toString();
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.