From b897b0fede5bd17068c7b682d09b2086e22bb3eb Mon Sep 17 00:00:00 2001 From: npacini <nicholas.pacini@intecs.it> Date: Wed, 20 May 2015 10:28:29 +0200 Subject: [PATCH] added javadoc tags. added comments (partially). package refactoring --- plugins/org.polarsys.chess.validator/.project | 6 + .../org.eclipse.core.resources.prefs | 2 +- .../org.polarsys.chess.validator/plugin.xml | 4 +- .../polarsys/chess/validator/Activator.java | 8 +- .../command/ChessGenericValidateCommand.java | 427 +++++---- .../{ => util}/ChessGenericDiagnostician.java | 87 +- .../{ => util}/ChessValidatorAdapter.java | 248 ++--- .../validator/constraints/Connector_01.java | 237 ++--- .../validator/constraints/Connector_02.java | 167 ++-- .../chess/validator/constraints/DV_01.java | 7 + .../chess/validator/constraints/DV_02.java | 7 + .../chess/validator/constraints/DV_03.java | 7 + .../chess/validator/constraints/DV_04.java | 7 + .../chess/validator/constraints/EFVRT_02.java | 7 + .../chess/validator/constraints/EFVRT_03.java | 7 + .../chess/validator/constraints/EFVRT_04.java | 7 + .../chess/validator/constraints/EFVRT_20.java | 7 + .../chess/validator/constraints/EFVRT_30.java | 7 + .../chess/validator/constraints/EFVRT_40.java | 7 + .../chess/validator/constraints/FV_02.java | 7 + .../chess/validator/constraints/FV_03.java | 20 + .../chess/validator/constraints/FV_04.java | 20 + .../chess/validator/constraints/FV_05.java | 7 + .../chess/validator/constraints/FV_06.java | 7 + .../chess/validator/constraints/FV_07.java | 7 + .../validator/constraints/FlowPorts_01.java | 104 +- .../validator/constraints/FlowPorts_02.java | 121 +-- .../validator/constraints/FlowPorts_03.java | 182 ++-- .../validator/constraints/StringParser.java | 149 +-- .../{managers => libs}/ActionsLib.java | 24 +- .../{managers => libs}/ConstraintsLib.java | 27 +- .../CrossViewActionLib.java | 24 +- .../{ => managers}/AddDiagramElement.java | 128 ++- .../validator/managers/ModelManager.java | 288 +++--- .../chess/validator/managers/ModelParser.java | 334 ++++--- .../{ => managers}/ResourceListener.java | 896 ++++++++++-------- .../ValidationDelegateClientSelector.java | 6 +- .../chess/validator/managers/ViewManager.java | 381 ++++---- .../{managers => messages}/Messages.java | 39 +- .../messages.properties | 0 40 files changed, 2341 insertions(+), 1686 deletions(-) rename plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/{ => util}/ChessGenericDiagnostician.java (70%) rename plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/{ => util}/ChessValidatorAdapter.java (77%) rename plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/{managers => libs}/ActionsLib.java (97%) rename plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/{managers => libs}/ConstraintsLib.java (97%) rename plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/{managers => libs}/CrossViewActionLib.java (85%) rename plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/{ => managers}/AddDiagramElement.java (86%) rename plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/{ => managers}/ResourceListener.java (89%) rename plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/{ => managers}/ValidationDelegateClientSelector.java (92%) rename plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/{managers => messages}/Messages.java (71%) rename plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/{managers => messages}/messages.properties (100%) diff --git a/plugins/org.polarsys.chess.validator/.project b/plugins/org.polarsys.chess.validator/.project index f39735c69..d566e6209 100644 --- a/plugins/org.polarsys.chess.validator/.project +++ b/plugins/org.polarsys.chess.validator/.project @@ -25,10 +25,16 @@ <arguments> </arguments> </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> </buildSpec> <natures> <nature>org.eclipse.pde.PluginNature</nature> <nature>org.eclipse.jdt.core.javanature</nature> <nature>com.jutils.lint4j.core.Nature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> </natures> </projectDescription> diff --git a/plugins/org.polarsys.chess.validator/.settings/org.eclipse.core.resources.prefs b/plugins/org.polarsys.chess.validator/.settings/org.eclipse.core.resources.prefs index 7aebdd628..edb4f0a0f 100644 --- a/plugins/org.polarsys.chess.validator/.settings/org.eclipse.core.resources.prefs +++ b/plugins/org.polarsys.chess.validator/.settings/org.eclipse.core.resources.prefs @@ -1,2 +1,2 @@ eclipse.preferences.version=1 -encoding//src/org/polarsys/chess/validator/managers/messages.properties=ISO-8859-1 +encoding//src/org/polarsys/chess/validator/messages/messages.properties=ISO-8859-1 diff --git a/plugins/org.polarsys.chess.validator/plugin.xml b/plugins/org.polarsys.chess.validator/plugin.xml index 1d0848121..30aafebf6 100644 --- a/plugins/org.polarsys.chess.validator/plugin.xml +++ b/plugins/org.polarsys.chess.validator/plugin.xml @@ -5,7 +5,7 @@ <extension point="org.polarsys.chess.resourceListener"> <listener name="resource listener" - realization="org.polarsys.chess.validator.ResourceListener"> + realization="org.polarsys.chess.validator.managers.ResourceListener"> </listener> </extension> @@ -14,7 +14,7 @@ default="false" id="CHESSvalidationContextID"> <selector - class="org.polarsys.chess.validator.ValidationDelegateClientSelector"> + class="org.polarsys.chess.validator.managers.ValidationDelegateClientSelector"> </selector> </clientContext> <binding diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/Activator.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/Activator.java index cbdb93321..9259e4ae1 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/Activator.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/Activator.java @@ -19,18 +19,20 @@ import org.eclipse.core.runtime.Plugin; import org.osgi.framework.BundleContext; /** - * The activator class controls the plug-in life cycle + * The activator class controls the plug-in life cycle. */ public class Activator extends Plugin { // The plug-in ID + /** The Constant PLUGIN_ID. */ public static final String PLUGIN_ID = "org.polarsys.chess.validator"; //$NON-NLS-1$ // The shared instance + /** The plugin. */ private static Activator plugin; /** - * The constructor + * The constructor. */ public Activator() { } @@ -54,7 +56,7 @@ public class Activator extends Plugin { } /** - * Returns the shared instance + * Returns the shared instance. * * @return the shared instance */ diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/ChessGenericValidateCommand.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/ChessGenericValidateCommand.java index eec0e045a..b0f08b083 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/ChessGenericValidateCommand.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/ChessGenericValidateCommand.java @@ -1,191 +1,236 @@ -package org.polarsys.chess.validator.command; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.common.util.BasicDiagnostic; -import org.eclipse.emf.common.util.Diagnostic; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; -import org.eclipse.emf.edit.provider.IItemLabelProvider; -import org.eclipse.emf.edit.ui.EMFEditUIPlugin; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.emf.validation.service.IConstraintDescriptor; -import org.eclipse.emf.validation.service.IConstraintFilter; -import org.eclipse.gmf.runtime.common.core.command.CommandResult; -import org.eclipse.papyrus.infra.services.markerlistener.util.MarkerListenerUtils; -import org.eclipse.papyrus.infra.services.validation.commands.AbstractValidateCommand; -import org.eclipse.papyrus.infra.services.validation.ValidationTool; -import org.eclipse.swt.widgets.Shell; - -public class ChessGenericValidateCommand extends AbstractValidateCommand { - - public Collection<String> pluginIds; - - public ChessGenericValidateCommand(String label, String pluginId, EObject selectedElement) { - super(label, TransactionUtil.getEditingDomain (selectedElement), selectedElement); - this.pluginIds = new ArrayList<String>(); - this.pluginIds.add(pluginId); - } - - public ChessGenericValidateCommand(String label, - Collection<String> pluginIds, EObject selectedElement) { - super(label, TransactionUtil.getEditingDomain (selectedElement), selectedElement); - this.pluginIds = new ArrayList<String>(); - - for (String id : pluginIds) { - this.pluginIds.add(id); - } - } - - @Override - protected CommandResult doExecuteWithResult(IProgressMonitor arg0, - IAdaptable arg1) throws ExecutionException { - - //System.err.println("ChessGenericValidationCommand : doExecuteWithResult"); - - // replace selection by model instead of current selection - while (selectedElement.eContainer() != null) { - selectedElement = selectedElement.eContainer (); - } - - runValidation (selectedElement); - - // Try to retrieve all markers on the file - Resource resource = selectedElement.eResource(); - if (resource != null) { - - IPath path = new Path(resource.getURI().toPlatformString (false)); - IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); - IFile file = wsRoot.getFile(path); - - try { - processMarkers(file); - } catch (CoreException e) { - e.printStackTrace(); - } - } - - return null; - } - - /** - * This simply execute the command. - */ - @Override - protected Diagnostic validate(IProgressMonitor progressMonitor, EObject validateElement) - { - //System.err.println("This is the ChessGenericValidationCommand Override for validate(IProgressMonitor,EObject) from AbstractValidateCommand"); - - int count = 0; - for (Iterator<?> i = validateElement.eAllContents(); i.hasNext(); i.next()) { - ++count; - } - - progressMonitor.beginTask("", count); - - // validate only error severity and worse - IConstraintFilter constraintFilter = new IConstraintFilter() { - @Override - public boolean accept(IConstraintDescriptor constraint, EObject target) { - // Check only constraints defined in the plugin using this generic command - //System.err.println("Evaluating constraint " + constraint.getName()+ " provided by " + constraint.getPluginId()); - return pluginIds.contains(constraint.getPluginId()); - } - }; - - AdapterFactory adapterFactory = - domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null; - ChessGenericDiagnostician diagnostician = createChessGenericDiagnostician(adapterFactory, progressMonitor, constraintFilter); - - BasicDiagnostic diagnostic = diagnostician.createDefaultDiagnostic(validateElement); - Map<Object, Object> context = diagnostician.createDefaultContext(); - - progressMonitor.setTaskName(EMFEditUIPlugin.INSTANCE.getString("_UI_Validating_message", new Object [] {diagnostician.getObjectLabel(validateElement)})); - diagnostician.validate(validateElement, diagnostic, context); - - return diagnostic; - } - - - //@Override - protected ChessGenericDiagnostician createChessGenericDiagnostician(final AdapterFactory adapterFactory, final IProgressMonitor progressMonitor, final IConstraintFilter filter) - { - return new ChessGenericDiagnostician(filter) { - @Override - public String getObjectLabel(EObject eObject) { - if (adapterFactory != null && !eObject.eIsProxy()) - { - IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(eObject, IItemLabelProvider.class); - if (itemLabelProvider != null) { - return itemLabelProvider.getText(eObject); - } - } - return super.getObjectLabel(eObject); - } - - }; - - - } - - - static protected void processMarkers(IResource resource) throws CoreException { - - //System.err.println("processMarkers for resource " + resource.getName()); - - IMarker[] markers = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); - Collection<IMarker> markersToDelete = new ArrayList<IMarker>(); - - - for (int index = 0; index < markers.length; index++ ) { - - IMarker currentMarker = markers[index]; - //String currentMessage = ((String) currentMarker.getAttribute("message")).replace("\n", ""); - //System.err.println("message:" + currentMessage); - - if (currentMarker.getAttributes().containsKey("relatedURIs")) { - markersToDelete.add(currentMarker); - } - } - - for (IMarker marker : markersToDelete) { - marker.delete(); - } - - } - - @Override - protected void handleDiagnostic(IProgressMonitor monitor, Diagnostic diagnostic, final EObject validateElement, final Shell shell){ - Resource resource = getValidationResource(); - if (resource != null) { - if (selectedElement != null) { - ValidationTool vt = new ValidationTool(selectedElement); - vt.deleteSubMarkers(); - } - for (Diagnostic childDiagnostic : diagnostic.getChildren()) { - // We have to filter on the source - if (pluginIds.contains(childDiagnostic.getSource())) { - MarkerListenerUtils.eclipseResourcesUtil.createMarkers(resource, childDiagnostic); - //if we create at least one marker report it - } - } - } - } - -} +package org.polarsys.chess.validator.command; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.common.util.BasicDiagnostic; +import org.eclipse.emf.common.util.Diagnostic; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.emf.edit.ui.EMFEditUIPlugin; +import org.eclipse.emf.transaction.util.TransactionUtil; +import org.eclipse.emf.validation.service.IConstraintDescriptor; +import org.eclipse.emf.validation.service.IConstraintFilter; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.papyrus.infra.services.markerlistener.util.MarkerListenerUtils; +import org.eclipse.papyrus.infra.services.validation.commands.AbstractValidateCommand; +import org.eclipse.papyrus.infra.services.validation.ValidationTool; +import org.eclipse.swt.widgets.Shell; +import org.polarsys.chess.validator.command.util.ChessGenericDiagnostician; + +// TODO: Auto-generated Javadoc +/** + * The Class ChessGenericValidateCommand. + * @see org.eclipse.papyrus.infra.services.validation.commands.AbstractValidateCommand + */ +public class ChessGenericValidateCommand extends AbstractValidateCommand { + + /** The plugin ids. */ + public Collection<String> pluginIds; + + /** + * Instantiates a new ChessGenericValidateCommand. + * + * @param label the label + * @param pluginId the plugin id + * @param selectedElement the selected element + */ + public ChessGenericValidateCommand(String label, String pluginId, EObject selectedElement) { + super(label, TransactionUtil.getEditingDomain (selectedElement), selectedElement); + this.pluginIds = new ArrayList<String>(); + this.pluginIds.add(pluginId); + } + + /** + * Instantiates a new ChessGenericValidateCommand. + * + * @param label the label + * @param pluginIds the list of plugin ids + * @param selectedElement the selected element + */ + public ChessGenericValidateCommand(String label, + Collection<String> pluginIds, EObject selectedElement) { + super(label, TransactionUtil.getEditingDomain (selectedElement), selectedElement); + this.pluginIds = new ArrayList<String>(); + + for (String id : pluginIds) { + this.pluginIds.add(id); + } + } + + /* (non-Javadoc) + * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + */ + @Override + protected CommandResult doExecuteWithResult(IProgressMonitor arg0, + IAdaptable arg1) throws ExecutionException { + + //System.err.println("ChessGenericValidationCommand : doExecuteWithResult"); + + // replace selection by model instead of current selection + while (selectedElement.eContainer() != null) { + selectedElement = selectedElement.eContainer (); + } + + runValidation (selectedElement); + + // Try to retrieve all markers on the file + Resource resource = selectedElement.eResource(); + if (resource != null) { + + IPath path = new Path(resource.getURI().toPlatformString (false)); + IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); + IFile file = wsRoot.getFile(path); + + try { + processMarkers(file); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + return null; + } + + /** + * This simply execute the command. + * + * @param progressMonitor the progress monitor + * @param validateElement the validate element + * @return the diagnostic + */ + @Override + protected Diagnostic validate(IProgressMonitor progressMonitor, EObject validateElement) + { + //System.err.println("This is the ChessGenericValidationCommand Override for validate(IProgressMonitor,EObject) from AbstractValidateCommand"); + + int count = 0; + for (Iterator<?> i = validateElement.eAllContents(); i.hasNext(); i.next()) { + ++count; + } + + progressMonitor.beginTask("", count); + + // validate only error severity and worse + IConstraintFilter constraintFilter = new IConstraintFilter() { + @Override + public boolean accept(IConstraintDescriptor constraint, EObject target) { + // Check only constraints defined in the plugin using this generic command + //System.err.println("Evaluating constraint " + constraint.getName()+ " provided by " + constraint.getPluginId()); + return pluginIds.contains(constraint.getPluginId()); + } + }; + + AdapterFactory adapterFactory = + domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null; + ChessGenericDiagnostician diagnostician = createChessGenericDiagnostician(adapterFactory, progressMonitor, constraintFilter); + + BasicDiagnostic diagnostic = diagnostician.createDefaultDiagnostic(validateElement); + Map<Object, Object> context = diagnostician.createDefaultContext(); + + progressMonitor.setTaskName(EMFEditUIPlugin.INSTANCE.getString("_UI_Validating_message", new Object [] {diagnostician.getObjectLabel(validateElement)})); + diagnostician.validate(validateElement, diagnostic, context); + + return diagnostic; + } + + + //@Override + /** + * Creates the ChessGenericDiagnostician. + * + * @param adapterFactory the adapter factory + * @param progressMonitor the progress monitor + * @param filter the filter + * @return the ChessGenericDiagnostician + */ + protected ChessGenericDiagnostician createChessGenericDiagnostician(final AdapterFactory adapterFactory, final IProgressMonitor progressMonitor, final IConstraintFilter filter) + { + return new ChessGenericDiagnostician(filter) { + @Override + public String getObjectLabel(EObject eObject) { + if (adapterFactory != null && !eObject.eIsProxy()) + { + IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(eObject, IItemLabelProvider.class); + if (itemLabelProvider != null) { + return itemLabelProvider.getText(eObject); + } + } + return super.getObjectLabel(eObject); + } + + }; + + + } + + + /** + * Process the markers + * + * @param resource the resource + * @throws CoreException the core exception + */ + static protected void processMarkers(IResource resource) throws CoreException { + + //System.err.println("processMarkers for resource " + resource.getName()); + + IMarker[] markers = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); + Collection<IMarker> markersToDelete = new ArrayList<IMarker>(); + + + for (int index = 0; index < markers.length; index++ ) { + + IMarker currentMarker = markers[index]; + //String currentMessage = ((String) currentMarker.getAttribute("message")).replace("\n", ""); + //System.err.println("message:" + currentMessage); + + if (currentMarker.getAttributes().containsKey("relatedURIs")) { + markersToDelete.add(currentMarker); + } + } + + for (IMarker marker : markersToDelete) { + marker.delete(); + } + + } + + /* (non-Javadoc) + * @see org.eclipse.papyrus.infra.services.validation.commands.AbstractValidateCommand#handleDiagnostic(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.emf.common.util.Diagnostic, org.eclipse.emf.ecore.EObject, org.eclipse.swt.widgets.Shell) + */ + @Override + protected void handleDiagnostic(IProgressMonitor monitor, Diagnostic diagnostic, final EObject validateElement, final Shell shell){ + Resource resource = getValidationResource(); + if (resource != null) { + if (selectedElement != null) { + ValidationTool vt = new ValidationTool(selectedElement); + vt.deleteSubMarkers(); + } + for (Diagnostic childDiagnostic : diagnostic.getChildren()) { + // We have to filter on the source + if (pluginIds.contains(childDiagnostic.getSource())) { + MarkerListenerUtils.eclipseResourcesUtil.createMarkers(resource, childDiagnostic); + //if we create at least one marker report it + } + } + } + } + +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/ChessGenericDiagnostician.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/util/ChessGenericDiagnostician.java similarity index 70% rename from plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/ChessGenericDiagnostician.java rename to plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/util/ChessGenericDiagnostician.java index 67a8bf7d3..62bd92d4d 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/ChessGenericDiagnostician.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/util/ChessGenericDiagnostician.java @@ -1,36 +1,51 @@ -package org.polarsys.chess.validator.command; - -import java.util.Map; - -import org.eclipse.emf.common.util.DiagnosticChain; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.Diagnostician; -import org.eclipse.emf.ecore.util.EObjectValidator; -import org.eclipse.emf.validation.service.IConstraintFilter; - - -public class ChessGenericDiagnostician extends Diagnostician { - - private ChessValidatorAdapter eChessValidatorAdapter; - - public ChessGenericDiagnostician(IConstraintFilter filter) { - this.eChessValidatorAdapter = new ChessValidatorAdapter(filter); - } - - @Override - public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) - { - //progressMonitor.worked(1); - //System.err.println("This is the ChessCheckerDiagnostician override of Diagnostician.validate(EClass, EObject,diagnostics,context)"); - - boolean circular = context.get(EObjectValidator.ROOT_OBJECT) == eObject; - @SuppressWarnings("null") - boolean result = eChessValidatorAdapter.validate(eClass, eObject, diagnostics, context); - if ((result || diagnostics != null) && !circular) - { - result &= doValidateContents(eObject, diagnostics, context); - } - return result; - } -} +package org.polarsys.chess.validator.command.util; + +import java.util.Map; + +import org.eclipse.emf.common.util.DiagnosticChain; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.Diagnostician; +import org.eclipse.emf.ecore.util.EObjectValidator; +import org.eclipse.emf.validation.service.IConstraintFilter; + + +// TODO: Auto-generated Javadoc +/** + * The Class ChessGenericDiagnostician. + * + * @see package org.eclipse.emf.ecore.util.Diagnostician + */ +public class ChessGenericDiagnostician extends Diagnostician { + + /** The eChessValidatorAdapter. */ + private ChessValidatorAdapter eChessValidatorAdapter; + + /** + * Instantiates a new chess generic diagnostician. + * + * @param filter the filter + */ + public ChessGenericDiagnostician(IConstraintFilter filter) { + this.eChessValidatorAdapter = new ChessValidatorAdapter(filter); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.util.Diagnostician#validate(org.eclipse.emf.ecore.EClass, org.eclipse.emf.ecore.EObject, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) + */ + @Override + public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) + { + //progressMonitor.worked(1); + //System.err.println("This is the ChessCheckerDiagnostician override of Diagnostician.validate(EClass, EObject,diagnostics,context)"); + + boolean circular = context.get(EObjectValidator.ROOT_OBJECT) == eObject; + @SuppressWarnings("null") + boolean result = eChessValidatorAdapter.validate(eClass, eObject, diagnostics, context); + if ((result || diagnostics != null) && !circular) + { + result &= doValidateContents(eObject, diagnostics, context); + } + return result; + } +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/ChessValidatorAdapter.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/util/ChessValidatorAdapter.java similarity index 77% rename from plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/ChessValidatorAdapter.java rename to plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/util/ChessValidatorAdapter.java index eb3d1dfab..21ec2374b 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/ChessValidatorAdapter.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/command/util/ChessValidatorAdapter.java @@ -1,106 +1,142 @@ -package org.polarsys.chess.validator.command; - -import java.util.Map; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.util.BasicDiagnostic; -import org.eclipse.emf.common.util.DiagnosticChain; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EObjectValidator; -import org.eclipse.emf.validation.model.EvaluationMode; -import org.eclipse.emf.validation.model.IConstraintStatus; -import org.eclipse.emf.validation.service.IBatchValidator; -import org.eclipse.emf.validation.service.IConstraintFilter; -import org.eclipse.emf.validation.service.ModelValidationService; - -public class ChessValidatorAdapter extends EObjectValidator{ - - private final IBatchValidator batchValidator; - - public ChessValidatorAdapter(IConstraintFilter constraintFilter) { - super(); - - this.batchValidator = (IBatchValidator) ModelValidationService.getInstance() - .newValidator(EvaluationMode.BATCH); - this.batchValidator.setIncludeLiveConstraints(true); - this.batchValidator.setReportSuccesses(false); - this.batchValidator.addConstraintFilter(constraintFilter); - } - - @Override - public boolean validate(final EObject eObject, - final DiagnosticChain diagnostics, - final Map<Object, Object> context) { - return validate(eObject.eClass(), eObject, diagnostics, context); - } - - @Override - public boolean validate(final EClass eClass, final EObject eObject, - final DiagnosticChain diagnostics, final Map<Object, Object> context) { - super.validate(eClass, eObject, diagnostics, context); - - IStatus status = Status.OK_STATUS; - - if (diagnostics != null) { - if (!hasProcessed(eObject, context)) { - status = this.batchValidator.validate( - eObject, - new NullProgressMonitor()); - - processed(eObject, context, status); - - appendDiagnostics(status, diagnostics); - } - } - - return status.isOK(); - } - - private void processed(final EObject eObject, - final Map<Object, Object> context, final IStatus status) { - if (context != null) { - context.put(eObject, status); - } - } - - private boolean hasProcessed(final EObject eObject, - final Map<Object, Object> context) { - boolean result = false; - EObject currentEObject = eObject; - if (context != null) { - while (currentEObject != null) { - if (context.containsKey(currentEObject)) { - result = true; - currentEObject = null; - } else { - currentEObject = currentEObject.eContainer(); - } - } - } - - return result; - } - - private void appendDiagnostics(final IStatus status, - final DiagnosticChain diagnostics) { - if (status.isMultiStatus()) { - IStatus[] children = status.getChildren(); - - for (int i = 0; i < children.length; i++) { - appendDiagnostics(children[i], diagnostics); - } - } else if (status instanceof IConstraintStatus) { - diagnostics.add(new BasicDiagnostic( - status.getSeverity(), - status.getPlugin(), - status.getCode(), - status.getMessage(), - ((IConstraintStatus) status).getResultLocus().toArray())); - } - } - - -} +package org.polarsys.chess.validator.command.util; + +import java.util.Map; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.util.BasicDiagnostic; +import org.eclipse.emf.common.util.DiagnosticChain; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EObjectValidator; +import org.eclipse.emf.validation.model.EvaluationMode; +import org.eclipse.emf.validation.model.IConstraintStatus; +import org.eclipse.emf.validation.service.IBatchValidator; +import org.eclipse.emf.validation.service.IConstraintFilter; +import org.eclipse.emf.validation.service.ModelValidationService; + +// TODO: Auto-generated Javadoc +/** + * The Class ChessValidatorAdapter. + */ +public class ChessValidatorAdapter extends EObjectValidator{ + + /** The batch validator. */ + private final IBatchValidator batchValidator; + + /** + * Instantiates a new chess validator adapter. + * + * @param constraintFilter the constraint filter + */ + public ChessValidatorAdapter(IConstraintFilter constraintFilter) { + super(); + + this.batchValidator = (IBatchValidator) ModelValidationService.getInstance() + .newValidator(EvaluationMode.BATCH); + this.batchValidator.setIncludeLiveConstraints(true); + this.batchValidator.setReportSuccesses(false); + this.batchValidator.addConstraintFilter(constraintFilter); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.util.EObjectValidator#validate(org.eclipse.emf.ecore.EObject, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) + */ + @Override + public boolean validate(final EObject eObject, + final DiagnosticChain diagnostics, + final Map<Object, Object> context) { + return validate(eObject.eClass(), eObject, diagnostics, context); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.util.EObjectValidator#validate(org.eclipse.emf.ecore.EClass, org.eclipse.emf.ecore.EObject, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) + */ + @Override + public boolean validate(final EClass eClass, final EObject eObject, + final DiagnosticChain diagnostics, final Map<Object, Object> context) { + super.validate(eClass, eObject, diagnostics, context); + + IStatus status = Status.OK_STATUS; + + if (diagnostics != null) { + if (!hasProcessed(eObject, context)) { + status = this.batchValidator.validate( + eObject, + new NullProgressMonitor()); + + processed(eObject, context, status); + + appendDiagnostics(status, diagnostics); + } + } + + return status.isOK(); + } + + /** + * Processed. + * + * @param eObject the e object + * @param context the context + * @param status the status + */ + private void processed(final EObject eObject, + final Map<Object, Object> context, final IStatus status) { + if (context != null) { + context.put(eObject, status); + } + } + + /** + * Checks for processed. + * + * @param eObject the e object + * @param context the context + * @return true, if successful + */ + private boolean hasProcessed(final EObject eObject, + final Map<Object, Object> context) { + boolean result = false; + EObject currentEObject = eObject; + if (context != null) { + while (currentEObject != null) { + if (context.containsKey(currentEObject)) { + result = true; + currentEObject = null; + } else { + currentEObject = currentEObject.eContainer(); + } + } + } + + return result; + } + + /** + * Append diagnostics. + * + * @param status the status + * @param diagnostics the diagnostics + */ + private void appendDiagnostics(final IStatus status, + final DiagnosticChain diagnostics) { + if (status.isMultiStatus()) { + IStatus[] children = status.getChildren(); + + for (int i = 0; i < children.length; i++) { + appendDiagnostics(children[i], diagnostics); + } + } else if (status instanceof IConstraintStatus) { + diagnostics.add(new BasicDiagnostic( + status.getSeverity(), + status.getPlugin(), + status.getCode(), + status.getMessage(), + ((IConstraintStatus) status).getResultLocus().toArray())); + } + } + + +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/Connector_01.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/Connector_01.java index 66c62927d..ced9937d1 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/Connector_01.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/Connector_01.java @@ -1,115 +1,122 @@ -/* ------------------------------------------------------------------------ --- CHESS Live/Batch Validator plugin -- --- -- --- Copyright (C) 2011-2012 -- --- University of Padova, ITALY -- --- -- --- Author: Nicholas Pacini -- --- -- --- 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 -- ------------------------------------------------------------------------ -*/ -package org.polarsys.chess.validator.constraints; - - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.emf.ecore.util.EObjectResolvingEList; -import org.eclipse.emf.validation.AbstractModelConstraint; -import org.eclipse.emf.validation.IValidationContext; -import org.eclipse.uml2.uml.Connector; -import org.eclipse.uml2.uml.ConnectorEnd; -import org.eclipse.uml2.uml.Interface; -import org.eclipse.uml2.uml.Port; -import org.eclipse.uml2.uml.Property; -import org.eclipse.uml2.uml.Stereotype; - -public class Connector_01 extends AbstractModelConstraint { - - private static final String CSPORT = "MARTE::MARTE_DesignModel::GCM::ClientServerPort"; - - @Override - public IStatus validate(IValidationContext ctx) { - // TODO Auto-generated method stub - IStatus success = ctx.createSuccessStatus(); - IStatus failure = ctx.createFailureStatus(); - - Connector con = (Connector) ctx.getTarget(); - try{ - //check that ports are compatible (provided-required) - ConnectorEnd ceFir = con.getEnds().get(0); - if(!(ceFir.getRole() instanceof Port)){ - return failure; - } - Port portFir = (Port) ceFir.getRole(); - Stereotype sFirst = portFir.getAppliedStereotype(CSPORT); - if(sFirst == null){ - return success; - } - String first = portFir.getValue(sFirst, "kind").toString(); - ConnectorEnd ceSec = con.getEnds().get(1); - if(!(ceSec.getRole() instanceof Port)){ - return failure; - } - Port portSec = (Port) ceSec.getRole(); - Stereotype sSecond = portSec.getAppliedStereotype(CSPORT); - if(sSecond == null){ - return success; - } - String second = portSec.getValue(sSecond, "kind").toString(); - if(first.equals(second)){ - //it's not an automatic failure if it's port delegation between parent and child - if(ceFir.getPartWithPort() == null || ceSec.getPartWithPort() == null){ - return success; - } - if(ceFir.getPartWithPort() instanceof Property || ceSec.getPartWithPort() instanceof Property){ - Property prFirst = ceFir.getPartWithPort(); - Property prSec = ceSec.getPartWithPort(); - //check that the one of the properties contains the other - if(prFirst.getType().getOwnedElements().contains(prSec) || prSec.getType().getOwnedElements().contains(prFirst)){ - return success; - } - } - - return failure; - } - //check that the ports are owned by components at the "same level" (no parent-child) - if (ceFir.getPartWithPort() == null || ceSec.getPartWithPort() == null){ - return failure; - } - - //check that interfaces provided/required are compatible (i.e the same interface or the provided can be a subtype of the required) - Interface iFirst = null, iSecond = null; - if (first.equals("provided")){ - iFirst = (Interface)((EObjectResolvingEList) portFir.getValue(sFirst, "provInterface")).get(0); - } else if(first.equals("required")){ - iFirst = (Interface)((EObjectResolvingEList) portFir.getValue(sFirst, "reqInterface")).get(0); - } - if (second.equals("provided")){ - iSecond = (Interface)((EObjectResolvingEList) portSec.getValue(sSecond, "provInterface")).get(0); - } else if(second.equals("required")){ - iSecond = (Interface)((EObjectResolvingEList) portSec.getValue(sSecond, "reqInterface")).get(0); - } - //if they are different it's ok only if the Provided interface inherits the Required Interface - if(!iFirst.equals(iSecond)){ - if(first.equals("provided")){ - if(!iFirst.allParents().contains(iSecond)){ - return failure; - } - }else if(second.equals("provided")){ - if(!iSecond.allParents().contains(iFirst)){ - return failure; - } - } - } - - return success; - }catch(IndexOutOfBoundsException e){ - return failure; - } - } - -} +/* +----------------------------------------------------------------------- +-- CHESS Live/Batch Validator plugin -- +-- -- +-- Copyright (C) 2011-2012 -- +-- University of Padova, ITALY -- +-- -- +-- Author: Nicholas Pacini -- +-- -- +-- 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 -- +----------------------------------------------------------------------- +*/ +package org.polarsys.chess.validator.constraints; + + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.ecore.util.EObjectResolvingEList; +import org.eclipse.emf.validation.AbstractModelConstraint; +import org.eclipse.emf.validation.IValidationContext; +import org.eclipse.uml2.uml.Connector; +import org.eclipse.uml2.uml.ConnectorEnd; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +// TODO: Auto-generated Javadoc +/** + * The Class Connector_01. + */ +public class Connector_01 extends AbstractModelConstraint { + + /** The Constant CSPORT. */ + private static final String CSPORT = "MARTE::MARTE_DesignModel::GCM::ClientServerPort"; + + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ + @Override + public IStatus validate(IValidationContext ctx) { + IStatus success = ctx.createSuccessStatus(); + IStatus failure = ctx.createFailureStatus(); + + Connector con = (Connector) ctx.getTarget(); + try{ + //check that ports are compatible (provided-required) + ConnectorEnd ceFir = con.getEnds().get(0); + if(!(ceFir.getRole() instanceof Port)){ + return failure; + } + Port portFir = (Port) ceFir.getRole(); + Stereotype sFirst = portFir.getAppliedStereotype(CSPORT); + if(sFirst == null){ + return success; + } + String first = portFir.getValue(sFirst, "kind").toString(); + ConnectorEnd ceSec = con.getEnds().get(1); + if(!(ceSec.getRole() instanceof Port)){ + return failure; + } + Port portSec = (Port) ceSec.getRole(); + Stereotype sSecond = portSec.getAppliedStereotype(CSPORT); + if(sSecond == null){ + return success; + } + String second = portSec.getValue(sSecond, "kind").toString(); + if(first.equals(second)){ + //it's not an automatic failure if it's port delegation between parent and child + if(ceFir.getPartWithPort() == null || ceSec.getPartWithPort() == null){ + return success; + } + if(ceFir.getPartWithPort() instanceof Property || ceSec.getPartWithPort() instanceof Property){ + Property prFirst = ceFir.getPartWithPort(); + Property prSec = ceSec.getPartWithPort(); + //check that the one of the properties contains the other + if(prFirst.getType().getOwnedElements().contains(prSec) || prSec.getType().getOwnedElements().contains(prFirst)){ + return success; + } + } + + return failure; + } + //check that the ports are owned by components at the "same level" (no parent-child) + if (ceFir.getPartWithPort() == null || ceSec.getPartWithPort() == null){ + return failure; + } + + //check that interfaces provided/required are compatible (i.e the same interface or the provided can be a subtype of the required) + Interface iFirst = null, iSecond = null; + if (first.equals("provided")){ + iFirst = (Interface)((EObjectResolvingEList) portFir.getValue(sFirst, "provInterface")).get(0); + } else if(first.equals("required")){ + iFirst = (Interface)((EObjectResolvingEList) portFir.getValue(sFirst, "reqInterface")).get(0); + } + if (second.equals("provided")){ + iSecond = (Interface)((EObjectResolvingEList) portSec.getValue(sSecond, "provInterface")).get(0); + } else if(second.equals("required")){ + iSecond = (Interface)((EObjectResolvingEList) portSec.getValue(sSecond, "reqInterface")).get(0); + } + //if they are different it's ok only if the Provided interface inherits the Required Interface + if(!iFirst.equals(iSecond)){ + if(first.equals("provided")){ + if(!iFirst.allParents().contains(iSecond)){ + return failure; + } + }else if(second.equals("provided")){ + if(!iSecond.allParents().contains(iFirst)){ + return failure; + } + } + } + + return success; + }catch(IndexOutOfBoundsException e){ + return failure; + } + } + +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/Connector_02.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/Connector_02.java index 64dda6231..75572ef17 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/Connector_02.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/Connector_02.java @@ -1,82 +1,85 @@ -package org.polarsys.chess.validator.constraints; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.validation.AbstractModelConstraint; -import org.eclipse.emf.validation.IValidationContext; -import org.eclipse.uml2.uml.Connector; -import org.eclipse.uml2.uml.ConnectorEnd; -import org.eclipse.uml2.uml.Dependency; -import org.eclipse.uml2.uml.Port; -import org.eclipse.uml2.uml.Property; -import org.eclipse.uml2.uml.Stereotype; - -public class Connector_02 extends AbstractModelConstraint { - - private static final String FLOWPORT = "MARTE::MARTE_DesignModel::GCM::FlowPort"; - - @Override - public IStatus validate(IValidationContext ctx) { - - IStatus success = ctx.createSuccessStatus(); - IStatus failure = ctx.createFailureStatus(); - - Connector con = (Connector) ctx.getTarget(); - - ConnectorEnd firstEnd = con.getEnds().get(0); - if(!(firstEnd.getRole() instanceof Port)){ - return failure; - } - - Port firstPort = (Port) firstEnd.getRole(); - Stereotype firstStereo = firstPort.getAppliedStereotype(FLOWPORT); - if(firstStereo == null){ - return success; - } - - ConnectorEnd secondEnd = con.getEnds().get(1); - if(!(secondEnd.getRole() instanceof Port)){ - return failure; - } - - Port secondPort = (Port) secondEnd.getRole(); - Stereotype secondStereo = secondPort.getAppliedStereotype(FLOWPORT); - if(secondStereo == null){ - return success; - } - - //check types - if(!(firstPort.getType().equals(secondPort.getType()))){ - return failure; - } - - //check directions: - //out -> in; in -> out; inout -> whatever - String firstDir = firstPort.getValue(firstStereo, "direction").toString(); - String secondDir = secondPort.getValue(secondStereo, "direction").toString(); - - if(!firstDir.equals("inout") && !(secondDir.equals("inout")) && firstDir.equals(secondDir)){ - //it's not an automatic failure if it's port delegation between parent and child - if(firstEnd.getPartWithPort() == null || secondEnd.getPartWithPort() == null){ - return success; - } - if(firstEnd.getPartWithPort() instanceof Property || secondEnd.getPartWithPort() instanceof Property){ - Property prFirst = firstEnd.getPartWithPort(); - Property prSec = secondEnd.getPartWithPort(); - //check that the one of the properties contains the other - if(prFirst.getType().getOwnedElements().contains(prSec) || prSec.getType().getOwnedElements().contains(prFirst)){ - return success; - } - } - return failure; - } - - //check mappings??? (maybe not needed) -// EList<Dependency> firstDepList = firstPort.getClientDependencies(); -// EList<Dependency> secondDepList = secondPort.getClientDependencies(); - - - return success; - } - -} +package org.polarsys.chess.validator.constraints; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.validation.AbstractModelConstraint; +import org.eclipse.emf.validation.IValidationContext; +import org.eclipse.uml2.uml.Connector; +import org.eclipse.uml2.uml.ConnectorEnd; +import org.eclipse.uml2.uml.Dependency; +import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +// TODO: Auto-generated Javadoc +/** + * The Class Connector_02. + */ +public class Connector_02 extends AbstractModelConstraint { + + /** The Constant FLOWPORT. */ + private static final String FLOWPORT = "MARTE::MARTE_DesignModel::GCM::FlowPort"; + + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ + @Override + public IStatus validate(IValidationContext ctx) { + + IStatus success = ctx.createSuccessStatus(); + IStatus failure = ctx.createFailureStatus(); + + Connector con = (Connector) ctx.getTarget(); + + ConnectorEnd firstEnd = con.getEnds().get(0); + if(!(firstEnd.getRole() instanceof Port)){ + return failure; + } + + Port firstPort = (Port) firstEnd.getRole(); + Stereotype firstStereo = firstPort.getAppliedStereotype(FLOWPORT); + if(firstStereo == null){ + return success; + } + + ConnectorEnd secondEnd = con.getEnds().get(1); + if(!(secondEnd.getRole() instanceof Port)){ + return failure; + } + + Port secondPort = (Port) secondEnd.getRole(); + Stereotype secondStereo = secondPort.getAppliedStereotype(FLOWPORT); + if(secondStereo == null){ + return success; + } + + //check types + if(!(firstPort.getType().equals(secondPort.getType()))){ + return failure; + } + + //check directions: + //out -> in; in -> out; inout -> whatever + String firstDir = firstPort.getValue(firstStereo, "direction").toString(); + String secondDir = secondPort.getValue(secondStereo, "direction").toString(); + + if(!firstDir.equals("inout") && !(secondDir.equals("inout")) && firstDir.equals(secondDir)){ + //it's not an automatic failure if it's port delegation between parent and child + if(firstEnd.getPartWithPort() == null || secondEnd.getPartWithPort() == null){ + return success; + } + if(firstEnd.getPartWithPort() instanceof Property || secondEnd.getPartWithPort() instanceof Property){ + Property prFirst = firstEnd.getPartWithPort(); + Property prSec = secondEnd.getPartWithPort(); + //check that the one of the properties contains the other + if(prFirst.getType().getOwnedElements().contains(prSec) || prSec.getType().getOwnedElements().contains(prFirst)){ + return success; + } + } + return failure; + } + + return success; + } + +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_01.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_01.java index 063bb7260..0abe66cf6 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_01.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_01.java @@ -31,8 +31,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.chessmlprofile.util.Constants; +// TODO: Auto-generated Javadoc +/** + * The Class DV_01. + */ public class DV_01 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_02.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_02.java index e93702166..9ae23a496 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_02.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_02.java @@ -28,8 +28,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.chessmlprofile.util.Constants; +// TODO: Auto-generated Javadoc +/** + * The Class DV_02. + */ public class DV_02 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_03.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_03.java index 1c927cc46..9c33eb930 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_03.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_03.java @@ -22,8 +22,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.chessmlprofile.util.Constants; +// TODO: Auto-generated Javadoc +/** + * The Class DV_03. + */ public class DV_03 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_04.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_04.java index 54d31009e..1cf9651ab 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_04.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/DV_04.java @@ -22,8 +22,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.chessmlprofile.util.Constants; +// TODO: Auto-generated Javadoc +/** + * The Class DV_04. + */ public class DV_04 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_02.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_02.java index 1e9c180f7..8b1a2e497 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_02.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_02.java @@ -27,8 +27,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.core.views.ViewUtils; +// TODO: Auto-generated Javadoc +/** + * The Class EFVRT_02. + */ public class EFVRT_02 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_03.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_03.java index 0ed9c5762..36dbe067c 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_03.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_03.java @@ -26,8 +26,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.core.views.ViewUtils; +// TODO: Auto-generated Javadoc +/** + * The Class EFVRT_03. + */ public class EFVRT_03 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_04.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_04.java index 802bcd7f4..395309cf1 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_04.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_04.java @@ -26,8 +26,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.core.views.ViewUtils; +// TODO: Auto-generated Javadoc +/** + * The Class EFVRT_04. + */ public class EFVRT_04 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_20.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_20.java index dd88fb493..12fd02013 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_20.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_20.java @@ -26,8 +26,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.core.views.ViewUtils; +// TODO: Auto-generated Javadoc +/** + * The Class EFVRT_20. + */ public class EFVRT_20 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_30.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_30.java index 4e7013e06..06c4dd928 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_30.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_30.java @@ -26,8 +26,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.core.views.ViewUtils; +// TODO: Auto-generated Javadoc +/** + * The Class EFVRT_30. + */ public class EFVRT_30 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_40.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_40.java index 35ed3849b..937ed842a 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_40.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/EFVRT_40.java @@ -26,8 +26,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.core.views.ViewUtils; +// TODO: Auto-generated Javadoc +/** + * The Class EFVRT_40. + */ public class EFVRT_40 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_02.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_02.java index 64201ce54..80c62add0 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_02.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_02.java @@ -26,8 +26,15 @@ import org.eclipse.emf.validation.AbstractModelConstraint; import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.chessmlprofile.util.Constants; +// TODO: Auto-generated Javadoc +/** + * The Class FV_02. + */ public class FV_02 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_03.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_03.java index f6afe3b0a..a8d218ffd 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_03.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_03.java @@ -37,8 +37,15 @@ import org.eclipse.emf.validation.IValidationContext; import org.eclipse.emf.validation.model.ConstraintStatus; import org.polarsys.chess.chessmlprofile.util.Constants; +// TODO: Auto-generated Javadoc +/** + * The Class FV_03. + */ public class FV_03 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); @@ -117,6 +124,13 @@ public class FV_03 extends AbstractModelConstraint { } + /** + * Compare operations. + * + * @param op1 the op1 + * @param op2 the op2 + * @return the boolean + */ private Boolean compareOperations(Operation op1, Operation op2) { Boolean result = true; @@ -156,6 +170,12 @@ public class FV_03 extends AbstractModelConstraint { return result; } + /** + * Removes the return parameter. + * + * @param ownedParameters the owned parameters + * @return the collection + */ private Collection<Parameter> removeReturnParameter( EList<Parameter> ownedParameters) { Collection<Parameter> result = new ArrayList<Parameter>(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_04.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_04.java index eb3ac7aa4..276686abe 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_04.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_04.java @@ -36,8 +36,15 @@ import org.eclipse.emf.validation.IValidationContext; import org.eclipse.emf.validation.model.ConstraintStatus; import org.polarsys.chess.chessmlprofile.util.Constants; +// TODO: Auto-generated Javadoc +/** + * The Class FV_04. + */ public class FV_04 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); @@ -100,6 +107,13 @@ public class FV_04 extends AbstractModelConstraint { } + /** + * Compare operations. + * + * @param op1 the op1 + * @param op2 the op2 + * @return the boolean + */ private Boolean compareOperations(Operation op1, Operation op2) { Boolean result = true; @@ -139,6 +153,12 @@ public class FV_04 extends AbstractModelConstraint { return result; } + /** + * Removes the return parameter. + * + * @param ownedParameters the owned parameters + * @return the collection + */ private Collection<Parameter> removeReturnParameter( EList<Parameter> ownedParameters) { Collection<Parameter> result = new ArrayList<Parameter>(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_05.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_05.java index b52e1c4ad..efaef30e1 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_05.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_05.java @@ -38,8 +38,15 @@ import org.eclipse.emf.validation.IValidationContext; import org.eclipse.emf.validation.model.ConstraintStatus; import org.polarsys.chess.chessmlprofile.util.Constants; +// TODO: Auto-generated Javadoc +/** + * The Class FV_05. + */ public class FV_05 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_06.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_06.java index 0298e145b..21206a84f 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_06.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_06.java @@ -38,8 +38,15 @@ import org.eclipse.emf.validation.IValidationContext; import org.eclipse.emf.validation.model.ConstraintStatus; import org.polarsys.chess.chessmlprofile.util.Constants; +// TODO: Auto-generated Javadoc +/** + * The Class FV_06. + */ public class FV_06 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_07.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_07.java index bb1516cdf..094d7cc75 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_07.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FV_07.java @@ -26,8 +26,15 @@ import org.eclipse.emf.validation.IValidationContext; import org.polarsys.chess.chessmlprofile.util.Constants; +// TODO: Auto-generated Javadoc +/** + * The Class FV_07. + */ public class FV_07 extends AbstractModelConstraint { + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ @Override public IStatus validate(IValidationContext ctx) { EObject eObject = ctx.getTarget(); diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_01.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_01.java index 250de910f..ee9826603 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_01.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_01.java @@ -1,47 +1,57 @@ -package org.polarsys.chess.validator.constraints; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.validation.AbstractModelConstraint; -import org.eclipse.emf.validation.IValidationContext; -import org.eclipse.uml2.uml.Abstraction; -import org.eclipse.uml2.uml.Dependency; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.Port; -import org.polarsys.chess.core.util.uml.UMLUtils; - -public class FlowPorts_01 extends AbstractModelConstraint { - - public static final String FLOWPORT = "MARTE::MARTE_DesignModel::GCM::FlowPort"; - public static final String ALLOCATE = "MARTE::MARTE_Foundations::Alloc::Allocate"; - - @Override - public IStatus validate(IValidationContext ctx) { - - IStatus success = ctx.createSuccessStatus(); - IStatus failure = ctx.createFailureStatus(); - - Port port = (Port) ctx.getTarget(); - if(port.getAppliedStereotype(FLOWPORT) == null){ - return success; - } - - Element owner = port.getOwner(); - if(!UMLUtils.isComponentType(owner)){ - return success; - } - - /* if it is a flow port of a component type it must have at least a mapping to a parameter - * (the validity of such mapping is checked through other constraints) - */ - - EList<Dependency> dependencies = port.getClientDependencies(); - for (Dependency dep : dependencies) { - if (dep instanceof Abstraction && dep.getAppliedStereotype(ALLOCATE) != null){ - return success; - } - } - return failure; - } - -} +package org.polarsys.chess.validator.constraints; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.validation.AbstractModelConstraint; +import org.eclipse.emf.validation.IValidationContext; +import org.eclipse.uml2.uml.Abstraction; +import org.eclipse.uml2.uml.Dependency; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Port; +import org.polarsys.chess.core.util.uml.UMLUtils; + +// TODO: Auto-generated Javadoc +/** + * The Class FlowPorts_01. + */ +public class FlowPorts_01 extends AbstractModelConstraint { + + /** The Constant FLOWPORT. */ + public static final String FLOWPORT = "MARTE::MARTE_DesignModel::GCM::FlowPort"; + + /** The Constant ALLOCATE. */ + public static final String ALLOCATE = "MARTE::MARTE_Foundations::Alloc::Allocate"; + + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ + @Override + public IStatus validate(IValidationContext ctx) { + + IStatus success = ctx.createSuccessStatus(); + IStatus failure = ctx.createFailureStatus(); + + Port port = (Port) ctx.getTarget(); + if(port.getAppliedStereotype(FLOWPORT) == null){ + return success; + } + + Element owner = port.getOwner(); + if(!UMLUtils.isComponentType(owner)){ + return success; + } + + /* if it is a flow port of a component type it must have at least a mapping to a parameter + * (the validity of such mapping is checked through other constraints) + */ + + EList<Dependency> dependencies = port.getClientDependencies(); + for (Dependency dep : dependencies) { + if (dep instanceof Abstraction && dep.getAppliedStereotype(ALLOCATE) != null){ + return success; + } + } + return failure; + } + +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_02.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_02.java index 20d19fd2d..c52c8251f 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_02.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_02.java @@ -1,57 +1,64 @@ -package org.polarsys.chess.validator.constraints; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.validation.AbstractModelConstraint; -import org.eclipse.emf.validation.IValidationContext; -import org.eclipse.uml2.uml.Abstraction; -import org.eclipse.uml2.uml.Dependency; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.NamedElement; -import org.eclipse.uml2.uml.Parameter; -import org.eclipse.uml2.uml.Port; -import org.eclipse.uml2.uml.Type; -import org.polarsys.chess.core.util.uml.UMLUtils; - -public class FlowPorts_02 extends AbstractModelConstraint { - - @Override - public IStatus validate(IValidationContext ctx) { - IStatus success = ctx.createSuccessStatus(); - IStatus failure = ctx.createFailureStatus(); - - Port port = (Port) ctx.getTarget(); - if(port.getAppliedStereotype(FlowPorts_01.FLOWPORT) == null){ - return success; - } - - Element owner = port.getOwner(); - if(!UMLUtils.isComponentType(owner)){ - return success; - } - - /* if it is a flow port of a component type, each of its mapped parameters should have the same type as the port - * - * note: creating a mapping will avoid this issue, but changing the type of the port - * or of another parameter at a different time is possible and will result in an erratic situation - */ - Type portType = port.getType(); - EList<Dependency> dependencies = port.getClientDependencies(); - for (Dependency dep : dependencies) { - if (dep instanceof Abstraction && dep.getAppliedStereotype(FlowPorts_01.ALLOCATE) != null){ - EList<NamedElement> suppList = dep.getSuppliers(); - for (NamedElement nElem : suppList) { - if(nElem instanceof Parameter){ - Parameter param = (Parameter) nElem; - if(param.getType() != portType){ - return failure; - } - } - } - } - } - - return success; - } - -} +package org.polarsys.chess.validator.constraints; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.validation.AbstractModelConstraint; +import org.eclipse.emf.validation.IValidationContext; +import org.eclipse.uml2.uml.Abstraction; +import org.eclipse.uml2.uml.Dependency; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.Type; +import org.polarsys.chess.core.util.uml.UMLUtils; + +// TODO: Auto-generated Javadoc +/** + * The Class FlowPorts_02. + */ +public class FlowPorts_02 extends AbstractModelConstraint { + + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ + @Override + public IStatus validate(IValidationContext ctx) { + IStatus success = ctx.createSuccessStatus(); + IStatus failure = ctx.createFailureStatus(); + + Port port = (Port) ctx.getTarget(); + if(port.getAppliedStereotype(FlowPorts_01.FLOWPORT) == null){ + return success; + } + + Element owner = port.getOwner(); + if(!UMLUtils.isComponentType(owner)){ + return success; + } + + /* if it is a flow port of a component type, each of its mapped parameters should have the same type as the port + * + * note: creating a mapping will avoid this issue, but changing the type of the port + * or of another parameter at a different time is possible and will result in an erratic situation + */ + Type portType = port.getType(); + EList<Dependency> dependencies = port.getClientDependencies(); + for (Dependency dep : dependencies) { + if (dep instanceof Abstraction && dep.getAppliedStereotype(FlowPorts_01.ALLOCATE) != null){ + EList<NamedElement> suppList = dep.getSuppliers(); + for (NamedElement nElem : suppList) { + if(nElem instanceof Parameter){ + Parameter param = (Parameter) nElem; + if(param.getType() != portType){ + return failure; + } + } + } + } + } + + return success; + } + +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_03.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_03.java index 036a791eb..22501e226 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_03.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/FlowPorts_03.java @@ -1,84 +1,98 @@ -package org.polarsys.chess.validator.constraints; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.validation.AbstractModelConstraint; -import org.eclipse.emf.validation.IValidationContext; -import org.eclipse.uml2.uml.Abstraction; -import org.eclipse.uml2.uml.Component; -import org.eclipse.uml2.uml.Dependency; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.NamedElement; -import org.eclipse.uml2.uml.Operation; -import org.eclipse.uml2.uml.Parameter; -import org.eclipse.uml2.uml.Port; -import org.polarsys.chess.core.util.uml.UMLUtils; - -public class FlowPorts_03 extends AbstractModelConstraint { - - @Override - public IStatus validate(IValidationContext ctx) { - IStatus success = ctx.createSuccessStatus(); - IStatus failure = ctx.createFailureStatus(); - - Port port = (Port) ctx.getTarget(); - if(port.getAppliedStereotype(FlowPorts_01.FLOWPORT) == null){ - return success; - } - - Element owner = port.getOwner(); - if(!UMLUtils.isComponentType(owner)){ - return success; - } - - /* if it is a flow port of a component type, each of its mapped parameters should have the direction consistent. ie: - * port direction IN -> param direction IN or INOUT (param of PROVIDED operation) - * port direction OUT -> param direction OUT or INOUT (param of PROVIDED operation) - * port direction IN -> param direction OUT or INOUT (param of REQUIRED operation) - * port direction OUT -> param direction IN or INOUT (param of REQUIRED operation) - * port direction INOUT -> param direction IN or OUT orINOUT (param of REQUIRED or PROVIDED operation) - * note: creating a mapping will avoid this issue, but changing the direction of the port - * or of another parameter at a different time is possible and may result in an erratic situation - */ - Component comp = (Component) owner; - String portDirection = port.getValue(port.getAppliedStereotype(FlowPorts_01.FLOWPORT), "direction").toString(); - EList<Dependency> dependencies = port.getClientDependencies(); - for (Dependency dep : dependencies) { - if (dep instanceof Abstraction && dep.getAppliedStereotype(FlowPorts_01.ALLOCATE) != null){ - EList<NamedElement> suppList = dep.getSuppliers(); - for (NamedElement nElem : suppList) { - if(nElem instanceof Parameter){ - Parameter param = (Parameter) nElem; - String paramDirection = param.getDirection().toString(); - Operation op = param.getOperation(); - if(provided(op, comp)){ - if((portDirection.equals("in") && paramDirection.equals("out")) || - (portDirection.equals("out") && paramDirection.equals("in"))){ - return failure; - } - }else{ - if((portDirection.equals("in") && paramDirection.equals("in")) || - (portDirection.equals("out") && paramDirection.equals("out"))){ - return failure; - } - } - } - } - } - } - - return null; - } - - private boolean provided(Operation op, Component comp) { - boolean provided = false; - for (Operation operation : comp.getAllOperations()) { - if(operation.getName().equals(op.getName())){ - provided = true; - break; - } - } - return provided; - } - -} +package org.polarsys.chess.validator.constraints; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.validation.AbstractModelConstraint; +import org.eclipse.emf.validation.IValidationContext; +import org.eclipse.uml2.uml.Abstraction; +import org.eclipse.uml2.uml.Component; +import org.eclipse.uml2.uml.Dependency; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Operation; +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.uml2.uml.Port; +import org.polarsys.chess.core.util.uml.UMLUtils; + +// TODO: Auto-generated Javadoc +/** + * The Class FlowPorts_03. + */ +public class FlowPorts_03 extends AbstractModelConstraint { + + /* (non-Javadoc) + * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext) + */ + @Override + public IStatus validate(IValidationContext ctx) { + IStatus success = ctx.createSuccessStatus(); + IStatus failure = ctx.createFailureStatus(); + + Port port = (Port) ctx.getTarget(); + if(port.getAppliedStereotype(FlowPorts_01.FLOWPORT) == null){ + return success; + } + + Element owner = port.getOwner(); + if(!UMLUtils.isComponentType(owner)){ + return success; + } + + /* if it is a flow port of a component type, each of its mapped parameters should have the direction consistent. ie: + * port direction IN -> param direction IN or INOUT (param of PROVIDED operation) + * port direction OUT -> param direction OUT or INOUT (param of PROVIDED operation) + * port direction IN -> param direction OUT or INOUT (param of REQUIRED operation) + * port direction OUT -> param direction IN or INOUT (param of REQUIRED operation) + * port direction INOUT -> param direction IN or OUT orINOUT (param of REQUIRED or PROVIDED operation) + * note: creating a mapping will avoid this issue, but changing the direction of the port + * or of another parameter at a different time is possible and may result in an erratic situation + */ + Component comp = (Component) owner; + String portDirection = port.getValue(port.getAppliedStereotype(FlowPorts_01.FLOWPORT), "direction").toString(); + EList<Dependency> dependencies = port.getClientDependencies(); + for (Dependency dep : dependencies) { + if (dep instanceof Abstraction && dep.getAppliedStereotype(FlowPorts_01.ALLOCATE) != null){ + EList<NamedElement> suppList = dep.getSuppliers(); + for (NamedElement nElem : suppList) { + if(nElem instanceof Parameter){ + Parameter param = (Parameter) nElem; + String paramDirection = param.getDirection().toString(); + Operation op = param.getOperation(); + if(provided(op, comp)){ + if((portDirection.equals("in") && paramDirection.equals("out")) || + (portDirection.equals("out") && paramDirection.equals("in"))){ + return failure; + } + }else{ + if((portDirection.equals("in") && paramDirection.equals("in")) || + (portDirection.equals("out") && paramDirection.equals("out"))){ + return failure; + } + } + } + } + } + } + + return null; + } + + /** + * Provided. + * + * @param op the op + * @param comp the comp + * @return true, if successful + */ + private boolean provided(Operation op, Component comp) { + boolean provided = false; + for (Operation operation : comp.getAllOperations()) { + if(operation.getName().equals(op.getName())){ + provided = true; + break; + } + } + return provided; + } + +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/StringParser.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/StringParser.java index 7c79a87f7..d1688d64f 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/StringParser.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/constraints/StringParser.java @@ -1,62 +1,87 @@ -/* ------------------------------------------------------------------------ --- CHESS Live/Batch Validator plugin -- --- -- --- Copyright (C) 2011-2012 -- --- University of Padova, ITALY -- --- -- --- Author: Alessandro Zovi azovi@math.unipd.it -- --- -- --- 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 -- ------------------------------------------------------------------------ -*/ -package org.polarsys.chess.validator.constraints; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class StringParser { - //String value = "PeriodicPattern(period(value=40,unit=ms),..)"; - // ex: WCET -> "(value=40, unit=ms)" - -public double getValuePattern(String value, String toSearch) { - - String[] array = value.split("[()=, ]"); - for(int i=0; i<array.length-1; i++) { - for(int j=i+1; j<array.length; j++) { - if(array[i].equalsIgnoreCase(toSearch) && array[j].equalsIgnoreCase("value")) { - String d = array[j+1]; - return Double.valueOf(d.trim()); - } - } - } - return -1; - } - - public String getComplexValuePattern(String value, String toSearch, String delimiter) { - String[] array = value.split("[()=, ]"); - Pattern p = Pattern.compile(".*"+toSearch+".*value.*"+delimiter+"(.*)"+delimiter+"", Pattern.CASE_INSENSITIVE); - Matcher m = p.matcher(value); - String group = ""; - if(m.find()){ - group = m.group(1); - } - - return group; - } - - public double getValueNFP(String value) { - String[] array = value.split("[()=,]"); - for(int i=0; i<array.length-1; i++) { - if(array[i].trim().equalsIgnoreCase("value")) { - String d = array[i+1].trim(); - return Double.valueOf(d); - } - } - return -1; - } - -} +/* +----------------------------------------------------------------------- +-- CHESS Live/Batch Validator plugin -- +-- -- +-- Copyright (C) 2011-2012 -- +-- University of Padova, ITALY -- +-- -- +-- Author: Alessandro Zovi azovi@math.unipd.it -- +-- -- +-- 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 -- +----------------------------------------------------------------------- +*/ +package org.polarsys.chess.validator.constraints; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +// TODO: Auto-generated Javadoc +/** + * The Class StringParser. + */ +public class StringParser { + //String value = "PeriodicPattern(period(value=40,unit=ms),..)"; + // ex: WCET -> "(value=40, unit=ms)" + +/** + * Gets the value pattern. + * + * @param value the value + * @param toSearch the to search + * @return the value pattern + */ + public double getValuePattern(String value, String toSearch) { + + String[] array = value.split("[()=, ]"); + for(int i=0; i<array.length-1; i++) { + for(int j=i+1; j<array.length; j++) { + if(array[i].equalsIgnoreCase(toSearch) && array[j].equalsIgnoreCase("value")) { + String d = array[j+1]; + return Double.valueOf(d.trim()); + } + } + } + return -1; + } + + /** + * Gets the complex value pattern. + * + * @param value the value + * @param toSearch the to search + * @param delimiter the delimiter + * @return the complex value pattern + */ + public String getComplexValuePattern(String value, String toSearch, String delimiter) { + String[] array = value.split("[()=, ]"); + Pattern p = Pattern.compile(".*"+toSearch+".*value.*"+delimiter+"(.*)"+delimiter+"", Pattern.CASE_INSENSITIVE); + Matcher m = p.matcher(value); + String group = ""; + if(m.find()){ + group = m.group(1); + } + + return group; + } + + /** + * Gets the value nfp. + * + * @param value the value + * @return the value nfp + */ + public double getValueNFP(String value) { + String[] array = value.split("[()=,]"); + for(int i=0; i<array.length-1; i++) { + if(array[i].trim().equalsIgnoreCase("value")) { + String d = array[i+1].trim(); + return Double.valueOf(d); + } + } + return -1; + } + +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ActionsLib.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/libs/ActionsLib.java similarity index 97% rename from plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ActionsLib.java rename to plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/libs/ActionsLib.java index 7354eac92..0280874bc 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ActionsLib.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/libs/ActionsLib.java @@ -14,7 +14,7 @@ ----------------------------------------------------------------------- */ -package org.polarsys.chess.validator.managers; +package org.polarsys.chess.validator.libs; import java.util.ArrayList; @@ -69,10 +69,16 @@ import org.polarsys.chess.core.util.uml.UMLUtils; import org.polarsys.chess.core.views.ViewUtils; import org.polarsys.chess.service.utils.CHESSEditorUtils; import org.polarsys.chess.validator.Activator; -import org.polarsys.chess.validator.AddDiagramElement; +import org.polarsys.chess.validator.managers.AddDiagramElement; +import org.polarsys.chess.validator.messages.Messages; +// TODO: Auto-generated Javadoc +/** + * The Class ActionsLib contains the implementation of the Automated Actions + */ public class ActionsLib { + /** The port modification action. */ public static IAutomatedAction portModificationAction = new IAutomatedAction() { @Override public Command compile(Notification notification, List<Notification> notificationList, @@ -137,6 +143,7 @@ public class ActionsLib { } }; + /** The port removal action. */ public static IAutomatedAction portRemovalAction = new IAutomatedAction() { @Override public Command compile(Notification notification, List<Notification> notificationList, @@ -176,6 +183,7 @@ public class ActionsLib { /* * inherited operations are automatically added */ + /** The component interface realization action. */ public static IAutomatedAction componentInterfaceRealizationAction = new IAutomatedAction() { @Override public Command compile(Notification notification, List<Notification> notificationList, @@ -197,6 +205,7 @@ public class ActionsLib { } }; + /** The component realization action. */ public static IAutomatedAction componentRealizationAction = new IAutomatedAction() { @Override public Command compile(Notification notification, List<Notification> notificationList, @@ -235,6 +244,7 @@ public class ActionsLib { }; + /** The remove realization operations action. */ public static IAutomatedAction removeRealizationOperationsAction = new IAutomatedAction() { private IStatus operationAborted = new Status(IStatus.ERROR, @@ -385,6 +395,7 @@ public class ActionsLib { } }; + /** The propagate operation modification. */ public static IAutomatedAction propagateOperationModification = new IAutomatedAction() { @Override @@ -439,6 +450,7 @@ public class ActionsLib { }; + /** The propagate interface modification. */ public static IAutomatedAction propagateInterfaceModification = new IAutomatedAction() { private IStatus operationAborted = new Status(IStatus.ERROR, @@ -557,6 +569,7 @@ public class ActionsLib { }; + /** The propagate parameter removal action. */ public static IAutomatedAction propagateParameterRemovalAction = new IAutomatedAction() { @Override @@ -645,6 +658,7 @@ public class ActionsLib { } }; + /** The propagate parameter addition action. */ public static IAutomatedAction propagateParameterAdditionAction = new IAutomatedAction() { @Override @@ -697,6 +711,7 @@ public class ActionsLib { }; + /** The comment action. */ public static IAutomatedAction commentAction = new IAutomatedAction() { @Override @@ -716,6 +731,7 @@ public class ActionsLib { } }; + /** The port addition action. */ public static IAutomatedAction portAdditionAction = new IAutomatedAction() { @Override public Command compile(Notification notification, @@ -742,6 +758,7 @@ public class ActionsLib { }; + /** The propagate port modification. */ public static IAutomatedAction propagatePortModification = new IAutomatedAction() { @Override @@ -810,7 +827,8 @@ public class ActionsLib { // propagateParameterRemovalAction, propagateParameterAdditionAction, // commentAction, portAdditionAction, propagatePortModification}; - public static IAutomatedAction[] actionList = {portModificationAction, + /** The action list. */ +public static IAutomatedAction[] actionList = {portModificationAction, componentInterfaceRealizationAction, componentRealizationAction, commentAction}; diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ConstraintsLib.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/libs/ConstraintsLib.java similarity index 97% rename from plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ConstraintsLib.java rename to plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/libs/ConstraintsLib.java index 9f37461ef..408fabb57 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ConstraintsLib.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/libs/ConstraintsLib.java @@ -14,7 +14,7 @@ ----------------------------------------------------------------------- */ -package org.polarsys.chess.validator.managers; +package org.polarsys.chess.validator.libs; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.BasicEList; @@ -51,8 +51,10 @@ import org.polarsys.chess.core.util.uml.ProfileUtils; import org.polarsys.chess.core.util.uml.UMLUtils; import org.polarsys.chess.core.views.DiagramStatus.DesignView; import org.polarsys.chess.core.views.ViewUtils; +import org.polarsys.chess.validator.managers.ViewManager; +// TODO: Auto-generated Javadoc /* * Framework usage: * @@ -76,14 +78,24 @@ import org.polarsys.chess.core.views.ViewUtils; +/** + * The Class ConstraintsLib contains the implementation of Dynamic Constraints + */ public class ConstraintsLib { + /** The Constant CSPORT. */ protected static final String CSPORT = "MARTE::MARTE_DesignModel::GCM::ClientServerPort"; + /** The viewmgr. */ private static ViewManager viewmgr = ViewManager.loadViewManager(); + /** The successfully verified. */ static boolean successfullyVerified; + + /** The diagram. */ static Diagram diagram = null; + + /** The notifier. */ static Object notifier; @@ -92,6 +104,7 @@ public class ConstraintsLib { * @FilterableDynamicConstraint R_S_1 * */ + /** The R_ s_1. */ public static FilterableDynamicConstraint R_S_1 = new FilterableDynamicConstraint("R_S_1", IConstraint.ERROR, "A predefined profile cannot be removed") { @Override @@ -111,6 +124,7 @@ public class ConstraintsLib { /* * @FilterableDynamicConstraint V_SR_1 */ + /** The V_ s r_1. */ public static FilterableDynamicConstraint V_SR_1 = new FilterableDynamicConstraint("V_SR_1", IConstraint.ERROR, "A view cannot be modified or removed") { @Override @@ -129,6 +143,7 @@ public class ConstraintsLib { * @FilterableDynamicConstraint S_S_1 * a predefined stereotype cannot be removed */ + /** The S_ s_1. */ public static FilterableDynamicConstraint S_S_1 = new FilterableDynamicConstraint("S_S_1", IConstraint.ERROR, "a predefined stereotype cannot be removed") { @Override @@ -156,6 +171,7 @@ public class ConstraintsLib { * @FilterableDynamicConstraint M_A_1 * cannot apply profiles */ + /** The M_ a_1. */ public static FilterableDynamicConstraint M_A_1 = new FilterableDynamicConstraint("M_A_1", IConstraint.ERROR, "Cannot apply further profiles in the model") { @Override @@ -176,6 +192,7 @@ public class ConstraintsLib { * @FilterableDynamicConstraint C_A_1 * Interface realization is not allowed because owned operations does not match. */ + /** The C_ a_1. */ public static FilterableDynamicConstraint C_A_1 = new FilterableDynamicConstraint("C_A_1", IConstraint.ERROR, "Interface realization is not allowed because owned operations does not match.") { @Override @@ -253,6 +270,7 @@ public class ConstraintsLib { * FilterableDynamicConstraint O_S_1 * Interface operations in the Functional View must have public visibility. */ + /** The O_ s_1. */ public static FilterableDynamicConstraint O_S_1 = new FilterableDynamicConstraint("O_S_1", IConstraint.ERROR, "Interface operations in the Functional View must have public visibility.") { @Override @@ -279,6 +297,7 @@ public class ConstraintsLib { }; + /** The Add remove dependency. */ public static FilterableDynamicConstraint AddRemoveDependency = new FilterableDynamicConstraint("ADD_REMOVEDependency", IConstraint.ERROR, "Cannot modify dependency for ComponentType") { @Override @@ -326,7 +345,8 @@ public class ConstraintsLib { * @FilterableDynamicConstraint P_T_1 * view stereotype cannot be applied */ - public static FilterableDynamicConstraint P_T_1 = + /** The P_ t_1. */ +public static FilterableDynamicConstraint P_T_1 = new FilterableDynamicConstraint("P_T_1", IConstraint.ERROR, "Appling a view stereotype is forbidden.") { @Override public boolean checkConstraint(Notification notification, DesignView currentView) { @@ -347,6 +367,7 @@ public class ConstraintsLib { * @FilterableDynamicConstraint P_A_1 * an interface can be added only in functionalView or deploymentView */ + /** The P_ a_1. */ public static FilterableDynamicConstraint P_A_1 = new FilterableDynamicConstraint("P_A_1", IConstraint.ERROR, "Creation of interfaces is only allowed in the Functional View and Deployment View.") { @@ -446,6 +467,7 @@ public class ConstraintsLib { // } // }; + /** The E_ s_1_ new. */ public static DynamicConstraint E_S_1_NEW = new DynamicConstraint("E_S_1", IConstraint.ERROR, "The view \"{0}\" has no write access on the {1} \"{2}\", therefore it cannot be modified.") { @@ -502,6 +524,7 @@ public class ConstraintsLib { }; + /** The check modified operation. */ public static FilterableDynamicConstraint checkModifiedOperation = new FilterableDynamicConstraint("ModifiedOperation", IConstraint.WARNING, "Cannot modify inherited operations.") { diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/CrossViewActionLib.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/libs/CrossViewActionLib.java similarity index 85% rename from plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/CrossViewActionLib.java rename to plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/libs/CrossViewActionLib.java index b79d97e77..c072c8aa8 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/CrossViewActionLib.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/libs/CrossViewActionLib.java @@ -14,7 +14,7 @@ ----------------------------------------------------------------------- */ -package org.polarsys.chess.validator.managers; +package org.polarsys.chess.validator.libs; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.impl.DynamicEObjectImpl; @@ -31,8 +31,22 @@ import org.eclipse.uml2.uml.Stereotype; import org.eclipse.uml2.uml.util.UMLUtil; import org.polarsys.chess.core.views.ViewUtils; import org.polarsys.chess.core.views.DiagramStatus.DesignView; +import org.polarsys.chess.validator.managers.ViewManager; +// TODO: Auto-generated Javadoc +/** + * The Class CrossViewActionLib. + */ public class CrossViewActionLib { + + /** + * Cross view deployment action. + * + * @param notifier the Object notifier + * @param notification the notification + * @param currentView the Package representing the current view + * @return true, if successful + */ public static boolean crossViewDeploymentAction(Object notifier, Notification notification, Package currentView) { PapyrusMultiDiagramEditor editor = (PapyrusMultiDiagramEditor) PlatformUI @@ -60,6 +74,14 @@ public class CrossViewActionLib { return false; } + /** + * Cross view deployment action. + * + * @param notifier the Object notifier + * @param notification the notification + * @param currentView the DesignView representing current view + * @return true, if successful + */ public static boolean crossViewDeploymentAction(Object notifier, Notification notification, DesignView currentView) { PapyrusMultiDiagramEditor editor = (PapyrusMultiDiagramEditor) PlatformUI diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/AddDiagramElement.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/AddDiagramElement.java similarity index 86% rename from plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/AddDiagramElement.java rename to plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/AddDiagramElement.java index 12cd803c3..f1d45505e 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/AddDiagramElement.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/AddDiagramElement.java @@ -14,7 +14,7 @@ ----------------------------------------------------------------------- */ -package org.polarsys.chess.validator; +package org.polarsys.chess.validator.managers; import java.util.ArrayList; import java.util.List; @@ -72,9 +72,22 @@ import org.polarsys.chess.core.views.ViewUtils; import org.polarsys.chess.service.utils.CHESSEditorUtils; +// TODO: Auto-generated Javadoc +/** + * The Class AddDiagramElement contains Commands to create new elements in the model + * and adds them to the current diagram, if possible + */ @SuppressWarnings("restriction") public class AddDiagramElement { + /** + * Creates an interface realization from a Component to the Interface provided by its Port + * + * @param domain the TransactionalEditingDomain of the model + * @param comp the Component owner of the port + * @param port the ClientServerPort providing and Interface + * @return the command + */ public static Command createDependencies(TransactionalEditingDomain domain, final Component comp, final ClientServerPort port){ return new RecordingCommand(domain) { @@ -133,6 +146,13 @@ public class AddDiagramElement { }; } + /** + * Removes dependencies from the model + * + * @param domain the TransactionalEditingDomain of the model + * @param deps the dependencies to be removed + * @return the command + */ public static Command destroyDependencies(TransactionalEditingDomain domain, final EList<? extends Dependency> deps){ return new RecordingCommand(domain) { @Override @@ -145,6 +165,14 @@ public class AddDiagramElement { } + /** + * Adds all the operations contained in a Classifier interf to a Component comp + * + * @param domain the TransactionalEditingDomain of the model + * @param interf the Classifier containing the operations + * @param comp the Component where the operation will be copied + * @return the command + */ public static Command addOperationCommand( TransactionalEditingDomain domain, final Classifier interf, final Component comp) { @@ -250,7 +278,15 @@ public class AddDiagramElement { // } // } - public static Command addAllPortsCommand(TransactionalEditingDomain domain, final Component providerComp, final Component clientComp) { + /** + * Adds all the ports contained in a Component providerComp to a Component clientComp + * + * @param domain the TransactionalEditingDomain of the model + * @param providerComp the Component containing the ports + * @param clientComp the Component where the ports will be copied + * @return the command + */ +public static Command addAllPortsCommand(TransactionalEditingDomain domain, final Component providerComp, final Component clientComp) { return new RecordingCommand(domain) { @Override protected void doExecute() { @@ -366,8 +402,18 @@ public class AddDiagramElement { - public static Command addPortCommand(TransactionalEditingDomain domain, final Component providerComp, final Component clientComp, final Port supplierPort) { - return new RecordingCommand(domain) { + +/** + * Adds the specified supplierPort contained in a Component providerComp to a Component clientComp + * + * @param domain the TransactionalEditingDomain of the model + * @param providerComp the Component containing the port + * @param clientComp the Component where the port will be copied + * @param supplierPort the supplier port + * @return the command + */ +public static Command addPortCommand(TransactionalEditingDomain domain, final Component providerComp, final Component clientComp, final Port supplierPort) { + return new RecordingCommand(domain) { @Override protected void doExecute() { //addClientServerPort(comp, interf.getClientDependencies()); @@ -391,6 +437,15 @@ public class AddDiagramElement { //add operation to the interface's clients + /** + * Copies an operation from an Interface to all the Component Type that realizes the Interface + * and to all the ComponentImplementation that realizes the ComponentType(s) + * + * @param domain the TransactionalEditingDomain of the model + * @param interf the Interface containing the operation + * @param operation the Operation to be copied + * @return the command + */ public static Command addOperationCommand1(TransactionalEditingDomain domain, final Interface interf, final Operation operation){ return new RecordingCommand(domain) { @@ -458,6 +513,12 @@ public class AddDiagramElement { }*/ + /** + * Creates a graphical action for a new Operation added to to a Component + * + * @param containerComp the container Component + * @param newOp the new Operation + */ private static void createGraphicalOperation(Component containerComp, Operation newOp){ IMultiDiagramEditor editor = EditorUtils.getMultiDiagramEditor(); /*ISashWindowsContainer container = null; @@ -522,6 +583,12 @@ public class AddDiagramElement { } + /** + * Creates a graphical action for a new Port added to to a Component + * + * @param containerComp the container Component + * @param port the new Port + */ private static void createGraphicalPort(Component containerComp, Port port){ IMultiDiagramEditor editor = EditorUtils.getMultiDiagramEditor(); Diagram diagram = (Diagram)editor.getAdapter(Diagram.class); @@ -557,7 +624,13 @@ public class AddDiagramElement { } - //adds a Comment stereotyped with Assign to the assignList of the deployment view + /** + * Adds the specified Comment stereotyped with Assign to the assignList of the deployment view + * + * @param domain the TransactionalEditingDomain of the model + * @param comm the Comment stereotyped as <<Assign>> to be added + * @return the command + */ public static Command addCommentCommand( TransactionalEditingDomain domain, final Comment comm) { @@ -593,7 +666,14 @@ public class AddDiagramElement { } }; } - + + /** + * Removes the specified Comment stereotyped with Assign to the assignList of the deployment view + * + * @param domain the TransactionalEditingDomain of the model + * @param comm the Comment stereotyped as <<Assign>> to be removed + * @return the command + */ public static Command removeCommentCommand( TransactionalEditingDomain domain, final Comment comm) { @@ -629,6 +709,16 @@ public class AddDiagramElement { } + /** + * Copies the specified parameter added to an operation of an interface to the + * corresponding operation in the Components that realize the interface + * + * @param opCont the Interface containing the operation + * @param param the Parameter to be copied + * @param operation the Operation containing the parameter + * @param TransactionalEditingDomain of the model + * @return the command + */ public static Command addParameterCommand(final Interface opCont, final Parameter param, final Operation operation, TransactionalEditingDomain domain) { return new RecordingCommand(domain) { @@ -652,7 +742,15 @@ public class AddDiagramElement { } - //TODO very similar to addAllPortsCommand: refactor? + /** + * Updates the ports, stereotyped as <<ClientServerPort>>, of the ComponentImplementations + * + * @see addAllPortsCommand + * + * @param domain the TransactionalEditingDomain of the model + * @param cspSupplied the Port stereotyped as <<ClientServerPort>> + * @return the command + */ public static Command updateImplementationsPorts( TransactionalEditingDomain domain, final ClientServerPort cspSupplied) { @@ -687,6 +785,15 @@ public class AddDiagramElement { } + /** + * Updates the ports, stereotyped as <<FlowPort>>, of the ComponentImplementations + * + * @see addAllPortsCommand + * + * @param domain the TransactionalEditingDomain of the model + * @param flPort the Port stereotyped as <<FlowPort>> + * @return the command + */ public static Command updateImplementationsFlowPorts( TransactionalEditingDomain domain, final FlowPort flPort) { @@ -718,6 +825,13 @@ public class AddDiagramElement { } + /** + * Removes the specified port of the ComponentImplementations + * + * @param domain the TransactionalEditingDomain of the model + * @param supplierPort the Port to be removed + * @return the command + */ public static Command removeImplementationsPorts( TransactionalEditingDomain domain, final Port supplierPort) { diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ModelManager.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ModelManager.java index 02df861db..ca9a203ae 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ModelManager.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ModelManager.java @@ -1,131 +1,157 @@ -/* ------------------------------------------------------------------------ --- CHESS validator plugin -- --- -- --- Copyright (C) 2011-2012 -- --- University of Padova, ITALY -- --- -- --- Author: Alessandro Zovi azovi@math.unipd.it -- --- -- --- 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 -- ------------------------------------------------------------------------ -*/ - -package org.polarsys.chess.validator.managers; - -import java.util.List; - -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.edit.command.SetCommand; -import org.eclipse.emf.transaction.RollbackException; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; -import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper; -import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; -import org.eclipse.uml2.uml.Component; -import org.eclipse.uml2.uml.Interface; -import org.eclipse.uml2.uml.NamedElement; -import org.eclipse.uml2.uml.Operation; -import org.eclipse.uml2.uml.Package; -import org.eclipse.uml2.uml.Parameter; -import org.eclipse.uml2.uml.Type; -import org.polarsys.chess.core.automatedActions.IAutomatedAction; -import org.polarsys.chess.core.util.uml.UMLUtils; -import org.polarsys.chess.core.views.DiagramStatus; -import org.polarsys.chess.core.views.ViewUtils; - -public class ModelManager { - - private static ModelManager instance = new ModelManager(); - - - private ModelManager() { - } - - public static ModelManager loadModelManager() { - return instance; - } - - public Command check(List<Notification> notificationList, Notification notification, - Object _notifier, StringBuffer s, DiagramStatus diagramStatus, - TransactionalEditingDomain domain) throws RollbackException { - - Command command = null; - - Object notifier = notification.getNotifier(); - - for (IAutomatedAction act : ActionsLib.actionList) { - command = act.compile(notification, notificationList, domain); - if (command != null) - return command; - } - - - /* - * @dynamicConstraint T_S_1 this code is used to catch modification that - * occurs on interfaces such that in case the latter are realized by - * some component: we need to perform checks in order to assure that the - * contract of the interface itself is fulfilled - */ - if (notifier instanceof Parameter) { - if (notification.getEventType() == Notification.SET && ((Parameter) notifier).eContainer() instanceof Operation) { - Parameter param = (Parameter) notifier; - Operation op = (Operation) param.eContainer(); - if (op != null && op.eContainer() instanceof Interface) { - Package view = ViewUtils.getView(op.eContainer()); - // we must check whether the classifier belongs to the - // functional view - if (ViewUtils.isComponentView(view)) { - - final Interface intFace = (Interface) op.eContainer(); - EList<NamedElement> relationships = UMLUtils.getInterfaceClients(intFace); - CompositeCommand cmd = new CompositeCommand("setCommand"); - if (relationships != null) { - for (int i = 0; i < relationships.size(); i++) { - if (relationships.get(i) instanceof Component) { - Component comp = (Component) relationships.get(i); - relationships.addAll(UMLUtils.getComponentImplementations(comp)); - - for (Operation cOperation : comp.getOwnedOperations()) { - if (cOperation.getName().equalsIgnoreCase(op.getName())) { - if (notification.getNewValue() instanceof String) { - if (UMLUtils.areParametersEquals(cOperation, op, param)) { - Parameter p = cOperation.getOwnedParameter((String) notification.getOldValue(), param.getType()); - SetCommand setC = new SetCommand(domain, p, (EStructuralFeature) notification.getFeature(), notification.getNewValue()); - cmd.add(new EMFtoGMFCommandWrapper(setC)); - } - } else if (UMLUtils.areParametersEquals(cOperation, op, param)) { - Type type = null; - if (notification.getNewValue() instanceof Type) - type = (Type) notification.getOldValue(); - else - type = param.getType(); - - Parameter p = cOperation.getOwnedParameter(param.getName(), type); - SetCommand setC = new SetCommand(domain, p, (EStructuralFeature) notification.getFeature(), notification.getNewValue()); - cmd.add(new EMFtoGMFCommandWrapper(setC)); - } - } - } - } - } - } - if (cmd.size() > 0) - return new GMFtoEMFCommandWrapper(cmd); - } - } - - } - } - - - - return command; - } -} +/* +----------------------------------------------------------------------- +-- CHESS validator plugin -- +-- -- +-- Copyright (C) 2011-2012 -- +-- University of Padova, ITALY -- +-- -- +-- Author: Alessandro Zovi azovi@math.unipd.it -- +-- -- +-- 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 -- +----------------------------------------------------------------------- +*/ + +package org.polarsys.chess.validator.managers; + +import java.util.List; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.transaction.RollbackException; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; +import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper; +import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; +import org.eclipse.uml2.uml.Component; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Operation; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.uml2.uml.Type; +import org.polarsys.chess.core.automatedActions.IAutomatedAction; +import org.polarsys.chess.core.util.uml.UMLUtils; +import org.polarsys.chess.core.views.DiagramStatus; +import org.polarsys.chess.core.views.ViewUtils; +import org.polarsys.chess.validator.libs.ActionsLib; + +// TODO: Auto-generated Javadoc +/** + * The Class ModelManager. + */ +public class ModelManager { + + /** The instance. */ + private static ModelManager instance = new ModelManager(); + + + /** + * Instantiates a new model manager. + */ + private ModelManager() { + } + + /** + * Load model manager. + * + * @return the model manager + */ + public static ModelManager loadModelManager() { + return instance; + } + + /** + * Check. + * + * @param notificationList the notification list + * @param notification the notification + * @param _notifier the _notifier + * @param s the s + * @param diagramStatus the diagram status + * @param domain the domain + * @return the command + * @throws RollbackException the rollback exception + */ + public Command check(List<Notification> notificationList, Notification notification, + Object _notifier, StringBuffer s, DiagramStatus diagramStatus, + TransactionalEditingDomain domain) throws RollbackException { + + Command command = null; + + Object notifier = notification.getNotifier(); + + for (IAutomatedAction act : ActionsLib.actionList) { + command = act.compile(notification, notificationList, domain); + if (command != null) + return command; + } + + + /* + * @dynamicConstraint T_S_1 this code is used to catch modification that + * occurs on interfaces such that in case the latter are realized by + * some component: we need to perform checks in order to assure that the + * contract of the interface itself is fulfilled + */ + if (notifier instanceof Parameter) { + if (notification.getEventType() == Notification.SET && ((Parameter) notifier).eContainer() instanceof Operation) { + Parameter param = (Parameter) notifier; + Operation op = (Operation) param.eContainer(); + if (op != null && op.eContainer() instanceof Interface) { + Package view = ViewUtils.getView(op.eContainer()); + // we must check whether the classifier belongs to the + // functional view + if (ViewUtils.isComponentView(view)) { + + final Interface intFace = (Interface) op.eContainer(); + EList<NamedElement> relationships = UMLUtils.getInterfaceClients(intFace); + CompositeCommand cmd = new CompositeCommand("setCommand"); + if (relationships != null) { + for (int i = 0; i < relationships.size(); i++) { + if (relationships.get(i) instanceof Component) { + Component comp = (Component) relationships.get(i); + relationships.addAll(UMLUtils.getComponentImplementations(comp)); + + for (Operation cOperation : comp.getOwnedOperations()) { + if (cOperation.getName().equalsIgnoreCase(op.getName())) { + if (notification.getNewValue() instanceof String) { + if (UMLUtils.areParametersEquals(cOperation, op, param)) { + Parameter p = cOperation.getOwnedParameter((String) notification.getOldValue(), param.getType()); + SetCommand setC = new SetCommand(domain, p, (EStructuralFeature) notification.getFeature(), notification.getNewValue()); + cmd.add(new EMFtoGMFCommandWrapper(setC)); + } + } else if (UMLUtils.areParametersEquals(cOperation, op, param)) { + Type type = null; + if (notification.getNewValue() instanceof Type) + type = (Type) notification.getOldValue(); + else + type = param.getType(); + + Parameter p = cOperation.getOwnedParameter(param.getName(), type); + SetCommand setC = new SetCommand(domain, p, (EStructuralFeature) notification.getFeature(), notification.getNewValue()); + cmd.add(new EMFtoGMFCommandWrapper(setC)); + } + } + } + } + } + } + if (cmd.size() > 0) + return new GMFtoEMFCommandWrapper(cmd); + } + } + + } + } + + + + return command; + } +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ModelParser.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ModelParser.java index 7828f4c11..3218961c2 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ModelParser.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ModelParser.java @@ -1,154 +1,180 @@ -/* ------------------------------------------------------------------------ --- CHESS validator plugin -- --- -- --- Copyright (C) 2011-2012 -- --- University of Padova, ITALY -- --- -- --- Author: Alessandro Zovi azovi@math.unipd.it -- --- -- --- 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 -- ------------------------------------------------------------------------ -*/ - -package org.polarsys.chess.validator.managers; - -import java.util.List; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.transaction.RollbackException; -import org.eclipse.jface.preference.IPreferencePage; -import org.eclipse.jface.preference.PreferenceManager; -import org.eclipse.jface.preference.PreferenceNode; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Model; -import org.polarsys.chess.core.constraint.ConstraintList; -import org.polarsys.chess.core.constraint.DynamicConstraint; -import org.polarsys.chess.core.preferences.FilterableConstraint; -import org.polarsys.chess.core.util.CHESSProjectSupport; -import org.polarsys.chess.core.views.DiagramStatus.DesignView; -import org.polarsys.chess.validator.Activator; - -public class ModelParser { - - private IStatus modelOutsideView = new Status(IStatus.ERROR, - Activator.PLUGIN_ID, Messages.NullViewMsg); - - - - public IPreferencePage getId(String id) { - PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager(); - List list = pm.getElements(PreferenceManager.PRE_ORDER); - - for (int i = 0; i < list.size(); i++) { - PreferenceNode node = (PreferenceNode) list.get(i); - IPreferencePage p = node.getPage(); - - if (p != null && node.getId().equals(id)) { - return p; - } - } - return null; - } - - public ModelParser() { - - - PreferenceManager mgr = PlatformUI.getWorkbench().getPreferenceManager(); - - - ConstraintsLib a = new ConstraintsLib(); - //IPreferencePage pp = getId("org.polarsys.chess.preferences.constraints"); - - -// PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn( -// null, -// "org.polarsys.chess.preferences.constraints", -// new String[] {}, null); -// PreferencePage selectedPage = -// (PreferencePage) dialog.getSelectedPage(); -// ((ConstraintPreferencePage)selectedPage).refresh(); -// dialog.close(); - -// for (Object o : mgr.getElements(PreferenceManager.PRE_ORDER)) { -// if (o instanceof IPreferenceNode) { -// IPreferenceNode n = (IPreferenceNode) o; -// if (n.getId().equals("org.polarsys.chess.preferences.constraints")){ -// if (n.getPage() == null) -// n.createPage(); -// ConstraintPreferencePage p = (ConstraintPreferencePage)n.getPage(); -// p.refresh(); -// break; -// } -// } -// } -// List<IPreferenceNode> preferencePageList = castList(IPreferenceNode.class, mgr.getElements(PreferenceManager.PRE_ORDER)); -// IPreferenceNode[] rootSubNodes = mgr.getRootSubNodes(); -// -// IPreferenceNode anode = rootSubNodes[7]; -// -// IPreferenceNode[] installUpadteSubNode = anode.getSubNodes(); -// //anode.remove(installUpadteSubNode[0]); -// PreferenceNode installNode = (PreferenceNode)installUpadteSubNode[0]; -// IPreferencePage page = installNode.getPage(); - } - -// //TODO manage the constraints with a priority list! -// static DynamicConstraint[] constraintList = { -// ConstraintsLib.M_A_1, -// ConstraintsLib.S_S_1, -// ConstraintsLib.C_A_1, -// ConstraintsLib.P_T_1, -// ConstraintsLib.P_A_1, -// ConstraintsLib.O_S_1, -// ConstraintsLib.AddRemoveDependency, -// ConstraintsLib.checkModifiedOperation}; - - public Command check(Notification notification, Object _notifier, DesignView currentView, boolean superuser) throws RollbackException { - Object notifier = notification.getNotifier(); - Command command = null; - if (currentView == null) { - if (notifier instanceof Model && notification.getFeature() instanceof EAttribute && ((EAttribute)notification.getFeature()).getName().equals("name")) - return command; - CHESSProjectSupport.printlnToCHESSConsole(modelOutsideView.getMessage()); - //throw new RollbackException(modelOutsideView); //TODO this Rollback can bring serious problems with Papyrus (loss of data in the model), for the moment we just comment it - return command; - } - - if (!superuser && !ConstraintsLib.E_S_1_NEW.check(notification, currentView).isOK()){ - CHESSProjectSupport.printlnToCHESSConsole(ConstraintsLib.E_S_1_NEW.getMessage()); - throw new RollbackException(ConstraintsLib.E_S_1_NEW.getStatus()); - } - - -// for (FilterableConstraint f: ConstraintList.getList()){ -// System.out.println(f.getConstraint().getName()+" "+f.isActive()); -// } - - for (FilterableConstraint fC: ConstraintList.getList()){ - if (!fC.isActive()) - continue; - DynamicConstraint constr = (DynamicConstraint) fC.getConstraint(); - if (!constr.check(notification, currentView).isOK()){ - CHESSProjectSupport.printlnToCHESSConsole(constr.getMessage()); - throw new RollbackException(constr.getStatus()); - } - } - -// for (DynamicConstraint constr : constraintList) { -// if (!constr.check(notification, currentView).isOK()){ -// CHESSProjectSupport.printlnToCHESSConsole(constr.getMessage()); -// throw new RollbackException(constr.getStatus()); -// } -// } - - return command; - } -} +/* +----------------------------------------------------------------------- +-- CHESS validator plugin -- +-- -- +-- Copyright (C) 2011-2012 -- +-- University of Padova, ITALY -- +-- -- +-- Author: Alessandro Zovi azovi@math.unipd.it -- +-- -- +-- 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 -- +----------------------------------------------------------------------- +*/ + +package org.polarsys.chess.validator.managers; + +import java.util.List; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.transaction.RollbackException; +import org.eclipse.jface.preference.IPreferencePage; +import org.eclipse.jface.preference.PreferenceManager; +import org.eclipse.jface.preference.PreferenceNode; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Model; +import org.polarsys.chess.core.constraint.ConstraintList; +import org.polarsys.chess.core.constraint.DynamicConstraint; +import org.polarsys.chess.core.preferences.FilterableConstraint; +import org.polarsys.chess.core.util.CHESSProjectSupport; +import org.polarsys.chess.core.views.DiagramStatus.DesignView; +import org.polarsys.chess.validator.Activator; +import org.polarsys.chess.validator.libs.ConstraintsLib; +import org.polarsys.chess.validator.messages.Messages; + +// TODO: Auto-generated Javadoc +/** + * The Class ModelParser. + */ +public class ModelParser { + + /** The model outside view. */ + private IStatus modelOutsideView = new Status(IStatus.ERROR, + Activator.PLUGIN_ID, Messages.NullViewMsg); + + + + /** + * Gets the IPreferencePage given the id. (never used?) + * + * @param id the id of the IPreferencePage + * @return the IPreferencePage corresponding to the given id, or null + */ + public IPreferencePage getId(String id) { + PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager(); + List list = pm.getElements(PreferenceManager.PRE_ORDER); + + for (int i = 0; i < list.size(); i++) { + PreferenceNode node = (PreferenceNode) list.get(i); + IPreferencePage p = node.getPage(); + + if (p != null && node.getId().equals(id)) { + return p; + } + } + return null; + } + + /** + * Instantiates a new model parser. + */ + public ModelParser() { + + + PreferenceManager mgr = PlatformUI.getWorkbench().getPreferenceManager(); + + + ConstraintsLib a = new ConstraintsLib(); + //IPreferencePage pp = getId("org.polarsys.chess.preferences.constraints"); + + +// PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn( +// null, +// "org.polarsys.chess.preferences.constraints", +// new String[] {}, null); +// PreferencePage selectedPage = +// (PreferencePage) dialog.getSelectedPage(); +// ((ConstraintPreferencePage)selectedPage).refresh(); +// dialog.close(); + +// for (Object o : mgr.getElements(PreferenceManager.PRE_ORDER)) { +// if (o instanceof IPreferenceNode) { +// IPreferenceNode n = (IPreferenceNode) o; +// if (n.getId().equals("org.polarsys.chess.preferences.constraints")){ +// if (n.getPage() == null) +// n.createPage(); +// ConstraintPreferencePage p = (ConstraintPreferencePage)n.getPage(); +// p.refresh(); +// break; +// } +// } +// } +// List<IPreferenceNode> preferencePageList = castList(IPreferenceNode.class, mgr.getElements(PreferenceManager.PRE_ORDER)); +// IPreferenceNode[] rootSubNodes = mgr.getRootSubNodes(); +// +// IPreferenceNode anode = rootSubNodes[7]; +// +// IPreferenceNode[] installUpadteSubNode = anode.getSubNodes(); +// //anode.remove(installUpadteSubNode[0]); +// PreferenceNode installNode = (PreferenceNode)installUpadteSubNode[0]; +// IPreferencePage page = installNode.getPage(); + } + +// //TODO manage the constraints with a priority list! +// static DynamicConstraint[] constraintList = { +// ConstraintsLib.M_A_1, +// ConstraintsLib.S_S_1, +// ConstraintsLib.C_A_1, +// ConstraintsLib.P_T_1, +// ConstraintsLib.P_A_1, +// ConstraintsLib.O_S_1, +// ConstraintsLib.AddRemoveDependency, +// ConstraintsLib.checkModifiedOperation}; + + /** + * Check. + * + * @param notification the notification + * @param _notifier the _notifier + * @param currentView the current view + * @param superuser the superuser + * @return the command + * @throws RollbackException the rollback exception + */ +public Command check(Notification notification, Object _notifier, DesignView currentView, boolean superuser) throws RollbackException { + Object notifier = notification.getNotifier(); + Command command = null; + if (currentView == null) { + if (notifier instanceof Model && notification.getFeature() instanceof EAttribute && ((EAttribute)notification.getFeature()).getName().equals("name")) + return command; + CHESSProjectSupport.printlnToCHESSConsole(modelOutsideView.getMessage()); + //throw new RollbackException(modelOutsideView); //TODO this Rollback can bring serious problems with Papyrus (loss of data in the model), for the moment we just comment it + return command; + } + + if (!superuser && !ConstraintsLib.E_S_1_NEW.check(notification, currentView).isOK()){ + CHESSProjectSupport.printlnToCHESSConsole(ConstraintsLib.E_S_1_NEW.getMessage()); + throw new RollbackException(ConstraintsLib.E_S_1_NEW.getStatus()); + } + + +// for (FilterableConstraint f: ConstraintList.getList()){ +// System.out.println(f.getConstraint().getName()+" "+f.isActive()); +// } + + for (FilterableConstraint fC: ConstraintList.getList()){ + if (!fC.isActive()) + continue; + DynamicConstraint constr = (DynamicConstraint) fC.getConstraint(); + if (!constr.check(notification, currentView).isOK()){ + CHESSProjectSupport.printlnToCHESSConsole(constr.getMessage()); + throw new RollbackException(constr.getStatus()); + } + } + +// for (DynamicConstraint constr : constraintList) { +// if (!constr.check(notification, currentView).isOK()){ +// CHESSProjectSupport.printlnToCHESSConsole(constr.getMessage()); +// throw new RollbackException(constr.getStatus()); +// } +// } + + return command; + } +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/ResourceListener.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ResourceListener.java similarity index 89% rename from plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/ResourceListener.java rename to plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ResourceListener.java index 04be55d35..44e71ea26 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/ResourceListener.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ResourceListener.java @@ -1,421 +1,475 @@ -/* ------------------------------------------------------------------------ --- CHESS validator plugin -- --- -- --- Copyright (C) 2011-2012 -- --- University of Padova, ITALY -- --- -- --- 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 -- ------------------------------------------------------------------------ -*/ - -package org.polarsys.chess.validator; - -import java.util.List; -import java.util.Map.Entry; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.common.command.CompoundCommand; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.util.EMap; -import org.eclipse.emf.ecore.EAnnotation; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.impl.DynamicEObjectImpl; -import org.eclipse.emf.ecore.impl.ENotificationImpl; -import org.eclipse.emf.transaction.ResourceSetChangeEvent; -import org.eclipse.emf.transaction.RollbackException; -import org.eclipse.gmf.runtime.notation.Diagram; -import org.eclipse.gmf.runtime.notation.Shape; -import org.eclipse.papyrus.infra.core.sashwindows.di.PageList; -import org.eclipse.papyrus.infra.core.services.ServiceException; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.InstanceSpecification; -import org.polarsys.chess.core.notifications.ResourceNotification; -import org.polarsys.chess.core.profiles.CHESSProfileManager; -import org.polarsys.chess.core.resourcelistener.ResourceSetListenerExtra; -import org.polarsys.chess.core.util.CHESSProjectSupport; -import org.polarsys.chess.core.util.NotificationManager; -import org.polarsys.chess.core.views.DiagramStatus; -import org.polarsys.chess.service.utils.CHESSEditorUtils; -import org.polarsys.chess.validator.managers.ModelManager; -import org.polarsys.chess.validator.managers.ModelParser; -import org.polarsys.chess.validator.managers.ViewManager; - -public class ResourceListener extends ResourceSetListenerExtra { - - private StringBuffer s = new StringBuffer(); - //private OCLEvaluator validator = OCLEvaluator.loadEvaluator(); - private ViewManager viewmgr = ViewManager.loadViewManager(); - private ModelManager automatedActionManager = ModelManager.loadModelManager(); - //private ModelManagerOld modelManager = ModelManagerOld.loadModelManagerOld(); - private ModelParser modelparser = new ModelParser(); - -// private IStatus statusCheckViewStereotype = new Status(IStatus.ERROR, Activator.PLUGIN_ID, -// "A view cannot be modified or removed"); - - -// -// private IStatus statusInstanceSpecification = new Status(IStatus.ERROR, Activator.PLUGIN_ID, -// "Cannot edit InstanceSpecification elements"); - -// private IStatus predefinedProfileError = new Status(IStatus.ERROR, Activator.PLUGIN_ID, -// "A predefined profile cannot be removed"); - - @Override - public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException { - List<Notification> list = event.getNotifications(); - DiagramStatus ds; - CompoundCommand command = new CompoundCommand(); - - ds = CHESSEditorUtils.getDiagramStatus(sr); - if (ds == null){ - return command; - } - - - //printList(list); - - boolean executeModelParser = true; - if (!ds.isUserAction()){ - System.out.println("SUPER USER ACTIONS"); - executeModelParser = false; - } - //ds.setUserAction(true); - int i = 0; - for (Notification notif : list) { - i++; - if (notif instanceof ENotificationImpl) { - ENotificationImpl notification = (ENotificationImpl) notif; - final Object notifier = notification.getNotifier(); - if (isNotationElement(notifier)) - continue; - - System.out.println("ACTION "+i+" OF "+list.size()+": "+notif); - System.out.println("TYPE: " + NotificationManager.printEventType(notification)); - System.out.println("NOTIFIER: " + notifier); - System.out.println("FEATURE: " + notification.getFeature()); - if (notification.getEventType()==Notification.REMOVE) - System.out.println("OLDVALUE: " + notification.getOldValue()); - else if (notification.getEventType()==Notification.ADD) - System.out.println("NEWVALUE: " + notification.getNewValue()); - else { - System.out.println("OLDVALUE: " + notification.getOldValue()); - System.out.println("NEWVALUE: " + notification.getNewValue()); - } - - System.out.println("SUPERUSER: " + !executeModelParser); - if (!allowedNotifier(notifier)){ - continue; - } - - - s.delete(0, s.length()); - s.append("R."); - s.append(NotificationManager.printEventType(notification)); - - -// /* -// * @dynamicConstraint R_S_1 -// */ -// if (notifier instanceof ProfileApplication){ -// System.out.println(notif.getEventType()); -// if ((notif.getEventType() == Notification.SET || -// notif.getEventType() == Notification.REMOVE) -// && UMLUtils.isPredefinedProfile(notif.getOldValue())){ -// ResourceNotification.showInfo(predefinedProfileError.getMessage()); -// throw new RollbackException(predefinedProfileError); -// } -// } - -// /* -// * @dynamicConstraint V_SR_1 -// * check if a view stereotype has been modified or removed -// */ -// if (ViewUtils.isViewModifiedOrRemoved(notification)) -// { -// if (!viewmgr.checkViewStereotype(notification)){ -// ResourceNotification.showInfo(statusCheckViewStereotype.getMessage()); -// throw new RollbackException(statusCheckViewStereotype); -// } -// } - - -// if (!ConstraintsLib.DefaultStereotypeRemoved.check(notification).isOK()){ -// ResourceNotification.showInfo(ConstraintsLib.DefaultStereotypeRemoved.getMessage()); -// throw new RollbackException(ConstraintsLib.DefaultStereotypeRemoved.getStatus()); -// } - - //TODO BUG when a ClientServerPort is removed it generates Slot-related transactions -// if (isInstanceSpecification((ENotificationImpl)notif)){ -// ResourceNotification.showInfo(statusInstanceSpecification.getMessage()); -// throw new RollbackException(statusInstanceSpecification); -// } - - try{ - //do not check any constraint in case of automated actions - if (executeModelParser){ - modelparser.check(notification, notifier, ds.getCurrentView(), ds.isSuperuser()); - } - } catch (RollbackException e) { - ResourceNotification.showInfo(e.getStatus().getMessage()); - throw e; - } - - if ( notifier instanceof Element - || notifier instanceof DynamicEObjectImpl - || canBeStaticStereotype(notifier)) - { - try { - Command comm = automatedActionManager.check(list, notification, notifier, s, ds,event.getEditingDomain()); - if ( comm != null ){ - ds.setUserAction(false); - command.append(comm); - - System.out.println("COMMAND: " + comm.getLabel()); - System.out.println("SUPERUSER set to true"); - } - } catch (RollbackException e) { - s.delete(0, s.length()); - s.append(e.getStatus().getMessage()); - ResourceNotification.showInfo(e.getStatus().getMessage()); - throw e; - } - } - /* - * Use "instanceof Shape" instead else if (notifier instanceof - * Diagram) { Diagram di = (Diagram) notifier; - * s.append(" model modified: "); s.append(di.getName()); - * - * }*/ - else - if (notifier instanceof Shape) { - Shape shape = (Shape) notifier; - s.append(" shape modified: "); - s.append(" for the element: "); - s.append(shape.getElement()); - if (shape.getElement()!= null){ - s.append(" that belong to the view: "); - s.append(shape.getElement().eContainer()); - } - - //modelmanager.check(notification, shape.getElement(), validator, s); - //TODO drag and drop constraints - //TODO same constraint of @dynamicConstraint P_A_1 an interface can be added only in - //functionalView -// if (shape.getElement() instanceof Interface && -// shape.getDiagram().getType().equals(ModelEditPart.MODEL_ID) && -// !UMLUtils.isFunctionalView(UMLUtils.getView(shape.getDiagram().getElement()))){ -// ResourceNotification.showInfo(ModelManager.cannotCreateInterface.getMessage()); -// throw new RollbackException(ModelManager.cannotCreateInterface); -// } - if (shape.getDiagram()!=null){ - s.append(" in the diagram: "); - s.append(shape.getDiagram().getName()); - s.append(" in the view: "); - s.append(shape.getDiagram().getElement()); - } - if (!(notification.getNewValue() instanceof EObject)) - continue; - } - - //it's needed to avoid the graphical representation of stereotype to be shown - //used in case of applying the view stereotype - else if (notifier instanceof EAnnotation) - { - EAnnotation annotation = (EAnnotation) notifier; - System.out.println("ANN: " + annotation); - EMap< String, String> details = annotation.getDetails(); - for (Entry<String, String> entry : details) { - if ( entry.getValue().indexOf(CHESSProfileManager.DEPLOYMENT_VIEW) > 0 - || entry.getValue().indexOf(CHESSProfileManager.COMPONENT_VIEW) > 0 - //|| entry.getValue().indexOf(CHESSProfileManager.EXTRAFUNCTIONAL_VIEW) > 0 - || entry.getValue().indexOf(CHESSProfileManager.ANALYSIS_VIEW) > 0 - || entry.getValue().indexOf(CHESSProfileManager.DEPENDABILITY_ANALYSIS_VIEW) > 0 - || entry.getValue().indexOf(CHESSProfileManager.RT_ANALYSIS_VIEW) > 0 - || entry.getValue().indexOf(CHESSProfileManager.TIMING_DATAFLOW_VIEW) > 0 ) - { - s.delete(0, s.length()); - s.append("Can't apply view stereotype!"); - CHESSProjectSupport.printlnToCHESSConsole(s.toString()); - ResourceNotification.showError(s.toString()); - throw new RollbackException(new Status(IStatus.ERROR, - Activator.PLUGIN_ID, s.toString())); - } - } - } - - else if (notifier instanceof PageList) { - try { - viewmgr.check(notification.getNewValue(), s, ds.getCurrentView(),event.getEditingDomain()); - } catch (RollbackException e) { - ResourceNotification.showInfo(e.getStatus().getMessage()); - throw e; - } - } - } - else { //check diagram creation permission - Object newz = notif.getNewValue(); - if (newz instanceof Diagram){ - - try { - viewmgr.check((Diagram) newz, s, ds.getCurrentView(),event.getEditingDomain()); - } catch (RollbackException e) { - ResourceNotification.showInfo(e.getStatus().getMessage()); - throw e; - } - } - } - } - - return command.getCommandList().isEmpty() ? super.transactionAboutToCommit(event) : command; - } - - - private void printList(List<Notification> list) { - System.out.println("----------------------------------"); - int j = 0; - for (Notification notif1 : list) { - j++; - if (notif1 instanceof ENotificationImpl) { - ENotificationImpl notification = (ENotificationImpl) notif1; - final Object notifier = notification.getNotifier(); - if (isNotationElement(notifier)) - continue; - - System.out.println("ACTION " + j + " OF " + list.size()); - System.out.println("TYPE: " - + NotificationManager.printEventType(notification)); - System.out.println("NOTIFIER: " + notifier); - System.out.println("FEATURE: " + notification.getFeature()); - if (notification.getEventType() == Notification.REMOVE) - System.out.println("OLDVALUE: " - + notification.getOldValue()); - else if (notification.getEventType() == Notification.ADD) - System.out.println("NEWVALUE: " - + notification.getNewValue()); - else { - System.out.println("OLDVALUE: " - + notification.getOldValue()); - System.out.println("NEWVALUE: " - + notification.getNewValue()); - } - } - } - System.out.println("----------------------------------"); - } - - - private boolean isNotationElement(Object notifier) { - if (notifier instanceof EObject){ - String pkgName = notifier.getClass().getPackage().getName(); - if (pkgName.startsWith("org.eclipse.gmf.runtime.notation")) - return true; - } - return false; - - } - - private boolean canBeStaticStereotype(Object notifier) { - if (notifier instanceof EObject) { - String pkgName = notifier.getClass().getPackage().getName(); - if (pkgName.startsWith("org.eclipse.papyrus.MARTE") || pkgName.startsWith("org.polarsys.chess.chessmlprofile")) - return true; - if (notifier instanceof EAnnotation || notifier instanceof Shape){ - return false; - } - return true; - } - return false; - } - - - private static Class[] allowedNotifierTypes = {Element.class, DynamicEObjectImpl.class, Diagram.class, PageList.class, Shape.class, EAnnotation.class, EObject.class}; - - - private boolean allowedNotifier(Object notifier) { - for (Class<?> allowedType : allowedNotifierTypes) { - if (allowedType.isInstance(notifier)) - return true; - } - return false; - } - - - private boolean isInstanceSpecification(ENotificationImpl notif) { - // TODO Problematic when we need to remove a clientserverport - // => it removes also Slot which is of an InstanceSpecification - - if (notif.getEventType() == Notification.SET){ - Object notifer = notif.getNotifier(); - return (notifer instanceof Element && isContainedInInstanceSpecification((Element) notifer)); - } - if (notif.getEventType() == Notification.REMOVE){ - Object notifer = notif.getOldValue(); - return (notifer instanceof Element && isContainedInInstanceSpecification((Element) notifer)); - } - return false; - } - - private boolean isContainedInInstanceSpecification(Element notifer) { - if (notifer == null) - return false; - if (notifer instanceof InstanceSpecification) - return true; - EObject cont = notifer.eContainer(); - if (cont instanceof Element) - return isContainedInInstanceSpecification((Element)cont); - return false; - } - - /* - private void printElementType(EObject notifier) { - if (notifier instanceof DynamicEObjectImpl) { - notifier = UMLUtil.getBaseElement((DynamicEObjectImpl) notifier); - } - if (notifier instanceof Model) { - Model m = (Model) notifier; - s.append(" for model: "); - s.append(m.getName()); - } else if (notifier instanceof Class) { - Class c = (Class) notifier; - s.append(" for class: "); - s.append(c.getName()); - s.append(" in the model: "); - s.append(c.getModel().getName()); - validator.validate(c); - } else if (notifier instanceof Interface) { - Interface in = (Interface) notifier; - s.append(" for interface: "); - s.append(in.getName()); - } else if (notifier instanceof Operation) { - Operation op = (Operation) notifier; - s.append(" for operation: "); - s.append(op.getName()); - - Classifier c = OCLUMLUtil.getClassifier(op.eClass(), op.eResource() - .getResourceSet()); - s.append(" in class: "); - s.append(c.getName()); - - } else if (notifier instanceof Property) { - Property pr = (Property) notifier; - s.append(" for property: "); - s.append(pr.getName()); - } else if (notifier instanceof NamedElement) { - NamedElement ne = (NamedElement) notifier; - s.append(" for unknown ne: "); - s.append(ne.getName()); - } else if (notifier instanceof DynamicEObjectImpl) { - Element el = UMLUtil.getBaseElement((DynamicEObjectImpl) notifier); - NamedElement ne = (NamedElement) el; - s.append(" for unknown ne: "); - s.append(ne.getName()); - } - } - */ -} +/* +----------------------------------------------------------------------- +-- CHESS validator plugin -- +-- -- +-- Copyright (C) 2011-2012 -- +-- University of Padova, ITALY -- +-- -- +-- 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 -- +----------------------------------------------------------------------- +*/ + +package org.polarsys.chess.validator.managers; + +import java.util.List; +import java.util.Map.Entry; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EMap; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.impl.DynamicEObjectImpl; +import org.eclipse.emf.ecore.impl.ENotificationImpl; +import org.eclipse.emf.transaction.ResourceSetChangeEvent; +import org.eclipse.emf.transaction.RollbackException; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.Shape; +import org.eclipse.papyrus.infra.core.sashwindows.di.PageList; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.InstanceSpecification; +import org.polarsys.chess.core.notifications.ResourceNotification; +import org.polarsys.chess.core.profiles.CHESSProfileManager; +import org.polarsys.chess.core.resourcelistener.ResourceSetListenerExtra; +import org.polarsys.chess.core.util.CHESSProjectSupport; +import org.polarsys.chess.core.util.NotificationManager; +import org.polarsys.chess.core.views.DiagramStatus; +import org.polarsys.chess.service.utils.CHESSEditorUtils; +import org.polarsys.chess.validator.Activator; + +// TODO: Auto-generated Javadoc +/** + * The listener interface for receiving resource events. + * The class that is interested in processing a resource + * event implements this interface, and the object created + * with that class is registered with a component using the + * component's <code>addResourceListener<code> method. When + * the resource event occurs, that object's appropriate + * method is invoked. + * + * @see ResourceEvent + */ +public class ResourceListener extends ResourceSetListenerExtra { + + /** The s. */ + private StringBuffer s = new StringBuffer(); + //private OCLEvaluator validator = OCLEvaluator.loadEvaluator(); + /** The viewmgr. */ + private ViewManager viewmgr = ViewManager.loadViewManager(); + + /** The automated action manager. */ + private ModelManager automatedActionManager = ModelManager.loadModelManager(); + //private ModelManagerOld modelManager = ModelManagerOld.loadModelManagerOld(); + /** The modelparser. */ + private ModelParser modelparser = new ModelParser(); + +// private IStatus statusCheckViewStereotype = new Status(IStatus.ERROR, Activator.PLUGIN_ID, +// "A view cannot be modified or removed"); + + +// +// private IStatus statusInstanceSpecification = new Status(IStatus.ERROR, Activator.PLUGIN_ID, +// "Cannot edit InstanceSpecification elements"); + +// private IStatus predefinedProfileError = new Status(IStatus.ERROR, Activator.PLUGIN_ID, +// "A predefined profile cannot be removed"); + + /* (non-Javadoc) + * @see org.eclipse.emf.transaction.ResourceSetListenerImpl#transactionAboutToCommit(org.eclipse.emf.transaction.ResourceSetChangeEvent) + */ +@Override + public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException { + List<Notification> list = event.getNotifications(); + DiagramStatus ds; + CompoundCommand command = new CompoundCommand(); + + ds = CHESSEditorUtils.getDiagramStatus(sr); + if (ds == null){ + return command; + } + + + //printList(list); + + boolean executeModelParser = true; + if (!ds.isUserAction()){ + System.out.println("SUPER USER ACTIONS"); + executeModelParser = false; + } + //ds.setUserAction(true); + int i = 0; + for (Notification notif : list) { + i++; + if (notif instanceof ENotificationImpl) { + ENotificationImpl notification = (ENotificationImpl) notif; + final Object notifier = notification.getNotifier(); + if (isNotationElement(notifier)) + continue; + + System.out.println("ACTION "+i+" OF "+list.size()+": "+notif); + System.out.println("TYPE: " + NotificationManager.printEventType(notification)); + System.out.println("NOTIFIER: " + notifier); + System.out.println("FEATURE: " + notification.getFeature()); + if (notification.getEventType()==Notification.REMOVE) + System.out.println("OLDVALUE: " + notification.getOldValue()); + else if (notification.getEventType()==Notification.ADD) + System.out.println("NEWVALUE: " + notification.getNewValue()); + else { + System.out.println("OLDVALUE: " + notification.getOldValue()); + System.out.println("NEWVALUE: " + notification.getNewValue()); + } + + System.out.println("SUPERUSER: " + !executeModelParser); + if (!allowedNotifier(notifier)){ + continue; + } + + + s.delete(0, s.length()); + s.append("R."); + s.append(NotificationManager.printEventType(notification)); + + +// /* +// * @dynamicConstraint R_S_1 +// */ +// if (notifier instanceof ProfileApplication){ +// System.out.println(notif.getEventType()); +// if ((notif.getEventType() == Notification.SET || +// notif.getEventType() == Notification.REMOVE) +// && UMLUtils.isPredefinedProfile(notif.getOldValue())){ +// ResourceNotification.showInfo(predefinedProfileError.getMessage()); +// throw new RollbackException(predefinedProfileError); +// } +// } + +// /* +// * @dynamicConstraint V_SR_1 +// * check if a view stereotype has been modified or removed +// */ +// if (ViewUtils.isViewModifiedOrRemoved(notification)) +// { +// if (!viewmgr.checkViewStereotype(notification)){ +// ResourceNotification.showInfo(statusCheckViewStereotype.getMessage()); +// throw new RollbackException(statusCheckViewStereotype); +// } +// } + + +// if (!ConstraintsLib.DefaultStereotypeRemoved.check(notification).isOK()){ +// ResourceNotification.showInfo(ConstraintsLib.DefaultStereotypeRemoved.getMessage()); +// throw new RollbackException(ConstraintsLib.DefaultStereotypeRemoved.getStatus()); +// } + + //TODO BUG when a ClientServerPort is removed it generates Slot-related transactions +// if (isInstanceSpecification((ENotificationImpl)notif)){ +// ResourceNotification.showInfo(statusInstanceSpecification.getMessage()); +// throw new RollbackException(statusInstanceSpecification); +// } + + try{ + //do not check any constraint in case of automated actions + if (executeModelParser){ + modelparser.check(notification, notifier, ds.getCurrentView(), ds.isSuperuser()); + } + } catch (RollbackException e) { + ResourceNotification.showInfo(e.getStatus().getMessage()); + throw e; + } + + if ( notifier instanceof Element + || notifier instanceof DynamicEObjectImpl + || canBeStaticStereotype(notifier)) + { + try { + Command comm = automatedActionManager.check(list, notification, notifier, s, ds,event.getEditingDomain()); + if ( comm != null ){ + ds.setUserAction(false); + command.append(comm); + + System.out.println("COMMAND: " + comm.getLabel()); + System.out.println("SUPERUSER set to true"); + } + } catch (RollbackException e) { + s.delete(0, s.length()); + s.append(e.getStatus().getMessage()); + ResourceNotification.showInfo(e.getStatus().getMessage()); + throw e; + } + } + /* + * Use "instanceof Shape" instead else if (notifier instanceof + * Diagram) { Diagram di = (Diagram) notifier; + * s.append(" model modified: "); s.append(di.getName()); + * + * }*/ + else + if (notifier instanceof Shape) { + Shape shape = (Shape) notifier; + s.append(" shape modified: "); + s.append(" for the element: "); + s.append(shape.getElement()); + if (shape.getElement()!= null){ + s.append(" that belong to the view: "); + s.append(shape.getElement().eContainer()); + } + + //modelmanager.check(notification, shape.getElement(), validator, s); + //TODO drag and drop constraints + //TODO same constraint of @dynamicConstraint P_A_1 an interface can be added only in + //functionalView +// if (shape.getElement() instanceof Interface && +// shape.getDiagram().getType().equals(ModelEditPart.MODEL_ID) && +// !UMLUtils.isFunctionalView(UMLUtils.getView(shape.getDiagram().getElement()))){ +// ResourceNotification.showInfo(ModelManager.cannotCreateInterface.getMessage()); +// throw new RollbackException(ModelManager.cannotCreateInterface); +// } + if (shape.getDiagram()!=null){ + s.append(" in the diagram: "); + s.append(shape.getDiagram().getName()); + s.append(" in the view: "); + s.append(shape.getDiagram().getElement()); + } + if (!(notification.getNewValue() instanceof EObject)) + continue; + } + + //it's needed to avoid the graphical representation of stereotype to be shown + //used in case of applying the view stereotype + else if (notifier instanceof EAnnotation) + { + EAnnotation annotation = (EAnnotation) notifier; + System.out.println("ANN: " + annotation); + EMap< String, String> details = annotation.getDetails(); + for (Entry<String, String> entry : details) { + if ( entry.getValue().indexOf(CHESSProfileManager.DEPLOYMENT_VIEW) > 0 + || entry.getValue().indexOf(CHESSProfileManager.COMPONENT_VIEW) > 0 + //|| entry.getValue().indexOf(CHESSProfileManager.EXTRAFUNCTIONAL_VIEW) > 0 + || entry.getValue().indexOf(CHESSProfileManager.ANALYSIS_VIEW) > 0 + || entry.getValue().indexOf(CHESSProfileManager.DEPENDABILITY_ANALYSIS_VIEW) > 0 + || entry.getValue().indexOf(CHESSProfileManager.RT_ANALYSIS_VIEW) > 0 + || entry.getValue().indexOf(CHESSProfileManager.TIMING_DATAFLOW_VIEW) > 0 ) + { + s.delete(0, s.length()); + s.append("Can't apply view stereotype!"); + CHESSProjectSupport.printlnToCHESSConsole(s.toString()); + ResourceNotification.showError(s.toString()); + throw new RollbackException(new Status(IStatus.ERROR, + Activator.PLUGIN_ID, s.toString())); + } + } + } + + else if (notifier instanceof PageList) { + try { + viewmgr.check(notification.getNewValue(), s, ds.getCurrentView(),event.getEditingDomain()); + } catch (RollbackException e) { + ResourceNotification.showInfo(e.getStatus().getMessage()); + throw e; + } + } + } + else { //check diagram creation permission + Object newz = notif.getNewValue(); + if (newz instanceof Diagram){ + + try { + viewmgr.check((Diagram) newz, s, ds.getCurrentView(),event.getEditingDomain()); + } catch (RollbackException e) { + ResourceNotification.showInfo(e.getStatus().getMessage()); + throw e; + } + } + } + } + + return command.getCommandList().isEmpty() ? super.transactionAboutToCommit(event) : command; + } + + + /** + * Prints the list. Test + * + * @param list the List to be printed + */ + private void printList(List<Notification> list) { + System.out.println("----------------------------------"); + int j = 0; + for (Notification notif1 : list) { + j++; + if (notif1 instanceof ENotificationImpl) { + ENotificationImpl notification = (ENotificationImpl) notif1; + final Object notifier = notification.getNotifier(); + if (isNotationElement(notifier)) + continue; + + System.out.println("ACTION " + j + " OF " + list.size()); + System.out.println("TYPE: " + + NotificationManager.printEventType(notification)); + System.out.println("NOTIFIER: " + notifier); + System.out.println("FEATURE: " + notification.getFeature()); + if (notification.getEventType() == Notification.REMOVE) + System.out.println("OLDVALUE: " + + notification.getOldValue()); + else if (notification.getEventType() == Notification.ADD) + System.out.println("NEWVALUE: " + + notification.getNewValue()); + else { + System.out.println("OLDVALUE: " + + notification.getOldValue()); + System.out.println("NEWVALUE: " + + notification.getNewValue()); + } + } + } + System.out.println("----------------------------------"); + } + + + /** + * Checks if is the notifier notation element. + * + * @param notifier the notifier + * @return true, if is notation element + */ + private boolean isNotationElement(Object notifier) { + if (notifier instanceof EObject){ + String pkgName = notifier.getClass().getPackage().getName(); + if (pkgName.startsWith("org.eclipse.gmf.runtime.notation")) + return true; + } + return false; + + } + + /** + * Chek if the notifier can be a static stereotype. + * + * @param notifier the notifier + * @return true, if successful + */ + private boolean canBeStaticStereotype(Object notifier) { + if (notifier instanceof EObject) { + String pkgName = notifier.getClass().getPackage().getName(); + if (pkgName.startsWith("org.eclipse.papyrus.MARTE") || pkgName.startsWith("org.polarsys.chess.chessmlprofile")) + return true; + if (notifier instanceof EAnnotation || notifier instanceof Shape){ + return false; + } + return true; + } + return false; + } + + + /** The allowed notifier types. */ + private static Class[] allowedNotifierTypes = {Element.class, DynamicEObjectImpl.class, Diagram.class, PageList.class, Shape.class, EAnnotation.class, EObject.class}; + + + /** + * Allowed notifier. + * + * @param notifier the notifier + * @return true, if successful + */ + private boolean allowedNotifier(Object notifier) { + for (Class<?> allowedType : allowedNotifierTypes) { + if (allowedType.isInstance(notifier)) + return true; + } + return false; + } + + + /** + * Checks if the notification is instance specification. + * + * @param notif the notification + * @return true, if is instance specification + */ + private boolean isInstanceSpecification(ENotificationImpl notif) { + // TODO Problematic when we need to remove a clientserverport + // => it removes also Slot which is of an InstanceSpecification + + if (notif.getEventType() == Notification.SET){ + Object notifer = notif.getNotifier(); + return (notifer instanceof Element && isContainedInInstanceSpecification((Element) notifer)); + } + if (notif.getEventType() == Notification.REMOVE){ + Object notifer = notif.getOldValue(); + return (notifer instanceof Element && isContainedInInstanceSpecification((Element) notifer)); + } + return false; + } + + /** + * Checks if the notifier is contained in instance specification. + * + * @param notifer the notifier + * @return true, if is contained in instance specification + */ + private boolean isContainedInInstanceSpecification(Element notifier) { + if (notifier == null) + return false; + if (notifier instanceof InstanceSpecification) + return true; + EObject cont = notifier.eContainer(); + if (cont instanceof Element) + return isContainedInInstanceSpecification((Element)cont); + return false; + } + + /* + private void printElementType(EObject notifier) { + if (notifier instanceof DynamicEObjectImpl) { + notifier = UMLUtil.getBaseElement((DynamicEObjectImpl) notifier); + } + if (notifier instanceof Model) { + Model m = (Model) notifier; + s.append(" for model: "); + s.append(m.getName()); + } else if (notifier instanceof Class) { + Class c = (Class) notifier; + s.append(" for class: "); + s.append(c.getName()); + s.append(" in the model: "); + s.append(c.getModel().getName()); + validator.validate(c); + } else if (notifier instanceof Interface) { + Interface in = (Interface) notifier; + s.append(" for interface: "); + s.append(in.getName()); + } else if (notifier instanceof Operation) { + Operation op = (Operation) notifier; + s.append(" for operation: "); + s.append(op.getName()); + + Classifier c = OCLUMLUtil.getClassifier(op.eClass(), op.eResource() + .getResourceSet()); + s.append(" in class: "); + s.append(c.getName()); + + } else if (notifier instanceof Property) { + Property pr = (Property) notifier; + s.append(" for property: "); + s.append(pr.getName()); + } else if (notifier instanceof NamedElement) { + NamedElement ne = (NamedElement) notifier; + s.append(" for unknown ne: "); + s.append(ne.getName()); + } else if (notifier instanceof DynamicEObjectImpl) { + Element el = UMLUtil.getBaseElement((DynamicEObjectImpl) notifier); + NamedElement ne = (NamedElement) el; + s.append(" for unknown ne: "); + s.append(ne.getName()); + } + } + */ +} diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/ValidationDelegateClientSelector.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ValidationDelegateClientSelector.java similarity index 92% rename from plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/ValidationDelegateClientSelector.java rename to plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ValidationDelegateClientSelector.java index c9a5bdf37..63685b840 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/ValidationDelegateClientSelector.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ValidationDelegateClientSelector.java @@ -13,12 +13,16 @@ -- http://www.eclipse.org/legal/epl-v10.html -- ----------------------------------------------------------------------- */ -package org.polarsys.chess.validator; +package org.polarsys.chess.validator.managers; import org.eclipse.emf.validation.model.IClientSelector; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Model; +// TODO: Auto-generated Javadoc +/** + * The Class ValidationDelegateClientSelector. + */ public class ValidationDelegateClientSelector diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ViewManager.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ViewManager.java index 34dc82961..bc12faa9f 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ViewManager.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/ViewManager.java @@ -1,180 +1,203 @@ -/* ------------------------------------------------------------------------ --- CHESS validator plugin -- --- -- --- Copyright (C) 2011-2012 -- --- University of Padova, ITALY -- --- -- --- Author: Alessandro Zovi azovi@math.unipd.it -- --- -- --- 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 -- ------------------------------------------------------------------------ -*/ - -package org.polarsys.chess.validator.managers; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.transaction.RollbackException; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gmf.runtime.notation.Diagram; -import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor; -import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef; -import org.eclipse.papyrus.uml.tools.listeners.PapyrusStereotypeListener; -import org.eclipse.uml2.uml.Model; -import org.polarsys.chess.core.profiles.CHESSProfileManager; -import org.polarsys.chess.core.util.CHESSProjectSupport; -import org.polarsys.chess.core.views.DiagramStatus; -import org.polarsys.chess.core.views.DiagramStatus.DesignView; -import org.polarsys.chess.core.views.ViewUtils; -import org.polarsys.chess.service.utils.CHESSEditorUtils; -import org.polarsys.chess.validator.Activator; -import org.eclipse.uml2.uml.Package; - -/** - * ViewManager is a singleton class which provides the data structure which contains the - * view-diagram association. - * Each CHESS view owns a list of types of diagram that view is allowed to expose and modify. - */ -public class ViewManager { - - public static String classDiagramKind = "PapyrusUMLClassDiagram"; - - private static ViewManager instance = new ViewManager(); - - public static ViewManager loadViewManager() { - return instance; - } - -// public boolean isDiagramAllowed(String view, String diagram) { -// if (view != null) { -// HashSet<String> diagrams = viewDiagramsAssociation.get(view); -// return diagrams.contains(diagram); -// } -// return false; -// } - - - /** - * Check constraints concerning view ownership of diagrams. - * A diagram must be created as a child of a view which allows its creation - * @param domain - * @param currentView - */ - public void check(Object notifier, StringBuffer s, DesignView currentView, TransactionalEditingDomain domain) - throws RollbackException { - if (notifier instanceof PageRef) { - PageRef ref = (PageRef) notifier; - Diagram diagram = null; - - // check if we are working on a real diagram - if (ref.getEmfPageIdentifier() instanceof Diagram) - diagram = (Diagram) ref.getEmfPageIdentifier(); - else - return; - - check(diagram, s, currentView, domain); - - } - } - - - /** - * Check constraints concerning view ownership of diagrams. - * A diagram must be created as a child of a view which allows its creation - * @param domain - * @param currentView - */ - public void check(Diagram diagram, StringBuffer s, DesignView currentView, TransactionalEditingDomain domain) - throws RollbackException { - - /* - * @dynamicConstraint D_1 - * if the diagram is created in the root of the model - */ - if (diagram.getElement() instanceof Model) { - s.append(Messages.error_diagramInView); -// ResourceNotification.showError(Messages.error_diagramInView); - throw new RollbackException(new Status(IStatus.ERROR, - Activator.PLUGIN_ID, Messages.error_diagramInView)); - } else { - /* - * dynamicConstraint D_2 - * A diagram must be created as a child of a view which allows its creation - */ - if (!currentView.isDiagramAllowed(diagram)){ - CHESSProjectSupport.printlnToCHESSConsole(s.toString()); - throw new RollbackException(new Status(IStatus.ERROR, - Activator.PLUGIN_ID, Messages.error_diagramCurrentView)); //$NON-NLS-1$ - } -// - } - - } - -// /* -// * dynamicConstraint D_2 -// * A diagram must be created as a child of a view which allows its creation -// */ -// private boolean isDiagramAllowed(Package containingView, Diagram diagram) { -// Stereotype view = ViewUtils.getViewStereotypeApplied(containingView); -// if (view != null) { -// HashSet<String> diagrams = viewDiagramsAssociation.get(view -// .getName()); -// return diagrams.contains(diagram.getType()); -// } -// return false; -// } - -// public void checkViewPackage(Notification notification) -// throws RollbackException { -// if (notification.getEventType() == Notification.REMOVE) { -// throw new RollbackException(new Status(IStatus.ERROR, -// Activator.PLUGIN_ID, "Can't delete a view!")); -// } -// } - - - /** - * Check if a stereotype representing a CHESS view has been modified. - * A stereotype representing a CHESS must not be modified or removed. - */ - public boolean checkViewStereotype(Notification notification) { - - //it should be allowed to modify the deployment view in order to add/remove assignment references - PapyrusMultiDiagramEditor editor = CHESSEditorUtils.getCHESSEditor(); - DiagramStatus ds = CHESSEditorUtils.getDiagramStatus(editor); - if(ds == null) - return true; - - DesignView dview = - ds.getCurrentView(); - - boolean isCurrentPackageDeploymentView = false; - Object n = notification.getNotifier(); - if (n instanceof Package) { - Package pkg = (Package) n; - isCurrentPackageDeploymentView=ViewUtils.isDeploymentView(pkg); - } - - - if(isCurrentPackageDeploymentView || notification.getEventType() == PapyrusStereotypeListener.MODIFIED_STEREOTYPE && - dview.getName().equals(CHESSProfileManager.DEPLOYMENT_VIEW)){ - return true; - } - - else if (notification.getEventType() == Notification.SET || - notification.getEventType() == Notification.REMOVE || - notification.getEventType() == PapyrusStereotypeListener.APPLIED_STEREOTYPE || - notification.getEventType() == PapyrusStereotypeListener.UNAPPLIED_STEREOTYPE || - notification.getEventType() == PapyrusStereotypeListener.MODIFIED_STEREOTYPE - ) { - return false; - } - return true; - } +/* +----------------------------------------------------------------------- +-- CHESS validator plugin -- +-- -- +-- Copyright (C) 2011-2012 -- +-- University of Padova, ITALY -- +-- -- +-- Author: Alessandro Zovi azovi@math.unipd.it -- +-- -- +-- 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 -- +----------------------------------------------------------------------- +*/ + +package org.polarsys.chess.validator.managers; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.transaction.RollbackException; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor; +import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef; +import org.eclipse.papyrus.uml.tools.listeners.PapyrusStereotypeListener; +import org.eclipse.uml2.uml.Model; +import org.polarsys.chess.core.profiles.CHESSProfileManager; +import org.polarsys.chess.core.util.CHESSProjectSupport; +import org.polarsys.chess.core.views.DiagramStatus; +import org.polarsys.chess.core.views.DiagramStatus.DesignView; +import org.polarsys.chess.core.views.ViewUtils; +import org.polarsys.chess.service.utils.CHESSEditorUtils; +import org.polarsys.chess.validator.Activator; +import org.polarsys.chess.validator.messages.Messages; +import org.eclipse.uml2.uml.Package; + +// TODO: Auto-generated Javadoc +/** + * ViewManager is a singleton class which provides the data structure which contains the + * view-diagram association. + * Each CHESS view owns a list of types of diagram that view is allowed to expose and modify. + */ +public class ViewManager { + + /** The class diagram kind. */ + public static String classDiagramKind = "PapyrusUMLClassDiagram"; + + /** The instance. */ + private static ViewManager instance = new ViewManager(); + + /** + * Load view manager. + * + * @return the single ViewManager instance + */ + public static ViewManager loadViewManager() { + return instance; + } + +// public boolean isDiagramAllowed(String view, String diagram) { +// if (view != null) { +// HashSet<String> diagrams = viewDiagramsAssociation.get(view); +// return diagrams.contains(diagram); +// } +// return false; +// } + + + /** + * Check constraints concerning view ownership of diagrams. + * A diagram must be created as a child of a view which allows its creation + * + * @param notifier the notifier Object + * @param s the StringBuffer used to store messages to be printed to the CHESSConsole + * @param currentView the CHESS current view + * @param domain the TransactionalEditingDomain domain of the diagram + * @throws RollbackException in case of DynamicConstraint failure + */ + @Deprecated + public void check(Object notifier, StringBuffer s, DesignView currentView, TransactionalEditingDomain domain) + throws RollbackException { + if (notifier instanceof PageRef) { + PageRef ref = (PageRef) notifier; + Diagram diagram = null; + + // check if we are working on a real diagram + if (ref.getEmfPageIdentifier() instanceof Diagram) + diagram = (Diagram) ref.getEmfPageIdentifier(); + else + return; + + check(diagram, s, currentView, domain); + + } + } + + + /** + * Check constraints concerning view ownership of diagrams. + * A diagram must be created as a child of a view which allows its creation + * + * @param diagram the Diagram about to be created + * @param s the StringBuffer used to store messages to be printed to the CHESSConsole + * @param currentView the CHESS current view + * @param domain the TransactionalEditingDomain domain of the diagram + * @throws RollbackException in case of DynamicConstraint failure + */ + public void check(Diagram diagram, StringBuffer s, DesignView currentView, TransactionalEditingDomain domain) + throws RollbackException { + + /* + * @dynamicConstraint D_1 + * if the diagram is created in the root of the model + */ + if (diagram.getElement() instanceof Model) { + s.append(Messages.error_diagramInView); +// ResourceNotification.showError(Messages.error_diagramInView); + throw new RollbackException(new Status(IStatus.ERROR, + Activator.PLUGIN_ID, Messages.error_diagramInView)); + } else { + /* + * dynamicConstraint D_2 + * A diagram must be created as a child of a view which allows its creation + */ + if (!currentView.isDiagramAllowed(diagram)){ + CHESSProjectSupport.printlnToCHESSConsole(s.toString()); + throw new RollbackException(new Status(IStatus.ERROR, + Activator.PLUGIN_ID, Messages.error_diagramCurrentView)); //$NON-NLS-1$ + } +// + } + + } + +// /* +// * dynamicConstraint D_2 +// * A diagram must be created as a child of a view which allows its creation +// */ +// private boolean isDiagramAllowed(Package containingView, Diagram diagram) { +// Stereotype view = ViewUtils.getViewStereotypeApplied(containingView); +// if (view != null) { +// HashSet<String> diagrams = viewDiagramsAssociation.get(view +// .getName()); +// return diagrams.contains(diagram.getType()); +// } +// return false; +// } + +// public void checkViewPackage(Notification notification) +// throws RollbackException { +// if (notification.getEventType() == Notification.REMOVE) { +// throw new RollbackException(new Status(IStatus.ERROR, +// Activator.PLUGIN_ID, "Can't delete a view!")); +// } +// } + + + /** + * Check if a stereotype representing a CHESS view has been modified. + * A stereotype representing a CHESS must not be modified or removed. + * + * @see org.polarsys.chess.validator.libs.ConstraintsLib + * + * @param notification the EMF notification + * @return true, if successful + */ + public boolean checkViewStereotype(Notification notification) { + + //it should be allowed to modify the deployment view in order to add/remove assignment references + PapyrusMultiDiagramEditor editor = CHESSEditorUtils.getCHESSEditor(); + DiagramStatus ds = CHESSEditorUtils.getDiagramStatus(editor); + if(ds == null) + return true; + + DesignView dview = + ds.getCurrentView(); + + boolean isCurrentPackageDeploymentView = false; + Object n = notification.getNotifier(); + if (n instanceof Package) { + Package pkg = (Package) n; + isCurrentPackageDeploymentView=ViewUtils.isDeploymentView(pkg); + } + + + if(isCurrentPackageDeploymentView || notification.getEventType() == PapyrusStereotypeListener.MODIFIED_STEREOTYPE && + dview.getName().equals(CHESSProfileManager.DEPLOYMENT_VIEW)){ + return true; + } + + else if (notification.getEventType() == Notification.SET || + notification.getEventType() == Notification.REMOVE || + notification.getEventType() == PapyrusStereotypeListener.APPLIED_STEREOTYPE || + notification.getEventType() == PapyrusStereotypeListener.UNAPPLIED_STEREOTYPE || + notification.getEventType() == PapyrusStereotypeListener.MODIFIED_STEREOTYPE + ) { + return false; + } + return true; + } }; \ No newline at end of file diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/Messages.java b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/messages/Messages.java similarity index 71% rename from plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/Messages.java rename to plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/messages/Messages.java index acdeb8bfe..0c1bbb7b2 100644 --- a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/Messages.java +++ b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/messages/Messages.java @@ -14,25 +14,59 @@ ----------------------------------------------------------------------- */ -package org.polarsys.chess.validator.managers; +package org.polarsys.chess.validator.messages; import org.eclipse.osgi.util.NLS; +// TODO: Auto-generated Javadoc +/** + * The Class Messages contains the string constants used in the validation + */ public class Messages extends NLS { + + /** The Constant BUNDLE_NAME. */ private static final String BUNDLE_NAME = "org.polarsys.chess.validator.managers.messages"; //$NON-NLS-1$ + + /** The error_diagram in view. */ public static String error_diagramInView; + + /** The error_diagram current view. */ public static String error_diagramCurrentView; + + /** The Null view msg. */ public static String NullViewMsg; + + /** The Model manager_1. */ public static String ModelManager_1; + + /** The Model manager_2. */ public static String ModelManager_2; + + /** The Model manager_3. */ public static String ModelManager_3; + + /** The Model manager_4. */ public static String ModelManager_4; + + /** The Model manager_5. */ public static String ModelManager_5; + + /** The Model manager_6. */ public static String ModelManager_6; + + /** The Model manager_7. */ public static String ModelManager_7; + + /** The Model manager_8. */ public static String ModelManager_8; + + /** The Model manager_9. */ public static String ModelManager_9; + + /** The View deletion msg. */ public static String ViewDeletionMsg; + + /** The operation aborted. */ public static String operationAborted; static { @@ -40,6 +74,9 @@ public class Messages extends NLS { NLS.initializeMessages(BUNDLE_NAME, Messages.class); } + /** + * Instantiates a new messages. + */ private Messages() { } } diff --git a/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/messages.properties b/plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/messages/messages.properties similarity index 100% rename from plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/managers/messages.properties rename to plugins/org.polarsys.chess.validator/src/org/polarsys/chess/validator/messages/messages.properties -- GitLab