コード例 #1
0
  /**
   * An apform instance to represent a legacy component discovered in the OSGi registry
   *
   * @param ipojoInstance
   */
  public ApformOSGiInstance(Specification specification, ServiceReference<?> reference) {

    super(
        new InstanceDeclaration(
            VersionedReference.any(generateImplementationName(specification, reference)),
            generateInstanceName(specification, reference)));

    this.specification = specification;

    for (PropertyDefinition property : specification.getDeclaration().getPropertyDefinitions()) {
      Object value = reference.getProperty(property.getName());

      if (value != null) this.declaration.getProperties().put(property.getName(), value.toString());
    }

    this.reference = reference;
    this.bundle = reference.getBundle();
    this.bundleContext =
        AccessController.doPrivileged(
            new PrivilegedAction<BundleContext>() {
              public BundleContext run() {
                return bundle.getBundleContext();
              }
            });

    this.service = null;
  }
コード例 #2
0
  /** Generate the uniques name of the implementation associated with this instance in Apam */
  private static ImplementationReference<?> generateImplementationName(
      Specification specification, ServiceReference<?> reference) {
    String bundle = reference.getBundle().getSymbolicName();

    if (bundle == null) bundle = (String) reference.getBundle().getHeaders().get("Bundle-Name");

    return new ApformOSGiImplementation.Reference(
        specification.getName() + "[provider.bundle=" + bundle + "]");
  }