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.EnterpriseBeans; 29 import org.netbeans.modules.j2ee.jboss4.config.gen.Entity; 30 import org.netbeans.modules.j2ee.jboss4.config.gen.Jboss; 31 import org.netbeans.modules.j2ee.jboss4.config.gen.MessageDestinationRef; 32 import org.netbeans.modules.j2ee.jboss4.config.gen.MessageDriven; 33 import org.netbeans.modules.j2ee.jboss4.config.gen.ResourceManager; 34 import org.netbeans.modules.j2ee.jboss4.config.gen.ResourceManagers; 35 import org.netbeans.modules.j2ee.jboss4.config.gen.ResourceRef; 36 import org.netbeans.modules.j2ee.jboss4.config.gen.Session; 37 import org.netbeans.modules.schema2beans.AttrProp; 38 import org.openide.ErrorManager; 39 import org.openide.util.NbBundle; 40 41 46 final class JbossMsgDestRefModifier { 47 48 57 static void modify(Jboss modifiedJboss, String msgDestRefName, Set beanNames, BEAN_TYPE beanType, String destPrefix) { 58 59 assert(beanNames.size() > 0); 60 61 if (modifiedJboss.getEnterpriseBeans() == null) 62 modifiedJboss.setEnterpriseBeans(new EnterpriseBeans()); 63 64 if (beanType == BEAN_TYPE.SESSION) { 65 addSessionMsgDestReference(modifiedJboss, msgDestRefName, beanNames, destPrefix); 66 } else 67 if (beanType == BEAN_TYPE.ENTITY) { 68 addEntityMsgDestReference(modifiedJboss, msgDestRefName, beanNames, destPrefix); 69 } 70 } 71 72 80 private static void addSessionMsgDestReference(Jboss modifiedJboss, String msgDestRefName, Set sessionNames, String destPrefix) { 81 82 List sesssionsWithoutReference = new LinkedList (); 83 84 EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); 85 86 Session[] sessions = eb.getSession(); 87 for (int i = 0; i < sessions.length; i++) { 88 String ejbName = sessions[i].getEjbName(); 89 if (sessionNames.contains(ejbName)) { sessionNames.remove(ejbName); MessageDestinationRef[] msgDestRefs = sessions[i].getMessageDestinationRef(); 92 int j = 0; 93 for ( ; j < msgDestRefs.length; j++) { 94 String mdrn = msgDestRefs[j].getMessageDestinationRefName(); 95 if (msgDestRefName.equals(mdrn)) 96 break; } 98 if (j == msgDestRefs.length) sesssionsWithoutReference.add(sessions[i]); 100 } 101 } 102 103 for (Iterator it = sessionNames.iterator(); it.hasNext(); ) { 106 String sessionName = (String )it.next(); 107 Session session = new Session(); 108 session.setEjbName(sessionName); 109 session.setJndiName(sessionName); 110 111 eb.addSession(session); 113 114 sesssionsWithoutReference.add(session); 116 } 117 118 for (Iterator it = sesssionsWithoutReference.iterator(); it.hasNext(); ) { 120 MessageDestinationRef mdr = new MessageDestinationRef(); 121 mdr.setMessageDestinationRefName(msgDestRefName); 122 String jndiName = getJndiName(msgDestRefName, destPrefix); 123 mdr.setJndiName(jndiName); 124 Session session = (Session)it.next(); 125 session.addMessageDestinationRef(mdr); 126 } 127 128 } 129 130 138 private static void addEntityMsgDestReference(Jboss modifiedJboss, String msgDestRefName, Set entityNames, String destPrefix) { 139 140 List entitiesWithoutReference = new LinkedList (); 141 142 EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); 143 144 Entity[] entities = eb.getEntity(); 145 for (int i = 0; i < entities.length; i++) { 146 String ejbName = entities[i].getEjbName(); 147 if (entityNames.contains(ejbName)) { entityNames.remove(ejbName); MessageDestinationRef[] msgDestRefs = entities[i].getMessageDestinationRef(); 150 int j = 0; 151 for ( ; j < msgDestRefs.length; j++) { 152 String mdrn = msgDestRefs[j].getMessageDestinationRefName(); 153 if (msgDestRefName.equals(mdrn)) 154 break; } 156 if (j == msgDestRefs.length) entitiesWithoutReference.add(entities[i]); 158 } 159 } 160 161 for (Iterator it = entityNames.iterator(); it.hasNext(); ) { 164 String entityName = (String )it.next(); 165 Entity entity = new Entity(); 166 entity.setEjbName(entityName); 167 entity.setJndiName(entityName); 168 169 eb.addEntity(entity); 171 172 entitiesWithoutReference.add(entity); 174 } 175 176 for (Iterator it = entitiesWithoutReference.iterator(); it.hasNext(); ) { 178 MessageDestinationRef mdr = new MessageDestinationRef(); 179 mdr.setMessageDestinationRefName(msgDestRefName); 180 String jndiName = getJndiName(msgDestRefName, destPrefix); 181 mdr.setJndiName(jndiName); 182 Entity entity = (Entity)it.next(); 183 entity.addMessageDestinationRef(mdr); 184 } 185 186 } 187 188 196 static void modifyMsgDrv(Jboss modifiedJboss, String msgDestRefName, Map beans, String destPrefix) { 197 198 assert(beans.size() > 0); 199 200 if (modifiedJboss.getEnterpriseBeans() == null) 201 modifiedJboss.setEnterpriseBeans(new EnterpriseBeans()); 202 203 addMsgDrvMsgDestReference(modifiedJboss, msgDestRefName, beans, destPrefix); 204 } 205 206 214 private static void addMsgDrvMsgDestReference(Jboss modifiedJboss, String msgDestRefName, Map beans, String destPrefix) { 215 216 List msgdrvsWithoutReference = new LinkedList (); 217 218 EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); 219 220 MessageDriven[] msgDrivens = eb.getMessageDriven(); 221 for (int i = 0; i < msgDrivens.length; i++) { 222 String ejbName = msgDrivens[i].getEjbName(); 223 if (beans.containsKey(ejbName)) { beans.remove(ejbName); MessageDestinationRef[] msgDestRefs = msgDrivens[i].getMessageDestinationRef(); 226 int j = 0; 227 for ( ; j < msgDestRefs.length; j++) { 228 String mdrn = msgDestRefs[j].getMessageDestinationRefName(); 229 if (msgDestRefName.equals(mdrn)) 230 break; } 232 if (j == msgDestRefs.length) msgdrvsWithoutReference.add(msgDrivens[i]); 234 } 235 } 236 237 for (Iterator it = beans.keySet().iterator(); it.hasNext(); ) { 240 String ejbName = (String )it.next(); 241 MessageDriven mdb = new MessageDriven(); 242 mdb.setEjbName(ejbName); 243 String msgDestination = (String )beans.get(ejbName); 244 mdb.setDestinationJndiName(msgDestination); 245 246 eb.addMessageDriven(mdb); 248 249 msgdrvsWithoutReference.add(mdb); 251 } 252 253 for (Iterator it = msgdrvsWithoutReference.iterator(); it.hasNext(); ) { 255 MessageDestinationRef mdr = new MessageDestinationRef(); 256 mdr.setMessageDestinationRefName(msgDestRefName); 257 String jndiName = getJndiName(msgDestRefName, destPrefix); 258 mdr.setJndiName(jndiName); 259 MessageDriven mdb = (MessageDriven)it.next(); 260 mdb.addMessageDestinationRef(mdr); 261 } 262 263 } 264 265 private static String getJndiName(String msgDestRefName, String destPrefix) { 266 String jndiName = msgDestRefName; 267 if (msgDestRefName.startsWith("jms/")) jndiName = destPrefix + msgDestRefName.substring("jms/".length()); 271 return jndiName; 272 } 273 274 } 275 | Popular Tags |