1 20 package org.objectweb.modfact.jmi.helper; 21 22 import javax.jmi.model.*; 23 import java.util.*; 24 25 public class MofHelper { 26 27 public static MofPackage[] packagesOfPackage(MofPackage p){ 28 List l = filterContentsByClass(p, MofPackage.class ,false); 29 return (MofPackage[]) l.toArray(new MofPackage[0]); 30 } 31 32 public static MofClass[] classesOfPackage(MofPackage p) { 33 List l = filterContentsByClass(p, MofClass.class ,false); 34 return (MofClass[]) l.toArray(new MofClass[0]); 35 } 36 37 public static Association[] associationsOfPackage(MofPackage p) { 38 List l = filterContentsByClass(p, Association.class ,false); 39 return (Association[]) l.toArray(new Association[0]); 40 } 41 42 public static Import[] importsOfPackage(MofPackage p) { 43 List l = filterContentsByClass(p, Import.class ,false); 44 return (Import[]) l.toArray(new Import[0]); 45 } 46 47 public static DataType[] datatypesOf(Namespace ns, boolean considerSupertypes) { 48 List l = filterContentsByClass(ns, DataType.class ,considerSupertypes); 49 return (DataType[]) l.toArray(new DataType[0]); 50 } 51 52 public static AssociationEnd[] associationEndsOfAssociation(Association a) { 53 List l = filterContentsByClass(a, AssociationEnd.class ,false); 54 return (AssociationEnd[]) l.toArray(new AssociationEnd[0]); 55 } 56 57 58 public static Constant[] constantsOfClass(MofClass c) { 59 List l = filterContentsByClass(c, Constant.class ,false); 60 return (Constant[]) l.toArray(new Constant[0]); 61 } 62 63 public static Reference[] referencesOfClass(MofClass c, boolean considerSupertypes) { 64 List l = filterContentsByClass(c, Reference.class , considerSupertypes); 65 return (Reference[]) l.toArray(new Reference[0]); 66 } 67 68 public static Operation[] operationsOfClass(MofClass cl, ScopeKind sk, boolean considerSupertypes) { 69 List l = filterContentsByClass(cl, Operation.class ,considerSupertypes); 70 List l2 = new Vector(); 71 Iterator it = l.iterator(); 72 while(it.hasNext()) { 73 Operation op = (Operation)it.next(); 74 if(op.getScope().equals(sk)) { 75 l2.add(op); 76 } 77 } 78 return (Operation[]) l2.toArray(new Operation[0]); 79 } 80 81 public static Attribute[] attributesOfClass( 82 MofClass cl, ScopeKind sk, boolean considerSupertypes) { 83 84 List l = filterContentsByClass(cl, Attribute.class ,considerSupertypes); 85 List l2 = new Vector(); 86 Iterator it = l.iterator(); 87 while(it.hasNext()) { 88 Attribute att = (Attribute)it.next(); 89 if(att.getScope().equals(sk)) { 90 l2.add(att); 91 } 92 } 93 return (Attribute[]) l2.toArray(new Attribute[0]); 94 } 95 96 public static StructureField[] structureFieldsOf(StructureType t) { 97 List l = filterContentsByClass(t, StructureField.class ,false); 98 return (StructureField[]) l.toArray(new StructureField[0]); 99 } 100 101 102 public static Parameter[] parametersOf(Operation op) { 103 List l = filterContentsByClass(op, Parameter.class ,false); 104 return (Parameter[]) l.toArray(new Parameter[0]); 105 } 106 107 public static MofException[] exceptionsOf(Operation op) { 108 List l = filterContentsByClass(op, MofException.class ,false); 109 return (MofException[]) l.toArray(new MofException[0]); 110 } 111 112 113 114 public static List filterContentsByClass 115 (Namespace ns, Class c, boolean considerSupertypes) { 116 List r = new Vector(); 117 if((ns instanceof GeneralizableElement) && considerSupertypes) { 118 Iterator it = ((GeneralizableElement)ns).getSupertypes().iterator(); 119 while(it.hasNext()) { 120 Namespace sup = (Namespace) it.next(); 121 Iterator it2 = filterContentsByClass(sup,c,true).iterator(); 122 while(it2.hasNext()) { 123 Object o = it2.next(); 124 if(!r.contains(o)) r.add(o); 125 } 126 } 127 } 128 Iterator it = ns.getContents().iterator(); 129 while(it.hasNext()) { 130 Object o = it.next(); 131 if(c.isInstance(o)) { 132 if(!r.contains(o)) r.add(o); 133 } 134 } 135 return r; 136 } 137 138 139 public static boolean isSinglePrimitive(TypedElement elem) { 140 if(!(elem.getType() instanceof PrimitiveType)) return false; 141 if(elem instanceof StructuralFeature) { 142 StructuralFeature f = (StructuralFeature)elem; 143 if(f.getMultiplicity().getLower()!=1) return false; 144 if(f.getMultiplicity().getUpper()!=1) return false; 145 return true; 146 } 147 if(elem instanceof Parameter) { 148 Parameter p = (Parameter)elem; 149 if(p.getMultiplicity().getLower()!=1) return false; 150 if(p.getMultiplicity().getUpper()!=1) return false; 151 return true; 152 } 153 return true; } 155 156 164 165 } 166 | Popular Tags |