Ejemplo n.º 1
0
    @Override
    void complete(DynamicConfiguration configuration, HK2Loader defaultLoader) {
      if (this.loader == null) {
        this.loader = defaultLoader;
      }
      AbstractActiveDescriptor descriptor = BuilderHelper.createConstantDescriptor(service);
      descriptor.setName(name);
      descriptor.setLoader(this.loader);

      if (scope != null) {
        descriptor.setScope(scope.getName());
      }

      if (ranked != null) {
        descriptor.setRanking(ranked);
      }

      for (String key : metadata.keySet()) {
        for (String value : metadata.get(key)) {
          descriptor.addMetadata(key, value);
        }
      }

      for (Annotation annotation : qualifiers) {
        descriptor.addQualifierAnnotation(annotation);
      }

      for (Type contract : contracts) {
        descriptor.addContractType(contract);
      }

      configuration.bind(descriptor);
    }
Ejemplo n.º 2
0
    @Override
    void complete(DynamicConfiguration configuration, HK2Loader defaultLoader) {
      if (this.loader == null) {
        this.loader = defaultLoader;
      }

      AbstractActiveDescriptor factoryContractDescriptor =
          BuilderHelper.createConstantDescriptor(factory);
      factoryContractDescriptor.addContractType(factory.getClass());
      factoryContractDescriptor.setName(name);
      factoryContractDescriptor.setLoader(this.loader);

      ActiveDescriptorBuilder descriptorBuilder =
          BuilderHelper.activeLink(factory.getClass()).named(name).andLoadWith(this.loader);
      if (scope != null) {
        descriptorBuilder.in(scope);
      }

      if (ranked != null) {
        descriptorBuilder.ofRank(ranked);
      }

      for (Annotation qualifier : qualifiers) {
        factoryContractDescriptor.addQualifierAnnotation(qualifier);
        descriptorBuilder.qualifiedBy(qualifier);
      }

      for (Type contract : contracts) {
        factoryContractDescriptor.addContractType(
            new ParameterizedTypeImpl(Factory.class, contract));
        descriptorBuilder.to(contract);
      }

      configuration.bind(
          new FactoryDescriptorsImpl(factoryContractDescriptor, descriptorBuilder.buildFactory()));
    }