commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1234608 - in /commons/proper/configuration/trunk/src/site/xdoc/userguide: howto_basicfeatures.xml howto_compositeconfiguration.xml howto_properties.xml howto_xml.xml
Date Sun, 22 Jan 2012 21:10:48 GMT
Author: oheger
Date: Sun Jan 22 21:10:47 2012
New Revision: 1234608

URL: http://svn.apache.org/viewvc?rev=1234608&view=rev
Log:
Updated user guide to API changes related to generics.

Modified:
    commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_basicfeatures.xml
    commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_compositeconfiguration.xml
    commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_properties.xml
    commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_xml.xml

Modified: commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_basicfeatures.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_basicfeatures.xml?rev=1234608&r1=1234607&r2=1234608&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_basicfeatures.xml (original)
+++ commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_basicfeatures.xml Sun
Jan 22 21:10:47 2012
@@ -115,7 +115,7 @@ config.addProperty("colors.graph", "#808
 
 // Access data
 String salut = config.getString("greeting");
-List colPie = config.getList("colors.pie");
+List<Object> colPie = config.getList("colors.pie");
 String[] colGraph = config.getStringArray("colors.graph");
 
 String firstPieColor = config.getString("colors.pie");
@@ -123,10 +123,13 @@ String firstPieColor = config.getString(
     <p>
       In this example the list delimiter character is changed from a comma
       to a slash. Because of this the <code>greeting</code> property won't
-      be splitted, but remains a single string. The string passed as value
+      be split, but remains a single string. The string passed as value
       for the <code>colors.graph</code> property in opposite contains the
       new delimiter character and thus will result in a property with three
-      values.
+      values. Note that lists are of type <code>Object</code>. This is because
+      the concrete class of the values of a property is not known. For instance,
+      if you call <code>addProperty(&quot;answer&quot;, 42)</code>, an
+      <code>Integer</code> object will be stored in the configuration.
     </p>
     <p>
       Of interest is also the last line of the example fragment. Here the

Modified: commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_compositeconfiguration.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_compositeconfiguration.xml?rev=1234608&r1=1234607&r2=1234608&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_compositeconfiguration.xml
(original)
+++ commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_compositeconfiguration.xml
Sun Jan 22 21:10:47 2012
@@ -68,7 +68,7 @@ cc.addConfiguration(fileToDefaults);
 				save changes made to a configuration, and you are using a
 				CompositeConfiguration, then you will need to pass into
 				the constructor of the CompositeConfiguration what Configuration
-				to save the changes via.  
+				to save the changes via.
 			</p>
     			<source><![CDATA[
 PropertiesConfiguration saveConfiguration = new PropertiesConfiguration(fileToSaveChangesIn);
@@ -79,19 +79,22 @@ saveConfiguration.save();
 ]]></source>
 			<p>
 				Alternatively, you can just request the
-				inMemoryConfiguration that stores the changes:
+				in-memory configuration that stores the changes. The following
+                example fragment copies all properties from the in-memory
+                configuration into a <code>DatabaseConfiguration</code>, so
+                that they are made persistent:
     			<source><![CDATA[
 Configuration changes = myCompositeConfiguration.getInMemoryConfiguration();
 DatabaseConfiguration config = new DatabaseConfiguration(datasource, "configuration", "key",
"value");
-for (Iterator i = changes.getKeys().iterator();i.hasNext()){
-	String key = (key)i.next();
+for (Iterator<String> i = changes.getKeys(); i.hasNext()){
+	String key = i.next();
 	Object value = changes.get(key);
 	config.setProperty(key,value);
 }
 ]]></source>
 			</p>
-		
-		</subsection>		
+
+		</subsection>
 	</section>
 </body>
 

Modified: commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_properties.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_properties.xml?rev=1234608&r1=1234607&r2=1234608&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_properties.xml (original)
+++ commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_properties.xml Sun Jan
22 21:10:47 2012
@@ -128,7 +128,7 @@ colors.pie = #FF0000, #00FF00, #0000FF
         </p>
 <source>
 String[] colors = config.getStringArray("colors.pie");
-List colorList = config.getList("colors.pie");
+List&lt;Object&gt; colorList = config.getList("colors.pie");
 </source>
         <p>
           Alternatively, you can specify a list of values in your properties file by using

Modified: commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_xml.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_xml.xml?rev=1234608&r1=1234607&r2=1234608&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_xml.xml (original)
+++ commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_xml.xml Sun Jan 22 21:10:47
2012
@@ -118,7 +118,7 @@ String textColor = config.getString("col
 String linkNormal = config.getString("colors.link[@normal]");
 String defColor = config.getString("colors.default");
 int rowsPerPage = config.getInt("rowsPerPage");
-List buttons = config.getList("buttons.name");
+List<Object> buttons = config.getList("buttons.name");
 ]]></source>
 			<p>
 				This listing demonstrates some important points about constructing
@@ -268,14 +268,14 @@ List buttons = config.getList("buttons.n
 Object prop = config.getProperty("tables.table.name");
 if(prop instanceof Collection)
 {
-	System.out.println("Number of tables: " + ((Collection) prop).size());
+	System.out.println("Number of tables: " + ((Collection<?>) prop).size());
 }
 ]]></source>
 			<p>
 				An alternative to this code would be the <code>getList()</code>
 				method of <code>Configuration</code>. If a property is known to
 				have multiple values (as is the table name property in this example),
-				<code>getList()</code> allows to retrieve all values at once.
+				<code>getList()</code> allows retrieving all values at once.
 				<b>Note:</b> it is legal to call <code>getString()</code>
 				or one of the other getter methods on a property with multiple
 				values; it returns the first element of the list.
@@ -372,7 +372,7 @@ if(prop instanceof Collection)
    			<source><![CDATA[
 HierarchicalConfiguration sub = config.configurationAt("tables.table(0)");
 String tableName = sub.getString("name");  // only need to provide relative path
-List fieldNames = sub.getList("fields.field.name");
+List<Object> fieldNames = sub.getList("fields.field.name");
 ]]></source>
             <p>
                 For dealing with complex list-like structures there is another
@@ -386,9 +386,9 @@ List fieldNames = sub.getList("fields.fi
                 by one:
             </p>
    			<source><![CDATA[
-List fieldNames = config.getList("tables.table(0).fields.field.name");
-List fieldTypes = config.getList("tables.table(0).fields.field.type");
-List ... // further calls for other data that might be stored in the config
+List<Object> fieldNames = config.getList("tables.table(0).fields.field.name");
+List<Object> fieldTypes = config.getList("tables.table(0).fields.field.type");
+List<Object> ... // further calls for other data that might be stored in the config
 ]]></source>
             <p>
                 But this is not very readable and will fail if not all field
@@ -405,10 +405,10 @@ List ... // further calls for other data
                 very handy when processing list-like structures:
             </p>
    			<source><![CDATA[
-List fields = config.configurationsAt("tables.table(0).fields.field");
-for(Iterator it = fields.iterator(); it.hasNext();)
+List<HierarchicalConfiguration> fields = 
+    config.configurationsAt("tables.table(0).fields.field");
+for(HierarchicalConfiguration sub : fields)
 {
-    HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();
     // sub contains all data about a single field
     String fieldName = sub.getString("name");
     String fieldType = sub.getString("type");
@@ -848,7 +848,7 @@ HierarchicalConfiguration config = ...
 config.setExpressionEngine(new XPathExpressionEngine());
 
 // Now we can use XPATH queries:
-List fields = config.getList("tables/table[1]/fields/name");
+List<Object> fields = config.getList("tables/table[1]/fields/name");
          ]]></source>
             <p>
                 XPATH expressions are not only used for selecting properties



Mime
View raw message