1 2 24 25 package com.sun.enterprise.deployment.node.ejb; 26 27 import java.util.ArrayList ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Map ; 32 import java.util.Set ; 33 import java.util.Vector ; 34 import org.w3c.dom.Node ; 35 36 import com.sun.enterprise.deployment.node.XMLElement; 37 import com.sun.enterprise.deployment.node.BundleNode; 38 import com.sun.enterprise.deployment.node.RootXMLNode; 39 import com.sun.enterprise.deployment.node.SecurityRoleNode; 40 import com.sun.enterprise.deployment.node.ContainerTransactionNode; 41 import com.sun.enterprise.deployment.node.DescriptorFactory; 42 import com.sun.enterprise.deployment.node.MessageDestinationNode; 43 44 import com.sun.enterprise.deployment.xml.TagNames; 45 import com.sun.enterprise.deployment.xml.EjbTagNames; 46 import com.sun.enterprise.deployment.Descriptor; 47 import com.sun.enterprise.deployment.EjbDescriptor; 48 import com.sun.enterprise.deployment.EjbSessionDescriptor; 49 import com.sun.enterprise.deployment.EjbEntityDescriptor; 50 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor; 51 import com.sun.enterprise.deployment.EjbBundleDescriptor; 52 import com.sun.enterprise.deployment.MethodDescriptor; 53 import com.sun.enterprise.deployment.MethodPermissionDescriptor; 54 import com.sun.enterprise.deployment.MethodPermission; 55 import com.sun.enterprise.deployment.SecurityRoleDescriptor; 56 import com.sun.enterprise.deployment.RelationshipDescriptor; 57 import com.sun.enterprise.deployment.EjbApplicationExceptionInfo; 58 import com.sun.enterprise.deployment.EjbInterceptor; 59 60 import com.sun.enterprise.deployment.util.DOLUtils; 61 62 import com.sun.enterprise.deployment.Role; 63 64 70 public class EjbBundleNode extends BundleNode implements RootXMLNode { 71 72 public final static XMLElement tag = new XMLElement(EjbTagNames.EJB_BUNDLE_TAG); 73 public final static String PUBLIC_DTD_ID = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"; 74 public final static String PUBLIC_DTD_ID_12 = "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; 75 76 77 public final static String SYSTEM_ID = "http://java.sun.com/dtd/ejb-jar_2_0.dtd"; 78 public final static String SYSTEM_ID_12 = "http://java.sun.com/dtd/ejb-jar_1_1.dtd"; 79 public final static String SCHEMA_ID_21 = "ejb-jar_2_1.xsd"; 80 public final static String SCHEMA_ID = "ejb-jar_3_0.xsd"; 81 public final static String SPEC_VERSION = "3.0"; 82 private static List <String > systemIDs = null; 83 84 90 public static String registerBundle(Map publicIDToDTD) { 91 publicIDToDTD.put(PUBLIC_DTD_ID, SYSTEM_ID); 92 publicIDToDTD.put(PUBLIC_DTD_ID_12, SYSTEM_ID_12); 93 return tag.getQName(); 94 } 95 96 private EjbBundleDescriptor descriptor; 98 99 public EjbBundleNode() { 100 super(); 101 registerElementHandler(new XMLElement(EjbTagNames.SESSION), 103 EjbSessionNode.class); 104 registerElementHandler(new XMLElement(EjbTagNames.ENTITY), 105 EjbEntityNode.class); 106 registerElementHandler(new XMLElement(EjbTagNames.MESSAGE_DRIVEN), 107 MessageDrivenBeanNode.class); 108 registerElementHandler(new XMLElement(EjbTagNames.METHOD_PERMISSION), 109 MethodPermissionNode.class); 110 registerElementHandler(new XMLElement(EjbTagNames.ROLE), 111 SecurityRoleNode.class, "addRole"); 112 registerElementHandler(new XMLElement(EjbTagNames.CONTAINER_TRANSACTION), 113 ContainerTransactionNode.class); 114 registerElementHandler(new XMLElement(EjbTagNames.EXCLUDE_LIST), 115 ExcludeListNode.class); 116 registerElementHandler(new XMLElement(EjbTagNames.RELATIONSHIPS), 117 RelationshipsNode.class); 118 registerElementHandler(new XMLElement(TagNames.MESSAGE_DESTINATION), 119 MessageDestinationNode.class, 120 "addMessageDestination"); 121 registerElementHandler(new XMLElement(EjbTagNames.APPLICATION_EXCEPTION), 122 EjbApplicationExceptionNode.class, 123 "addApplicationException"); 124 registerElementHandler(new XMLElement(EjbTagNames.INTERCEPTOR), 125 EjbInterceptorNode.class, 126 "addInterceptor"); 127 128 registerElementHandler(new XMLElement(EjbTagNames.INTERCEPTOR_BINDING), 129 InterceptorBindingNode.class, 130 "appendInterceptorBinding"); 131 } 132 133 139 public void addDescriptor(Object newDescriptor) { 140 if (newDescriptor instanceof EjbDescriptor) { 141 descriptor.addEjb((EjbDescriptor) newDescriptor); 142 } else if (newDescriptor instanceof RelationshipDescriptor) { 143 descriptor.addRelationship((RelationshipDescriptor) newDescriptor); 144 } else if (newDescriptor instanceof MethodPermissionDescriptor) { 145 MethodPermissionDescriptor nd = (MethodPermissionDescriptor) newDescriptor; 146 MethodDescriptor[] array = nd.getMethods(); 147 for (int i=0;i<array.length;i++) { 148 EjbDescriptor target = descriptor.getEjbByName(array[i].getEjbName()); 149 MethodPermission[] mps = nd.getMethodPermissions(); 150 for (int j=0;j<mps.length;j++) { 151 DOLUtils.getDefaultLogger().fine("Adding mp " + mps[j] + " to " + array[i] + " for ejb " + array[i].getEjbName()); 152 target.addPermissionedMethod(mps[j], array[i]); 153 } 154 } 155 } else super.addDescriptor(newDescriptor); 156 } 157 158 161 public Object getDescriptor() { 162 163 if (descriptor==null) { 164 descriptor = (EjbBundleDescriptor) DescriptorFactory.getDescriptor(getXMLPath()); 165 } 166 return descriptor; 167 } 168 169 172 protected XMLElement getXMLRootTag() { 173 return tag; 174 } 175 176 182 protected Map getDispatchTable() { 183 Map table = super.getDispatchTable(); 185 table.put(EjbTagNames.EJB_CLIENT_JAR, "setEjbClientJarUri"); 186 return table; 187 } 188 189 196 public Node writeDescriptor(Node parent, Descriptor descriptor) { 197 if (! (descriptor instanceof EjbBundleDescriptor)) { 198 throw new IllegalArgumentException (getClass() + " cannot handles descriptors of type " + descriptor.getClass()); 199 } 200 EjbBundleDescriptor ejbDesc = (EjbBundleDescriptor) descriptor; 201 Node jarNode = super.writeDescriptor(parent, ejbDesc); 202 Node entrepriseBeansNode = appendChild(jarNode, EjbTagNames.EJBS); 203 for (Iterator ejbs = ejbDesc.getEjbs().iterator();ejbs.hasNext();) { 204 EjbDescriptor ejb = (EjbDescriptor) ejbs.next(); 205 if (EjbSessionDescriptor.TYPE.equals(ejb.getType())) { 206 EjbNode subNode = new EjbSessionNode(); 207 subNode.writeDescriptor(entrepriseBeansNode, 208 EjbTagNames.SESSION, ejb); 209 } else if (EjbEntityDescriptor.TYPE.equals(ejb.getType())) { 210 EjbNode subNode = new EjbEntityNode(); 211 subNode.writeDescriptor(entrepriseBeansNode, 212 EjbTagNames.ENTITY, ejb); 213 } else if (EjbMessageBeanDescriptor.TYPE.equals(ejb.getType())) { 214 EjbNode subNode = new MessageDrivenBeanNode(); 215 subNode.writeDescriptor(entrepriseBeansNode, 216 EjbTagNames.MESSAGE_DRIVEN, ejb); 217 } else { 218 throw new IllegalStateException ("Unknow ejb type " + ejb.getType()); 219 } 220 } 221 222 if( ejbDesc.hasInterceptors() ) { 223 224 Node interceptorsNode = appendChild(jarNode, 225 EjbTagNames.INTERCEPTORS); 226 EjbInterceptorNode interceptorNode = new EjbInterceptorNode(); 227 for(EjbInterceptor next : ejbDesc.getInterceptors()) { 228 interceptorNode.writeDescriptor( interceptorsNode, 229 EjbTagNames.INTERCEPTOR, next); 230 } 231 232 } 233 234 if (ejbDesc.hasRelationships()) { 236 (new RelationshipsNode()).writeDescriptor(jarNode, EjbTagNames.RELATIONSHIPS, ejbDesc); 237 } 238 239 writeAssemblyDescriptor(jarNode, ejbDesc); 241 242 appendTextChild(jarNode, EjbTagNames.EJB_CLIENT_JAR, ejbDesc.getEjbClientJarUri()); 243 return jarNode; 244 } 245 246 249 public String getDocType() { 250 return null; 251 } 252 253 256 public String getSystemID() { 257 return SCHEMA_ID; 258 } 259 260 263 public List <String > getSystemIDs() { 264 if (systemIDs != null) { 265 return systemIDs; 266 } 267 268 systemIDs = new ArrayList <String >(); 269 systemIDs.add(SCHEMA_ID); 270 systemIDs.add(SCHEMA_ID_21); 271 return systemIDs; 272 } 273 274 277 private void writeAssemblyDescriptor(Node parentNode, EjbBundleDescriptor bundleDescriptor) { 278 Node assemblyNode = parentNode.getOwnerDocument().createElement(EjbTagNames.ASSEMBLY_DESCRIPTOR); 279 280 SecurityRoleNode roleNode = new SecurityRoleNode(); 282 for (Iterator e = bundleDescriptor.getRoles().iterator();e.hasNext();) { 283 roleNode.writeDescriptor(assemblyNode, EjbTagNames.ROLE, (Role) e.next()); 284 } 285 286 Map excludedMethodsByEjb = new HashMap (); 288 MethodPermissionNode mpNode = new MethodPermissionNode(); 289 for (Iterator e = bundleDescriptor.getEjbs().iterator();e.hasNext();) { 290 EjbDescriptor ejbDesc = (EjbDescriptor) e.next(); 291 if (ejbDesc instanceof EjbMessageBeanDescriptor) 292 continue; 293 Vector excludedMethods = new Vector (); 294 addMethodPermissions(ejbDesc, ejbDesc.getPermissionedMethodsByPermission(), excludedMethods, mpNode, assemblyNode); 295 addMethodPermissions(ejbDesc, ejbDesc.getStyledPermissionedMethodsByPermission(), excludedMethods, mpNode, assemblyNode); 296 if (excludedMethods.size()>0) { 297 excludedMethodsByEjb.put(ejbDesc, excludedMethods); 298 } 299 } 300 301 ContainerTransactionNode ctNode = new ContainerTransactionNode(); 303 for (Iterator e = bundleDescriptor.getEjbs().iterator();e.hasNext();) { 304 EjbDescriptor ejbDesc = (EjbDescriptor) e.next(); 305 ctNode.writeDescriptor(assemblyNode, EjbTagNames.CONTAINER_TRANSACTION, ejbDesc); 306 } 307 308 Set ejbsForInterceptors = bundleDescriptor.getEjbs(); 310 InterceptorBindingNode interceptorBindingNode = new 311 InterceptorBindingNode(); 312 313 for(Iterator itr = ejbsForInterceptors.iterator(); itr.hasNext();) { 314 315 EjbDescriptor ejbDesc = (EjbDescriptor) itr.next(); 316 if( ejbDesc.getInterceptorClasses().size() > 0 ) { 317 interceptorBindingNode.writeBindings(assemblyNode, 318 ejbDesc); 319 } 320 321 } 322 323 324 writeMessageDestinations 326 (assemblyNode, bundleDescriptor.getMessageDestinations().iterator()); 327 328 if (excludedMethodsByEjb.size()>0) { 330 Node excludeListNode = this.appendChild(assemblyNode, EjbTagNames.EXCLUDE_LIST); 331 for (Iterator ejbs = excludedMethodsByEjb.keySet().iterator(); ejbs.hasNext();) { 332 EjbDescriptor ejbDesc = (EjbDescriptor) ejbs.next(); 333 Vector excludedMethods = (Vector ) excludedMethodsByEjb.get(ejbDesc); 334 335 MethodPermissionDescriptor mpd = new MethodPermissionDescriptor(); 336 mpd.addMethodPermission(MethodPermission.getExcludedMethodPermission()); 337 mpd.addMethods(excludedMethods); 338 mpNode.writeDescriptorInNode(excludeListNode, mpd, ejbDesc); 339 } 340 } 341 342 for(EjbApplicationExceptionInfo next : 343 bundleDescriptor.getApplicationExceptions()) { 344 345 EjbApplicationExceptionNode node = new EjbApplicationExceptionNode(); 346 347 node.writeDescriptor(assemblyNode, EjbTagNames.APPLICATION_EXCEPTION, 348 next); 349 350 } 351 352 if (assemblyNode.hasChildNodes()) { 353 parentNode.appendChild(assemblyNode); 354 } 355 } 356 357 private void addMethodPermissions( 358 EjbDescriptor ejb, 359 Map mpToMethods, 360 Vector excludedMethods, 361 MethodPermissionNode mpNode, 362 Node assemblyNode) { 363 364 if (mpToMethods==null || mpToMethods.size()==0) { 365 return; 366 } 367 368 for (Iterator mpIterator = mpToMethods.keySet().iterator();mpIterator.hasNext();) { 369 MethodPermission mp = (MethodPermission) mpIterator.next(); 370 if (mp.isExcluded()) { 371 Set methods = (Set ) mpToMethods.get(mp); 373 excludedMethods.addAll(methods); 374 } else { 375 MethodPermissionDescriptor mpd = new MethodPermissionDescriptor(); 376 mpd.addMethodPermission(mp); 377 mpd.addMethods((Set ) mpToMethods.get(mp)); 378 mpNode.writeDescriptor(assemblyNode, EjbTagNames.METHOD_PERMISSION, mpd, ejb); 379 } 380 } 381 } 382 383 386 public String getSpecVersion() { 387 return SPEC_VERSION; 388 } 389 390 } 391 | Popular Tags |