1 5 package xdoclet.modules.ejb.dd; 6 7 import java.util.*; 8 9 import xjavadoc.*; 10 11 import xdoclet.XDocletException; 12 13 import xdoclet.modules.ejb.EjbTagsHandler; 14 import xdoclet.modules.ejb.intf.InterfaceTagsHandler; 15 import xdoclet.util.DocletUtil; 16 17 23 public class SecurityTagsHandler extends EjbTagsHandler 24 { 25 32 protected transient String currentSecurityRoleName; 33 34 42 public String securityRoleName() throws XDocletException 43 { 44 return currentSecurityRoleName; 45 } 46 47 56 public void forAllSecurityRoles(String template) throws XDocletException 57 { 58 Collection classes = getXJavaDoc().getSourceClasses(); 59 60 Set roleSet = new HashSet(); 61 62 for (Iterator i = classes.iterator(); i.hasNext(); ) { 63 XClass clazz = (XClass) i.next(); 64 65 setCurrentClass(clazz); 66 67 if (hasPermission(getCurrentClass().getDoc())) { 69 Collection permissions = getCurrentClass().getDoc().getTags("ejb.permission"); 70 71 for (Iterator k = permissions.iterator(); k.hasNext(); ) { 72 XTag tag = (XTag) k.next(); 73 String roleName = tag.getAttributeValue("role-name"); 74 75 if (roleName != null) { 76 roleSet.addAll(Arrays.asList(DocletUtil.tokenizeDelimitedToArray(roleName, ","))); 77 } 78 } 79 } 81 82 Collection methods = getCurrentClass().getMethods(); 84 85 for (Iterator j = methods.iterator(); j.hasNext(); ) { 86 XMethod method = (XMethod) j.next(); 87 88 setCurrentMethod(method); 89 90 if (hasPermission(getCurrentMethod().getDoc()) && InterfaceTagsHandler.isInterfaceMethod(getCurrentMethod())) { 91 Collection permissions = getCurrentMethod().getDoc().getTags("ejb.permission"); 92 93 for (Iterator k = permissions.iterator(); k.hasNext(); ) { 94 XTag tag = (XTag) k.next(); 95 String role_name = tag.getAttributeValue("role-name"); 96 97 if (role_name != null) { 98 roleSet.addAll(Arrays.asList(DocletUtil.tokenizeDelimitedToArray(role_name, ","))); 99 } 100 } 101 } 103 } 104 105 Collection finders = getCurrentClass().getDoc().getTags("ejb:finder"); 107 108 for (Iterator j = finders.iterator(); j.hasNext(); ) { 109 XTag tag = (XTag) j.next(); 110 String roleName = tag.getAttributeValue("role-name"); 111 112 if (roleName != null) { 113 roleSet.addAll(Arrays.asList(DocletUtil.tokenizeDelimitedToArray(roleName, ","))); 114 } 115 } 116 117 Collection pk = getCurrentClass().getDoc().getTags("ejb:pk"); 119 120 for (Iterator j = pk.iterator(); j.hasNext(); ) { 121 XTag tag = (XTag) j.next(); 122 String roleName = tag.getAttributeValue("role-name"); 123 124 if (roleName != null) { 125 roleSet.addAll(Arrays.asList(DocletUtil.tokenizeDelimitedToArray(roleName, ","))); 126 } 127 } 128 } 129 130 Iterator roleEnum = roleSet.iterator(); 132 133 while (roleEnum.hasNext()) { 134 currentSecurityRoleName = (String ) roleEnum.next(); 135 136 generate(template); 137 } 138 } 139 140 147 private boolean hasPermission(XDoc doc) 148 { 149 return doc.hasTag("ejb:permission"); 150 } 151 } 152 | Popular Tags |