KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > results > ResultsFactory


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.org
21  * e-Mail: support@hammurapi.biz
22  */

23 package org.hammurapi.results;
24
25 import java.util.Stack JavaDoc;
26
27 import org.hammurapi.HammurapiException;
28
29 import com.pavelvlasov.jsel.CompilationUnit;
30 import com.pavelvlasov.persistence.Storage;
31
32 /**
33  * @author Pavel Vlasov
34  * @version $Revision: 1.6 $
35  */

36 public abstract class ResultsFactory {
37     /**
38      * Task to be executed possibly in a separate thread
39      */

40     public interface Task {
41         void execute() throws HammurapiException;
42     }
43     
44     private static ResultsFactory instance;
45     
46     /**
47      * Makes this instance a singleton
48      */

49     public void install() {
50         instance=this;
51     }
52     
53     public static ResultsFactory getInstance() {
54         return instance;
55     }
56     
57     public abstract AggregatedResults newAggregatedResults();
58
59     public abstract NamedResults newNamedResults(String JavaDoc name);
60
61     public abstract DetailedResults newDetailedResults(String JavaDoc name);
62
63     public abstract CompositeResults newCompositeResults(String JavaDoc name);
64
65     public abstract ReviewResults newReviewResults(CompilationUnit compilationUnit);
66
67     private static ThreadLocal JavaDoc threadInstance = new ThreadLocal JavaDoc() {
68         protected Object JavaDoc initialValue() {
69             return new Stack JavaDoc();
70         }
71     };
72
73     /**
74      * @return Detailed results instance for current thread
75      */

76     public static DetailedResults getThreadResults() {
77         Stack JavaDoc stack = (Stack JavaDoc) threadInstance.get();
78         return stack.isEmpty() ? null : (DetailedResults) stack.peek();
79     }
80     
81     public static DetailedResults popThreadResults() {
82         Stack JavaDoc stack = (Stack JavaDoc) threadInstance.get();
83         return stack.isEmpty() ? null : (DetailedResults) stack.pop();
84     }
85
86     public static void pushThreadResults(DetailedResults result) {
87         Stack JavaDoc stack = (Stack JavaDoc) threadInstance.get();
88         stack.push(result);
89     }
90
91     public abstract void setSummary(AggregatedResults summary);
92 // public abstract AggregatedResults getSummary();
93

94     public abstract Storage getStorage();
95     
96     /**
97      * @param cu Compilation unit
98      * @return Previously collected review results.
99      */

100     public abstract ReviewResults findReviewResults(CompilationUnit cu);
101
102     public abstract void commit(long l);
103     
104     public abstract void execute(Task task) throws HammurapiException;
105
106     /**
107      * Waits until all commands in the background thread are executed.
108      */

109     public abstract void join() throws HammurapiException;
110 }
111
Popular Tags