How to create an iPOJO Component at runtime

See How to use iPOJO Factories

1. Find iPOJO Component Factory reference.
----
import org.apache.felix.ipojo.Factory;

public ServiceReference getComponentFactoryReference(String factoryClassName) {
  try {
    ServiceReference[] refs = bundleContext.getServiceReferences(
      Factory.class.getName(),
      "(component.class=" + factoryClassName + ")");

    if (refs == null || refs.length == 0)
      return null;

    return refs[0];
  } catch (InvalidSyntaxException e) {
  ...
  }
  return null;
}

2. Get iPOJO Component Factory.
ServiceReference factoryReference = getComponentFactoryReference(YOUR_COMPONENT_CLASS_NAME);
Factory factory = (Factory) context.getService(factoryReference);

3. Create iPOJO Component using iPOJO Component Factory.
Properties configuration = new Properties();
// additional component configuration here..
ComponentInstance instance = factory.createComponentInstance(configuration);
instance.start();
by xeraph | 2009/04/15 23:34 | 학술 | 트랙백 | 덧글(0)
트랙백 주소 : http://xeraph.com/tb/4915517
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]

:         :

:

비공개 덧글