public boolean predicate2(Object dm, Designer dsgr) { if (!(dm instanceof MClassifier)) return NO_PROBLEM; MClassifier cls = (MClassifier) dm; String myName = cls.getName(); //@ if (myName.equals(Name.UNSPEC)) return NO_PROBLEM; String myNameString = myName; if (myNameString.length() == 0) return NO_PROBLEM; Collection pkgs = cls.getElementImports2(); if (pkgs == null) return NO_PROBLEM; for (Iterator iter = pkgs.iterator(); iter.hasNext();) { MElementImport imp = (MElementImport)iter.next(); MNamespace ns = imp.getPackage(); Collection siblings = ns.getOwnedElements(); if (siblings == null) return NO_PROBLEM; Iterator enum = siblings.iterator(); while (enum.hasNext()) { MElementImport eo = (MElementImport) enum.next(); MModelElement me = (MModelElement) eo.getModelElement(); if (!(me instanceof MClassifier)) continue; if (me == cls) continue; String meName = me.getName(); if (meName == null || meName.equals("")) continue; if (meName.equals(myNameString)) return PROBLEM_FOUND; } }; return NO_PROBLEM; }
/** * Return all interfaces the given class realizes. * * @param clazz * @return Collection */ public Collection getRealizedInterfaces(MClassifier clazz) { if (clazz == null) return new ArrayList(); Iterator it = clazz.getClientDependencies().iterator(); List list = new ArrayList(); MNamespace model = ProjectBrowser.TheInstance.getProject().getModel(); while (it.hasNext()) { Object o = it.next(); if (o instanceof MAbstraction) { MAbstraction abstraction = (MAbstraction) o; MStereotype stereo = abstraction.getStereotype(); if (stereo != null && stereo.getBaseClass() != null && stereo.getName() != null && stereo.getBaseClass().equals("Abstraction") && stereo.getName().equals("realize")) { Iterator it2 = abstraction.getSuppliers().iterator(); while (it2.hasNext()) { Object o2 = it2.next(); if (o2 instanceof MInterface) { list.add(o2); } } } } } return list; }
/** * Returns all attributes of some classifier clazz and of its parents * * @param clazz * @return Collection */ public Collection getAllAttributes(MClassifier clazz) { if (clazz == null) return new ArrayList(); List list = new ArrayList(); Iterator it = clazz.getFeatures().iterator(); while (it.hasNext()) { MFeature element = (MFeature) it.next(); if (element instanceof MAttribute) { list.add(element); } } it = clazz.getGeneralizations().iterator(); while (it.hasNext()) { list.addAll(getAllAttributes((MClassifier) it.next())); } return list; }
/** * Returns the contents (owned elements) of this classifier and all its parents as specified in * section 2.5.3.8 of the UML 1.3 spec * * @param clazz * @return Collection */ public Collection getAllContents(MClassifier clazz) { if (clazz == null) return new ArrayList(); List list = new ArrayList(); Iterator it = clazz.getOwnedElements().iterator(); while (it.hasNext()) { MModelElement element = (MModelElement) it.next(); if (element.getVisibility().equals(MVisibilityKind.PUBLIC) || element.getVisibility().equals(MVisibilityKind.PROTECTED)) { list.add(element); } } it = clazz.getGeneralizations().iterator(); while (it.hasNext()) { list.addAll(getAllContents((MClassifier) it.next())); } return list; }
/** * Returns the associationend between some classifier type and some associaton assoc. * * @param type * @param assoc * @return MAssociationEnd */ public MAssociationEnd getAssociationEnd(MClassifier type, MAssociation assoc) { if (type == null || assoc == null) return null; Iterator it = type.getAssociationEnds().iterator(); while (it.hasNext()) { MAssociationEnd end = (MAssociationEnd) it.next(); if (assoc.getConnections().contains(end)) return end; } return null; }
/** * This method returns all operations of a given Classifier * * @param classifier the classifier you want to have the operations for * @return a collection of the operations */ public Collection getOperations(MClassifier classifier) { Collection result = new ArrayList(); Iterator features = classifier.getFeatures().iterator(); while (features.hasNext()) { MFeature feature = (MFeature) features.next(); if (feature instanceof MOperation) result.add(feature); } return result; }
/** * This method returns all operations of a given Classifier, including inherited * * @param classifier the classifier you want to have the operations for * @return a collection of the operations */ public Collection getOperationsInh(MClassifier classifier) { Collection result = new ArrayList(); result.addAll(getOperations(classifier)); Iterator parents = classifier.getParents().iterator(); while (parents.hasNext()) { result.addAll(getOperationsInh((MClassifier) parents.next())); } return result; }
/** * Returns all associations for some classifier * * @param classifier * @return Collection */ public Collection getAssociations(MClassifier classifier) { if (classifier == null) return new ArrayList(); Iterator it = classifier.getAssociationEnds().iterator(); List associations = new ArrayList(); while (it.hasNext()) { associations.add(((MAssociationEnd) it.next()).getAssociation()); } return associations; }
/** * This method returns all opposite AssociationEnds of a given Classifier * * @param classifier the classifier you want to have the opposite association ends for * @return a collection of the opposite associationends */ public Collection getAssociateEnds(MClassifier classifier) { Collection result = new ArrayList(); Iterator ascends = classifier.getAssociationEnds().iterator(); while (ascends.hasNext()) { MAssociationEnd ascend = (MAssociationEnd) ascends.next(); if ((ascend.getOppositeEnd() != null)) result.add(ascend.getOppositeEnd()); } return result; }
/** * This method returns all attributes of a given Classifier, including inherited * * @param classifier the classifier you want to have the attributes for * @return a collection of the attributes */ public Collection getAttributesInh(MClassifier classifier) { Collection result = new ArrayList(); result.addAll(getAttributes(classifier)); Iterator parents = classifier.getParents().iterator(); while (parents.hasNext()) { MClassifier parent = (MClassifier) parents.next(); cat.debug("Adding attributes for: " + parent); result.addAll(getAttributesInh(parent)); } return result; }
/** * This method returns all Classifiers of which this class is a direct subtype. * * @param cls the class you want to have the parents for * @return a collection of the parents, each of which is a {@link MGeneralizableElement * MGeneralizableElement} */ public Collection getSupertypes(MClassifier cls) { Collection result = new HashSet(); Collection gens = cls.getGeneralizations(); Iterator genIterator = gens.iterator(); while (genIterator.hasNext()) { MGeneralization next = (MGeneralization) genIterator.next(); result.add(next.getParent()); } return result; }
/** * This method returns all Classifiers of which this class is a direct supertype. * * @param cls the class you want to have the children for * @return a collection of the children, each of which is a {@link MGeneralizableElement * MGeneralizableElement} */ public Collection getSubtypes(MClassifier cls) { Collection result = new Vector(); Collection gens = cls.getSpecializations(); Iterator genIterator = gens.iterator(); while (genIterator.hasNext()) { MGeneralization next = (MGeneralization) genIterator.next(); result.add(next.getChild()); } return result; }
public Enumeration gen(Object o) { Vector res = new Vector(); if (!(o instanceof MClassifier)) return res.elements(); MClassifier cls = (MClassifier) o; Vector ends = new Vector(cls.getAssociationEnds()); if (ends == null) return res.elements(); Iterator enum = ends.iterator(); while (enum.hasNext()) { MAssociationEnd ae = (MAssociationEnd) enum.next(); if (MAggregationKind.COMPOSITE.equals(ae.getAggregation())) { MAssociation asc = ae.getAssociation(); List conn = asc.getConnections(); if (conn == null || conn.size() != 2) continue; Object otherEnd = (ae == conn.get(0)) ? conn.get(1) : conn.get(0); MClassifier componentClass = ((MAssociationEnd)otherEnd).getType(); res.add(componentClass); } } return res.elements(); }
/** * Returns all behavioralfeatures found in this classifier and its children * * @return Collection */ public Collection getAllBehavioralFeatures(MClassifier clazz) { List features = new ArrayList(); if (!(clazz instanceof MDataType)) { Iterator it = clazz.getFeatures().iterator(); while (it.hasNext()) { Object o = it.next(); if (!(o instanceof MStructuralFeature)) { features.add(o); } } } return features; }
/** * Returns all classifiers that extend some classifier clazz. * * @param clazz * @return Collection */ public Collection getExtendingClassifiers(MClassifier clazz) { if (clazz == null) return new ArrayList(); Iterator it = clazz.getSpecializations().iterator(); List list = new ArrayList(); while (it.hasNext()) { MGeneralization gen = (MGeneralization) it.next(); MGeneralizableElement client = gen.getChild(); if (client instanceof MClassifier) { list.add(client); } } return list; }
/** * Returns all Interfaces of which this class is a realization. * * @param cls the class you want to have the interfaces for * @return a collection of the Interfaces */ public Collection getSpecifications(MClassifier cls) { Collection result = new Vector(); Collection deps = cls.getClientDependencies(); Iterator depIterator = deps.iterator(); while (depIterator.hasNext()) { MDependency dep = (MDependency) depIterator.next(); if ((dep instanceof MAbstraction) && dep.getStereotype() != null && dep.getStereotype().getName() != null && dep.getStereotype().getName().equals("realize")) { MInterface i = (MInterface) dep.getSuppliers().toArray()[0]; result.add(i); } } return result; }
/** * Gets all classifiers that are associated to the given classifier (have an association * relationship with the classifier). * * @param classifier * @return Collection */ public Collection getAssociatedClassifiers(MClassifier classifier) { if (classifier == null) return new ArrayList(); List list = new ArrayList(); Iterator it = classifier.getAssociationEnds().iterator(); while (it.hasNext()) { MAssociationEnd end = (MAssociationEnd) it.next(); MAssociation assoc = end.getAssociation(); Iterator it2 = assoc.getConnections().iterator(); while (it2.hasNext()) { MAssociationEnd end2 = (MAssociationEnd) it2.next(); if (end2 != end) { list.add(end2.getType()); } } } return list; }
/** * Gets the associations between the classifiers from and to. Returns null if from or to is null * or if there is no association between them. * * @param from * @param to * @return MAssociation */ public Collection getAssociations(MClassifier from, MClassifier to) { Set ret = new HashSet(); if (from == null || to == null) return ret; Iterator it = from.getAssociationEnds().iterator(); while (it.hasNext()) { MAssociationEnd end = (MAssociationEnd) it.next(); MAssociation assoc = end.getAssociation(); Iterator it2 = assoc.getConnections().iterator(); while (it2.hasNext()) { MAssociationEnd end2 = (MAssociationEnd) it2.next(); if (end2.getType() == to) { ret.add(assoc); } } } return ret; }
/** * Returns the realization (abstraction) between some class and some interface * * @param source * @param clazz * @return MAbstraction */ public MAbstraction getRealization(MInterface source, MClassifier clazz) { if (source == null || clazz == null) return null; Iterator it = clazz.getClientDependencies().iterator(); MNamespace model = ProjectBrowser.TheInstance.getProject().getModel(); MStereotype stereo = ExtensionMechanismsFactory.getFactory() .buildStereotype(new MAbstractionImpl(), "realize", model); while (it.hasNext()) { Object o = it.next(); if (o instanceof MAbstraction && ((MAbstraction) o).getStereotype().equals(stereo)) { Iterator it2 = ((MAbstraction) o).getSuppliers().iterator(); while (it2.hasNext()) { Object o2 = it2.next(); if (o2.equals(source)) { return (MAbstraction) o; } } } } return null; }