1 6 7 package org.netbeans.mdr.test; 8 9 import javax.jmi.model.*; 10 import javax.jmi.reflect.*; 11 12 import java.util.Iterator ; 13 import java.util.List ; 14 import java.util.LinkedList ; 15 16 import java.io.PrintStream ; 17 18 import org.netbeans.lib.jmi.xmi.*; 19 import org.netbeans.lib.jmi.util.*; 20 21 25 public class EventsDataGenerator extends RandomDataGenerator { 26 27 private RefPackage extent; 28 29 30 public EventsDataGenerator(RefPackage pkg) { 31 super(pkg); 32 extent = pkg; 33 } 34 35 public List generateAssociation(RefAssociation assocProxy, Association assoc, PrintStream ps, boolean planned) { 36 LinkedList ends = new LinkedList (); 38 39 Iterator iterCont = ((Namespace) assoc).getContents().iterator(); 40 while (iterCont.hasNext()) { 41 RefObject refObj = (RefObject) iterCont.next(); 42 if (refObj instanceof AssociationEnd) { 43 MofClass mofClass = (MofClass) ((AssociationEnd) refObj).getType(); 44 if (mofClass.isAbstract()) { 45 mofClass = findSubtype(mofClass); 46 } 47 ends.add(mofClass); 48 } 49 } 50 51 if (assocProxy instanceof Contains) { 52 Namespace nmspc = (Namespace) generateInstance((MofClass) ends.get(0)); 53 ModelElement mdlelm = (ModelElement) generateInstance((MofClass) ends.get(1)); 54 55 assocProxy.refAddLink(nmspc, mdlelm); 56 57 Iterator nmIter = nmspc.getContents().iterator(); 58 while (nmIter.hasNext()) { 59 RefObject obj = (RefObject) nmIter.next(); 60 if (obj instanceof Reference) { 61 System.out.println(((Reference) obj).getReferencedEnd()); 62 } 63 } 64 65 return ends; 66 67 } else if (assocProxy instanceof Constrains) { 68 assocProxy.refAddLink((Constraint) generateInstance((MofClass) ends.get(0)), 69 (ModelElement) generateInstance((MofClass) ends.get(1))); 70 return ends; 71 } else if (assocProxy instanceof Aliases) { 72 assocProxy.refAddLink((Import) generateInstance((MofClass) ends.get(0)), 73 (Namespace) generateInstance((MofClass) ends.get(1))); 74 return ends; 75 } else if (assocProxy instanceof Generalizes) { 76 assocProxy.refAddLink((GeneralizableElement) generateInstance((MofClass) ends.get(0)), 77 (GeneralizableElement) generateInstance((MofClass) ends.get(1))); 78 return ends; 79 } else if (assocProxy instanceof AttachesTo) { 80 assocProxy.refAddLink((ModelElement) generateInstance((MofClass) ends.get(0)), 81 (Tag) generateInstance((MofClass) ends.get(1))); 82 return ends; 83 } else if (assocProxy instanceof CanRaise) { 84 assocProxy.refAddLink((Operation) generateInstance((MofClass) ends.get(0)), 85 (MofException) generateInstance((MofClass) ends.get(1))); 86 return ends; 87 } else if (assocProxy instanceof IsOfType) { 88 assocProxy.refAddLink((Classifier) generateInstance((MofClass) ends.get(0)), 89 (TypedElement) generateInstance((MofClass) ends.get(1))); 90 return ends; 91 } 92 93 98 99 101 return null; 102 103 } 104 105 109 public boolean setAttribute(RefObject refObj, PrintStream ps, boolean planned) { 110 boolean setAttr = false; 111 Iterator contents = ((Namespace) refObj.refMetaObject()).getContents().iterator(); 112 while (contents.hasNext()) { 113 Object contObj = contents.next(); 114 if (contObj instanceof Attribute) { 115 Object attr = generateAttributeValue((Attribute) contObj); 116 if ( ((Attribute) contObj).isChangeable() && ((Attribute) contObj).getMultiplicity().getUpper() == 1 ) { 117 refObj.refSetValue((RefObject) contObj, attr); 119 setAttr = true; 120 } 121 } 122 } 123 return setAttr; 124 } 125 126 130 public boolean addAttribute(RefObject refObj, boolean remove, PrintStream ps, boolean planned) { 131 boolean ws = false; 132 Iterator contents = ((Namespace) refObj.refMetaObject()).getContents().iterator(); 133 while (contents.hasNext()) { 134 Object contObj = contents.next(); 135 if (contObj instanceof Attribute) { 136 if ( ((Attribute) contObj).isChangeable() && ((Attribute) contObj).getMultiplicity().getUpper() == -1 ) { 137 Classifier type = ((Attribute) contObj).getType(); 139 List attrValues = (List ) refObj.refGetValue((RefObject) contObj); 140 for (int i = 0; i < 5; i++) { 141 Object val = generateValue(type); 142 attrValues.add(val); 143 ws = true; 144 } 145 if (remove) { 146 for (int j = 0; j < 5; j++) { 147 attrValues.remove(0); 148 } 149 } 150 } 151 } 152 } 153 return ws; 154 } 155 156 public RefObject generateWrongInstance(MofClass mofClass) { 157 RefPackage refPackage = (RefPackage) elementsCache.findProxy(mofClass); 158 RefClass proxy = refPackage.refClass(mofClass); 159 List args = new LinkedList (); 160 args.add(new java.util.Date ()); 161 return proxy.refCreateInstance(args); 162 } 163 164 } 165 | Popular Tags |