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