1 package org.kuali.rice.krms.service.impl;
2
3 import org.kuali.rice.krms.framework.engine.expression.ComparisonOperator;
4 import org.kuali.rice.krms.builder.ComponentBuilder;
5 import org.kuali.rice.krms.service.TemplateRegistry;
6 import org.kuali.rice.krms.dto.TemplateInfo;
7
8 import java.util.HashMap;
9 import java.util.Map;
10
11
12
13
14
15 public class TemplateRegistryImpl implements TemplateRegistry {
16
17 private Map<String, TemplateInfo> templatesMap;
18 private Map<String, ComponentBuilder> componentBuilderMap = new HashMap<String, ComponentBuilder>();
19
20 public void setTemplatesMap(Map<String, TemplateInfo> templatesMap) {
21 this.templatesMap = templatesMap;
22 }
23
24 public TemplateInfo getTemplateForType(String type) {
25 TemplateInfo template = templatesMap.get(type);
26 return (template != null ? template : null);
27 }
28
29 public String getTermSpecNameForType(String type) {
30 TemplateInfo template = templatesMap.get(type);
31 return (template != null ? template.getTermSpecName() : null);
32 }
33
34 public String getOperationForType(String type) {
35 TemplateInfo template = templatesMap.get(type);
36 if (template == null) {
37 return null;
38 }
39 ComparisonOperator operator = ComparisonOperator.fromCode(template.getOperator());
40 return (operator != null ? operator.getCode() : null);
41 }
42
43 public String getValueForType(String type) {
44 TemplateInfo template = templatesMap.get(type);
45 return (template != null ? template.getValue() : null);
46 }
47
48 public ComponentBuilder getComponentBuilderForType(String type){
49 TemplateInfo template = templatesMap.get(type);
50 if ((template == null) || (template.getComponentBuilderClass() == null)){
51 return null;
52 }
53
54 ComponentBuilder builder = componentBuilderMap.get(template.getComponentBuilderClass());
55 if (builder == null){
56 try {
57 builder = (ComponentBuilder) Class.forName(template.getComponentBuilderClass()).newInstance();
58 componentBuilderMap.put(template.getComponentBuilderClass(), builder);
59 } catch (InstantiationException e) {
60 e.printStackTrace();
61 } catch (IllegalAccessException e) {
62 e.printStackTrace();
63 } catch (ClassNotFoundException e) {
64 e.printStackTrace();
65 }
66 }
67
68 return builder;
69 }
70
71 }