private <P> SheetBindingErrors<P> loadSheet(final Sheet sheet, final Class<P> clazz, final AnnotationReader annoReader)
            throws XlsMapperException {

        // 値の読み込み対象のJavaBeanオブジェクトの作成
        final P beanObj = configuration.createBean(clazz);

        final SheetBindingErrors<P> errors =  configuration.getBindingErrorsFactory().create(beanObj);
        errors.setSheetName(sheet.getSheetName());
        errors.setSheetIndex(sheet.getWorkbook().getSheetIndex(sheet));

        final LoadingWorkObject work = new LoadingWorkObject();
        work.setAnnoReader(annoReader);
        work.setErrors(errors);

        // セルのキャッシュ情報の初期化
        configuration.getCellFormatter().init(configuration.isCacheCellValueOnLoad());

        final FieldAccessorFactory adpterFactory = new FieldAccessorFactory(annoReader);

        // リスナークラスの@PreLoad用メソッドの実行
        final XlsListener listenerAnno = annoReader.getAnnotation(beanObj.getClass(), XlsListener.class);
        if(listenerAnno != null) {
            for(Class<?> listenerClass : listenerAnno.value()) {
                final Object listenerObj = configuration.createBean(listenerClass);

                for(Method method : listenerObj.getClass().getMethods()) {
                    if(annoReader.hasAnnotation(method, XlsPreLoad.class)) {
                        Utils.invokeNeedProcessMethod(listenerObj, method, beanObj, sheet, configuration, work.getErrors(), ProcessCase.Load);
                    }
                }
            }

        }

        // @PreLoad用のメソッドの実行
        for(Method method : clazz.getMethods()) {

            if(annoReader.hasAnnotation(method, XlsPreLoad.class)) {
                Utils.invokeNeedProcessMethod(beanObj, method, beanObj, sheet, configuration, work.getErrors(), ProcessCase.Load);
            }
        }

        final List<FieldAccessorProxy> accessorProxies = new ArrayList<>();

        // public メソッドの処理
        for(Method method : clazz.getMethods()) {
            method.setAccessible(true);
            for(Annotation anno : annoReader.getAnnotations(method)) {
                final XlsFieldProcessor annoFieldProcessor = anno.annotationType().getAnnotation(XlsFieldProcessor.class);
                if(ClassUtils.isAccessorMethod(method) && annoFieldProcessor != null) {
                    // 登録済みのFieldProcessorの取得
                    FieldProcessor<?> processor = configuration.getFieldProcessorRegistry().getProcessor(anno.annotationType());

                    // アノテーションに指定されているFieldProcessorの場合
                    if(processor == null && annoFieldProcessor.value().length > 0) {
                        processor = configuration.createBean(annoFieldProcessor.value()[0]);

                    }

                    if(processor != null) {
                        final FieldAccessor accessor = adpterFactory.create(method);
                        final FieldAccessorProxy accessorProxy = new FieldAccessorProxy(anno, processor, accessor);
                        if(!accessorProxies.contains(accessorProxy)) {
                            accessorProxies.add(accessorProxy);
                        }

                    } else {
                        // FieldProcessorが見つからない場合
                        throw new AnnotationInvalidException(anno, MessageBuilder.create("anno.XlsFieldProcessor.notResolve")
                                .varWithAnno("anno", anno.annotationType())
                                .format());
                    }

                }

                if(anno instanceof XlsPostLoad) {
                    work.addNeedPostProcess(new NeedProcess(beanObj, beanObj, method));
                }
            }

        }

        // フィールドの処理
        for(Field field : clazz.getDeclaredFields()) {

            field.setAccessible(true);
            for(Annotation anno : annoReader.getAnnotations(field)) {

                final XlsFieldProcessor annoFieldProcessor = anno.annotationType().getAnnotation(XlsFieldProcessor.class);
                if(annoFieldProcessor != null) {

                    // 登録済みのFieldProcessorの取得
                    FieldProcessor<?> processor = configuration.getFieldProcessorRegistry().getProcessor(anno.annotationType());

                    // アノテーションに指定されているFieldProcessorの場合
                    if(processor == null && annoFieldProcessor.value().length > 0) {
                        processor = configuration.createBean(annoFieldProcessor.value()[0]);

                    }

                    if(processor != null) {
                        final FieldAccessor accessor = adpterFactory.create(field);
                        final FieldAccessorProxy accessorProxy = new FieldAccessorProxy(anno, processor, accessor);
                        if(!accessorProxies.contains(accessorProxy)) {
                            accessorProxies.add(accessorProxy);
                        }

                    } else {
                        // FieldProcessorが見つからない場合
                        throw new AnnotationInvalidException(anno, MessageBuilder.create("anno.XlsFieldProcessor.notResolve")
                                .varWithAnno("anno", anno.annotationType())
                                .format());
                    }

                }


            }
        }

        // 順番を並び替えて保存処理を実行する
        Collections.sort(accessorProxies, new FieldAccessorProxyComparator());
        for(FieldAccessorProxy accessorProxy : accessorProxies) {
            accessorProxy.loadProcess(sheet, beanObj, configuration, work);
        }

        // リスナークラスの@PostLoadの取得
        if(listenerAnno != null) {
            for(Class<?> listenerClass : listenerAnno.value()) {
                Object listenerObj = configuration.createBean(listenerClass);
                for(Method method : listenerObj.getClass().getMethods()) {
                    if(annoReader.hasAnnotation(method, XlsPostLoad.class)) {
                        work.addNeedPostProcess(new NeedProcess(beanObj, listenerObj, method));
                    }
                }
            }

        }

        //@PostLoadが付与されているメソッドの実行
        for(NeedProcess need : work.getNeedPostProcesses()) {
            Utils.invokeNeedProcessMethod(need.getProcess(), need.getMethod(), need.getTarget(), sheet, configuration, work.getErrors(), ProcessCase.Load);
        }

        // セルのキャッシュ情報の初期化
        configuration.getCellFormatter().init(configuration.isCacheCellValueOnLoad());

        return errors;
    }
