注册{@link BeanParser}

@param supportClasses 该bean parser支持的数据类型
329196
public static void registerBeanParser(BeanParser beanParser, Class<?>... supportClasses) {
    for (Class<?> supportClass : supportClasses) {
      typeBeanParserMap.put(supportClass, beanParser);
    }
  }
779522
private void resolveCurrentclassFieldDependencies(final Object reference) {
        for (final FieldInjectionPoint injectionPoint : fieldInjectionPoints) {
            final Object injection = beanManager.getInjectableReference(injectionPoint);
            final Field field = injectionPoint.getAnnotated().getJavaMember();

            try {
                final Field declaredField = proxyClass.getDeclaredField(field.getName());

                if (declaredField.isAnnotationPresent(Inject.class)) {
                    try {
                        declaredField.set(reference, injection);
                    } catch (final Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            } catch (final NoSuchFieldException ex) {
                try {
                    field.set(reference, injection);
                } catch (final Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
1322366
private function parseAnnotationParsers($className)
    {
        if(!isset($this->data[$className]))
        {
            return;
        }
        if(isset($this->parsers[$className]))
        {
            return;
        }
        $ref = new \ReflectionClass($className);
        if(!$ref->isSubclassOf('Imi\Bean\Annotation\Base'))
        {
            return;
        }
        $hasParser = false;
        foreach($this->data[$className]['class'] as $annotation)
        {
            if($annotation instanceof \Imi\Bean\Annotation\Parser)
            {
                $this->parsers[$className] = $annotation->className;
                $hasParser = true;
                break;
            }
        }
        if(!$hasParser)
        {
            throw new \Exception(sprintf('Annotation %s has no @Parser()', $className));
        }
    }
740419
static List<TypeArgument> parseList(final Parser parser, final String definingClassName) throws ParseException {
        if (parser.peek() == '<') {
            parser.expect('<');
            final List<TypeArgument> typeArguments = new ArrayList<>(2);
            while (parser.peek() != '>') {
                if (!parser.hasMore()) {
                    throw new ParseException(parser, "Missing '>'");
                }
                typeArguments.add(parse(parser, definingClassName));
            }
            parser.expect('>');
            return typeArguments;
        } else {
            return Collections.emptyList();
        }
    }
228180
private void getEJBWithProviderClasses(Set<String> classeNames, EJBEndpoint ejb, String ejbInterfaceName, ClassLoader appClassloader) {
        final String methodName = "getEJBWithProviderClasses";
        if (tc.isEntryEnabled())
            Tr.entry(tc, methodName, classeNames, ejb, ejbInterfaceName);

        if (classeNames == null) {
            if (tc.isEntryEnabled())
                Tr.exit(tc, methodName, Collections.emptySet());
            return;
        }

        Class<Provider> providerClass = Provider.class;
        final String ejbClassName = (ejbInterfaceName == null) ? ejb.getClassName() : ejbInterfaceName;
        Class<?> c = null;
        try {
            c = appClassloader.loadClass(ejbClassName);
        } catch (ClassNotFoundException e) {

//            if (tc.isDebugEnabled()) {
//                Tr.debug(tc, "getEJBWithProviderClasses() exit - due to Class Not Found for " + ejbClassName + ": " + e);
//            }
            Tr.error(tc, "error.failed.toloadejbclass", ejbClassName);
        }

        if (c != null && c.getAnnotation(providerClass) != null) {
            classeNames.add(ejbClassName);
        }

        if (tc.isEntryEnabled())
            Tr.exit(tc, methodName, classeNames);
    }
1348467
@SuppressWarnings("unchecked")
	public static <T> T handleRow(int columnCount, ResultSetMetaData meta, ResultSet rs, Class<T> beanClass) throws SQLException {
		Assert.notNull(beanClass, "Bean Class must be not null !");
		
		if(beanClass.isArray()) {
			//返回数组
			final Class<?> componentType = beanClass.getComponentType();
			final Object[] result = ArrayUtil.newArray(componentType, columnCount);
			for(int i = 0,j = 1; i < columnCount; i++, j++) {
				result[i] = getColumnValue(rs, j, meta.getColumnType(j), componentType);
			}
			return (T) result;
		} else if(Iterable.class.isAssignableFrom(beanClass)) {
			//集合
			final Object[] objRow = handleRow(columnCount, meta, rs, Object[].class);
			return Convert.convert(beanClass, objRow);
		} else if(beanClass.isAssignableFrom(Entity.class)) {
			//Entity的父类都可按照Entity返回
			return (T) handleRow(columnCount, meta, rs);
		} else if(String.class == beanClass) {
			//字符串
			final Object[] objRow = handleRow(columnCount, meta, rs, Object[].class);
			return (T) StrUtil.join(", ", objRow);
		}
		
		//普通bean
		final T bean = ReflectUtil.newInstanceIfPossible(beanClass);
		//忽略字段大小写
		final Map<String, PropDesc> propMap = BeanUtil.getBeanDesc(beanClass).getPropMap(true);
		String columnLabel;
		PropDesc pd;
		Method setter = null;
		Object value = null;
		for (int i = 1; i <= columnCount; i++) {
			columnLabel = meta.getColumnLabel(i);
			//驼峰命名风格
			pd = propMap.get(StrUtil.toCamelCase(columnLabel));
			setter = (null == pd) ? null : pd.getSetter();
			if(null != setter) {
				value = getColumnValue(rs, columnLabel,  meta.getColumnType(i), TypeUtil.getFirstParamType(setter));
				ReflectUtil.invokeWithCheck(bean, setter, new Object[] {value});
			}
		}
		return bean;
	}
29698
public static Class<?> getPropertyClass(Class<?> beanClass, String field) {
        try {
            return INSTANCE.findPropertyClass(beanClass, field);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            throw handleReflectionException(beanClass, field, e);
        }
    }
519377
public static <E> BeanListHandler<E> create(Class<E> beanType) {
		return new BeanListHandler<E>(beanType);
	}
1180044
public void scanConfigurableBeans(String... basePackages) throws BeanRuleException {
        if (basePackages == null || basePackages.length == 0) {
            return;
        }

        log.info("Auto component scanning on packages [" + StringUtils.joinCommaDelimitedList(basePackages) + "]");

        for (String basePackage : basePackages) {
            BeanClassScanner scanner = new BeanClassScanner(classLoader);
            List<BeanRule> beanRules = new ArrayList<>();
            scanner.scan(basePackage + ".**", (resourceName, targetClass) -> {
                if (targetClass.isAnnotationPresent(Component.class)) {
                    BeanRule beanRule = new BeanRule();
                    beanRule.setBeanClass(targetClass);
                    beanRule.setScopeType(ScopeType.SINGLETON);
                    beanRules.add(beanRule);
                }
            });
            for (BeanRule beanRule : beanRules) {
                saveConfigurableBeanRule(beanRule);
            }
        }
    }
1248792
public <A extends Annotation> A findAnnotationOnBean(Class<A> annotationType) {
        return applicationContext.findAnnotationOnBean(beanName, annotationType);
    }
711230
public void resolveBeanClass(AutowireRule autowireRule) throws IllegalRuleException {
        if (autowireRule.getTargetType() == AutowireTargetType.FIELD) {
            if (autowireRule.isRequired()) {
                Class<?>[] types = autowireRule.getTypes();
                String[] qualifiers = autowireRule.getQualifiers();
                reserveBeanReference(qualifiers[0], types[0], autowireRule);
            }
        } else if (autowireRule.getTargetType() == AutowireTargetType.FIELD_VALUE) {
            Token token = autowireRule.getToken();
            resolveBeanClass(token, autowireRule);
        } else if (autowireRule.getTargetType() == AutowireTargetType.METHOD ||
                autowireRule.getTargetType() == AutowireTargetType.CONSTRUCTOR) {
            if (autowireRule.isRequired()) {
                Class<?>[] types = autowireRule.getTypes();
                String[] qualifiers = autowireRule.getQualifiers();
                for (int i = 0; i < types.length; i++) {
                    reserveBeanReference(qualifiers[i], types[i], autowireRule);
                }
            }
        }
    }
55089
protected @Nonnull Iterable<BeanConfiguration> resolveBeanConfigurations() {
        final SoftServiceLoader<BeanConfiguration> definitions = SoftServiceLoader.load(BeanConfiguration.class, classLoader);
        List<BeanConfiguration> list = new ArrayList<>(20);
        for (ServiceDefinition<BeanConfiguration> definition : definitions) {
            if (definition.isPresent()) {
                list.add(definition.load());
            }
        }
        return list;
    }
49207
protected <T> void buildCallbackMethods(final BeanMapping<T> beanMapping, final Class<T> beanType, final CsvBean beanAnno) {
        
        // コールバック用のメソッドの取得
        for(Method method : beanType.getDeclaredMethods()) {
            
            if(method.getAnnotation(CsvPreRead.class) != null) {
                beanMapping.addPreReadMethod(new CallbackMethod(method));
            }
            
            if(method.getAnnotation(CsvPostRead.class) != null) {
                beanMapping.addPostReadMethod(new CallbackMethod(method));
            }
            
            if(method.getAnnotation(CsvPreWrite.class) != null) {
                beanMapping.addPreWriteMethod(new CallbackMethod(method));
            }
            
            if(method.getAnnotation(CsvPostWrite.class) != null) {
                beanMapping.addPostWriteMethod(new CallbackMethod(method));
            }
        }
        
        // リスナークラスの取得
        final List<Object> listeners = Arrays.stream(beanAnno.listeners())
                .map(l -> configuration.getBeanFactory().create(l))
                .collect(Collectors.toList());
        beanMapping.addAllListeners(listeners);
        
        for(Object listener : listeners) {
            for(Method method : listener.getClass().getDeclaredMethods()) {
                if(method.getAnnotation(CsvPreRead.class) != null) {
                    beanMapping.addPreReadMethod(new ListenerCallbackMethod(listener, method));
                }
                
                if(method.getAnnotation(CsvPostRead.class) != null) {
                    beanMapping.addPostReadMethod(new ListenerCallbackMethod(listener, method));
                }
                
                if(method.getAnnotation(CsvPreWrite.class) != null) {
                    beanMapping.addPreWriteMethod(new ListenerCallbackMethod(listener, method));
                }
                
                if(method.getAnnotation(CsvPostWrite.class) != null) {
                    beanMapping.addPostWriteMethod(new ListenerCallbackMethod(listener, method));
                }
            }
        }
        
        beanMapping.getPreReadMethods().sort(null);
        beanMapping.getPostReadMethods().sort(null);
        beanMapping.getPreWriteMethods().sort(null);
        beanMapping.getPostWriteMethods().sort(null);
        
    }
423503
public static <T> ArgumentProcessor<T> forType(Class<? extends T> beanType) {
    return newInstance(beanType, new GnuParser());
  }
538289
@SuppressWarnings("null")
    private Object parseBean(final Class<?> beanType) throws Exception {
        String propName = "";
        try {
            XMLEvent event = null;
            // handle case where whole bean is Joda-Convert string
            if (settings.getConverter().isConvertible(beanType)) {
                StringBuilder buf = new StringBuilder();
                while (reader.hasNext()) {
                    event = nextEvent(">btxt ");
                    if (event.isCharacters()) {
                        buf.append(event.asCharacters().getData());
                    } else if (event.isEndElement()) {
                        return settings.getConverter().convertFromString(beanType, buf.toString());
                    } else if (event.isStartElement()) {
                        break;  // not serialized via Joda-Convert
                    } else if (event.isEndDocument()) {
                        throw new IllegalArgumentException("Unexpected end of document");
                    }
                }
            } else {
                event = nextEvent(">bean ");
            }
            // handle structured bean
            SerDeserializer deser = settings.getDeserializers().findDeserializer(beanType);
            MetaBean metaBean = deser.findMetaBean(beanType);
            BeanBuilder<?> builder = deser.createBuilder(beanType, metaBean);
            // handle beans with structure
            while (event.isEndElement() == false) {
                if (event.isStartElement()) {
                    StartElement start = event.asStartElement();
                    propName = start.getName().getLocalPart();
                    MetaProperty<?> metaProp = deser.findMetaProperty(beanType, metaBean, propName);
                    if (metaProp == null || metaProp.style().isDerived()) {
                        int depth = 0;
                        event = nextEvent(" skip ");
                        while (event.isEndElement() == false || depth > 0) {
                            if (event.isStartElement()) {
                                depth++;
                            } else if (event.isEndElement()) {
                                depth--;
                            }
                            event = nextEvent(" skip ");
                        }
                        // skip elements
                    } else {
                        Class<?> childType = parseTypeAttribute(start, SerOptional.extractType(metaProp, beanType));
                        Object value;
                        if (Bean.class.isAssignableFrom(childType)) {
                            value = parseBean(childType);
                        } else {
                            SerIterable iterable = settings.getIteratorFactory().createIterable(metaProp, beanType);
                            if (iterable != null) {
                                value = parseIterable(start, iterable);
                            } else {
                                // metatype
                                Attribute metaTypeAttr = start.getAttributeByName(METATYPE_QNAME);
                                if (metaTypeAttr != null) {
                                    iterable = settings.getIteratorFactory().createIterable(metaTypeAttr.getValue(), settings, knownTypes);
                                    if (iterable == null) {
                                        throw new IllegalArgumentException("Invalid metaType");
                                    }
                                    value = parseIterable(start, iterable);
                                } else {
                                    String text = advanceAndParseText();
                                    value = settings.getConverter().convertFromString(childType, text);
                                }
                            }
                        }
                        deser.setValue(builder, metaProp, SerOptional.wrapValue(metaProp, beanType, value));
                    }
                    propName = "";
                }
                event = nextEvent(".bean ");
            }
            return deser.build(beanType, builder);
        } catch (Exception ex) {
            throw new RuntimeException("Error parsing bean: " + beanType.getName() + "::" + propName + ", " + ex.getMessage(), ex);
        }
    }
593329
public static BeanParser getBeanParser(Method method) {
    Type returnType = method.getReturnType();
    if (isCompletableFutureType(method.getReturnType())) {
      returnType = getActualReturnType(method);
    }
    BeanParser beanParser = typeBeanParserMap.get(returnType);
    if (beanParser != null) {
      return beanParser;
    }
    return defaultBeanParser;
  }
450889
public boolean isTypeSupportedForDeserialization( TreeLogger logger, JClassType classType ) {
        return allSupportedDeserializationClass.contains( classType )
                || additionalSupportedTypes.isIncluded( logger, classType.getQualifiedSourceName() );
    }