EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.pcm.gmf.composite.edit.commands]

COVERAGE SUMMARY FOR SOURCE FILE [AssemblyEventConnectorCreateCommand.java]

nameclass, %method, %block, %line, %
AssemblyEventConnectorCreateCommand.java0%   (0/1)0%   (0/9)0%   (0/197)0%   (0/62)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AssemblyEventConnectorCreateCommand0%   (0/1)0%   (0/9)0%   (0/197)0%   (0/62)
AssemblyEventConnectorCreateCommand (CreateRelationshipRequest, EObject, EObj... 0%   (0/1)0%   (0/19)0%   (0/5)
canExecute (): boolean 0%   (0/1)0%   (0/44)0%   (0/13)
deduceContainer (EObject, EObject): ComposedStructure 0%   (0/1)0%   (0/16)0%   (0/5)
doConfigure (AssemblyEventConnector, IProgressMonitor, IAdaptable): void 0%   (0/1)0%   (0/49)0%   (0/16)
doExecuteWithResult (IProgressMonitor, IAdaptable): CommandResult 0%   (0/1)0%   (0/54)0%   (0/19)
getContainer (): ComposedStructure 0%   (0/1)0%   (0/3)0%   (0/1)
getSource (): SourceRole 0%   (0/1)0%   (0/4)0%   (0/1)
getTarget (): SinkRole 0%   (0/1)0%   (0/4)0%   (0/1)
setElementToEdit (EObject): void 0%   (0/1)0%   (0/4)0%   (0/1)

1/*
2 * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH)
3 */
4package de.uka.ipd.sdq.pcm.gmf.composite.edit.commands;
5 
6import org.eclipse.core.commands.ExecutionException;
7import org.eclipse.core.runtime.IAdaptable;
8import org.eclipse.core.runtime.IProgressMonitor;
9import org.eclipse.emf.ecore.EObject;
10import org.eclipse.gmf.runtime.common.core.command.CommandResult;
11import org.eclipse.gmf.runtime.common.core.command.ICommand;
12import org.eclipse.gmf.runtime.emf.type.core.IElementType;
13import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
14import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
15import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
16import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
17 
18import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext;
19import de.uka.ipd.sdq.pcm.core.composition.AssemblyEventConnector;
20import de.uka.ipd.sdq.pcm.core.composition.ComposedStructure;
21import de.uka.ipd.sdq.pcm.core.composition.CompositionFactory;
22import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy;
23import de.uka.ipd.sdq.pcm.repository.SinkRole;
24import de.uka.ipd.sdq.pcm.repository.SourceRole;
25 
26/**
27 * @generated
28 */
29public class AssemblyEventConnectorCreateCommand extends EditElementCommand {
30 
31        /**
32         * @generated
33         */
34        private final EObject source;
35 
36        /**
37         * @generated
38         */
39        private final EObject target;
40 
41        /**
42         * @generated
43         */
44        private final ComposedStructure container;
45 
46        /**
47         * Constructor to set the default attributes for connector elements.
48         * 
49         * This has been modified to deduce the container from the request, while
50         * the assembly connector is not accessible from source or target.
51         * Note: The request object is not accessible by the deduceContainer() method.
52         * For this, the container is deduced directly in the contructor.
53         * 
54         * @generated not
55         */
56        public AssemblyEventConnectorCreateCommand(
57                        CreateRelationshipRequest request, EObject source, EObject target) {
58                super(request.getLabel(), null, request);
59                this.source = source;
60                this.target = target;
61 
62                // The container has been placed in the request during the SinkRoleItemSemanticEditPolicy
63                container = (ComposedStructure) request.getParameter("CONTAINER");
64        }
65 
66        /**
67         * @generated
68         */
69        public boolean canExecute() {
70                if (source == null && target == null) {
71                        return false;
72                }
73                if (source != null && false == source instanceof SourceRole) {
74                        return false;
75                }
76                if (target != null && false == target instanceof SinkRole) {
77                        return false;
78                }
79                if (getSource() == null) {
80                        return true; // link creation is in progress; source is not defined yet
81                }
82                // target may be null here but it's possible to check constraint
83                if (getContainer() == null) {
84                        return false;
85                }
86                return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints
87                                .canCreateAssemblyEventConnector_4007(getContainer(),
88                                                getSource(), getTarget());
89        }
90 
91        /**
92         * Execute the command to build up the new assembly event connector.
93         * 
94         * This has been manually modified to set the additional 
95         * assembly context references
96         * 
97         * @generated not
98         */
99        protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
100                        IAdaptable info) throws ExecutionException {
101                if (!canExecute()) {
102                        throw new ExecutionException(
103                                        "Invalid arguments in create link command"); //$NON-NLS-1$
104                }
105 
106                AssemblyEventConnector newElement = CompositionFactory.eINSTANCE
107                                .createAssemblyEventConnector();
108 
109                getContainer().getConnectors__ComposedStructure().add(newElement);
110                newElement.setSourceRole__AssemblyEventConnector(getSource());
111                newElement.setSinkRole__AssemblyEventConnector(getTarget());
112 
113                // set the assembly contexts.
114                CreateRelationshipRequest req = (CreateRelationshipRequest) this
115                                .getRequest();
116                newElement
117                                .setSourceAssemblyContext__AssemblyEventConnector((AssemblyContext) req
118                                                .getParameter("SOURCE_CONTEXT"));
119                newElement
120                                .setSinkAssemblyContext__AssemblyEventConnector((AssemblyContext) req
121                                                .getParameter("SINK_CONTEXT"));
122 
123                doConfigure(newElement, monitor, info);
124                ((CreateElementRequest) getRequest()).setNewElement(newElement);
125                return CommandResult.newOKCommandResult(newElement);
126 
127        }
128 
129        /**
130         * @generated
131         */
132        protected void doConfigure(AssemblyEventConnector newElement,
133                        IProgressMonitor monitor, IAdaptable info)
134                        throws ExecutionException {
135                IElementType elementType = ((CreateElementRequest) getRequest())
136                                .getElementType();
137                ConfigureRequest configureRequest = new ConfigureRequest(
138                                getEditingDomain(), newElement, elementType);
139                configureRequest.setClientContext(((CreateElementRequest) getRequest())
140                                .getClientContext());
141                configureRequest.addParameters(getRequest().getParameters());
142                configureRequest.setParameter(CreateRelationshipRequest.SOURCE,
143                                getSource());
144                configureRequest.setParameter(CreateRelationshipRequest.TARGET,
145                                getTarget());
146                ICommand configureCommand = elementType
147                                .getEditCommand(configureRequest);
148                if (configureCommand != null && configureCommand.canExecute()) {
149                        configureCommand.execute(monitor, info);
150                }
151        }
152 
153        /**
154         * @generated
155         */
156        protected void setElementToEdit(EObject element) {
157                throw new UnsupportedOperationException();
158        }
159 
160        /**
161         * @generated
162         */
163        protected SourceRole getSource() {
164                return (SourceRole) source;
165        }
166 
167        /**
168         * @generated
169         */
170        protected SinkRole getTarget() {
171                return (SinkRole) target;
172        }
173 
174        /**
175         * @generated
176         */
177        public ComposedStructure getContainer() {
178                return container;
179        }
180 
181        /**
182         * Default approach is to traverse ancestors of the source to find instance of container.
183         * Modify with appropriate logic.
184         * @generated
185         */
186        private static ComposedStructure deduceContainer(EObject source,
187                        EObject target) {
188                // Find container element for the new link.
189                // Climb up by containment hierarchy starting from the source
190                // and return the first element that is instance of the container class.
191                for (EObject element = source; element != null; element = element
192                                .eContainer()) {
193                        if (element instanceof ComposedStructure) {
194                                return (ComposedStructure) element;
195                        }
196                }
197                return null;
198        }
199 
200}

[all classes][de.uka.ipd.sdq.pcm.gmf.composite.edit.commands]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov