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.jdiagnose;
17  
18  import java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.List;
21  
22  /***
23   * Used to contain and run a number of Diagnostic instances.
24   * @author jamie
25   */
26  public class Diagnostics implements DiagnosticContainer {
27  
28      private List diagnostics = new ArrayList();
29      private List diagnosticContainers = new ArrayList();
30      private String name = Diagnostics.class.getName();
31      
32      /***
33       * Create an empty Diagnostics. Diagnostics will
34       * have to be set using setDiagnostics()
35       * @see #setDiagnostics(List)
36       */
37      public Diagnostics() {
38          
39      }
40      
41      /***
42       * Create a Diagnostics with a list of children
43       * @param diagnostics diagnostics that will get
44       * run with diagnose() is called on this class.
45       */
46      public Diagnostics(List diagnosticContainers, List diagnostics) {
47          this.diagnostics = diagnostics;
48          this.diagnosticContainers = diagnosticContainers;
49      }
50  
51      /***
52       * Sets the name of this diagnostic
53       * @param name the new Fully Qualified Name
54       */
55      public void setName(String name) {
56          this.name = name;
57      }
58  
59      /***
60       * @return the name of this Diagnostic, defaults to the 
61       * FQN class name.
62       */
63      public String getName() {
64          return name;
65      }
66  
67      /***
68       * Set the diagnostics that will be run
69       * @param diagnostics
70       */
71      public void setDiagnostics(List diagnostics) {
72          this.diagnostics = Collections.unmodifiableList(diagnostics);
73      }
74  
75      public void setDiagnosticContainers(List diagnosticContainers) {
76          this.diagnosticContainers = Collections.unmodifiableList(diagnosticContainers);
77      }
78  
79      /***
80       * Add a diagnostic to the diagnostics contained in this
81       * class. Once this diagnostic has been set into a DiagnosticRunner
82       * this method should not be called.
83       * 
84       * @param diagnostic another diagnostic that should be run
85       * when diagnose() is run.
86       */
87      public void addDiagnostic(Diagnostic diagnostic) {
88          if(this.diagnostics == null) {
89              this.diagnostics = new ArrayList();
90          }
91          this.diagnostics.add(diagnostic);
92      }
93  
94      /***
95       * @return a list of child diagnostics
96       */
97      public List getDiagnostics() {
98          return diagnostics;
99      }
100 
101     /***
102      * @see org.jdiagnose.DiagnosticContainer#getDiagnosticContainers()
103      */
104     public List getDiagnosticContainers() {
105         return diagnosticContainers;
106     }
107 
108     /***
109      * @param diagnostic
110      */
111     public void addDiagnosticContainer(DiagnosticContainer container) {
112         diagnosticContainers.add(container);
113     }
114 }