1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.api.extension;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.reflect.ObjectDefinition;
20 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
21
22 import javax.xml.namespace.QName;
23
24
25
26
27
28
29 public final class ExtensionUtils {
30
31
32
33
34
35
36
37
38
39 public static <T> T loadExtension(ExtensionDefinitionContract extensionDefinition) {
40 return ExtensionUtils.<T>loadExtension(extensionDefinition, null);
41 }
42
43
44
45
46
47
48
49
50
51
52
53
54 public static <T> T loadExtension(ExtensionDefinitionContract extensionDefinition, String defaultApplicationId) {
55 T extensionService = null;
56
57 String resourceDescriptor = extensionDefinition.getResourceDescriptor();
58 ObjectDefinition extensionObjectDefinition = getExtensionObjectDefinition(extensionDefinition,
59 defaultApplicationId);
60 extensionService = GlobalResourceLoader.<T>getObject(extensionObjectDefinition);
61 if (extensionService == null) {
62
63 extensionService = GlobalResourceLoader.<T>getService(QName.valueOf(resourceDescriptor));
64 }
65 return extensionService;
66 }
67
68 private static ObjectDefinition getExtensionObjectDefinition(ExtensionDefinitionContract extensionDefinition, String defaultApplicationId) {
69 if (StringUtils.isBlank(extensionDefinition.getApplicationId()) && StringUtils.isNotBlank(defaultApplicationId)) {
70 return new ObjectDefinition(extensionDefinition.getResourceDescriptor(), defaultApplicationId);
71 } else {
72 return new ObjectDefinition(extensionDefinition.getResourceDescriptor(), extensionDefinition.getApplicationId());
73 }
74 }
75
76 private ExtensionUtils() {
77 throw new UnsupportedOperationException();
78 }
79
80 }