1 19 package org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres; 20 21 import java.io.IOException ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import org.netbeans.api.project.Project; 25 import org.netbeans.api.project.ProjectUtils; 26 import org.netbeans.api.project.ui.OpenProjects; 27 import org.netbeans.modules.j2ee.dd.api.common.MessageDestination; 28 import org.netbeans.modules.j2ee.dd.api.common.MessageDestinationRef; 29 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException; 30 import org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor; 31 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; 32 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 33 import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven; 34 import org.openide.ErrorManager; 35 36 40 public class MessageDestinationPanelController { 41 42 public ProjectView[] getJMSProjectRepresentation() { 43 Project[] proj = OpenProjects.getDefault().getOpenProjects(); 44 List <ProjectView> projectViews = new LinkedList <ProjectView>(); 46 for (int i=0; i<proj.length; i++) { 47 if (org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(proj[i]).length > 0) { 48 projectViews.add(new ProjectView(proj[i])); 49 } 50 } 51 return projectViews.toArray(new ProjectView[projectViews.size()]); 52 } 53 54 public EjbJar getEjbJar(Object item) throws IOException { 55 Project project = ((ProjectView) item).getProject(); 56 org.netbeans.modules.j2ee.api.ejbjar.EjbJar apiEjbJar = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(project)[0]; 57 return org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(apiEjbJar.getMetadataUnit()); 58 } 59 60 public List <JMSDestination> extractEjbProjectDestinations(EjbJar ejbJar, Object selectedItem) { 61 Project project = ((ProjectView) selectedItem).getProject(); 62 List <JMSDestination> jmsDestinations = new LinkedList <JMSDestination>(); 63 64 AssemblyDescriptor assemblyDescriptor = ejbJar.getSingleAssemblyDescriptor(); 65 if (assemblyDescriptor != null) { 66 try { 67 MessageDestination[] destination = assemblyDescriptor.getMessageDestination(); 68 if (destination != null) { 69 for (int i = 0; i < destination.length; i++) { 70 String name = destination[i].getMessageDestinationName(); 71 String type = findEjbBinding(name, ejbJar); 72 if (type != null) { 73 jmsDestinations.add(new JMSDestination(name, project, type)); 74 } 75 } 76 } 77 } catch (VersionNotSupportedException vnse) { 78 ErrorManager.getDefault().notify(vnse); 79 } 80 } 81 82 return jmsDestinations; 83 } 84 85 private String findEjbBinding(String destinationName, EjbJar ejbJar) { 86 if (ejbJar.getEnterpriseBeans() == null || 87 ejbJar.getEnterpriseBeans().getEjbs() == null) { 88 return null; 89 } 90 MessageDriven[] messageDrivenBeans = ejbJar.getEnterpriseBeans().getMessageDriven(); 92 if (messageDrivenBeans != null) { 93 for (int i=0; i < messageDrivenBeans.length; i++) { 94 try { 95 if (messageDrivenBeans[i].getMessagingType() == null || 96 messageDrivenBeans[i].getMessagingType().equals("javax.jms.MessageListener")) { 97 if (destinationName.equals(messageDrivenBeans[i].getMessageDestinationLink())) { 98 return messageDrivenBeans[i].getMessageDestinationType(); 99 } 100 } 101 } catch (VersionNotSupportedException vnse) { 102 ErrorManager.getDefault().notify(vnse); 103 } 104 } 105 } 106 107 Ejb[] ejb = ejbJar.getEnterpriseBeans().getEjbs(); 109 for (int i=0; i < ejb.length; i++) { 110 try { 111 MessageDestinationRef[] refs = ejb[i].getMessageDestinationRef(); 112 String type = findDestinationRef(destinationName,refs); 113 if (type != null) { 114 return type; 115 } 116 } catch (VersionNotSupportedException vnse) { 117 ErrorManager.getDefault().notify(vnse); 118 } 119 } 120 121 return null; 122 } 123 124 private String findDestinationRef(String destination, MessageDestinationRef[] refs) { 125 String type = null; 126 if (refs != null) { 127 for (int i=0; i<refs.length; i++) { 128 boolean consumes = 129 org.netbeans.modules.j2ee.dd.api.common.MessageDestinationRef.MESSAGE_DESTINATION_USAGE_CONSUMES.equals(refs[i].getMessageDestinationUsage()); 130 String destinationType = refs[i].getMessageDestinationType(); 131 boolean jms = 132 "javax.jms.Queue".equals(destinationType) || "javax.jms.Topic".equals(destinationType); if (consumes && jms) { 135 if (destination.equals(refs[i].getMessageDestinationLink())) { 136 type = destinationType; 137 } 138 } 139 } 140 } 141 return type; 142 } 143 144 private static class ProjectView { 145 private final Project project; 146 public ProjectView(Project project) { 147 this.project = project; 148 } 149 150 public String toString() { 151 return ProjectUtils.getInformation(project).getDisplayName(); 152 } 153 154 public Project getProject() { 155 return project; 156 } 157 158 } 159 160 } | Popular Tags |