Skip to content

Package: EMFFormsLegacyServicesManagerImpl

EMFFormsLegacyServicesManagerImpl

nameinstructionbranchcomplexitylinemethod
EMFFormsLegacyServicesManagerImpl()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
activate(BundleContext)
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%
deactivate()
M: 0 C: 18
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
instantiate()
M: 0 C: 34
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
parseExtensions()
M: 10 C: 67
87%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 2 C: 15
88%
M: 0 C: 1
100%
setReportService(ReportService)
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%

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: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.core.services.legacy;
15:
16: import java.util.LinkedHashSet;
17: import java.util.Set;
18:
19: import org.eclipse.core.runtime.CoreException;
20: import org.eclipse.core.runtime.IConfigurationElement;
21: import org.eclipse.core.runtime.IExtensionRegistry;
22: import org.eclipse.core.runtime.Platform;
23: import org.eclipse.emf.ecp.view.spi.context.EMFFormsLegacyServicesManager;
24: import org.eclipse.emf.ecp.view.spi.context.GlobalViewModelService;
25: import org.eclipse.emf.ecp.view.spi.context.ViewModelService;
26: import org.eclipse.emfforms.spi.common.report.AbstractReport;
27: import org.eclipse.emfforms.spi.common.report.ReportService;
28: import org.eclipse.emfforms.spi.core.services.view.EMFFormsViewServiceFactory;
29: import org.osgi.framework.BundleContext;
30: import org.osgi.framework.ServiceRegistration;
31: import org.osgi.service.component.annotations.Activate;
32: import org.osgi.service.component.annotations.Component;
33: import org.osgi.service.component.annotations.Deactivate;
34: import org.osgi.service.component.annotations.Reference;
35: import org.osgi.service.component.annotations.ReferenceCardinality;
36: import org.osgi.service.component.annotations.ReferencePolicy;
37:
38: /**
39: * This implements the {@link EMFFormsLegacyServicesManager} which allows to use {@link ViewModelService} registered
40: * using an extension point with the new osgi based architecture.
41: *
42: * @author Eugen Neufeld
43: *
44: */
45: @SuppressWarnings("rawtypes")
46: @Component
47: public class EMFFormsLegacyServicesManagerImpl implements EMFFormsLegacyServicesManager {
48:
49:         private ReportService reportService;
50:         private final Set<ServiceRegistration<EMFFormsViewServiceFactory>> registrations = new LinkedHashSet<ServiceRegistration<EMFFormsViewServiceFactory>>();
51:         private BundleContext bundleContext;
52:         private boolean instantiated;
53:
54:         /**
55:          * Called by OSGi to set the {@link ReportService}.
56:          *
57:          * @param reportService The {@link ReportService}
58:          */
59:         @Reference(cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.STATIC, unbind = "-")
60:         protected void setReportService(ReportService reportService) {
61:                 this.reportService = reportService;
62:         }
63:
64:         /**
65:          * Called by OSGi when the component is ready to be activated.
66:          *
67:          * @param bundleContext The {@link BundleContext}
68:          */
69:         @Activate
70:         protected void activate(BundleContext bundleContext) {
71:                 this.bundleContext = bundleContext;
72:         }
73:
74:         /**
75:          * Called by OSGi when the component must be deactivated.
76:          */
77:         @Deactivate
78:         protected void deactivate() {
79:•                for (final ServiceRegistration<EMFFormsViewServiceFactory> registration : registrations) {
80:                         registration.unregister();
81:                 }
82:                 registrations.clear();
83:         }
84:
85:         @SuppressWarnings("unchecked")
86:         private Set<EMFFormsViewServiceFactory<? extends ViewModelService>> parseExtensions() {
87:                 final Set<EMFFormsViewServiceFactory<? extends ViewModelService>> legacyServiceProviders = new LinkedHashSet<EMFFormsViewServiceFactory<? extends ViewModelService>>();
88:                 final IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
89:•                if (extensionRegistry == null) {
90:                         return legacyServiceProviders;
91:                 }
92:                 final IConfigurationElement[] controls = extensionRegistry
93:                         .getConfigurationElementsFor("org.eclipse.emf.ecp.view.context.viewServices"); //$NON-NLS-1$
94:•                for (final IConfigurationElement e : controls) {
95:                         try {
96:                                 final ViewModelService viewService = (ViewModelService) e.createExecutableExtension("class"); //$NON-NLS-1$
97:•                                if (GlobalViewModelService.class.isInstance(viewService)) {
98:                                         legacyServiceProviders.add(new EMFFormsLegacyGlobalServiceFactory(viewService.getClass(),
99:                                                 viewService.getPriority(), reportService));
100:                                 } else {
101:                                         legacyServiceProviders.add(new EMFFormsLegacyLocalServiceFactory(viewService.getClass(),
102:                                                 viewService.getPriority(), reportService));
103:                                 }
104:                         } catch (final CoreException e1) {
105:                                 reportService.report(new AbstractReport(e1));
106:                         }
107:                 }
108:                 return legacyServiceProviders;
109:         }
110:
111:         /**
112:          * {@inheritDoc}
113:          *
114:          * @see org.eclipse.emf.ecp.view.spi.context.EMFFormsLegacyServicesManager#instantiate()
115:          */
116:         @Override
117:         public void instantiate() {
118:•                if (instantiated) {
119:                         return;
120:                 }
121:                 final Set<EMFFormsViewServiceFactory<? extends ViewModelService>> legacyServiceProviders = parseExtensions();
122:•                for (final EMFFormsViewServiceFactory<? extends ViewModelService> provider : legacyServiceProviders) {
123:                         final ServiceRegistration<EMFFormsViewServiceFactory> registerService = bundleContext
124:                                 .registerService(EMFFormsViewServiceFactory.class, provider, null);
125:                         registrations.add(registerService);
126:                 }
127:                 instantiated = true;
128:         }
129: }