View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.saxbenchmark;
17  
18  import java.io.File;
19  import java.io.FileWriter;
20  import java.util.Properties;
21  
22  import org.apache.velocity.app.VelocityEngine;
23  
24  /***
25   * @author JMcCrindle
26   */
27  public class SaxBenchmarkBean {
28      
29      private String outputDir = null;
30      private String inputDir = null;
31      private String relativeOutputDir = null;
32      private String relativeInputDir = null;
33      private String resultsOutputDir = null;
34      private int count = 1;
35  
36      public void run() throws Throwable {
37          SaxBenchmark bench = new SaxBenchmark();
38          DefaultBenchmarkFactory benchmarkFactory = new DefaultBenchmarkFactory();
39          benchmarkFactory.setReaderSupplier(new DefaultReaderSupplier());
40          benchmarkFactory.setSourceFactorySupplier(new FolderSourceFactorySupplier(inputDir));
41          benchmarkFactory.setCount(count);
42          bench.setBenchmarkFactory(benchmarkFactory);
43          bench.setWriterFactory(new DefaultWriterFactory(outputDir));
44          bench.setOutputterFactorySupplier(new DefaultOutputterFactorySupplier());
45  
46          VelocityEngine engine = new VelocityEngine();
47          Properties properties = new Properties();
48          properties.setProperty("resource.loader", "class");
49          properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
50          engine.init(properties);
51          
52          BenchmarkResults results = bench.run();
53  
54          VelocityResultsWriter service = new VelocityResultsWriter();
55          service.setSourceDir(relativeInputDir);
56          service.setOutputDir(relativeOutputDir);
57          service.setVelocityEngine(engine);
58          service.setTemplateFile("org/saxbenchmark/results.vm");
59          FileWriter writer = new FileWriter(new File(resultsOutputDir, "results.xml"));
60          
61          ChartResultsWriter chartWriter = new ChartResultsWriter(new File(resultsOutputDir, "images"));
62          chartWriter.writeMemoryResults(results);
63  
64          service.writeResults(results, writer);
65          writer.flush();
66          writer.close();
67      }
68      
69      public String getInputDir() {
70          return inputDir;
71      }
72  
73      public void setInputDir(String inputDir) {
74          this.inputDir = inputDir;
75      }
76  
77      public String getOutputDir() {
78          return outputDir;
79      }
80      
81      public void setOutputDir(String outputDir) {
82          this.outputDir = outputDir;
83      }
84      public String getRelativeInputDir() {
85          return relativeInputDir;
86      }
87      public void setRelativeInputDir(String relativeInputDir) {
88          this.relativeInputDir = relativeInputDir;
89      }
90      public String getRelativeOutputDir() {
91          return relativeOutputDir;
92      }
93      public void setRelativeOutputDir(String relativeOutputDir) {
94          this.relativeOutputDir = relativeOutputDir;
95      }
96      public String getResultsOutputDir() {
97          return resultsOutputDir;
98      }
99      public void setResultsOutputDir(String resultsOutputDir) {
100         this.resultsOutputDir = resultsOutputDir;
101     }
102     public int getCount() {
103         return count;
104     }
105     public void setCount(int count) {
106         this.count = count;
107     }
108 }