KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > samples > performance > PerformanceSupport


1 /*
2  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
3  *
4  * This software is open source.
5  * See the bottom of this file for the licence.
6  *
7  * $Id: PerformanceSupport.java,v 1.4 2005/01/29 14:53:13 maartenc Exp $
8  */

9
10 package org.dom4j.samples.performance;
11
12 import org.dom4j.samples.SAXDemo;
13
14 /**
15  * Base class for all simple performance tests
16  *
17  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan </a>
18  * @version $Revision: 1.4 $
19  */

20 public abstract class PerformanceSupport extends SAXDemo {
21
22     /** Whether the performance of each run is printed */
23     protected static boolean VERBOSE = false;
24
25     /** Default number of loops */
26     protected static final int DEFAULT_LOOP_COUNT = 40;
27
28     /** The XML file to process */
29     protected String JavaDoc xmlFile;
30
31     public PerformanceSupport() {
32     }
33
34     public void run(String JavaDoc[] args) throws Exception JavaDoc {
35         if (args.length < 1) {
36             printUsage("<XML document URL> [<loopCount>]");
37             return;
38         }
39
40         xmlFile = args[0];
41
42         int loopCount = DEFAULT_LOOP_COUNT;
43         if (args.length > 1) {
44             loopCount = Integer.parseInt(args[1]);
45         }
46
47         setUp();
48
49         Timer timer = new Timer();
50         timer.setLoopCount(loopCount);
51         timer.setTask(createTask());
52         timer.run();
53
54         tearDown();
55     }
56
57     protected void setUp() throws Exception JavaDoc {
58     }
59
60     protected void tearDown() throws Exception JavaDoc {
61     }
62
63     protected abstract Task createTask() throws Exception JavaDoc;
64 }
65
66 /*
67  * Redistribution and use of this software and associated documentation
68  * ("Software"), with or without modification, are permitted provided that the
69  * following conditions are met:
70  *
71  * 1. Redistributions of source code must retain copyright statements and
72  * notices. Redistributions must also contain a copy of this document.
73  *
74  * 2. Redistributions in binary form must reproduce the above copyright notice,
75  * this list of conditions and the following disclaimer in the documentation
76  * and/or other materials provided with the distribution.
77  *
78  * 3. The name "DOM4J" must not be used to endorse or promote products derived
79  * from this Software without prior written permission of MetaStuff, Ltd. For
80  * written permission, please contact dom4j-info@metastuff.com.
81  *
82  * 4. Products derived from this Software may not be called "DOM4J" nor may
83  * "DOM4J" appear in their names without prior written permission of MetaStuff,
84  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
85  *
86  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
87  *
88  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
89  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
90  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
91  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
92  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
93  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
94  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
95  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
96  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
97  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
98  * POSSIBILITY OF SUCH DAMAGE.
99  *
100  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
101  *
102  * $Id: PerformanceSupport.java,v 1.4 2005/01/29 14:53:13 maartenc Exp $
103  */

104
Popular Tags