public Object buildManifestation(Object utilizedElement) { if (!(utilizedElement instanceof PackageableElement)) { throw new IllegalArgumentException( "The utilized element must be an instance of PackageableElement."); //$NON-NLS-1$ } Manifestation m = UMLFactory.eINSTANCE.createManifestation(); m.setName(((PackageableElement) utilizedElement).getName() + " manifestation"); m.setUtilizedElement((PackageableElement) utilizedElement); return m; }
/** * States if the given object is related to the context {@link Classifier}. * * @param toFilter the candidate to check for relation * @param context the classifier context object. * @return <code>true</code> if the given object is related to the context {@link Classifier}, * <code>false</code> otherwise. */ public boolean isRelated(EObject toFilter, EObject context) { boolean res = false; if (toFilter.equals(context)) { res = true; } else if (context instanceof Classifier) { if (toFilter instanceof Generalization) { res = ((Classifier) context).getGeneralizations().contains(toFilter) || ((Generalization) toFilter).getGeneral() == context; } else if (toFilter instanceof InterfaceRealization && context instanceof Class) { res = ((Class) context).getInterfaceRealizations().contains(toFilter) || ((InterfaceRealization) toFilter).getContract() == context; } else if (toFilter instanceof Association) { res = ((Classifier) context).getAssociations().contains(toFilter); } else if (toFilter instanceof Artifact && context instanceof ExecutionEnvironment) { for (final Deployment deployment : ((ExecutionEnvironment) context).getDeployments()) { if (deployment.getSuppliers().contains(toFilter)) { res = true; } } } else if (toFilter instanceof ExecutionEnvironment && context instanceof Artifact) { for (final Deployment deployment : ((ExecutionEnvironment) toFilter).getDeployments()) { if (deployment.getSuppliers().contains(context)) { res = true; } } } else if (toFilter instanceof PackageableElement && context instanceof Artifact) { res = ((Artifact) context).getManifestations().contains(toFilter); for (final Manifestation manifestation : ((Artifact) context).getManifestations()) { if (manifestation.getTargets().contains(toFilter)) { res = true; } } } else if (toFilter instanceof Artifact && context instanceof PackageableElement) { res = ((Artifact) toFilter).getManifestations().contains(context); for (final Manifestation manifestation : ((Artifact) toFilter).getManifestations()) { if (manifestation.getTargets().contains(context)) { res = true; } } } else if (toFilter instanceof Feature) { res = isRelated(toFilter.eContainer(), context); } else if (toFilter instanceof Classifier) { if (context == toFilter) { return false; } res = context == toFilter; if (context instanceof EncapsulatedClassifier && toFilter instanceof EncapsulatedClassifier) { if (!res) { if (((EncapsulatedClassifier) context).getOwnedElements().contains(toFilter)) { res = true; } else { for (final Port portContext : ((EncapsulatedClassifier) context).getOwnedPorts()) { if (portIsRelated(toFilter, portContext)) { res = true; break; } } } } } if (context instanceof EncapsulatedClassifier && toFilter instanceof Property) { if (!res) { if (((EncapsulatedClassifier) context).getOwnedAttributes().contains(toFilter)) { res = true; } } } // is it a generalization end if (!res) { for (final Generalization generalization : ((Classifier) context).getGeneralizations()) { if (generalization.getGeneral() == toFilter) { res = true; break; } } } // is it a generalization opposite end if (!res) { for (final Generalization generalization : ((Classifier) toFilter).getGeneralizations()) { if (generalization.getGeneral() == context) { res = true; break; } } } if (toFilter instanceof NamedElement && context instanceof NamedElement) { // is it a dependency end if (!res) { for (final Dependency dependency : ((NamedElement) context).getClientDependencies()) { if (dependency.getClients().contains(toFilter) || dependency.getSuppliers().contains(toFilter)) { res = true; break; } } } } if (context instanceof NamedElement && toFilter instanceof NamedElement) { // is it a dependency end if (!res) { for (final Dependency dependency : ((NamedElement) toFilter).getClientDependencies()) { if (dependency.getClients().contains(context) || dependency.getSuppliers().contains(context)) { res = true; break; } } } } if (toFilter instanceof Interface && context instanceof Class) { // is it a realization end if (!res) { for (final InterfaceRealization realization : ((Class) context).getInterfaceRealizations()) { if (realization.getContract() == toFilter) { res = true; break; } } } } if (context instanceof Interface && toFilter instanceof Class) { // is it a realization end if (!res) { for (final InterfaceRealization realization : ((Class) toFilter).getInterfaceRealizations()) { if (realization.getContract() == context) { res = true; break; } } } } // is it an association end if (!res) { final List<Association> toFilterAsso = ((Classifier) toFilter).getAssociations(); final List<Association> contextAsso = ((Classifier) context).getAssociations(); for (final Association association : toFilterAsso) { if (contextAsso.contains(association)) { res = true; break; } } } } else if (toFilter instanceof Package) { for (final EObject content : toFilter.eContents()) { if (isRelated(content, context)) { res = true; break; } } } } else if (context instanceof Package) { if (toFilter instanceof Package) { res = ((Package) context).getNestedPackages().contains(toFilter) || ((Package) context).getImportedPackages().contains(toFilter); for (final PackageImport packageImport : ((Package) context).getPackageImports()) { if (packageImport.getImportedPackage().equals(toFilter)) { res = true; } } } else { res = ((Package) context).getOwnedElements().contains(toFilter); } } else if (context instanceof Port) { res = portIsRelated(toFilter, (Port) context); } return res; }