| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| JavaBeanFieldsDetector |
|
| 2.6666666666666665;2.667 |
| 1 | /** | |
| 2 | * Copyright 2005-2013 Dozer Project | |
| 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 | package org.dozer.classmap.generator; | |
| 17 | ||
| 18 | import org.dozer.util.ReflectionUtils; | |
| 19 | ||
| 20 | import java.beans.PropertyDescriptor; | |
| 21 | import java.util.HashSet; | |
| 22 | import java.util.Set; | |
| 23 | ||
| 24 | /** | |
| 25 | * @author Dmitry Spikhalskiy | |
| 26 | */ | |
| 27 | 1 | public class JavaBeanFieldsDetector implements BeanMappingGenerator.BeanFieldsDetector { |
| 28 | public boolean accepts(Class<?> clazz) { | |
| 29 | 17294 | return true; |
| 30 | } | |
| 31 | ||
| 32 | public Set<String> getReadableFieldNames(Class<?> clazz) { | |
| 33 | 8647 | Set<String> srcFieldNames = new HashSet<String>(); |
| 34 | 8647 | PropertyDescriptor[] srcProperties = ReflectionUtils.getPropertyDescriptors(clazz); |
| 35 | 61377 | for (PropertyDescriptor srcPropertyDescriptor : srcProperties) { |
| 36 | 52730 | String fieldName = srcPropertyDescriptor.getName(); |
| 37 | ||
| 38 | 52730 | if (srcPropertyDescriptor.getReadMethod() == null) { |
| 39 | 335 | continue; |
| 40 | } | |
| 41 | ||
| 42 | 52395 | srcFieldNames.add(fieldName); |
| 43 | } | |
| 44 | 8647 | return srcFieldNames; |
| 45 | } | |
| 46 | ||
| 47 | public Set<String> getWritableFieldNames(Class<?> clazz) { | |
| 48 | 8647 | Set<String> destFieldNames = new HashSet<String>(); |
| 49 | 8647 | PropertyDescriptor[] destProperties = ReflectionUtils.getPropertyDescriptors(clazz); |
| 50 | 60534 | for (PropertyDescriptor destPropertyDescriptor : destProperties) { |
| 51 | 51887 | String fieldName = destPropertyDescriptor.getName(); |
| 52 | ||
| 53 | // If destination field does not have a write method, then skip | |
| 54 | 51887 | if (destPropertyDescriptor.getWriteMethod() == null && ReflectionUtils.getNonVoidSetter(clazz, fieldName) == null) { |
| 55 | 9246 | continue; |
| 56 | } | |
| 57 | ||
| 58 | 42641 | destFieldNames.add(fieldName); |
| 59 | } | |
| 60 | 8647 | return destFieldNames; |
| 61 | } | |
| 62 | } |