View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.rice.krms.framework.engine;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.kuali.rice.krms.api.engine.EngineResults;
24  import org.kuali.rice.krms.api.engine.ResultEvent;
25  
26  
27  public class EngineResultsImpl implements EngineResults {
28  	
29  	private List<ResultEvent> results = new ArrayList<ResultEvent>();
30  	private Map<String, Object> attributes = new HashMap<String, Object>();
31  	
32  	@Override
33  	public void addResult(ResultEvent result) {
34  		results.add(result);
35  	}
36  
37  	@Override
38  	public List<ResultEvent> getAllResults() {		
39  		return new ArrayList<ResultEvent>(results); // shallow copy should be defensive enough
40  	}
41  
42  	@Override
43  	public ResultEvent getResultEvent(int index) {
44  		// TODO Auto-generated method stub
45  		return null;
46  	}
47  
48  	@Override
49  	public List<ResultEvent> getResultsOfType(String type) {
50  		// TODO Auto-generated method stub
51  		ArrayList<ResultEvent> newList = new ArrayList<ResultEvent>();
52  		if (type == null) return newList;
53  		for (int i=0; i<results.size(); i++){
54  			if (type.equalsIgnoreCase(results.get(i).getType())){
55  				newList.add(results.get(i));
56  			}
57  		}
58  		return newList;
59  	}
60  	
61  	/**
62  	 * @see org.kuali.rice.krms.api.engine.EngineResults#getAttribute(java.lang.String)
63  	 */
64  	@Override
65  	public Object getAttribute(String key) {
66  	    return attributes.get(key);
67  	}
68  	
69  	/**
70  	 * @see org.kuali.rice.krms.api.engine.EngineResults#setAttribute(java.lang.String, java.lang.Object)
71  	 */
72  	@Override
73  	public void setAttribute(String key, Object attr) {
74  	    attributes.put(key, attr);
75  	}
76  	
77  }