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.MessageDriven; 32 import org.netbeans.modules.j2ee.jboss4.config.gen.ResourceManager; 33 import org.netbeans.modules.j2ee.jboss4.config.gen.ResourceManagers; 34 import org.netbeans.modules.j2ee.jboss4.config.gen.ResourceRef; 35 import org.netbeans.modules.j2ee.jboss4.config.gen.Session; 36 import org.netbeans.modules.schema2beans.AttrProp; 37 import org.openide.ErrorManager; 38 import org.openide.util.NbBundle; 39 40 45 final class JbossDataSourceRefModifier { 46 47 56 static void modify(Jboss modifiedJboss, String resRefName, Set beanNames, BEAN_TYPE beanType, String jndiName) { 57 58 assert(beanNames.size() > 0); 59 60 if (modifiedJboss.getEnterpriseBeans() == null) 61 modifiedJboss.setEnterpriseBeans(new EnterpriseBeans()); 62 63 if (beanType == BEAN_TYPE.SESSION) { 64 addSessionResReference(modifiedJboss, resRefName, beanNames, jndiName); 65 } else 66 if (beanType == BEAN_TYPE.ENTITY) { 67 addEntityResReference(modifiedJboss, resRefName, beanNames, jndiName); 68 } 69 } 70 71 79 private static void addSessionResReference(Jboss modifiedJboss, String resRefName, Set sessionNames, String jndiName) { 80 81 List sesssionsWithoutReference = new LinkedList (); 82 83 EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); 84 85 Session[] sessions = eb.getSession(); 86 for (int i = 0; i < sessions.length; i++) { 87 String ejbName = sessions[i].getEjbName(); 88 if (sessionNames.contains(ejbName)) { sessionNames.remove(ejbName); ResourceRef[] resourceRefs = sessions[i].getResourceRef(); 91 int j = 0; 92 for ( ; j < resourceRefs.length; j++) { 93 String rrn = resourceRefs[j].getResRefName(); 94 if (resRefName.equals(rrn)) 95 break; } 97 if (j == resourceRefs.length) sesssionsWithoutReference.add(sessions[i]); 99 } 100 } 101 102 for (Iterator it = sessionNames.iterator(); it.hasNext(); ) { 105 String sessionName = (String )it.next(); 106 Session session = new Session(); 107 session.setEjbName(sessionName); 108 session.setJndiName(sessionName); 109 110 eb.addSession(session); 112 113 sesssionsWithoutReference.add(session); 115 } 116 117 for (Iterator it = sesssionsWithoutReference.iterator(); it.hasNext(); ) { 119 ResourceRef newRR = new ResourceRef(); 120 newRR.setResRefName(resRefName); 121 newRR.setJndiName(jndiName); 122 Session session = (Session)it.next(); 123 session.addResourceRef(newRR); 124 } 125 126 } 127 128 136 private static void addEntityResReference(Jboss modifiedJboss, String resRefName, Set entityNames, String jndiName) { 137 138 List entitiesWithoutReference = new LinkedList (); 139 140 EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); 141 142 Entity[] entities = eb.getEntity(); 143 for (int i = 0; i < entities.length; i++) { 144 String ejbName = entities[i].getEjbName(); 145 if (entityNames.contains(ejbName)) { entityNames.remove(ejbName); ResourceRef[] resourceRefs = entities[i].getResourceRef(); 148 int j = 0; 149 for ( ; j < resourceRefs.length; j++) { 150 String rrn = resourceRefs[j].getResRefName(); 151 if (resRefName.equals(rrn)) 152 break; } 154 if (j == resourceRefs.length) entitiesWithoutReference.add(entities[i]); 156 } 157 } 158 159 for (Iterator it = entityNames.iterator(); it.hasNext(); ) { 162 String entityName = (String )it.next(); 163 Entity entity = new Entity(); 164 entity.setEjbName(entityName); 165 entity.setJndiName(entityName); 166 167 eb.addEntity(entity); 169 170 entitiesWithoutReference.add(entity); 172 } 173 174 for (Iterator it = entitiesWithoutReference.iterator(); it.hasNext(); ) { 176 ResourceRef newRR = new ResourceRef(); 177 newRR.setResRefName(resRefName); 178 newRR.setJndiName(jndiName); 179 Entity entity = (Entity)it.next(); 180 entity.addResourceRef(newRR); 181 } 182 183 } 184 185 194 static void modifyMsgDrv(Jboss modifiedJboss, String resRefName, Map beans, String jndiName) { 195 196 assert(beans.size() > 0); 197 198 if (modifiedJboss.getEnterpriseBeans() == null) 199 modifiedJboss.setEnterpriseBeans(new EnterpriseBeans()); 200 201 addMsgDrvResReference(modifiedJboss, resRefName, beans, jndiName); 202 } 203 204 213 private static void addMsgDrvResReference(Jboss modifiedJboss, String resRefName, Map beans, String jndiName) { 214 215 List msgdrvsWithoutReference = new LinkedList (); 216 217 EnterpriseBeans eb = modifiedJboss.getEnterpriseBeans(); 218 219 MessageDriven[] msgDrivens = eb.getMessageDriven(); 220 for (int i = 0; i < msgDrivens.length; i++) { 221 String ejbName = msgDrivens[i].getEjbName(); 222 if (beans.containsKey(ejbName)) { beans.remove(ejbName); ResourceRef[] resourceRefs = msgDrivens[i].getResourceRef(); 225 int j = 0; 226 for ( ; j < resourceRefs.length; j++) { 227 String rrn = resourceRefs[j].getResRefName(); 228 if (resRefName.equals(rrn)) 229 break; } 231 if (j == resourceRefs.length) msgdrvsWithoutReference.add(msgDrivens[i]); 233 } 234 } 235 236 for (Iterator it = beans.keySet().iterator(); it.hasNext(); ) { 239 String ejbName = (String )it.next(); 240 MessageDriven mdb = new MessageDriven(); 241 mdb.setEjbName(ejbName); 242 String msgDestination = (String )beans.get(ejbName); 243 mdb.setDestinationJndiName(msgDestination); 244 245 eb.addMessageDriven(mdb); 247 248 msgdrvsWithoutReference.add(mdb); 250 } 251 252 for (Iterator it = msgdrvsWithoutReference.iterator(); it.hasNext(); ) { 254 ResourceRef newRR = new ResourceRef(); 255 newRR.setResRefName(resRefName); 256 newRR.setJndiName(jndiName); 257 MessageDriven mdb = (MessageDriven)it.next(); 258 mdb.addResourceRef(newRR); 259 } 260 261 } 262 263 } 264 | Popular Tags |