Skip to content

Package: ECPProjectManagerFactory

ECPProjectManagerFactory

nameinstructionbranchcomplexitylinemethod
ECPProjectManagerFactory()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
beforeDestroy(UISessionEvent)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getService(Bundle, ServiceRegistration)
M: 0 C: 38
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
getSessionProvider()
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
init()
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%
ungetService(Bundle, ServiceRegistration, ECPProjectManager)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 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: * Neil Mackenzie - initial implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.core.rap;
15:
16: import java.util.HashMap;
17: import java.util.Map;
18:
19: import org.eclipse.emf.ecp.core.ECPProjectManager;
20: import org.eclipse.emf.ecp.core.util.ECPUtil;
21: import org.eclipse.emf.ecp.internal.core.ECPProjectManagerImpl;
22: import org.eclipse.net4j.util.lifecycle.Lifecycle;
23: import org.eclipse.rap.rwt.service.UISessionEvent;
24: import org.eclipse.rap.rwt.service.UISessionListener;
25: import org.osgi.framework.Bundle;
26: import org.osgi.framework.BundleContext;
27: import org.osgi.framework.FrameworkUtil;
28: import org.osgi.framework.PrototypeServiceFactory;
29: import org.osgi.framework.ServiceReference;
30: import org.osgi.framework.ServiceRegistration;
31:
32: /**
33: * This is the factory for creating the ECPProjectManager service.
34: *
35: * @author neilmack
36: *
37: */
38: public class ECPProjectManagerFactory implements
39:         PrototypeServiceFactory<ECPProjectManager>, UISessionListener {
40:
41:         /**
42:          * The session provider used to retrieve the current session.
43:          */
44:         private SessionProvider sessionProvider;
45:         /**
46:          * a map of sessions to services.
47:          */
48:         private final Map<String, ECPProjectManagerImpl> sessionRegistry = new HashMap<String, ECPProjectManagerImpl>();
49:
50:         /**
51:          * default constructor.
52:          */
53:         public ECPProjectManagerFactory() {
54:                 init();
55:         }
56:
57:         /**
58:          * initialise the factory.
59:          */
60:         public final void init() {
61:                 getSessionProvider();
62:         }
63:
64:         /**
65:          * this class retrieves the session provider. If the sessionProvider is
66:          * not set yet then it is created and set.
67:          *
68:          * @return the session provider
69:          */
70:         private SessionProvider getSessionProvider() {
71:•                if (sessionProvider == null) {
72:                         final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
73:                         final ServiceReference<SessionProvider> serviceReference = bundleContext
74:                                 .getServiceReference(SessionProvider.class);
75:                         sessionProvider = bundleContext.getService(serviceReference);
76:                 }
77:                 return sessionProvider;
78:         }
79:
80:         /**
81:          * this method returns the ECPProjectManager service for the
82:          * current session.
83:          * It is called by the OSGI framework.
84:          *
85:          * @param bundle the OSGI bundle
86:          * @param registration the service registration
87:          *
88:          * @return the service
89:          */
90:         @Override
91:         public ECPProjectManager getService(Bundle bundle,
92:                 ServiceRegistration<ECPProjectManager> registration) {
93:                 ECPProjectManagerImpl ecpProjectManager;
94:                 final String sessionId = getSessionProvider().getSessionId();
95:                 // final UISession uiSession = RWT.getUISession();
96:                 // uiSession.addUISessionListener(this);
97:                 getSessionProvider().registerListenerWithSession(this);
98:•                if (sessionRegistry.containsKey(sessionId)) {
99:                         ecpProjectManager = sessionRegistry.get(sessionId);
100:                 } else {
101:                         ecpProjectManager = new ECPProjectManagerImpl(sessionId);
102:                         ecpProjectManager.setECPObserverBus(ECPUtil.getECPObserverBus());
103:                         sessionRegistry.put(sessionId, ecpProjectManager);
104:                         ((Lifecycle) ecpProjectManager).activate();
105:
106:                 }
107:                 return ecpProjectManager;
108:         }
109:
110:         /**
111:          * this methodis called to unget a serive from a service registration.
112:          *
113:          * @param bundle the OSGI bundle
114:          * @param registration the service registration
115:          * @param service the service
116:          */
117:         @Override
118:         public void ungetService(Bundle bundle,
119:                 ServiceRegistration<ECPProjectManager> registration,
120:                 ECPProjectManager service) {
121:
122:         }
123:
124:         /**
125:          * {@inheritDoc}
126:          *
127:          * @see org.eclipse.rap.rwt.service.UISessionListener#beforeDestroy(org.eclipse.rap.rwt.service.UISessionEvent)
128:          */
129:         @Override
130:         public void beforeDestroy(UISessionEvent event) {
131:                 sessionRegistry.remove(event.getUISession().toString());
132:
133:         }
134:
135: }