| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.dozer.util; |
| 17 | |
|
| 18 | |
import org.dozer.config.BeanContainer; |
| 19 | |
|
| 20 | |
import java.io.IOException; |
| 21 | |
import java.io.InputStream; |
| 22 | |
import java.net.URL; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
public final class MappingValidator { |
| 32 | |
|
| 33 | 0 | private MappingValidator() {} |
| 34 | |
|
| 35 | |
public static void validateMappingRequest(Object srcObj) { |
| 36 | 132067 | if (srcObj == null) { |
| 37 | 3 | MappingUtils.throwMappingException("Source object must not be null"); |
| 38 | |
} |
| 39 | 132064 | } |
| 40 | |
|
| 41 | |
public static void validateMappingRequest(Object srcObj, Object destObj) { |
| 42 | 131205 | validateMappingRequest(srcObj); |
| 43 | 131205 | if (destObj == null) { |
| 44 | 1 | MappingUtils.throwMappingException("Destination object must not be null"); |
| 45 | |
} |
| 46 | 131204 | } |
| 47 | |
|
| 48 | |
public static void validateMappingRequest(Object srcObj, Class<?> destClass) { |
| 49 | 861 | validateMappingRequest(srcObj); |
| 50 | 859 | if (destClass == null) { |
| 51 | 2 | MappingUtils.throwMappingException("Destination class must not be null"); |
| 52 | |
} |
| 53 | 857 | } |
| 54 | |
|
| 55 | |
public static URL validateURL(String fileName) { |
| 56 | 602 | DozerClassLoader classLoader = BeanContainer.getInstance().getClassLoader(); |
| 57 | 602 | if (fileName == null) { |
| 58 | 1 | MappingUtils.throwMappingException("File name is null"); |
| 59 | |
} |
| 60 | |
|
| 61 | 601 | URL url = classLoader.loadResource(fileName); |
| 62 | 601 | if (url == null) { |
| 63 | 1 | MappingUtils.throwMappingException("Unable to locate dozer mapping file [" + fileName + "] in the classpath!"); |
| 64 | |
} |
| 65 | |
|
| 66 | 600 | InputStream stream = null; |
| 67 | |
try { |
| 68 | 600 | stream = url.openStream(); |
| 69 | 0 | } catch (IOException e) { |
| 70 | 0 | MappingUtils.throwMappingException("Unable to open URL input stream for dozer mapping file [" + url + "]"); |
| 71 | |
} finally { |
| 72 | 600 | if (stream != null) { |
| 73 | |
try { |
| 74 | 600 | stream.close(); |
| 75 | 0 | } catch (IOException e) { |
| 76 | 0 | MappingUtils.throwMappingException("Unable to close input stream for dozer mapping file [" + url + "]"); |
| 77 | 600 | } |
| 78 | |
} |
| 79 | |
} |
| 80 | |
|
| 81 | 600 | return url; |
| 82 | |
} |
| 83 | |
|
| 84 | |
} |