1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.rule;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.kuali.rice.kew.engine.RouteContext;
24 import org.kuali.rice.kew.routeheader.DocumentContent;
25
26
27
28
29
30
31
32
33 public abstract class UnqualifiedRoleAttribute extends AbstractRoleAttribute {
34
35 private static final long serialVersionUID = -356582375961050905L;
36 protected List<Role> roles;
37
38
39
40
41 public UnqualifiedRoleAttribute() {
42 roles = Collections.emptyList();
43 }
44
45
46
47
48 public UnqualifiedRoleAttribute(List<Role> roles) {
49 this.roles = roles;
50 }
51
52 public List<Role> getRoleNames() {
53 return roles;
54 }
55
56
57
58
59 public List<String> getQualifiedRoleNames(String roleName, DocumentContent documentContent) {
60 List<String> qualifiedRoleName = new ArrayList<String>(1);
61 qualifiedRoleName.add(roleName);
62 return qualifiedRoleName;
63 }
64
65
66
67
68
69
70
71 protected String parseRoleNameFromClassAndRole(String classAndRole) {
72 return classAndRole.substring(classAndRole.indexOf("!") + 1);
73 }
74
75
76
77
78
79 protected boolean isValidRoleName(String roleName) {
80
81 boolean valid = false;
82 for (Role role: getRoleNames()) {
83 if (parseRoleNameFromClassAndRole(role.getName()).equals(roleName)) {
84 valid = true;
85 break;
86 }
87 }
88 return valid;
89 }
90
91 public ResolvedQualifiedRole resolveQualifiedRole(RouteContext routeContext, String roleName, String qualifiedRole) {
92
93 if (!roleName.equals(qualifiedRole)) {
94 throw new IllegalArgumentException("UnqualifiedRoleAttribute resolveQualifiedRole invoked with differing role and qualified role (they should be the same)");
95 }
96 if (!isValidRoleName(roleName)) {
97 throw new IllegalArgumentException("This attribute does not support the role: '" + roleName + "'");
98 }
99 return resolveRole(routeContext, roleName);
100 }
101
102
103
104
105
106
107
108 protected abstract ResolvedQualifiedRole resolveRole(RouteContext routeContext, String roleName);
109 }