|
| 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.adapter; |
| 23 | + |
| 24 | +import java.util.Collection; |
| 25 | + |
| 26 | +import org.eclipse.emf.common.util.EList; |
| 27 | +import org.omg.sysml.lang.sysml.Element; |
| 28 | +import org.omg.sysml.lang.sysml.Import; |
| 29 | +import org.omg.sysml.lang.sysml.Membership; |
| 30 | +import org.omg.sysml.lang.sysml.Namespace; |
| 31 | +import org.omg.sysml.lang.sysml.OwningMembership; |
| 32 | +import org.omg.sysml.lang.sysml.Type; |
| 33 | +import org.omg.sysml.lang.sysml.VisibilityKind; |
| 34 | +import org.omg.sysml.util.NamespaceUtil; |
| 35 | + |
| 36 | +public abstract class ImportAdapter extends RelationshipAdapter { |
| 37 | + |
| 38 | + public ImportAdapter(Import element) { |
| 39 | + super(element); |
| 40 | + } |
| 41 | + |
| 42 | + public Import getTarget() { |
| 43 | + return (Import)super.getTarget(); |
| 44 | + } |
| 45 | + |
| 46 | + // Additional operations |
| 47 | + // Note: The excludedType parameter is needed in case the imported Namespace |
| 48 | + // is a Type that has one or more Generalizations. |
| 49 | + public abstract EList<Membership> importMemberships(EList<Membership> importedMembership, |
| 50 | + Collection<Membership> nonpublicMembership, Collection<Namespace> excludedNamespaces, |
| 51 | + Collection<Type> excludedTypes); |
| 52 | + |
| 53 | + protected void importMembershipsFrom(Namespace importedNamespace, EList<Membership> importedMembership, |
| 54 | + Collection<Membership> nonpublicMembership, Collection<Namespace> excludedNamespaces, |
| 55 | + Collection<Type> excludedTypes, boolean isRecursive) { |
| 56 | + Import target = getTarget(); |
| 57 | + Collection<Membership> namespaceMembership = |
| 58 | + NamespaceUtil.getVisibleMembershipsFor(importedNamespace, excludedNamespaces, excludedTypes, target.isImportAll()); |
| 59 | + importedMembership.addAll(namespaceMembership); |
| 60 | + if (nonpublicMembership != null && !VisibilityKind.PUBLIC.equals(target.getVisibility())) { |
| 61 | + nonpublicMembership.addAll(namespaceMembership); |
| 62 | + } |
| 63 | + if (isRecursive) { |
| 64 | + excludedNamespaces.add(importedNamespace); |
| 65 | + for (Membership membership: namespaceMembership) { |
| 66 | + if (membership instanceof OwningMembership) { |
| 67 | + Element member = membership.getMemberElement(); |
| 68 | + if (member instanceof Namespace) { |
| 69 | + importMembershipsFrom((Namespace)member, importedMembership, nonpublicMembership, |
| 70 | + excludedNamespaces, excludedTypes, true); |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + excludedNamespaces.remove(importedNamespace); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments