Skip to content

Package: ECPRepositoryImpl

ECPRepositoryImpl

nameinstructionbranchcomplexitylinemethod
ECPRepositoryImpl(ECPProvider, String, ECPProperties)
M: 5 C: 28
85%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 8
89%
M: 0 C: 1
100%
ECPRepositoryImpl(ObjectInput)
M: 11 C: 35
76%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 9
90%
M: 0 C: 1
100%
addDisposeListener(ECPDisposable.DisposeListener)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
canDelete()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
delete()
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
disposed(ECPDisposable)
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getAdapter(Class)
M: 20 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getDescription()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getLabel()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getOpenProjects()
M: 0 C: 36
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 5
100%
M: 0 C: 1
100%
getProvider()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getProviderSpecificData()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getType()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isDisposed()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isStorable()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
notifyObjectsChanged(Collection)
M: 11 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
propertiesChanged(Collection, Collection)
M: 0 C: 9
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
removeDisposeListener(ECPDisposable.DisposeListener)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setDescription(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setLabel(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setProviderSpecificData(Object)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
write(ObjectOutput)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eike Stepper - initial API and implementation
13: * Eugen Neufeld - JavaDoc
14: *******************************************************************************/
15:
16: package org.eclipse.emf.ecp.internal.core;
17:
18: import java.io.IOException;
19: import java.io.ObjectInput;
20: import java.io.ObjectOutput;
21: import java.util.ArrayList;
22: import java.util.Collection;
23: import java.util.Collections;
24: import java.util.List;
25: import java.util.Map.Entry;
26:
27: import org.eclipse.core.runtime.Platform;
28: import org.eclipse.emf.ecp.core.ECPProject;
29: import org.eclipse.emf.ecp.core.ECPProvider;
30: import org.eclipse.emf.ecp.core.ECPRepository;
31: import org.eclipse.emf.ecp.core.util.ECPProperties;
32: import org.eclipse.emf.ecp.core.util.ECPUtil;
33: import org.eclipse.emf.ecp.internal.core.util.Disposable;
34: import org.eclipse.emf.ecp.internal.core.util.PropertiesElement;
35: import org.eclipse.emf.ecp.spi.core.InternalProject;
36: import org.eclipse.emf.ecp.spi.core.InternalProvider;
37: import org.eclipse.emf.ecp.spi.core.InternalProvider.LifecycleEvent;
38: import org.eclipse.emf.ecp.spi.core.InternalRepository;
39: import org.eclipse.emf.ecp.spi.core.util.DisposeException;
40: import org.eclipse.emf.ecp.spi.core.util.ECPDisposable;
41: import org.eclipse.emf.ecp.spi.core.util.ECPDisposable.DisposeListener;
42: import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
43:
44: /**
45: * This Class describes a repository.
46: *
47: * @author Eike Stepper
48: * @author Eugen Neufeld
49: */
50: public final class ECPRepositoryImpl extends PropertiesElement implements InternalRepository, DisposeListener {
51:         @ExcludeFromDump
52:         private final Disposable disposable = new Disposable(this) {
53:                 @Override
54:                 protected void doDispose() {
55:                         provider = null;
56:                         providerSpecificData = null;
57:                 }
58:         };
59:
60:         private String label;
61:
62:         private String description;
63:
64:         private InternalProvider provider;
65:
66:         private Object providerSpecificData;
67:
68:         /**
69:          * Constructor used to create an instance through user input.
70:          *
71:          * @param provider the {@link ECPProvider} for this repository
72:          * @param name the name of this repository
73:          * @param properties the {@link ECPProperties} of this repository
74:          */
75:         public ECPRepositoryImpl(ECPProvider provider, String name, ECPProperties properties) {
76:                 super(name, properties);
77:                 label = name;
78:                 description = ""; //$NON-NLS-1$
79:
80:•                if (provider == null) {
81:                         throw new IllegalArgumentException("Provider is null"); //$NON-NLS-1$
82:                 }
83:
84:                 this.provider = (InternalProvider) provider;
85:                 this.provider.addDisposeListener(this);
86:         }
87:
88:         /**
89:          * Constructor used by the {@link org.eclipse.emf.ecp.core.ECPRepositoryManager ECPRepositoryManager} when loading
90:          * existing repositories during startup.
91:          *
92:          * @param in the {@link ObjectInput} to parse
93:          * @throws IOException when an error occurs
94:          */
95:         public ECPRepositoryImpl(ObjectInput in) throws IOException {
96:                 super(in);
97:
98:                 label = in.readUTF();
99:                 description = in.readUTF();
100:
101:                 final String providerName = in.readUTF();
102:                 provider = (InternalProvider) ECPUtil.getECPProviderRegistry().getProvider(providerName);
103:•                if (provider == null) {
104:                         throw new IllegalStateException("Provider not found: " + providerName); //$NON-NLS-1$
105:                 }
106:
107:                 provider.addDisposeListener(this);
108:         }
109:
110:         /** {@inheritDoc} **/
111:         @Override
112:         public String getType() {
113:                 return ECPRepository.TYPE;
114:         }
115:
116:         /** {@inheritDoc} **/
117:         @Override
118:         public void disposed(ECPDisposable disposable) throws DisposeException {
119:•                if (disposable == provider) {
120:                         dispose();
121:                 }
122:         }
123:
124:         /** {@inheritDoc} **/
125:         @Override
126:         public boolean isStorable() {
127:                 return true;
128:         }
129:
130:         @Override
131:         public void write(ObjectOutput out) throws IOException {
132:                 super.write(out);
133:                 out.writeUTF(label);
134:                 out.writeUTF(description);
135:                 out.writeUTF(provider.getName());
136:         }
137:
138:         /** {@inheritDoc} **/
139:         @Override
140:         public String getLabel() {
141:                 return label;
142:         }
143:
144:         /** {@inheritDoc} **/
145:         @Override
146:         public void setLabel(String label) {
147:                 this.label = label;
148:         }
149:
150:         /** {@inheritDoc} **/
151:         @Override
152:         public String getDescription() {
153:                 return description;
154:         }
155:
156:         /** {@inheritDoc} **/
157:         @Override
158:         public void setDescription(String description) {
159:                 this.description = description;
160:         }
161:
162:         /** {@inheritDoc} **/
163:         @Override
164:         public boolean isDisposed() {
165:                 return disposable.isDisposed();
166:         }
167:
168:         /**
169:          * Returns an object which is an instance of the given class associated with this object. Returns <code>null</code>
170:          * if
171:          * no such object can be found.
172:          * <p>
173:          * This implementation of the method declared by <code>IAdaptable</code> passes the request along to the platform's
174:          * adapter manager; roughly <code>Platform.getAdapterManager().getAdapter(this, adapter)</code>. Subclasses may
175:          * override this method (however, if they do so, they should invoke the method on their superclass to ensure that
176:          * the Platform's adapter manager is consulted).
177:          * </p>
178:          *
179:          * @param adapterType
180:          * the class to adapt to
181:          * @return the adapted object or <code>null</code>
182:          * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
183:          */
184:         @SuppressWarnings({ "unchecked", "rawtypes" })
185:         public Object getAdapter(Class adapterType) {
186:                 final InternalProvider provider = getProvider();
187:•                if (!provider.isDisposed()) {
188:                         final Object result = provider.getAdapter(this, adapterType);
189:•                        if (result != null) {
190:                                 return result;
191:                         }
192:                 }
193:
194:                 return Platform.getAdapterManager().getAdapter(this, adapterType);
195:         }
196:
197:         /** {@inheritDoc} **/
198:         @Override
199:         public void dispose() {
200:                 disposable.dispose();
201:         }
202:
203:         /** {@inheritDoc} **/
204:         @Override
205:         public void addDisposeListener(DisposeListener listener) {
206:                 disposable.addDisposeListener(listener);
207:         }
208:
209:         /** {@inheritDoc} **/
210:         @Override
211:         public void removeDisposeListener(DisposeListener listener) {
212:                 disposable.removeDisposeListener(listener);
213:         }
214:
215:         /** {@inheritDoc} **/
216:         @Override
217:         public InternalProvider getProvider() {
218:                 return provider;
219:         }
220:
221:         /** {@inheritDoc} **/
222:         @Override
223:         public Object getProviderSpecificData() {
224:                 return providerSpecificData;
225:         }
226:
227:         /** {@inheritDoc} **/
228:         @Override
229:         public void setProviderSpecificData(Object providerSpecificData) {
230:                 this.providerSpecificData = providerSpecificData;
231:         }
232:
233:         /** {@inheritDoc} **/
234:         @Override
235:         public boolean canDelete() {
236:                 return isStorable();
237:         }
238:
239:         /** {@inheritDoc} **/
240:         @Override
241:         public void delete() {
242:•                if (!canDelete()) {
243:                         throw new UnsupportedOperationException();
244:                 }
245:                 // FIXME https://bugs.eclipse.org/bugs/show_bug.cgi?id=462399
246:                 cleanup();
247:                 try {
248:                         provider.handleLifecycle(this, LifecycleEvent.REMOVE);
249:                 } catch (final Exception ex) {
250:                         Activator.log(ex);
251:                 }
252:
253:                 ((ECPRepositoryManagerImpl) ECPUtil.getECPRepositoryManager()).changeElements(Collections.singleton(getName()),
254:                         null);
255:         }
256:
257:         /** {@inheritDoc} **/
258:         @Override
259:         public void notifyObjectsChanged(Collection<Object> objects) {
260:•                if (objects != null && objects.size() != 0) {
261:                         ((ECPRepositoryManagerImpl) ECPUtil.getECPRepositoryManager()).notifyObjectsChanged(this, objects);
262:                 }
263:         }
264:
265:         /**
266:          * Return all open projects of that are shared on this repository.
267:          *
268:          * @return array of currently open {@link ECPProject ECPProjects} that are shared on this repository
269:          */
270:         public InternalProject[] getOpenProjects() {
271:                 final List<InternalProject> result = new ArrayList<InternalProject>();
272:•                for (final ECPProject project : ECPUtil.getECPProjectManager().getProjects()) {
273:•                        if (project.isOpen() && project.getRepository().equals(this)) {
274:                                 result.add((InternalProject) project);
275:                         }
276:                 }
277:
278:                 // TODO Consider to cache the result
279:                 return result.toArray(new InternalProject[result.size()]);
280:         }
281:
282:         @Override
283:         protected void propertiesChanged(Collection<Entry<String, String>> oldProperties,
284:                 Collection<Entry<String, String>> newProperties) {
285:                 final ECPRepositoryManagerImpl repositoryManager = (ECPRepositoryManagerImpl) ECPUtil.getECPRepositoryManager();
286:•                if (repositoryManager != null) {
287:                         repositoryManager.storeElement(this);
288:                 }
289:         }
290: }