Convert from an internal Spring bean definition to a DTO.

@param beanDefinition The internal Spring bean definition.
@return Returns a DTO representation.
423075
public BeanDefinitionInfo toDto(BeanDefinition beanDefinition) {
		if (beanDefinition instanceof GenericBeanDefinition) {
			GenericBeanDefinitionInfo info = new GenericBeanDefinitionInfo();
			info.setClassName(beanDefinition.getBeanClassName());

			if (beanDefinition.getPropertyValues() != null) {
				Map<String, BeanMetadataElementInfo> propertyValues = new HashMap<String, BeanMetadataElementInfo>();
				for (PropertyValue value : beanDefinition.getPropertyValues().getPropertyValueList()) {
					Object obj = value.getValue();
					if (obj instanceof BeanMetadataElement) {
						propertyValues.put(value.getName(), toDto((BeanMetadataElement) obj));
					} else {
						throw new IllegalArgumentException("Type " + obj.getClass().getName()
								+ " is not a BeanMetadataElement for property: " + value.getName());
					}
				}
				info.setPropertyValues(propertyValues);
			}
			return info;
		} else {
			throw new IllegalArgumentException("Conversion to DTO of " + beanDefinition.getClass().getName()
					+ " not implemented");
		}
	}
1132582
public static XContentBuilder marshall(PolicyDefinitionBean bean) throws StorageException {
        try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
            preMarshall(bean);
            builder
                .startObject()
                    .field("id", bean.getId())
                    .field("name", bean.getName())
                    .field("description", bean.getDescription())
                    .field("form", bean.getForm())
                    .field("formType", bean.getFormType())
                    .field("icon", bean.getIcon())
                    .field("pluginId", bean.getPluginId())
                    .field("policyImpl", bean.getPolicyImpl())
                    .field("deleted", bean.isDeleted());

            Set<PolicyDefinitionTemplateBean> templates = bean.getTemplates();
            if (templates != null) {
                builder.field("templates").startArray();
                for (PolicyDefinitionTemplateBean template : templates) {
                    builder.startObject();
                    builder.field("language", template.getLanguage());
                    builder.field("template", template.getTemplate());
                    builder.endObject();
                }
                builder.endArray();
            }

            builder.endObject();
            postMarshall(bean);
            return builder;
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }
964830
protected final Definition bean(Class<?> clazz) {
    Definition def = new Definition(clazz.getName(), clazz, Scope.SINGLETON.toString());
    def.beanName = clazz.getName() + "#" + Math.abs(System.identityHashCode(def));
    return def;
  }
1144206
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Object source,
			ParserContext context) {

		AbstractBeanDefinition definition = builder.getRawBeanDefinition();
		definition.setSource(context.extractSource(source));

		return definition;
	}
272017
private void beanToBean(Object providerBean, Object destBean) {
		valueProviderToBean(new BeanValueProvider(providerBean, this.copyOptions.ignoreCase, this.copyOptions.ignoreError), destBean);
	}
1101413
public static BeanDefinitionHolder registerBean(String beanId, Class<?> beanClass, ParserContext parserContext, boolean shouldFireEvents) {
        return registerBean(beanId, BeanDefinitionBuilder.genericBeanDefinition(beanClass).getBeanDefinition(), parserContext, shouldFireEvents);
    }
620016
private int parseBeanDefinition() {
        for (int index = 0; index < content.size(); index++) {
            String line = content.get(index).trim();
            if (line.startsWith("@BeanDefinition")) {
                return index;
            }
        }
        return -1;
    }
53336
private static POJODefinition _construct(Class<?> beanType)
    {
        Map<String,Prop> propsByName = new TreeMap<String,Prop>();
        _introspect(beanType, propsByName);

        Constructor<?> defaultCtor = null;
        Constructor<?> stringCtor = null;
        Constructor<?> longCtor = null;

        for (Constructor<?> ctor : beanType.getDeclaredConstructors()) {
            Class<?>[] argTypes = ctor.getParameterTypes();
            if (argTypes.length == 0) {
                defaultCtor = ctor;
            } else if (argTypes.length == 1) {
                Class<?> argType = argTypes[0];
                if (argType == String.class) {
                    stringCtor = ctor;
                } else if (argType == Long.class || argType == Long.TYPE) {
                    longCtor = ctor;
                } else {
                    continue;
                }
            } else {
                continue;
            }
        }
        Prop[] props;
        if (propsByName.isEmpty()) {
            props = NO_PROPS;
        } else {
            props = propsByName.values().toArray(NO_PROPS);
        }
        return new POJODefinition(beanType, props, defaultCtor, stringCtor, longCtor);
    }
