Author: bobtarling Date: 2015-01-11 10:10:42-0800 New Revision: 19960 Added: trunk/src/argouml-app/src/org/argouml/uml/util/ModelUtil.java
Log: Move method to generate package from classes out of the Java RE module and into core argo to allow reuse elsewhere Added: trunk/src/argouml-app/src/org/argouml/uml/util/ModelUtil.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/util/ModelUtil.java?view=markup&pathrev=19960 ============================================================================== --- (empty file) +++ trunk/src/argouml-app/src/org/argouml/uml/util/ModelUtil.java 2015-01-11 10:10:42-0800 @@ -0,0 +1,71 @@ +/* $Id$ + ******************************************************************************* + * Copyright (c) 2015 Contributors - see below + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bob Tarling + ******************************************************************************* + */ + +package org.argouml.uml.util; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.argouml.kernel.Project; +import org.argouml.model.IllegalModelElementConnectionException; +import org.argouml.model.Model; + +/** + * A general utility class for manipulating the UML metamodel via the model interface package + */ +public class ModelUtil { + + private ModelUtil () { + } + + /** + * Create package dependencies based on classifier relationships. + * Basically, if class A depends on class B then the package containing class A + * will be made to depend on the package containing class B. + * @param project + * @throws IllegalModelElementConnectionException + */ + public static void generatePackageDependencies(Project project) throws IllegalModelElementConnectionException { + List models = project.getUserDefinedModelList(); + + for (Object model : models) { + + for (Object classifier : Model.getModelManagementHelper().getAllModelElementsOfKindWithModel(model, Model.getMetaTypes().getClassifier())) { + + Object namespace = Model.getFacade().getNamespace(classifier); + Set dependentNamespaces = new HashSet(); + + for (Object dependency : Model.getFacade().getClientDependencies(classifier)) { + for (Object dependentClass : Model.getFacade().getSuppliers(dependency)) { + dependentNamespaces.add(Model.getFacade().getNamespace(dependentClass)); + } + } + for (Object generalization : Model.getFacade().getGeneralizations(classifier)) { + Object superClass = Model.getFacade().getGeneral(generalization); + dependentNamespaces.add(Model.getFacade().getNamespace(superClass)); + } + for (Object associatedClassifier : Model.getFacade().getAssociatedClasses(classifier)) { + dependentNamespaces.add(Model.getFacade().getNamespace(associatedClassifier)); + } + + for (Object dependentNamespace : dependentNamespaces) { + if (Model.getCoreHelper().getDependencies(dependentNamespace, namespace).isEmpty()) { + Model.getUmlFactory().buildConnection(Model.getMetaTypes().getDependency(), namespace, null, dependentNamespace, null, true, namespace); + } + } + } + } + } + +} ------------------------------------------------------ http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=3094014 To unsubscribe from this discussion, e-mail: [[email protected]].
