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

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

COVERAGE BREAKDOWN BY CLASS AND METHOD

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

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