Package org.osgi.service.component

Examples of org.osgi.service.component.ComponentInstance


        final ComponentFactory factory = ( ComponentFactory ) bundleContext.getService( refs[0] );
        TestCase.assertNotNull( factory );

        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
        final ComponentInstance instance = factory.newInstance( props );
        TestCase.assertNotNull( instance );
        TestCase.assertNotNull( instance.getInstance() );
        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );

        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
        TestCase.assertNotNull( comp10 );
        TestCase.assertEquals( srv1, comp10.m_singleRef );
        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
View Full Code Here


        main.enable();
        delay(300);
        dep1Reg.unregister();
        delay(2000);

        ComponentInstance mainCompInst = main.getComponentInstance();
        TestCase.assertNull(mainCompInst);

        dep1Reg = register(new SimpleComponent(), 0);
        delay(300);
View Full Code Here

        try {
            BundleContext bundleContext = (BundleContext) context.getAttribute(BundleContext.class.getName());
            ServiceReference serviceReference = bundleContext.getServiceReferences(null,
                MAPPING_ENGINE_COMPONENT_FACTORY_FILTER)[0];
            ComponentFactory componentFactory = (ComponentFactory) bundleContext.getService(serviceReference);
            @SuppressWarnings("rawtypes")
            ComponentInstance componentInstance = componentFactory.newInstance(new Hashtable());
            this.engine = (MappingEngine) componentInstance.getInstance();

        } catch (InvalidSyntaxException e) {
            logger.warn("Mapping engine instance could not be instantiated", e);
            throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
        }
View Full Code Here

        try {
            BundleContext bundleContext = (BundleContext) context.getAttribute(BundleContext.class.getName());
            ServiceReference serviceReference = bundleContext.getServiceReferences(null,
                "(component.factory=org.apache.stanbol.cmsadapter.servicesapi.mapping.MappingEngineFactory)")[0];
            ComponentFactory componentFactory = (ComponentFactory) bundleContext.getService(serviceReference);
            ComponentInstance componentInstance = componentFactory
                    .newInstance(new Hashtable<Object,Object>());
            this.engine = (MappingEngine) componentInstance.getInstance();
            this.tcManager = (TcManager) ContextHelper.getServiceFromContext(TcManager.class, context);

        } catch (InvalidSyntaxException e) {
            logger.warn("Mapping engine instance could not be instantiated", e);
            throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
View Full Code Here

    final Properties props = new Properties();

    props.put("reference.target", "(component.factory=bench.*)");

    final ComponentInstance instance = factory.newInstance(props);

  }
View Full Code Here

      dict = null;
    } else {
      dict = new Hashtable<String, String>(props);
    }

    final ComponentInstance wrapper = factoryOSGI().newInstance(dict);

    return wrapper;

  }
View Full Code Here

    if (factoryWrapper == null) {
      log.error("unknown factory id", new Exception(factoryId));
      return null;
    }

    final ComponentInstance instanceWrapper;

    try {
      instanceWrapper = factoryWrapper.newInstance(props);
    } catch (final Exception e) {
      log.error("factory can not produce instance", new Exception(
          factoryId));
      return null;
    }

    @SuppressWarnings("unchecked")
    final F instance = (F) instanceWrapper.getInstance();
    if (instance == null) {
      log.error("instance == null", new Exception(factoryId));
      instanceWrapper.dispose();
      return null;
    }

    final String instanceId;

    try {
      instanceId = instance.getInstanceId();
    } catch (final Exception e) {
      log.error("invalid instanceId", new Exception(factoryId));
      instanceWrapper.dispose();
      return null;
    }

    if (instanceId == null) {
      log.error("instanceId == null", new Exception(factoryId));
      instanceWrapper.dispose();
      return null;
    }

    if (instanceMap.containsKey(instanceId)) {
      log.error("duplicate instance id", new Exception(instanceId));
      instanceWrapper.dispose();
      return null;
    }

    instanceMap.put(instanceId, instanceWrapper);
View Full Code Here

    if (instanceId == null) {
      log.error("instanceId == null", new Exception());
      return false;
    }

    final ComponentInstance instanceWrapper = instanceMap.remove(instanceId);
    if (instanceWrapper == null) {
      log.error("unknown instance id", new Exception(instanceId));
      return false;
    }

    final Object instance = instanceWrapper.getInstance();
    if (instance == null) {
      log.error("instance == null", new Exception(instanceId));
      return false;
    }

    instanceWrapper.dispose();

    log.debug("destroyed : {}", fidget);

    return true;
View Full Code Here

  }

  @Override
  public final F getInstance(final String instanceId) {

    final ComponentInstance instanceWrapper = instanceMap.get(instanceId);

    if (instanceWrapper == null) {
      return null;
    }

    @SuppressWarnings("unchecked")
    final F fidget = (F) instanceWrapper.getInstance();

    return fidget;

  }
View Full Code Here

TOP

Related Classes of org.osgi.service.component.ComponentInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.