Skip to content

Package: ECPRepositoryManagerFactory

ECPRepositoryManagerFactory

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