EMMA Coverage Report (generated Tue May 06 07:28:24 PDT 2008)
[all classes][org.springframework.batch.item.adapter]

COVERAGE SUMMARY FOR SOURCE FILE [PropertyExtractingDelegatingItemWriter.java]

nameclass, %method, %block, %line, %
PropertyExtractingDelegatingItemWriter.java100% (1/1)67%  (4/6)96%  (46/48)86%  (12/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PropertyExtractingDelegatingItemWriter100% (1/1)67%  (4/6)96%  (46/48)86%  (12/14)
clear (): void 0%   (0/1)0%   (0/1)0%   (0/1)
flush (): void 0%   (0/1)0%   (0/1)0%   (0/1)
PropertyExtractingDelegatingItemWriter (): void 100% (1/1)100% (3/3)100% (1/1)
afterPropertiesSet (): void 100% (1/1)100% (6/6)100% (3/3)
setFieldsUsedAsTargetMethodArguments (String []): void 100% (1/1)100% (4/4)100% (2/2)
write (Object): void 100% (1/1)100% (33/33)100% (6/6)

1/*
2 * Copyright 2006-2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17package org.springframework.batch.item.adapter;
18 
19import org.springframework.batch.item.ClearFailedException;
20import org.springframework.batch.item.FlushFailedException;
21import org.springframework.batch.item.ItemWriter;
22import org.springframework.beans.BeanWrapper;
23import org.springframework.beans.BeanWrapperImpl;
24import org.springframework.util.Assert;
25 
26/**
27 * Delegates processing to a custom method -  extracts property values 
28 * from item object and uses them as arguments for the delegate method.
29 * 
30 * @see ItemWriterAdapter
31 * 
32 * @author Robert Kasanicky
33 */
34public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvokingDelegator implements ItemWriter {
35        
36        private String[] fieldsUsedAsTargetMethodArguments;
37        
38        /**
39         * Extracts values from item's fields named in fieldsUsedAsTargetMethodArguments
40         * and passes them as arguments to the delegate method.
41         */
42        public void write(Object item) throws Exception {
43                // helper for extracting property values from a bean
44                BeanWrapper beanWrapper = new BeanWrapperImpl(item);
45                
46                Object[] methodArguments = new Object[fieldsUsedAsTargetMethodArguments.length];
47                for (int i = 0; i < fieldsUsedAsTargetMethodArguments.length; i++) {
48                        methodArguments[i] = beanWrapper.getPropertyValue(fieldsUsedAsTargetMethodArguments[i]);
49                }
50                
51                invokeDelegateMethodWithArguments(methodArguments);
52        }
53                
54 
55        public void afterPropertiesSet() throws Exception {
56                super.afterPropertiesSet();
57                Assert.notEmpty(fieldsUsedAsTargetMethodArguments);
58        }
59 
60        /**
61         * @param fieldsUsedAsMethodArguments the values of the these item's fields
62         * will be used as arguments for the delegate method. Nested property values are
63         * supported, e.g. <code>address.city</code>
64         */
65        public void setFieldsUsedAsTargetMethodArguments(String[] fieldsUsedAsMethodArguments) {
66                this.fieldsUsedAsTargetMethodArguments = fieldsUsedAsMethodArguments;
67        }
68 
69 
70        public void clear() throws ClearFailedException {
71        }
72 
73 
74        public void flush() throws FlushFailedException {
75        }
76}

[all classes][org.springframework.batch.item.adapter]
EMMA 2.0.5312 (C) Vladimir Roubtsov