1 19 20 package org.netbeans.modules.j2ee.jboss4.config; 21 22 import java.util.Iterator ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import java.util.Map ; 26 import java.util.Set ; 27 import org.netbeans.modules.j2ee.jboss4.config.EjbDeploymentConfiguration.BEAN_TYPE; 28 import org.netbeans.modules.j2ee.jboss4.config.gen.EjbRef; 29 import org.netbeans.modules.j2ee.jboss4.config.gen.EnterpriseBeans; 30 import org.netbeans.modules.j2ee.jboss4.config.gen.Entity; 31 import org.netbeans.modules.j2ee.jboss4.config.gen.Jboss; 32 import org.netbeans.modules.j2ee.jboss4.config.gen.MessageDriven; 33 import org.netbeans.modules.j2ee.jboss4.config.gen.Session; 34 import org.openide.ErrorManager; 35 import org.openide.util.NbBundle; 36 37 42 final class JbossEjbRefModifier { 43 44 52 static void modify(Jboss modifiedJboss, String ejbRefName, Set beanNames, BEAN_TYPE beanType) { 53 54 assert(beanNames.size() > 0); 55 56 if (modifiedJboss.getEnterpriseBeans() == null) 57 modifiedJboss.setEnterpriseBeans(new EnterpriseBeans()); 58 59 if (beanType == BEAN_TYPE.SESSION) { 60 addSessionEjbReference(modifiedJboss, ejbRefName, beanNames); 61 } else 62 if (beanType == BEAN_TYPE.ENTITY) { 63 addEntityEjbReference(modifiedJboss, ejbRefName, beanNames); 64 } 65 } 66 67 74 private static void addSessionEjbReference(Jboss modifiedJboss, String ejbRefName, Set sessionNames) { 75 76 List sesssionsWithoutReference = new LinkedList (); 77 78 EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); 79 80 Session[] sessions = eb.getSession(); 81 for (int i = 0; i < sessions.length; i++) { 82 String ejbName = sessions[i].getEjbName(); 83 if (sessionNames.contains(ejbName)) { sessionNames.remove(ejbName); EjbRef[] ejbRefs = sessions[i].getEjbRef(); 86 int j = 0; 87 for ( ; j < ejbRefs.length; j++) { 88 String rrn = ejbRefs[j].getEjbRefName(); 89 if (ejbRefName.equals(rrn)) 90 break; } 92 if (j == ejbRefs.length) sesssionsWithoutReference.add(sessions[i]); 94 } 95 } 96 97 for (Iterator it = sessionNames.iterator(); it.hasNext(); ) { 100 String sessionName = (String )it.next(); 101 Session session = new Session(); 102 session.setEjbName(sessionName); 103 session.setJndiName(sessionName); 104 105 eb.addSession(session); 107 108 sesssionsWithoutReference.add(session); 110 } 111 112 for (Iterator it = sesssionsWithoutReference.iterator(); it.hasNext(); ) { 114 EjbRef newER = new EjbRef(); 115 newER.setEjbRefName(ejbRefName); 116 newER.setJndiName(JBDeploymentConfiguration.JBOSS4_EJB_JNDI_PREFIX + ejbRefName); 117 Session session = (Session)it.next(); 118 session.addEjbRef(newER); 119 } 120 121 } 122 123 130 private static void addEntityEjbReference(Jboss modifiedJboss, String ejbRefName, Set entityNames) { 131 132 List entitiesWithoutReference = new LinkedList (); 133 134 EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); 135 136 Entity[] entities = eb.getEntity(); 137 for (int i = 0; i < entities.length; i++) { 138 String ejbName = entities[i].getEjbName(); 139 if (entityNames.contains(ejbName)) { entityNames.remove(ejbName); EjbRef[] ejbRefs = entities[i].getEjbRef(); 142 int j = 0; 143 for ( ; j < ejbRefs.length; j++) { 144 String rrn = ejbRefs[j].getEjbRefName(); 145 if (ejbRefName.equals(rrn)) 146 break; } 148 if (j == ejbRefs.length) entitiesWithoutReference.add(entities[i]); 150 } 151 } 152 153 for (Iterator it = entityNames.iterator(); it.hasNext(); ) { 156 String entityName = (String )it.next(); 157 Entity entity = new Entity(); 158 entity.setEjbName(entityName); 159 entity.setJndiName(entityName); 160 161 eb.addEntity(entity); 163 164 entitiesWithoutReference.add(entity); 166 } 167 168 for (Iterator it = entitiesWithoutReference.iterator(); it.hasNext(); ) { 170 EjbRef newER = new EjbRef(); 171 newER.setEjbRefName(ejbRefName); 172 newER.setJndiName(JBDeploymentConfiguration.JBOSS4_EJB_JNDI_PREFIX + ejbRefName); 173 Entity entity = (Entity)it.next(); 174 entity.addEjbRef(newER); 175 } 176 177 } 178 179 187 static void modifyMsgDrv(Jboss modifiedJboss, String ejbRefName, Map beans) { 188 189 assert(beans.size() > 0); 190 191 if (modifiedJboss.getEnterpriseBeans() == null) 192 modifiedJboss.setEnterpriseBeans(new EnterpriseBeans()); 193 194 addMsgDrvEjbReference(modifiedJboss, ejbRefName, beans); 195 } 196 197 205 private static void addMsgDrvEjbReference(Jboss modifiedJboss, String ejbRefName, Map beans) { 206 207 List msgdrvsWithoutReference = new LinkedList (); 208 209 EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); 210 211 MessageDriven[] msgDrivens = eb.getMessageDriven(); 212 for (int i = 0; i < msgDrivens.length; i++) { 213 String ejbName = msgDrivens[i].getEjbName(); 214 if (beans.containsKey(ejbName)) { beans.remove(ejbName); EjbRef[] ejbRefs = msgDrivens[i].getEjbRef(); 217 int j = 0; 218 for ( ; j < ejbRefs.length; j++) { 219 String rrn = ejbRefs[j].getEjbRefName(); 220 if (ejbRefName.equals(rrn)) 221 break; } 223 if (j == ejbRefs.length) msgdrvsWithoutReference.add(msgDrivens[i]); 225 } 226 } 227 228 for (Iterator it = beans.keySet().iterator(); it.hasNext(); ) { 231 String ejbName = (String )it.next(); 232 MessageDriven mdb = new MessageDriven(); 233 mdb.setEjbName(ejbName); 234 String msgDestination = (String )beans.get(ejbName); 235 mdb.setDestinationJndiName(msgDestination); 236 237 eb.addMessageDriven(mdb); 239 240 msgdrvsWithoutReference.add(mdb); 242 } 243 244 for (Iterator it = msgdrvsWithoutReference.iterator(); it.hasNext(); ) { 246 EjbRef newER = new EjbRef(); 247 newER.setEjbRefName(ejbRefName); 248 newER.setJndiName(JBDeploymentConfiguration.JBOSS4_EJB_JNDI_PREFIX + ejbRefName); 249 MessageDriven mdb = (MessageDriven)it.next(); 250 mdb.addEjbRef(newER); 251 } 252 253 } 254 255 } 256 | Popular Tags |