public static List<EClass> filterByContainmentFeature( Collection<EClass> eClasses, MappingEntry mappingEntry) { EClass superType = null; if (mappingEntry instanceof NodeMapping) { NodeReference nodeReference = (NodeReference) mappingEntry.eContainer(); if (nodeReference != null) { EReference modelReference = nodeReference.getChildrenFeature() != null ? nodeReference.getChildrenFeature() : nodeReference.getContainmentFeature(); if (modelReference != null) { superType = modelReference.getEReferenceType(); } } } else if (mappingEntry instanceof LinkMapping) { if (((LinkMapping) mappingEntry).getContainmentFeature() != null) { superType = ((LinkMapping) mappingEntry).getContainmentFeature().getEReferenceType(); } } return sort( getConcreteEClasses( getSubtypesOf( filterValidEObjectsFrom(eClasses, mappingEntry.eResource().getResourceSet()), superType))); }
public static List<EReference> filterByContainerMetaclass( Collection<EReference> eReferences, NodeReference nodeReference, boolean containmentOnly) { EClass containerMetaClass = null; EClass targetMetaClass = null; if (nodeReference instanceof ChildReference) { containerMetaClass = ((ChildReference) nodeReference).getParentNode().getDomainMetaElement(); } else if (nodeReference instanceof TopNodeReference) { CanvasMapping diagram = ((Mapping) nodeReference.eContainer()).getDiagram(); if (diagram != null) { containerMetaClass = diagram.getDomainMetaElement(); } } if (nodeReference.isSetChild()) { targetMetaClass = nodeReference.getChild().getDomainMetaElement(); } List<EReference> fromHierarchy = sort( getEReferences( getEStructuralFeaturesOf(eReferences, containerMetaClass), containmentOnly)); if (targetMetaClass == null) { // no child known, thus can take references from metaelement's hierarchy only return fromHierarchy; } List<EReference> targetsToChild = sort(getEReferences(getEReferencesOfType(eReferences, targetMetaClass), containmentOnly)); for (Iterator<EReference> it = targetsToChild.iterator(); it.hasNext(); ) { if (fromHierarchy.contains(it.next())) { it.remove(); } } ArrayList<EReference> rv = new ArrayList<EReference>(fromHierarchy.size() + targetsToChild.size()); rv.addAll(fromHierarchy); rv.addAll(targetsToChild); return rv; }