Package org.springframework.beans.factory.config

Examples of org.springframework.beans.factory.config.DependencyDescriptor


          if (this.cachedMethodArguments != null) {
            arguments = new Object[this.cachedMethodArguments.length];
            for (int i = 0; i < arguments.length; i++) {
              Object cachedArg = this.cachedMethodArguments[i];
              if (cachedArg instanceof DependencyDescriptor) {
                DependencyDescriptor descriptor = (DependencyDescriptor) cachedArg;
                TypeConverter typeConverter = beanFactory.getTypeConverter();
                arguments[i] = beanFactory.resolveDependency(descriptor, beanName, null, typeConverter);
              }
              else if (cachedArg instanceof RuntimeBeanReference) {
                arguments[i] = beanFactory.getBean(((RuntimeBeanReference) cachedArg).getBeanName());
              }
              else {
                arguments[i] = cachedArg;
              }
            }
          }
        }
        else {
          Class[] paramTypes = method.getParameterTypes();
          arguments = new Object[paramTypes.length];
          Set<String> autowiredBeanNames = new LinkedHashSet<String>(arguments.length);
          TypeConverter typeConverter = beanFactory.getTypeConverter();
          this.cachedMethodArguments = new Object[arguments.length];
          for (int i = 0; i < arguments.length; i++) {
            MethodParameter methodParam = new MethodParameter(method, i);
            GenericTypeResolver.resolveParameterType(methodParam, bean.getClass());
            DependencyDescriptor descriptor = new DependencyDescriptor(methodParam, this.required);
            this.cachedMethodArguments[i] = descriptor;
            arguments[i] = beanFactory.resolveDependency(
                descriptor, beanName, autowiredBeanNames, typeConverter);
            if (arguments[i] == null) {
              arguments = null;
View Full Code Here


        return getBeanFromSpringContext(beanName, injectee, required);
    }

    private Object getBeanFromSpringContext(String beanName, Injectee injectee, final boolean required) {
        try {
            DependencyDescriptor dependencyDescriptor = createSpringDependencyDescriptor(injectee);
            Set<String> autowiredBeanNames = new HashSet<>(1);
            autowiredBeanNames.add(beanName);
            return ctx.getAutowireCapableBeanFactory().resolveDependency(dependencyDescriptor, null,
                    autowiredBeanNames, null);
        } catch (NoSuchBeanDefinitionException e) {
View Full Code Here

    }

    private DependencyDescriptor createSpringDependencyDescriptor(final Injectee injectee) {
        AnnotatedElement annotatedElement = injectee.getParent();
        if (annotatedElement.getClass().isAssignableFrom(Field.class)) {
            return new DependencyDescriptor((Field) annotatedElement,
                    !injectee.isOptional());
        } else {
            return new DependencyDescriptor(
                    new MethodParameter((Constructor) annotatedElement, injectee.getPosition()), !injectee.isOptional());
        }
    }
View Full Code Here

  /**
   * Resolve the specified cached method argument or field value.
   */
  private Object resolvedCachedArgument(String beanName, Object cachedArgument) {
    if (cachedArgument instanceof DependencyDescriptor) {
      DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
      return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
    }
    else if (cachedArgument instanceof RuntimeBeanReference) {
      return this.beanFactory.getBean(((RuntimeBeanReference) cachedArgument).getBeanName());
    }
View Full Code Here

        Object value;
        if (this.cached) {
          value = resolvedCachedArgument(beanName, this.cachedFieldValue);
        }
        else {
          DependencyDescriptor desc = new DependencyDescriptor(field, this.required);
          desc.setContainingClass(bean.getClass());
          Set<String> autowiredBeanNames = new LinkedHashSet<String>(1);
          TypeConverter typeConverter = beanFactory.getTypeConverter();
          value = beanFactory.resolveDependency(desc, beanName, autowiredBeanNames, typeConverter);
          synchronized (this) {
            if (!this.cached) {
View Full Code Here

          DependencyDescriptor[] descriptors = new DependencyDescriptor[paramTypes.length];
          Set<String> autowiredBeanNames = new LinkedHashSet<String>(paramTypes.length);
          TypeConverter typeConverter = beanFactory.getTypeConverter();
          for (int i = 0; i < arguments.length; i++) {
            MethodParameter methodParam = new MethodParameter(method, i);
            DependencyDescriptor desc = new DependencyDescriptor(methodParam, this.required);
            desc.setContainingClass(bean.getClass());
            descriptors[i] = desc;
            Object arg = beanFactory.resolveDependency(desc, beanName, autowiredBeanNames, typeConverter);
            if (arg == null && !this.required) {
              arguments = null;
              break;
View Full Code Here

   */
  protected Object resolveAutowiredArgument(
      MethodParameter param, String beanName, Set<String> autowiredBeanNames, TypeConverter typeConverter) {

    return this.beanFactory.resolveDependency(
        new DependencyDescriptor(param, true), beanName, autowiredBeanNames, typeConverter);
  }
View Full Code Here

          converter.convertIfNecessary(value, type, descriptor.getMethodParameter()));
    }

    if (type.isArray()) {
      Class<?> componentType = type.getComponentType();
      DependencyDescriptor targetDesc = new DependencyDescriptor(descriptor);
      targetDesc.increaseNestingLevel();
      Map<String, Object> matchingBeans = findAutowireCandidates(beanName, componentType, targetDesc);
      if (matchingBeans.isEmpty()) {
        if (descriptor.isRequired()) {
          raiseNoSuchBeanDefinitionException(componentType, "array of " + componentType.getName(), descriptor);
        }
        return null;
      }
      if (autowiredBeanNames != null) {
        autowiredBeanNames.addAll(matchingBeans.keySet());
      }
      TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
      Object result = converter.convertIfNecessary(matchingBeans.values(), type);
      if (getDependencyComparator() != null && result instanceof Object[]) {
        Arrays.sort((Object[]) result, adaptDependencyComparator(matchingBeans));
      }
      return result;
    }
    else if (Collection.class.isAssignableFrom(type) && type.isInterface()) {
      Class<?> elementType = descriptor.getCollectionType();
      if (elementType == null) {
        if (descriptor.isRequired()) {
          throw new FatalBeanException("No element type declared for collection [" + type.getName() + "]");
        }
        return null;
      }
      DependencyDescriptor targetDesc = new DependencyDescriptor(descriptor);
      targetDesc.increaseNestingLevel();
      Map<String, Object> matchingBeans = findAutowireCandidates(beanName, elementType, targetDesc);
      if (matchingBeans.isEmpty()) {
        if (descriptor.isRequired()) {
          raiseNoSuchBeanDefinitionException(elementType, "collection of " + elementType.getName(), descriptor);
        }
        return null;
      }
      if (autowiredBeanNames != null) {
        autowiredBeanNames.addAll(matchingBeans.keySet());
      }
      TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
      Object result = converter.convertIfNecessary(matchingBeans.values(), type);
      if (getDependencyComparator() != null && result instanceof List) {
        Collections.sort((List<?>) result, adaptDependencyComparator(matchingBeans));
      }
      return result;
    }
    else if (Map.class.isAssignableFrom(type) && type.isInterface()) {
      Class<?> keyType = descriptor.getMapKeyType();
      if (keyType == null || !String.class.isAssignableFrom(keyType)) {
        if (descriptor.isRequired()) {
          throw new FatalBeanException("Key type [" + keyType + "] of map [" + type.getName() +
              "] must be assignable to [java.lang.String]");
        }
        return null;
      }
      Class<?> valueType = descriptor.getMapValueType();
      if (valueType == null) {
        if (descriptor.isRequired()) {
          throw new FatalBeanException("No value type declared for map [" + type.getName() + "]");
        }
        return null;
      }
      DependencyDescriptor targetDesc = new DependencyDescriptor(descriptor);
      targetDesc.increaseNestingLevel();
      Map<String, Object> matchingBeans = findAutowireCandidates(beanName, valueType, targetDesc);
      if (matchingBeans.isEmpty()) {
        if (descriptor.isRequired()) {
          raiseNoSuchBeanDefinitionException(valueType, "map with value type " + valueType.getName(), descriptor);
        }
View Full Code Here

      if (!isSelfReference(beanName, candidateName) && isAutowireCandidate(candidateName, descriptor)) {
        result.put(candidateName, getBean(candidateName));
      }
    }
    if (result.isEmpty()) {
      DependencyDescriptor fallbackDescriptor = descriptor.forFallbackMatch();
      for (String candidateName : candidateNames) {
        if (!candidateName.equals(beanName) && isAutowireCandidate(candidateName, fallbackDescriptor)) {
          result.put(candidateName, getBean(candidateName));
        }
      }
View Full Code Here

   */
  @UsesJava8
  private class OptionalDependencyFactory {

    public Object createOptionalDependency(DependencyDescriptor descriptor, String beanName) {
      DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) {
        @Override
        public boolean isRequired() {
          return false;
        }
      };
      descriptorToUse.increaseNestingLevel();
      return Optional.ofNullable(doResolveDependency(descriptorToUse, beanName, null, null));
    }
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.config.DependencyDescriptor

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.