001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.org
021: * e-Mail: support@hammurapi.biz
022: */
023: package org.hammurapi.results;
024:
025: import java.util.Stack;
026:
027: import org.hammurapi.HammurapiException;
028:
029: import com.pavelvlasov.jsel.CompilationUnit;
030: import com.pavelvlasov.persistence.Storage;
031:
032: /**
033: * @author Pavel Vlasov
034: * @version $Revision: 1.6 $
035: */
036: public abstract class ResultsFactory {
037: /**
038: * Task to be executed possibly in a separate thread
039: */
040: public interface Task {
041: void execute() throws HammurapiException;
042: }
043:
044: private static ResultsFactory instance;
045:
046: /**
047: * Makes this instance a singleton
048: */
049: public void install() {
050: instance = this ;
051: }
052:
053: public static ResultsFactory getInstance() {
054: return instance;
055: }
056:
057: public abstract AggregatedResults newAggregatedResults();
058:
059: public abstract NamedResults newNamedResults(String name);
060:
061: public abstract DetailedResults newDetailedResults(String name);
062:
063: public abstract CompositeResults newCompositeResults(String name);
064:
065: public abstract ReviewResults newReviewResults(
066: CompilationUnit compilationUnit);
067:
068: private static ThreadLocal threadInstance = new ThreadLocal() {
069: protected Object initialValue() {
070: return new Stack();
071: }
072: };
073:
074: /**
075: * @return Detailed results instance for current thread
076: */
077: public static DetailedResults getThreadResults() {
078: Stack stack = (Stack) threadInstance.get();
079: return stack.isEmpty() ? null : (DetailedResults) stack.peek();
080: }
081:
082: public static DetailedResults popThreadResults() {
083: Stack stack = (Stack) threadInstance.get();
084: return stack.isEmpty() ? null : (DetailedResults) stack.pop();
085: }
086:
087: public static void pushThreadResults(DetailedResults result) {
088: Stack stack = (Stack) threadInstance.get();
089: stack.push(result);
090: }
091:
092: public abstract void setSummary(AggregatedResults summary);
093:
094: // public abstract AggregatedResults getSummary();
095:
096: public abstract Storage getStorage();
097:
098: /**
099: * @param cu Compilation unit
100: * @return Previously collected review results.
101: */
102: public abstract ReviewResults findReviewResults(CompilationUnit cu);
103:
104: public abstract void commit(long l);
105:
106: public abstract void execute(Task task) throws HammurapiException;
107:
108: /**
109: * Waits until all commands in the background thread are executed.
110: */
111: public abstract void join() throws HammurapiException;
112: }
|