1 /**
2 * Copyright 2005-2012 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 * An implementation of {@link EngineResults} using List<{@link ResultEvent}> for results and Map<String, Object> for
28 * attributes
29 * @author Kuali Rice Team (rice.collab@kuali.org)
30 */
31 public class EngineResultsImpl implements EngineResults {
32
33 private List<ResultEvent> results = new ArrayList<ResultEvent>();
34 private Map<String, Object> attributes = new HashMap<String, Object>();
35
36 @Override
37 public void addResult(ResultEvent result) {
38 results.add(result);
39 }
40
41 /**
42 * Return a shallow copy of the list of ResultEvents.
43 * @return a shallow copy of all the ResultEvents
44 */
45 @Override
46 public List<ResultEvent> getAllResults() {
47 return new ArrayList<ResultEvent>(results); // shallow copy should be defensive enough
48 }
49
50 /**
51 * Returns null, unimplemented.
52 * @param index of the ResultEvent to return
53 * @return null
54 */
55 @Override
56 public ResultEvent getResultEvent(int index) {
57 // TODO Auto-generated method stub
58 return null;
59 }
60
61 @Override
62 public List<ResultEvent> getResultsOfType(String type) {
63 // TODO Auto-generated method stub
64 ArrayList<ResultEvent> newList = new ArrayList<ResultEvent>();
65 if (type == null) return newList;
66 for (int i=0; i<results.size(); i++){
67 if (type.equalsIgnoreCase(results.get(i).getType())){
68 newList.add(results.get(i));
69 }
70 }
71 return newList;
72 }
73
74 /**
75 * @see org.kuali.rice.krms.api.engine.EngineResults#getAttribute(java.lang.String)
76 */
77 @Override
78 public Object getAttribute(String key) {
79 return attributes.get(key);
80 }
81
82 /**
83 * @see org.kuali.rice.krms.api.engine.EngineResults#setAttribute(java.lang.String, java.lang.Object)
84 */
85 @Override
86 public void setAttribute(String key, Object attr) {
87 attributes.put(key, attr);
88 }
89
90 }