private ConstructionInfo selectFactory(Class beanClass, MutableBeanMetadata beanMetadata, MappingMetaData metadata, Set definedProperties) { String factoryMethodName = beanMetadata.getFactoryMethod(); // get the factory methods sorted by longest arg length first Method[] methods = beanClass.getMethods(); List<Method> factoryMethods = new ArrayList<Method>(methods.length); for (Method method : methods) { if (method.getName().equals(factoryMethodName)) { factoryMethods.add(method); } } Collections.sort(factoryMethods, new MethodArgLengthComparator()); // if a factory method has been annotated as the default constructor we always use that constructor for (Method factoryMethod : factoryMethods) { if (metadata.isDefaultFactoryMethod(beanClass, factoryMethod)) { return new ConstructionInfo(beanClass, factoryMethod, metadata); } } // try to find a constructor for which we have all of the properties defined for (Method factoryMethod : factoryMethods) { ConstructionInfo constructionInfo = new ConstructionInfo(beanClass, factoryMethod, metadata); if (isUsableConstructor(constructionInfo, definedProperties)) { return constructionInfo; } } return null; }
private ConstructionInfo selectFactory(Class beanClass, MutableBeanMetadata beanMetadata, MappingMetaData metadata, Set definedProperties) { String factoryMethodName = beanMetadata.getFactoryMethod(); // get the factory methods sorted by longest arg length first Method[] methods = beanClass.getMethods(); List<Method> factoryMethods = new ArrayList<Method>(methods.length); for (Method method : methods) { if (method.getName().equals(factoryMethodName)) { factoryMethods.add(method); } } Collections.sort(factoryMethods, new MethodArgLengthComparator()); // if a factory method has been annotated as the default constructor we always use that constructor for (Method factoryMethod : factoryMethods) { if (metadata.isDefaultFactoryMethod(beanClass, factoryMethod)) { return new ConstructionInfo(beanClass, factoryMethod, metadata); } } // try to find a constructor for which we have all of the properties defined for (Method factoryMethod : factoryMethods) { ConstructionInfo constructionInfo = new ConstructionInfo(beanClass, factoryMethod, metadata); if (isUsableConstructor(constructionInfo, definedProperties)) { return constructionInfo; } } return null; }
private ConstructionInfo selectConstructionMethod(MutableBeanMetadata beanMetadata, MappingMetaData metadata) { Class beanClass = beanMetadata.getRuntimeClass(); // get a set containing the names of the defined properties Set<String> definedProperties = new HashSet<String>(); List<BeanProperty> values = beanMetadata.getProperties(); for (BeanProperty beanProperty : values) { definedProperties.add(beanProperty.getName()); } // first check for a factory method if (beanMetadata.getFactoryMethod() != null) { return selectFactory(beanClass, beanMetadata, metadata, definedProperties); } else { return selectConstructor(beanClass, metadata, definedProperties); } }
private ConstructionInfo selectConstructionMethod(MutableBeanMetadata beanMetadata, MappingMetaData metadata) { Class beanClass = beanMetadata.getRuntimeClass(); // get a set containing the names of the defined properties Set<String> definedProperties = new HashSet<String>(); List<BeanProperty> values = beanMetadata.getProperties(); for (BeanProperty beanProperty : values) { definedProperties.add(beanProperty.getName()); } // first check for a factory method if (beanMetadata.getFactoryMethod() != null) { return selectFactory(beanClass, beanMetadata, metadata, definedProperties); } else { return selectConstructor(beanClass, metadata, definedProperties); } }