|
| 1 | +/******************************************************************************* |
| 2 | + * SysML 2 Pilot Implementation |
| 3 | + * Copyright (c) 2024 Model Driven Solutions, Inc. |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Lesser General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public License |
| 16 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + * |
| 18 | + * @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later> |
| 19 | + * |
| 20 | + *******************************************************************************/ |
| 21 | + |
| 22 | +package org.omg.sysml.delegate.invocation; |
| 23 | + |
| 24 | +import java.lang.reflect.InvocationTargetException; |
| 25 | +import java.util.Collection; |
| 26 | +import java.util.HashSet; |
| 27 | + |
| 28 | +import org.eclipse.emf.common.util.EList; |
| 29 | +import org.eclipse.emf.ecore.EOperation; |
| 30 | +import org.eclipse.emf.ecore.InternalEObject; |
| 31 | +import org.eclipse.emf.ecore.util.BasicInternalEList; |
| 32 | +import org.eclipse.emf.ecore.util.BasicInvocationDelegate; |
| 33 | +import org.omg.sysml.lang.sysml.Element; |
| 34 | +import org.omg.sysml.lang.sysml.Import; |
| 35 | +import org.omg.sysml.lang.sysml.Membership; |
| 36 | +import org.omg.sysml.lang.sysml.Namespace; |
| 37 | +import org.omg.sysml.lang.sysml.OwningMembership; |
| 38 | +import org.omg.sysml.lang.sysml.SysMLPackage; |
| 39 | +import org.omg.sysml.lang.sysml.Type; |
| 40 | +import org.omg.sysml.lang.sysml.VisibilityKind; |
| 41 | + |
| 42 | +public abstract class Import_importedMemberships_InvocationDelegate extends BasicInvocationDelegate { |
| 43 | + |
| 44 | + public Import_importedMemberships_InvocationDelegate(EOperation operation) { |
| 45 | + super(operation); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public Object dynamicInvoke(InternalEObject target, EList<?> arguments) throws InvocationTargetException { |
| 50 | + Import self = (Import) target; |
| 51 | + @SuppressWarnings("unchecked") |
| 52 | + EList<Namespace> excluded = (EList<Namespace>) arguments.get(0); |
| 53 | + |
| 54 | + return importMemberships(self, new BasicInternalEList<>(Membership.class), null, |
| 55 | + excluded, new HashSet<>()); |
| 56 | + } |
| 57 | + |
| 58 | + // Note: The excludedType parameter is needed in case the imported Namespace |
| 59 | + // is a Type that has one or more Generalizations. |
| 60 | + public abstract EList<Membership> importMemberships(Import self, EList<Membership> importedMembership, |
| 61 | + Collection<Membership> nonpublicMembership, Collection<Namespace> excludedNamespaces, |
| 62 | + Collection<Type> excludedTypes); |
| 63 | + |
| 64 | + protected void importMembershipsFrom(Import self, Namespace importedNamespace, EList<Membership> importedMembership, |
| 65 | + Collection<Membership> nonpublicMembership, Collection<Namespace> excludedNamespaces, |
| 66 | + Collection<Type> excludedTypes, boolean isRecursive) { |
| 67 | + Collection<Membership> namespaceMembership = |
| 68 | + Namespace_visibleMemberships_InvocationDelegate.getVisibleMembershipsFor(importedNamespace, excludedNamespaces, excludedTypes, self.isImportAll()); |
| 69 | + importedMembership.addAll(namespaceMembership); |
| 70 | + if (nonpublicMembership != null && !VisibilityKind.PUBLIC.equals(self.getVisibility())) { |
| 71 | + nonpublicMembership.addAll(namespaceMembership); |
| 72 | + } |
| 73 | + if (isRecursive) { |
| 74 | + excludedNamespaces.add(importedNamespace); |
| 75 | + for (Membership membership: namespaceMembership) { |
| 76 | + if (membership instanceof OwningMembership) { |
| 77 | + Element member = membership.getMemberElement(); |
| 78 | + if (member instanceof Namespace) { |
| 79 | + importMembershipsFrom(self, (Namespace)member, importedMembership, nonpublicMembership, |
| 80 | + excludedNamespaces, excludedTypes, true); |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + excludedNamespaces.remove(importedNamespace); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + public static EList<Membership> importMembershipsFor(Import _import, EList<Membership> importedMembership, |
| 89 | + Collection<Membership> nonpublicMembership, Collection<Namespace> excludedNamespaces, |
| 90 | + Collection<Type> excludedTypes) { |
| 91 | + Import_importedMemberships_InvocationDelegate importedMembershipsDelegate = (Import_importedMemberships_InvocationDelegate) |
| 92 | + OperationInvocationDelegateFactory.getInvocationDelegate(_import.eClass(), SysMLPackage.eINSTANCE.getImport__ImportedMemberships__EList()); |
| 93 | + return importedMembershipsDelegate.importMemberships(_import, importedMembership, nonpublicMembership, excludedNamespaces, excludedTypes); |
| 94 | + } |
| 95 | +} |
0 commit comments