1 28 29 package org.objectweb.openccm.uml.transformation.rules.xml; 30 31 import ispuml.mdaTransformation.model.ModelContext; 32 33 38 public class AssociatedClassUtils { 39 40 52 public Object getAssociatedClass(Object bean, String associationStereotype, String classStereotype, ModelContext context) { 53 org.omg.uml.core.ModelElement modelElement = (org.omg.uml.core.ModelElement) bean; 54 java.util.Iterator it = modelElement.getNamespace().getOwnedElement().iterator(); 55 java.util.List list = new java.util.ArrayList (); 56 while (it.hasNext()) { 57 Object obj = it.next(); 58 if (obj instanceof org.omg.uml.core.Association) { 59 org.omg.uml.core.Association asso = (org.omg.uml.core.Association) obj; 60 boolean stereotypeOk = false; 61 if (asso.getStereotype().size() == 0 && (associationStereotype == null || associationStereotype.length() == 0)) 62 stereotypeOk = true; 63 else { 64 java.util.Iterator itSt = asso.getStereotype().iterator(); 65 while (itSt.hasNext()) { 66 org.omg.uml.core.Stereotype st = (org.omg.uml.core.Stereotype) itSt.next(); 67 if (st.getName().equals(associationStereotype)) 68 stereotypeOk = true; 69 } 70 } 71 if (stereotypeOk) { 72 java.util.List connections = asso.getConnection(); 73 if (connections.size() == 2) { 74 org.omg.uml.core.AssociationEnd firstSide = (org.omg.uml.core.AssociationEnd) connections.get(0); 75 org.omg.uml.core.AssociationEnd secondSide = (org.omg.uml.core.AssociationEnd) connections.get(1); 76 if (firstSide.getParticipant().refMofId().equals(modelElement.refMofId())) { 77 list.add(secondSide); 78 } 79 if (secondSide.getParticipant().refMofId().equals(modelElement.refMofId())) { 80 list.add(firstSide); 81 } 82 } 83 } 84 } 85 } 86 if (classStereotype != null && classStereotype.length() > 0) { 87 it = list.iterator(); 88 while (it.hasNext()) { 89 org.omg.uml.core.AssociationEnd assoEnd = (org.omg.uml.core.AssociationEnd)it.next(); 90 if (!context.isStereotyped(assoEnd.getParticipant(), classStereotype)) 91 it.remove(); 92 } 93 } 94 if (list.size() == 1) 95 return list.get(0); 96 else 97 return list; 98 } 99 100 109 public Object getAssociatedClass(Object bean, String associationType, ModelContext context) { 110 java.util.List list = new java.util.ArrayList (); 111 String association = associationType; 112 javax.jmi.reflect.RefObject refObject = (javax.jmi.reflect.RefObject) bean; 113 javax.jmi.reflect.RefPackage pck = refObject.refOutermostPackage(); 114 int index = association.indexOf("."); 115 while (index != -1) { 116 pck = pck.refPackage(association.substring(0, index)); 117 association = association.substring(index+1); 118 index = association.indexOf("."); 119 } 120 javax.jmi.reflect.RefAssociation asso = pck.refAssociation(association); 121 122 java.util.Collection links = asso.refAllLinks(); 123 java.util.Iterator linksIt = links.iterator(); 124 while (linksIt.hasNext()) { 125 javax.jmi.reflect.RefAssociationLink link = (javax.jmi.reflect.RefAssociationLink)linksIt.next(); 126 if (link.refFirstEnd().refMofId().equals(refObject.refMofId())) 127 list.add(link.refSecondEnd()); 128 else if (link.refSecondEnd().refMofId().equals(refObject.refMofId())) 129 list.add(link.refFirstEnd()); 130 } 131 if (list.size() == 1) 132 return list.get(0); 133 else 134 return list; 135 } 136 137 } 138 | Popular Tags |