402981
public static BeanDescriptor getInstance(Class<?> type) {
        BeanDescriptor bd = cache.get(type);
        if (bd == null) {
            bd = new BeanDescriptor(type);
            BeanDescriptor existing = cache.putIfAbsent(type, bd);
            if (existing != null) {
                bd = existing;
            }
        }
        return bd;
    }
338203
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

		for (String beanName : registry.getBeanDefinitionNames()) {
			BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
			String beanClassName = beanDefinition.getBeanClassName();
			try {
				Class beanClass = Class.forName(beanClassName);
				// large project need using Google Collection's lookup
				for (final Field field : ClassUtil.getAllDecaredFields(beanClass)) {
					if (field.isAnnotationPresent(Autowired.class)) {
						// inject jdon components into spring components with
						// AutoWire;
						Object o = findBeanClassInJdon(field.getType());
						if (o != null) {
							neededJdonComponents.put(field.getName(), o);
						}
					}
				}
			} catch (ClassNotFoundException ex) {
				ex.printStackTrace();
			}
		}
	}
1155750
protected static GenericBeanDefinition createModuleBeanDefinition(String className, Map<String,String> params, String role)
        throws IOException {
        ScannedGenericBeanDefinition result = getScannedBeanDefinition(className);
        result.setParentName(Module.class.getName());
        result.setScope(BeanDefinition.SCOPE_SINGLETON);
        result.setAttribute("id", role);
        result.setAttribute("name", role);
        result.setAttribute("init-method", "initModule");
        result.setEnforceInitMethod(true);
        result.setAttribute("destroy-method", "shutdownModule");
        result.setEnforceDestroyMethod(true);

        ConstructorArgumentValues cArgs = new ConstructorArgumentValues();
        cArgs.addIndexedArgumentValue(0, params,MODULE_CONSTRUCTOR_PARAM1_CLASS);
        // one server bean in context
        BeanReference serverRef = new RuntimeBeanReference(MODULE_CONSTRUCTOR_PARAM2_CLASS);
        cArgs.addIndexedArgumentValue(1, serverRef);
        cArgs.addIndexedArgumentValue(2, role,MODULE_CONSTRUCTOR_PARAM3_CLASS);
        result.setConstructorArgumentValues(cArgs);
        return result;
    }
1352030
protected void beanDefinitionCheck() {
        for (int i = 0; i < beanDefinitions.size(); i++) {
            for (int j = i + 1; j < beanDefinitions.size(); j++) {
                BeanDefinition b1 = beanDefinitions.get(i);
                BeanDefinition b2 = beanDefinitions.get(j);

                // Two components' id are equal
                if (VerifyUtils.isNotEmpty(b1.getId())
                        && VerifyUtils.isNotEmpty(b2.getId())
                        && b1.getId().equals(b2.getId())) {
                    error("Duplicated bean ID of " + b1.getClassName() + " and " + b2.getClassName());
                }

                if (b1.getClassName().equals(b2.getClassName())) {
                    // Two components' class name are equal, but one of them does not set id.
                    if (VerifyUtils.isEmpty(b1.getId()) || VerifyUtils.isEmpty(b2.getId())) {
                        error("Duplicated class definition. Please set a ID for " + b1.getClassName());
                    } else {
                        // Their id are different, save them to memo.
                        // When the component is injecting by type, throw an exception.
                        errorMemo.add(b1.getClassName());
                    }
                }

                for (String iname1 : b1.getInterfaceNames()) {
                    for (String iname2 : b2.getInterfaceNames()) {
                        if (iname1.equals(iname2)) {
                            // Two components' interface name are equal, but one of them does not set id.
                            if (VerifyUtils.isEmpty(b1.getId()) || VerifyUtils.isEmpty(b2.getId())) {
                                error("Duplicated class definition. Please set a ID for " + b1.getClassName());
                            } else {
                                // Their id are different, save them to memo.
                                // When the component is injecting by type, throw an exception.
                                errorMemo.add(iname1);
                            }
                        }
                    }
                }

            }
        }
    }
