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

nameclass, %method, %block, %line, %
AssemblyConnectorCreateCommand.java0%   (0/1)0%   (0/9)0%   (0/180)0%   (0/54)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AssemblyConnectorCreateCommand0%   (0/1)0%   (0/9)0%   (0/180)0%   (0/54)
AssemblyConnectorCreateCommand (CreateRelationshipRequest, EObject, 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 (AssemblyConnector, IProgressMonitor, IAdaptable): void 0%   (0/1)0%   (0/49)0%   (0/16)
doExecuteWithResult (IProgressMonitor, IAdaptable): CommandResult 0%   (0/1)0%   (0/38)0%   (0/11)
getContainer (): ComposedStructure 0%   (0/1)0%   (0/3)0%   (0/1)
getSource (): OperationRequiredRole 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.AssemblyConnector;
19import de.uka.ipd.sdq.pcm.core.composition.ComposedStructure;
20import de.uka.ipd.sdq.pcm.core.composition.CompositionFactory;
21import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy;
22import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole;
23import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole;
24 
25/**
26 * @generated
27 */
28public class AssemblyConnectorCreateCommand extends 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 AssemblyConnectorCreateCommand(CreateRelationshipRequest request,
49                        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 OperationRequiredRole) {
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                                .canCreateAssemblyConnector_4004(getContainer(), getSource(),
78                                                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                AssemblyConnector newElement = CompositionFactory.eINSTANCE
92                                .createAssemblyConnector();
93                getContainer().getConnectors__ComposedStructure().add(newElement);
94                newElement.setRequiredRole_AssemblyConnector(getSource());
95                newElement.setProvidedRole_AssemblyConnector(getTarget());
96                doConfigure(newElement, monitor, info);
97                ((CreateElementRequest) getRequest()).setNewElement(newElement);
98                return CommandResult.newOKCommandResult(newElement);
99 
100        }
101 
102        /**
103         * @generated
104         */
105        protected void doConfigure(AssemblyConnector newElement,
106                        IProgressMonitor monitor, IAdaptable info)
107                        throws ExecutionException {
108                IElementType elementType = ((CreateElementRequest) getRequest())
109                                .getElementType();
110                ConfigureRequest configureRequest = new ConfigureRequest(
111                                getEditingDomain(), newElement, elementType);
112                configureRequest.setClientContext(((CreateElementRequest) getRequest())
113                                .getClientContext());
114                configureRequest.addParameters(getRequest().getParameters());
115                configureRequest.setParameter(CreateRelationshipRequest.SOURCE,
116                                getSource());
117                configureRequest.setParameter(CreateRelationshipRequest.TARGET,
118                                getTarget());
119                ICommand configureCommand = elementType
120                                .getEditCommand(configureRequest);
121                if (configureCommand != null && configureCommand.canExecute()) {
122                        configureCommand.execute(monitor, info);
123                }
124        }
125 
126        /**
127         * @generated
128         */
129        protected void setElementToEdit(EObject element) {
130                throw new UnsupportedOperationException();
131        }
132 
133        /**
134         * @generated
135         */
136        protected OperationRequiredRole getSource() {
137                return (OperationRequiredRole) source;
138        }
139 
140        /**
141         * @generated
142         */
143        protected OperationProvidedRole getTarget() {
144                return (OperationProvidedRole) target;
145        }
146 
147        /**
148         * @generated
149         */
150        public ComposedStructure getContainer() {
151                return container;
152        }
153 
154        /**
155         * Default approach is to traverse ancestors of the source to find instance of container.
156         * Modify with appropriate logic.
157         * @generated
158         */
159        private static ComposedStructure deduceContainer(EObject source,
160                        EObject target) {
161                // Find container element for the new link.
162                // Climb up by containment hierarchy starting from the source
163                // and return the first element that is instance of the container class.
164                for (EObject element = source; element != null; element = element
165                                .eContainer()) {
166                        if (element instanceof ComposedStructure) {
167                                return (ComposedStructure) element;
168                        }
169                }
170                return null;
171        }
172 
173}

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