| 1 19 package org.netbeans.modules.j2ee.sun.share.configbean; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 import javax.enterprise.deploy.model.DDBean ; 27 import javax.enterprise.deploy.model.XpathEvent ; 28 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 29 30 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 31 import org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException; 32 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 33 34 import org.netbeans.modules.j2ee.sun.share.PrincipalNameMapping; 35 import org.netbeans.modules.j2ee.sun.share.configbean.Base.DefaultSnippet; 36 37 38 53 public class SecurityRoleMapping extends Base { 54 55 57 public static final String ROLE_NAME = "roleName"; 59 private DDBean securityRoleNameDD; 60 61 62 private ArrayList principalNames; 63 64 65 private ArrayList groupNames; 66 67 68 private BaseRoot rootParent; 69 70 71 public SecurityRoleMapping() { 72 setDescriptorElement(bundle.getString("BDN_SecurityRoleMapping")); } 74 75 79 protected void init(DDBean dDBean, Base parent) throws ConfigurationException { 80 super.init(dDBean, parent); 81 84 securityRoleNameDD = getNameDD("role-name"); 86 updateNamedBeanCache(SunWebApp.SECURITY_ROLE_MAPPING); 87 88 loadFromPlanFile(getConfig()); 89 } 90 91 protected String getComponentName() { 92 return getRoleName(); 93 } 94 95 98 public String getHelpId() { 99 return "AS_CFG_SecurityRoleAssignment"; 100 } 101 102 107 public void notifyDDChange(XpathEvent xpathEvent) { 108 super.notifyDDChange(xpathEvent); 109 110 if(securityRoleNameDD == xpathEvent.getBean()) { 111 getPCS().firePropertyChange(ROLE_NAME, "", getRoleName()); 113 getPCS().firePropertyChange(DISPLAY_NAME, "", getDisplayName()); 114 115 updateNamedBeanCache(SunWebApp.SECURITY_ROLE_MAPPING); 116 } 117 } 118 119 123 public String getRoleName() { 124 return cleanDDBeanText(securityRoleNameDD); } 126 127 131 public List getPrincipalNames() { 132 return principalNames; 133 } 134 135 public PrincipalNameMapping getPrincipalName(int index) { 136 return (PrincipalNameMapping) principalNames.get(index); 137 } 138 139 145 public void setPrincipalNames(ArrayList newPrincipalNames) throws java.beans.PropertyVetoException { 146 List oldPrincipalNames = principalNames; 147 getVCS().fireVetoableChange("principalNames", oldPrincipalNames, newPrincipalNames); principalNames = newPrincipalNames; 149 getPCS().firePropertyChange("principalNames", oldPrincipalNames, principalNames); } 151 152 public void addPrincipalName(PrincipalNameMapping newPrincipalName) throws java.beans.PropertyVetoException { 153 getVCS().fireVetoableChange("principalName", null, newPrincipalName); principalNames.add(newPrincipalName); 155 getPCS().firePropertyChange("principalName", null, newPrincipalName ); } 157 158 public void removePrincipalName(PrincipalNameMapping oldPrincipalName) throws java.beans.PropertyVetoException { 159 getVCS().fireVetoableChange("principalName", oldPrincipalName, null); principalNames.remove(oldPrincipalName); 161 getPCS().firePropertyChange("principalName", oldPrincipalName, null ); } 163 164 168 public List getGroupNames() { 169 return this.groupNames; 170 } 171 172 public String getGroupName(int index) { 173 return (String ) groupNames.get(index); 174 } 175 176 182 public void setGroupNames(ArrayList newGroupNames) throws java.beans.PropertyVetoException { 183 List oldGroupNames = groupNames; 184 getVCS().fireVetoableChange("groupNames", oldGroupNames, newGroupNames); groupNames = newGroupNames; 186 getPCS().firePropertyChange("groupNames", oldGroupNames, groupNames); } 188 189 public void addGroupName(String newGroupName) throws java.beans.PropertyVetoException { 190 getVCS().fireVetoableChange("groupName", null, newGroupName); groupNames.add(newGroupName); 192 getPCS().firePropertyChange("groupName", null, newGroupName ); } 194 195 public void removeGroupName(String oldGroupName) throws java.beans.PropertyVetoException { 196 getVCS().fireVetoableChange("groupName", oldGroupName, null); groupNames.remove(oldGroupName); 198 getPCS().firePropertyChange("groupName", oldGroupName, null ); } 200 201 205 Collection getSnippets() { 206 Collection snippets = new ArrayList (); 207 Snippet snipOne = new DefaultSnippet() { 208 public CommonDDBean getDDSnippet() { 209 org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping srm = 210 getConfig().getStorageFactory().createSecurityRoleMapping(); 211 212 srm.setRoleName(getRoleName()); 214 215 if(principalNames.size() > 0) { 216 Iterator principalIter = principalNames.iterator(); 217 while(principalIter.hasNext()) { 218 PrincipalNameMapping nameMap = (PrincipalNameMapping) principalIter.next(); 219 int index = srm.addPrincipalName(nameMap.getPrincipalName()); 220 if(Utils.notEmpty(nameMap.getClassName())) { 221 try { 222 srm.setPrincipalNameClassName(index, nameMap.getClassName()); 223 } catch(VersionNotSupportedException ex) { 224 } 226 } 227 } 228 } 229 230 if(groupNames.size() > 0) { 231 String [] names = (String []) groupNames.toArray(new String [groupNames.size()]); 232 srm.setGroupName(names); 233 } 234 235 return srm; 236 } 237 238 public boolean hasDDSnippet() { 239 if(principalNames != null && principalNames.size() > 0) { 240 return true; 241 } 242 243 if(groupNames != null && groupNames.size() > 0) { 244 return true; 245 } 246 247 return false; 248 } 249 250 public String getPropertyName() { 251 return SunWebApp.SECURITY_ROLE_MAPPING; 252 } 253 }; 254 255 snippets.add(snipOne); 256 return snippets; 257 } 258 259 private class SecurityRoleMappingFinder extends NameBasedFinder { 260 public SecurityRoleMappingFinder(String beanName) { 261 super(org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping.ROLE_NAME, 262 beanName, org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping.class); 263 } 264 } 265 266 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 267 String uriText = getUriText(); 268 269 org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping beanGraph = 270 (org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping) config.getBeans( 271 uriText, constructFileName(), getParser(), new SecurityRoleMappingFinder(getRoleName())); 272 273 clearProperties(); 274 275 if(beanGraph != null) { 276 String [] names = beanGraph.getPrincipalName(); 277 if(names != null && names.length > 0) { 278 principalNames = new ArrayList (names.length+3); 279 for(int i = 0; i < names.length; i++) { 280 String className = null; 281 try { 282 className = beanGraph.getPrincipalNameClassName(i); 283 } catch(VersionNotSupportedException ex) { 284 } 286 principalNames.add(new PrincipalNameMapping(names[i], className)); 287 } 288 } 289 290 names = beanGraph.getGroupName(); 291 if(names != null && names.length > 0) { 292 groupNames = new ArrayList (names.length+3); 293 for(int i = 0; i < names.length; i++) { 294 groupNames.add(names[i]); 295 } 296 } 297 } else { 298 setDefaultProperties(); 299 } 300 301 return (beanGraph != null); 302 } 303 304 protected void clearProperties() { 305 principalNames = new ArrayList (3); 306 groupNames = new ArrayList (3); 307 } 308 309 protected void setDefaultProperties() { 310 } 312 } 313 | Popular Tags |