1 package org
.argeo
.slc
.core
.test
.tree
;
5 import java
.util
.SortedMap
;
6 import java
.util
.TreeMap
;
7 import java
.util
.Vector
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.slc
.core
.SlcException
;
13 import org
.argeo
.slc
.core
.structure
.StructureAware
;
14 import org
.argeo
.slc
.core
.structure
.StructurePath
;
15 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
16 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
17 import org
.argeo
.slc
.core
.test
.NumericTRId
;
18 import org
.argeo
.slc
.core
.test
.TestResult
;
19 import org
.argeo
.slc
.core
.test
.TestResultId
;
20 import org
.argeo
.slc
.core
.test
.TestResultListener
;
21 import org
.argeo
.slc
.core
.test
.TestResultPart
;
24 * Complex implementation of a test result compatible with a tree based
27 public class TreeTestResult
implements TestResult
, StructureAware
{
28 private Log log
= LogFactory
.getLog(TreeTestResult
.class);
32 private NumericTRId testResultId
;
33 private List
<TestResultListener
> listeners
= new Vector
<TestResultListener
>();
35 private TreeSPath currentPath
;
37 private Date closeDate
;
39 private boolean isClosed
= false;
41 private SortedMap
<TreeSPath
, PartSubList
> resultParts
= new TreeMap
<TreeSPath
, PartSubList
>();
43 private StructureRegistry registry
;
45 public TestResultId
getTestResultId() {
50 * Use of a <code>NumericTRId</code> is required by Hibernate. <b>It may
51 * change in the future.</b>
53 public NumericTRId
getNumericResultId() {
57 /** Sets the test result id as a numeric test result id. */
58 public void setNumericResultId(NumericTRId testResultId
) {
59 this.testResultId
= testResultId
;
62 /** Sets the list of listeners. */
63 public void setListeners(List
<TestResultListener
> listeners
) {
64 this.listeners
= listeners
;
67 public void addResultPart(TestResultPart part
) {
68 if (currentPath
== null) {
69 throw new SlcException("No current path set.");
71 PartSubList subList
= resultParts
.get(currentPath
);
72 if (subList
== null) {
73 subList
= new PartSubList();
74 resultParts
.put(currentPath
, subList
);
76 subList
.getParts().add(part
);
79 synchronized (listeners
) {
80 for (TestResultListener listener
: listeners
) {
81 listener
.resultPartAdded(this, part
);
86 public void notifyCurrentPath(StructureRegistry registry
, StructurePath path
) {
87 currentPath
= (TreeSPath
) path
;
88 this.registry
= registry
;
91 /** Gets the current path. */
92 public TreeSPath
getCurrentPath() {
96 /** Gets all the results structured as a map of <code>PartSubList<code>s. */
97 public SortedMap
<TreeSPath
, PartSubList
> getResultParts() {
101 /** Used by ORM systems. */
102 void setResultParts(SortedMap
<TreeSPath
, PartSubList
> resultParts
) {
103 this.resultParts
= resultParts
;
106 public void close() {
108 throw new SlcException("Test Result #" + getTestResultId()
109 + " alredy closed.");
111 closeDate
= new Date();
113 synchronized (listeners
) {
114 for (TestResultListener listener
: listeners
) {
115 listener
.close(this);
121 log
.info("Test Result #" + getTestResultId() + " closed.");
128 void setTid(Long tid
) {
132 /** Gets the related registry (can be null). */
133 public StructureRegistry
getRegistry() {
137 /** Sets the related registry. */
138 public void setRegistry(StructureRegistry registry
) {
139 this.registry
= registry
;
142 public Date
getCloseDate() {
146 /** Sets the close date (for ORM) */
147 public void setCloseDate(Date closeDate
) {
148 this.closeDate
= closeDate
;