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 [ProvidedDelegationConnectorCreateCommand.java]

nameclass, %method, %block, %line, %
ProvidedDelegationConnectorCreateCommand.java0%   (0/1)0%   (0/9)0%   (0/180)0%   (0/56)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProvidedDelegationConnectorCreateCommand0%   (0/1)0%   (0/9)0%   (0/180)0%   (0/56)
ProvidedDelegationConnectorCreateCommand (CreateRelationshipRequest, EObject,... 0%   (0/1)0%   (0/18)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 (ProvidedDelegationConnector, IProgressMonitor, IAdaptable): void 0%   (0/1)0%   (0/49)0%   (0/16)
doExecuteWithResult (IProgressMonitor, IAdaptable): CommandResult 0%   (0/1)0%   (0/38)0%   (0/13)
getContainer (): ComposedStructure 0%   (0/1)0%   (0/3)0%   (0/1)
getSource (): OperationProvidedRole 0%   (0/1)0%   (0/4)0%   (0/1)
getTarget (): OperationProvidedRole 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.ComposedStructure;
19import de.uka.ipd.sdq.pcm.core.composition.CompositionFactory;
20import de.uka.ipd.sdq.pcm.core.composition.ProvidedDelegationConnector;
21import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy;
22import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole;
23 
24/**
25 * @generated
26 */
27public class ProvidedDelegationConnectorCreateCommand extends
28                EditElementCommand {
29 
30        /**
31         * @generated
32         */
33        private final EObject source;
34 
35        /**
36         * @generated
37         */
38        private final EObject target;
39 
40        /**
41         * @generated
42         */
43        private final ComposedStructure container;
44 
45        /**
46         * @generated
47         */
48        public ProvidedDelegationConnectorCreateCommand(
49                        CreateRelationshipRequest request, EObject source, EObject target) {
50                super(request.getLabel(), null, request);
51                this.source = source;
52                this.target = target;
53                container = deduceContainer(source, target);
54        }
55 
56        /**
57         * @generated
58         */
59        public boolean canExecute() {
60                if (source == null && target == null) {
61                        return false;
62                }
63                if (source != null && false == source instanceof OperationProvidedRole) {
64                        return false;
65                }
66                if (target != null && false == target instanceof OperationProvidedRole) {
67                        return false;
68                }
69                if (getSource() == null) {
70                        return true; // link creation is in progress; source is not defined yet
71                }
72                // target may be null here but it's possible to check constraint
73                if (getContainer() == null) {
74                        return false;
75                }
76                return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints
77                                .canCreateProvidedDelegationConnector_4006(getContainer(),
78                                                getSource(), getTarget());
79        }
80 
81        /**
82         * @generated
83         */
84        protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
85                        IAdaptable info) throws ExecutionException {
86                if (!canExecute()) {
87                        throw new ExecutionException(
88                                        "Invalid arguments in create link command"); //$NON-NLS-1$
89                }
90 
91                ProvidedDelegationConnector newElement = CompositionFactory.eINSTANCE
92                                .createProvidedDelegationConnector();
93                getContainer().getConnectors__ComposedStructure().add(newElement);
94                newElement
95                                .setOuterProvidedRole_ProvidedDelegationConnector(getSource());
96                newElement
97                                .setInnerProvidedRole_ProvidedDelegationConnector(getTarget());
98                doConfigure(newElement, monitor, info);
99                ((CreateElementRequest) getRequest()).setNewElement(newElement);
100                return CommandResult.newOKCommandResult(newElement);
101 
102        }
103 
104        /**
105         * @generated
106         */
107        protected void doConfigure(ProvidedDelegationConnector newElement,
108                        IProgressMonitor monitor, IAdaptable info)
109                        throws ExecutionException {
110                IElementType elementType = ((CreateElementRequest) getRequest())
111                                .getElementType();
112                ConfigureRequest configureRequest = new ConfigureRequest(
113                                getEditingDomain(), newElement, elementType);
114                configureRequest.setClientContext(((CreateElementRequest) getRequest())
115                                .getClientContext());
116                configureRequest.addParameters(getRequest().getParameters());
117                configureRequest.setParameter(CreateRelationshipRequest.SOURCE,
118                                getSource());
119                configureRequest.setParameter(CreateRelationshipRequest.TARGET,
120                                getTarget());
121                ICommand configureCommand = elementType
122                                .getEditCommand(configureRequest);
123                if (configureCommand != null && configureCommand.canExecute()) {
124                        configureCommand.execute(monitor, info);
125                }
126        }
127 
128        /**
129         * @generated
130         */
131        protected void setElementToEdit(EObject element) {
132                throw new UnsupportedOperationException();
133        }
134 
135        /**
136         * @generated
137         */
138        protected OperationProvidedRole getSource() {
139                return (OperationProvidedRole) source;
140        }
141 
142        /**
143         * @generated
144         */
145        protected OperationProvidedRole getTarget() {
146                return (OperationProvidedRole) target;
147        }
148 
149        /**
150         * @generated
151         */
152        public ComposedStructure getContainer() {
153                return container;
154        }
155 
156        /**
157         * Default approach is to traverse ancestors of the source to find instance of container.
158         * Modify with appropriate logic.
159         * @generated
160         */
161        private static ComposedStructure deduceContainer(EObject source,
162                        EObject target) {
163                // Find container element for the new link.
164                // Climb up by containment hierarchy starting from the source
165                // and return the first element that is instance of the container class.
166                for (EObject element = source; element != null; element = element
167                                .eContainer()) {
168                        if (element instanceof ComposedStructure) {
169                                return (ComposedStructure) element;
170                        }
171                }
172                return null;
173        }
174 
175}

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