private < P > SheetBindingErrors < P > loadSheet ( final Sheet sheet , final Class < P > clazz , final AnnotationReader annoReader ) throws XlsMapperException { final P beanObj = configuration . createBean ( clazz ) ; final SheetBindingErrors < P > errors = configuration . getBindingErrorsFactory ( ) . create ( beanObj ) ; errors . setSheetName ( sheet . getSheetName ( ) ) ; errors . setSheetIndex ( sheet . getWorkbook ( ) . getSheetIndex ( sheet ) ) ; final LoadingWorkObject work = new LoadingWorkObject ( ) ; work . setAnnoReader ( annoReader ) ; work . setErrors ( errors ) ; configuration . getCellFormatter ( ) . init ( configuration . isCacheCellValueOnLoad ( ) ) ; final FieldAccessorFactory adpterFactory = new FieldAccessorFactory ( annoReader ) ; final XlsListener listenerAnno = annoReader . getAnnotation ( beanObj . getClass ( ) , XlsListener . class ) ; if ( listenerAnno != null ) { for ( Class < ? > listenerClass : listenerAnno . value ( ) ) { final Object listenerObj = configuration . createBean ( listenerClass ) ; for ( Method method : listenerObj . getClass ( ) . getMethods ( ) ) { if ( annoReader . hasAnnotation ( method , XlsPreLoad . class ) ) { Utils . invokeNeedProcessMethod ( listenerObj , method , beanObj , sheet , configuration , work . getErrors ( ) , ProcessCase . Load ) ; } } } } for ( Method method : clazz . getMethods ( ) ) { if ( annoReader . hasAnnotation ( method , XlsPreLoad . class ) ) { Utils . invokeNeedProcessMethod ( beanObj , method , beanObj , sheet , configuration , work . getErrors ( ) , ProcessCase . Load ) ; } } final List < FieldAccessorProxy > accessorProxies = new ArrayList < > ( ) ; for ( Method method : clazz . getMethods ( ) ) { method . setAccessible ( true ) ; for ( Annotation anno : annoReader . getAnnotations ( method ) ) { final XlsFieldProcessor annoFieldProcessor = anno . annotationType ( ) . getAnnotation ( XlsFieldProcessor . class ) ; if ( ClassUtils . isAccessorMethod ( method ) && annoFieldProcessor != null ) { FieldProcessor < ? > processor = configuration . getFieldProcessorRegistry ( ) . getProcessor ( anno . annotationType ( ) ) ; if ( processor == null && annoFieldProcessor . value ( ) . length > 0 ) { processor = configuration . createBean ( annoFieldProcessor . value ( ) [ 0 ] ) ; } if ( processor != null ) { final FieldAccessor accessor = adpterFactory . create ( method ) ; final FieldAccessorProxy accessorProxy = new FieldAccessorProxy ( anno , processor , accessor ) ; if ( ! accessorProxies . contains ( accessorProxy ) ) { accessorProxies . add ( accessorProxy ) ; } } else { throw new AnnotationInvalidException ( anno , MessageBuilder . create ( "anno.XlsFieldProcessor.notResolve" ) . varWithAnno ( "anno" , anno . annotationType ( ) ) . format ( ) ) ; } } if ( anno instanceof XlsPostLoad ) { work . addNeedPostProcess ( new NeedProcess ( beanObj , beanObj , method ) ) ; } } } for ( Field field : clazz . getDeclaredFields ( ) ) { field . setAccessible ( true ) ; for ( Annotation anno : annoReader . getAnnotations ( field ) ) { final XlsFieldProcessor annoFieldProcessor = anno . annotationType ( ) . getAnnotation ( XlsFieldProcessor . class ) ; if ( annoFieldProcessor != null ) { FieldProcessor < ? > processor = configuration . getFieldProcessorRegistry ( ) . getProcessor ( anno . annotationType ( ) ) ; if ( processor == null && annoFieldProcessor . value ( ) . length > 0 ) { processor = configuration . createBean ( annoFieldProcessor . value ( ) [ 0 ] ) ; } if ( processor != null ) { final FieldAccessor accessor = adpterFactory . create ( field ) ; final FieldAccessorProxy accessorProxy = new FieldAccessorProxy ( anno , processor , accessor ) ; if ( ! accessorProxies . contains ( accessorProxy ) ) { accessorProxies . add ( accessorProxy ) ; } } else { throw new AnnotationInvalidException ( anno , MessageBuilder . create ( "anno.XlsFieldProcessor.notResolve" ) . varWithAnno ( "anno" , anno . annotationType ( ) ) . format ( ) ) ; } } } } Collections . sort ( accessorProxies , new FieldAccessorProxyComparator ( ) ) ; for ( FieldAccessorProxy accessorProxy : accessorProxies ) { accessorProxy . loadProcess ( sheet , beanObj , configuration , work ) ; } if ( listenerAnno != null ) { for ( Class < ? > listenerClass : listenerAnno . value ( ) ) { Object listenerObj = configuration . createBean ( listenerClass ) ; for ( Method method : listenerObj . getClass ( ) . getMethods ( ) ) { if ( annoReader . hasAnnotation ( method , XlsPostLoad . class ) ) { work . addNeedPostProcess ( new NeedProcess ( beanObj , listenerObj , method ) ) ; } } } } for ( NeedProcess need : work . getNeedPostProcesses ( ) ) { Utils . invokeNeedProcessMethod ( need . getProcess ( ) , need . getMethod ( ) , need . getTarget ( ) , sheet , configuration , work . getErrors ( ) , ProcessCase . Load ) ; } configuration . getCellFormatter ( ) . init ( configuration . isCacheCellValueOnLoad ( ) ) ; return errors ; }
シートを読み込み、任意のクラスにマッピングする。
@param sheet シート情報
@param clazz マッピング先のクラスタイプ。
@param annoReader
@return シートのマッピング情報
@throws XlsMapperException