Source Code Cross Referenced for AbstractXPathTest.java in  » Library » Apache-commons-configuration-1.4-src » org » apache » commons » configuration » tree » xpath » 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 » Library » Apache commons configuration 1.4 src » org.apache.commons.configuration.tree.xpath 
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:        package org.apache.commons.configuration.tree.xpath;
018:
019:        import java.util.ArrayList;
020:        import java.util.List;
021:
022:        import org.apache.commons.configuration.tree.ConfigurationNode;
023:        import org.apache.commons.configuration.tree.DefaultConfigurationNode;
024:        import org.apache.commons.jxpath.ri.model.NodeIterator;
025:
026:        import junit.framework.TestCase;
027:
028:        /**
029:         * A base class for testing classes of the XPath package. This base class
030:         * creates a hierarchy of nodes in its setUp() method that can be used for test
031:         * cases.
032:         *
033:         * @author Oliver Heger
034:         * @version $Id: AbstractXPathTest.java 505938 2007-02-11 12:41:13Z brett $
035:         */
036:        public abstract class AbstractXPathTest extends TestCase {
037:            /** Constant for the name of the counter attribute. */
038:            protected static final String ATTR_NAME = "counter";
039:
040:            /** Constant for the name of the first child. */
041:            protected static final String CHILD_NAME1 = "subNode";
042:
043:            /** Constant for the name of the second child. */
044:            protected static final String CHILD_NAME2 = "childNode";
045:
046:            /** Constant for the number of sub nodes. */
047:            protected static final int CHILD_COUNT = 5;
048:
049:            /** Constant for the number of levels in the hierarchy. */
050:            protected static final int LEVEL_COUNT = 3;
051:
052:            /** Stores the root node of the hierarchy. */
053:            protected ConfigurationNode root;
054:
055:            protected void setUp() throws Exception {
056:                super .setUp();
057:                root = constructHierarchy(LEVEL_COUNT);
058:            }
059:
060:            /**
061:             * Clears the test environment.
062:             */
063:            protected void tearDown() throws Exception {
064:                root = null;
065:            }
066:
067:            /**
068:             * Builds up a hierarchy of nodes. Each node has <code>CHILD_COUNT</code>
069:             * child nodes having the names <code>CHILD_NAME1</code> or
070:             * <code>CHILD_NAME2</code>. Their values are named like their parent
071:             * node with an additional index. Each node has an attribute with a counter
072:             * value.
073:             *
074:             * @param levels the number of levels in the hierarchy
075:             * @return the root node of the hierarchy
076:             */
077:            protected ConfigurationNode constructHierarchy(int levels) {
078:                ConfigurationNode result = new DefaultConfigurationNode();
079:                createLevel(result, levels);
080:                return result;
081:            }
082:
083:            /**
084:             * Determines the number of elements contained in the given iterator.
085:             *
086:             * @param iterator the iterator
087:             * @return the number of elements in this iteration
088:             */
089:            protected int iteratorSize(NodeIterator iterator) {
090:                int cnt = 0;
091:                boolean ok;
092:
093:                do {
094:                    ok = iterator.setPosition(cnt + 1);
095:                    if (ok) {
096:                        cnt++;
097:                    }
098:                } while (ok);
099:
100:                return cnt;
101:            }
102:
103:            /**
104:             * Returns a list with all configuration nodes contained in the specified
105:             * iteration. It is assumed that the iteration contains only elements of
106:             * this type.
107:             *
108:             * @param iterator the iterator
109:             * @return a list with configuration nodes obtained from the iterator
110:             */
111:            protected List iterationElements(NodeIterator iterator) {
112:                List result = new ArrayList();
113:                for (int pos = 1; iterator.setPosition(pos); pos++) {
114:                    result.add(iterator.getNodePointer().getNode());
115:                }
116:                return result;
117:            }
118:
119:            /**
120:             * Recursive helper method for creating a level of the node hierarchy.
121:             *
122:             * @param parent the parent node
123:             * @param level the level counter
124:             */
125:            private void createLevel(ConfigurationNode parent, int level) {
126:                if (level >= 0) {
127:                    String prefix = (parent.getValue() == null) ? "" : parent
128:                            .getValue()
129:                            + ".";
130:                    for (int i = 1; i <= CHILD_COUNT; i++) {
131:                        ConfigurationNode child = new DefaultConfigurationNode(
132:                                (i % 2 == 0) ? CHILD_NAME1 : CHILD_NAME2,
133:                                prefix + i);
134:                        parent.addChild(child);
135:                        child.addAttribute(new DefaultConfigurationNode(
136:                                ATTR_NAME, String.valueOf(i)));
137:
138:                        createLevel(child, level - 1);
139:                    }
140:                }
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.