611264
public <T> InternalEjbDescriptor<T> get(String beanName) {
        return cast(ejbByName.get(beanName));
    }
557261
public static final Object getValue(Object bean, String property)
    {
        return doFor(bean, property, null, BeanHelper::getValue, BeanHelper::getValue, BeanHelper::getFieldValue, BeanHelper::getMethodValue);
    }
686871
@Override
  public Set<BeanDefinitionHolder> doScan(String... basePackages) {
    Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);

    if (beanDefinitions.isEmpty()) {
      logger.warn("No MyBatis mapper was found in '" + Arrays.toString(basePackages) + "' package. Please check your configuration.");
    } else {
      for (BeanDefinitionHolder holder : beanDefinitions) {
        GenericBeanDefinition definition = (GenericBeanDefinition) holder.getBeanDefinition();

        if (logger.isDebugEnabled()) {
          logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '" + definition.getBeanClassName() + "' mapperInterface");
        }

        // the mapper interface is the original class of the bean
        // but, the actual class of the bean is MapperFactoryBean
        definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName());
        definition.setBeanClass(MapperFactoryBean.class);

        definition.getPropertyValues().add("addToConfig", this.addToConfig);

        boolean explicitFactoryUsed = false;
        if (StringUtils.hasText(this.sqlSessionFactoryBeanName)) {
          definition.getPropertyValues().add("sqlSessionFactory", new RuntimeBeanReference(this.sqlSessionFactoryBeanName));
          explicitFactoryUsed = true;
        } else if (this.sqlSessionFactory != null) {
          definition.getPropertyValues().add("sqlSessionFactory", this.sqlSessionFactory);
          explicitFactoryUsed = true;
        }

        if (StringUtils.hasText(this.sqlSessionTemplateBeanName)) {
          if (explicitFactoryUsed) {
            logger.warn("Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
          }
          definition.getPropertyValues().add("sqlSessionTemplate", new RuntimeBeanReference(this.sqlSessionTemplateBeanName));
          explicitFactoryUsed = true;
        } else if (this.sqlSessionTemplate != null) {
          if (explicitFactoryUsed) {
            logger.warn("Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
          }
          definition.getPropertyValues().add("sqlSessionTemplate", this.sqlSessionTemplate);
          explicitFactoryUsed = true;
        }

        if (!explicitFactoryUsed) {
          if (logger.isDebugEnabled()) {
            logger.debug("Enabling autowire by type for MapperFactoryBean with name '" + holder.getBeanName() + "'.");
          }
          definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
        }
      }
    }

    return beanDefinitions;
  }
579579
public <T> void define(Class<T> classDefinition, ObjectFactory<T> factory) {
        injectorConfiguration = injectorConfiguration.withFactory(classDefinition, factory);
    }
169714
protected @Nonnull <T> Collection<BeanDefinition> findBeanCandidatesForInstance(@Nonnull T instance) {
        ArgumentUtils.requireNonNull("instance", instance);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Finding candidate beans for instance: {}", instance);
        }
        Collection<BeanDefinitionReference> beanDefinitionsClasses = this.beanDefinitionsClasses;
        return beanCandidateCache.computeIfAbsent(instance.getClass(), aClass -> {
            // first traverse component definition classes and load candidates

            if (!beanDefinitionsClasses.isEmpty()) {

                List<BeanDefinition> candidates = beanDefinitionsClasses
                        .stream()
                        .filter(reference -> {
                            if (reference.isEnabled(this)) {
                                Class<?> candidateType = reference.getBeanType();

                                return candidateType != null && candidateType.isInstance(instance);
                            } else {
                                return false;
                            }
                        })
                        .map(ref -> ref.load(this))
                        .filter(candidate -> candidate.isEnabled(this))
                        .collect(Collectors.toList());

                if (candidates.size() > 1) {
                    // try narrow to exact type
                    candidates = candidates
                            .stream()
                            .filter(candidate ->
                                    !(candidate instanceof NoInjectionBeanDefinition) &&
                                            candidate.getBeanType() == instance.getClass()
                            )
                            .collect(Collectors.toList());
                    return candidates;
                }
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Resolved bean candidates {} for instance: {}", candidates, instance);
                }
                return candidates;
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("No bean candidates found for instance: {}", instance);
                }
                return Collections.emptySet();
            }
        });

    }