| |
| /** |
| * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| */ |
| |
| |
| |
| package org.eclipse.osbp.xtext.builder.participant.dmodelsample.impl; |
| |
| import java.net.URL; |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.eclipse.osbp.xtext.builder.metadata.services.AbstractBuilderParticipant; |
| import org.eclipse.osbp.xtext.builder.metadata.services.IBuilderParticipant; |
| import org.eclipse.osbp.xtext.builder.metadata.services.IMetadataBuilderService; |
| import org.osgi.framework.Bundle; |
| import org.osgi.framework.wiring.BundleWiring; |
| import org.osgi.service.component.ComponentContext; |
| import org.osgi.service.component.annotations.Activate; |
| import org.osgi.service.component.annotations.Component; |
| import org.osgi.service.component.annotations.Deactivate; |
| |
| import com.google.inject.Inject; |
| |
| @Component(service={IBuilderParticipant.class}) |
| public class DomainmodelBuilderParticipant extends AbstractBuilderParticipant { |
| |
| @Inject |
| private IMetadataBuilderService metadataBuilderService; |
| |
| private ComponentContext context; |
| |
| public DomainmodelBuilderParticipant() { |
| |
| } |
| |
| @Activate |
| protected void activate(ComponentContext context) { |
| this.context = context; |
| } |
| |
| @Deactivate |
| protected void deactivate(ComponentContext context) { |
| metadataBuilderService.removeFromBundleSpace(context.getBundleContext() |
| .getBundle()); |
| |
| this.context = null; |
| } |
| |
| @Override |
| public List<URL> getModels(Bundle suspect) { |
| List<URL> results = new ArrayList<URL>(); |
| BundleWiring wiring = suspect.adapt(BundleWiring.class); |
| results.addAll(wiring.findEntries("/", "*.dmodel", |
| BundleWiring.LISTRESOURCES_RECURSE)); |
| return results; |
| } |
| |
| @Override |
| public void notifyLifecyle(LifecycleEvent event) { |
| if (event.getState() == IBuilderParticipant.LifecycleEvent.INITIALIZE) { |
| initialize(); |
| } else if (event.getState() == IBuilderParticipant.LifecycleEvent.ACTIVATED) { |
| // XBaseService xbaseService = new XBaseService(); |
| // serviceRegister = context.getBundleContext().registerService( |
| // IXbaseMetadataService.class, xbaseService, null); |
| } else { |
| // if (serviceRegister != null) { |
| // serviceRegister.unregister(); |
| // serviceRegister = null; |
| // } |
| |
| if (metadataBuilderService != null) { |
| metadataBuilderService.removeFromBundleSpace(context |
| .getBundleContext().getBundle()); |
| } |
| } |
| } |
| |
| private void initialize() { |
| DomainmodelBundleSpaceStandaloneSetup.doSetup(); |
| metadataBuilderService.addToBundleSpace(context.getBundleContext() |
| .getBundle()); |
| } |
| } |