01: /*
02: * $Id: PropertyReaderConverter.java,v 1.16 2007/03/16 09:54:58 agoubard Exp $
03: *
04: * Copyright 2003-2007 Orange Nederland Breedband B.V.
05: * See the COPYRIGHT file for redistribution and use restrictions.
06: */
07: package org.xins.common.collections;
08:
09: import java.util.Iterator;
10: import java.util.Properties;
11: import org.xins.common.MandatoryArgumentChecker;
12:
13: /**
14: * Converter that is able to convert <code>PropertyReader</code> objects to
15: * other kinds of objects.
16: *
17: * @version $Revision: 1.16 $ $Date: 2007/03/16 09:54:58 $
18: * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
19: *
20: * @since XINS 1.0.1
21: */
22: public final class PropertyReaderConverter {
23:
24: /**
25: * Constructs a new <code>PropertyReaderConverter</code>.
26: */
27: private PropertyReaderConverter() {
28: // empty
29: }
30:
31: /**
32: * Converts the specified <code>PropertyReader</code> object to a new
33: * <code>Properties</code> object.
34: *
35: * @param propertyReader
36: * the {@link PropertyReader} object, cannot be <code>null</code>.
37: *
38: * @return
39: * a new {@link Properties} object, never <code>null</code>.
40: *
41: * @throws IllegalArgumentException
42: * if <code>propertyReader == null</code>.
43: */
44: public static Properties toProperties(PropertyReader propertyReader)
45: throws IllegalArgumentException {
46:
47: // Check preconditions
48: MandatoryArgumentChecker
49: .check("propertyReader", propertyReader);
50:
51: Properties prop = new Properties();
52: Iterator keys = propertyReader.getNames();
53: while (keys.hasNext()) {
54: String key = (String) keys.next();
55: String value = propertyReader.get(key);
56:
57: prop.setProperty(key, value);
58: }
59: return prop;
60: }
61: }
|