View Javadoc

1   /**
2    * Copyright 2005-2013 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.impl.repository.mock;
17  
18  import java.util.ArrayList;
19  import java.util.LinkedHashMap;
20  import java.util.List;
21  import java.util.Map;
22  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
23  import org.kuali.rice.krms.api.repository.function.FunctionDefinition;
24  import org.kuali.rice.krms.api.repository.function.FunctionRepositoryService;
25  
26  public class FunctionRepositoryServiceMockImpl implements FunctionRepositoryService {
27      // cache variable 
28      // The LinkedHashMap is just so the values come back in a predictable order
29  
30      private Map<String, FunctionDefinition> functionDefinitionMap = new LinkedHashMap<String, FunctionDefinition>();
31  
32      public Map<String, FunctionDefinition> getFunctionDefinitionMap() {
33          return functionDefinitionMap;
34      }
35  
36      public void setFunctionDefinitionMap(Map<String, FunctionDefinition> functionDefinitionMap) {
37          this.functionDefinitionMap = functionDefinitionMap;
38      }
39  
40      public void clear() {
41          this.functionDefinitionMap.clear();
42      }
43  
44      @Override
45      public FunctionDefinition getFunction(String functionId)
46              throws RiceIllegalArgumentException {
47          // GET_BY_ID
48          if (!this.functionDefinitionMap.containsKey(functionId)) {
49              throw new RiceIllegalArgumentException(functionId);
50          }
51          return this.functionDefinitionMap.get(functionId);
52      }
53  
54      @Override
55      public List<FunctionDefinition> getFunctions(List<String> functionIds)
56              throws RiceIllegalArgumentException {
57          List<FunctionDefinition> list = new ArrayList<FunctionDefinition> ();
58          for (String id : functionIds) {
59              list.add (this.getFunction(id));
60          }
61          return list;
62      }
63  }