Example #1
0
 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;
 }
 /**
  * Gets the first namespace two namespaces share. That is: it returns the first namespace that
  * owns the given namespaces itself or some owner of the given namespaces.
  *
  * @param ns1
  * @param ns2
  * @return MNamespace
  */
 public MNamespace getFirstSharedNamespace(MNamespace ns1, MNamespace ns2) {
   if (ns1 == null || ns2 == null) return null;
   if (ns1 == ns2) return ns1;
   boolean ns1Owner = ModelManagementHelper.getHelper().getAllNamespaces(ns1).contains(ns2);
   boolean ns2Owner = ModelManagementHelper.getHelper().getAllNamespaces(ns2).contains(ns1);
   if (ns1Owner) return ns1;
   if (ns2Owner) return ns2;
   return getFirstSharedNamespace(ns1.getNamespace(), ns2.getNamespace());
 }
 private boolean isValidNamespace(MCollaboration collab, MNamespace ns) {
   Iterator it = collab.getOwnedElements().iterator();
   while (it.hasNext()) {
     MModelElement m = (MModelElement) it.next();
     if (m instanceof MClassifierRole) {
       MClassifierRole role = (MClassifierRole) m;
       Iterator it2 = role.getBases().iterator();
       while (it2.hasNext()) {
         if (!ns.getOwnedElements().contains(it2.next())) return false;
       }
     } else if (m instanceof MAssociationRole) {
       if (!ns.getOwnedElements().contains(((MAssociationRole) m).getBase())) return false;
     }
   }
   return true;
 }
 private boolean isValidNamespace(MGeneralizableElement gen, MNamespace ns) {
   Iterator it = gen.getParents().iterator();
   while (it.hasNext()) {
     MGeneralizableElement gen2 = (MGeneralizableElement) it.next();
     if (!ns.getOwnedElements().contains(gen2)) {
       return false;
     }
   }
   return true;
 }
  public synchronized void createModelUUIDS(MNamespace model) {

    cat.info("NOTE: The temporary method 'createModelUUIDs' has been called.");

    Collection ownedElements = model.getOwnedElements();
    Iterator oeIterator = ownedElements.iterator();

    String uuid = model.getUUID();
    if (uuid == null) model.setUUID(getNewUUID());

    while (oeIterator.hasNext()) {
      MModelElement me = (MModelElement) oeIterator.next();
      if (me instanceof MModel
          ||
          // me instanceof MNamespace ||
          me instanceof MClassifier
          || me instanceof MFeature
          || me instanceof MStateVertex
          || me instanceof MStateMachine
          || me instanceof MTransition
          || me instanceof MCollaboration
          || me instanceof MMessage
          || me instanceof MAssociation
          || me instanceof MAssociationEnd
          || me instanceof MGeneralization
          || me instanceof MDependency
          || me instanceof MStereotype
          || me instanceof MUseCase) {
        uuid = me.getUUID();
        if (uuid == null) {
          me.setUUID(getNewUUID());
        }
      }
      // recursive handling of namespaces, needed for Collaborations
      if (me instanceof MNamespace) {
        cat.debug("Found another namespace: " + me);
        createModelUUIDS((MNamespace) me);
      }
    }
  }
 /**
  * Returns true if some modelelement may be owned by the given namespace
  *
  * @param m
  * @param ns
  * @return boolean
  */
 public boolean isValidNamespace(MModelElement m, MNamespace ns) {
   if (m == null || ns == null) return false;
   if (ns.getModel() != m.getModel()) return false;
   if (m == ns) return false;
   if (m instanceof MNamespace && m == getFirstSharedNamespace((MNamespace) m, ns)) return false;
   if (ns instanceof MInterface || ns instanceof MActor || ns instanceof MUseCase) return false;
   else if (ns instanceof MComponent) return (m instanceof MComponent && m != ns);
   else if (ns instanceof MCollaboration) {
     if (!(m instanceof MClassifierRole
         || m instanceof MAssociationRole
         || m instanceof MGeneralization
         || m instanceof MConstraint)) return false;
   } else if (ns instanceof MPackage) {
     if (!(m instanceof MPackage
         || m instanceof MClassifier
         || m instanceof MAssociation
         || m instanceof MGeneralization
         || m instanceof MDependency
         || m instanceof MConstraint
         || m instanceof MCollaboration
         || m instanceof MStateMachine
         || m instanceof MStereotype)) return false;
   } else if (ns instanceof MClass) {
     if (!(m instanceof MClass
         || m instanceof MAssociation
         || m instanceof MGeneralization
         || m instanceof MUseCase
         || m instanceof MConstraint
         || m instanceof MDependency
         || m instanceof MCollaboration
         || m instanceof MDataType
         || m instanceof MInterface)) return false;
   } else if (ns instanceof MClassifierRole) {
     if (!(((MClassifierRole) ns).getAvailableContentses().contains(m)
         || ((MClassifierRole) ns).getAvailableFeatures().contains(m))) return false;
   }
   if (m instanceof MStructuralFeature) {
     if (!isValidNamespace((MStructuralFeature) m, ns)) return false;
   } else if (m instanceof MGeneralizableElement) {
     if (!isValidNamespace((MGeneralizableElement) m, ns)) return false;
   } else if (m instanceof MGeneralization) {
     if (!isValidNamespace((MGeneralization) m, ns)) return false;
   }
   if (m instanceof MAssociation) {
     if (!isValidNamespace((MAssociation) m, ns)) return false;
   } else if (m instanceof MCollaboration) {
     if (!isValidNamespace((MCollaboration) m, ns)) return false;
   }
   return true;
 }
 /**
  * Returns all classifiers found in this namespace and in its children
  *
  * @return Collection
  */
 public Collection getAllClassifiers(MNamespace ns) {
   if (ns == null) return new ArrayList();
   Iterator it = ns.getOwnedElements().iterator();
   List list = new ArrayList();
   while (it.hasNext()) {
     Object o = it.next();
     if (o instanceof MNamespace) {
       list.addAll(getAllClasses((MNamespace) o));
     }
     if (o instanceof MClassifier) {
       list.add(o);
     }
   }
   return list;
 }