Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lincesoft.imperator.displayer.provider;
- import org.osgi.framework.Bundle;
- import org.osgi.framework.ServiceFactory;
- import org.osgi.framework.ServiceRegistration;
- import com.lincesoft.imperator.displayer.api.Displayer;
- public class DisplayerServiceFactory implements ServiceFactory<Displayer> {
- public static final String NAME = "displayer_service_factory";
- @Override
- public void ungetService(Bundle bundle, ServiceRegistration<Displayer> registration, Displayer service) {
- // TODO Auto-generated method stub
- }
- @Override
- public Displayer getService(Bundle bundle, ServiceRegistration<Displayer> registration) {
- return new DisplayerImplementation();
- }
- }
- package com.lincesoft.imperator.displayer.launcher;
- import java.util.Hashtable;
- import org.osgi.framework.BundleActivator;
- import org.osgi.framework.BundleContext;
- import org.osgi.framework.ServiceFactory;
- import org.osgi.framework.ServiceRegistration;
- import com.lincesoft.imperator.displayer.api.Displayer;
- import com.lincesoft.imperator.displayer.provider.DisplayerServiceFactory;
- public class Activator implements BundleActivator {
- private ServiceRegistration<?> DisplayerFactoryRegistration;
- @Override
- public void start(BundleContext bundle_context) throws Exception {
- System.out.println("Starting the Displayer Provider Bundle");
- ServiceFactory<Displayer> displayer_service_factory = new DisplayerServiceFactory();
- Hashtable<String,String> properties = new Hashtable<String,String>();
- properties.put("service.vendor", DisplayerServiceFactory.NAME);
- DisplayerFactoryRegistration = bundle_context.registerService(Displayer.class.getName(), displayer_service_factory,properties);
- }
- @Override
- public void stop(BundleContext context) throws Exception {
- System.out.println("Stopping the Displayer Provider Bundle");
- DisplayerFactoryRegistration.unregister();
- }
- }
- /* Get a displayer instance from the service factory provided by the displayer provider bundle */
- ServiceReference<?>[] service_references = null;
- try {
- service_references = my_bundle_context.getServiceReferences(Displayer.class.getName(),"(service.vendor=displayer_service_factory)");
- } catch (InvalidSyntaxException e) {
- System.out.println("Sintaxis para obtener displayer_service_factory_reference invalida.");
- e.printStackTrace();
- }
- ServiceReference<?> displayer_service_factory_reference = null;
- if (service_references!=null && service_references.length==1) {
- displayer_service_factory_reference = service_references[0];
- } else {
- //Throw new NoDisplayerFactoryException();
- }
- Displayer bundle_displayer_instance = (Displayer) my_bundle_context.getService(displayer_service_factory_reference);
- Exception in thread "main" java.lang.ClassCastException: com.lincesoft.imperator.displayer.provider.DisplayerImplementation cannot be cast to com.lincesoft.imperator.displayer.api.Displayer
- at com.lincesoft.imperator.procurator.launcher.Procurator.main(Procurator.java:94)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement