pier 2004/05/09 04:32:08
Modified: src/kernel/org/apache/cocoon/kernel/configuration
Parameters.java
Log:
Added a method to convert Parameters into java.util.Properties.
Fixed a bug in the creation of Parameters from a Configuration.
Better JavaDoc comments.
Revision Changes Path
1.5 +34 -7
cocoon-2.2/src/kernel/org/apache/cocoon/kernel/configuration/Parameters.java
Index: Parameters.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/kernel/org/apache/cocoon/kernel/configuration/Parameters.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Parameters.java 31 Mar 2004 13:01:38 -0000 1.4
+++ Parameters.java 9 May 2004 11:32:08 -0000 1.5
@@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Properties;
/**
* <p>The [EMAIL PROTECTED] Parameters} class defines a simple [EMAIL
PROTECTED] Map} that can
@@ -50,8 +51,16 @@
}
/**
- * <p>Create a new [EMAIL PROTECTED] Parameters} instance from a [EMAIL
PROTECTED] Configuration}
- * instance.</p>
+ * <p>Create a new [EMAIL PROTECTED] Parameters} instance parsing all
elements of a
+ * [EMAIL PROTECTED] Configuration} instance.</p>
+ *
+ * <p>Elements of the configuration that will be parsed must look like
+ * this:</p>
+ *
+ * <p><nobr><code><parameter
+ * name="<b>name</b>"
+ * value="<b>value</b>"
+ * <i>type="<b>type identifier</b>"</i>/></code></nobr></p>
*
* @throws ConfigurationException if the instance cannot be created.
*/
@@ -76,10 +85,9 @@
} else if ("long".equalsIgnoreCase(t)) {
this.put(n, c.getLongValue(c.getLongAttribute("value")));
} else if ("configuration".equalsIgnoreCase(t)) {
- if (c.size() == 1) this.put(n, c.get(0));
- throw new ConfigurationException("Too many/few children for "
- + "parameter \"" + n + "\"
of"
- + "type \"configuration\"",
c);
+ Configuration k = new Configuration(n);
+ k.addAll(c);
+ this.put(n, k);
} else {
this.put(n, c.getValue(c.getAttribute("value")));
}
@@ -502,6 +510,25 @@
}
}
+ /*
====================================================================== */
+
+ /**
+ * <p>Convert this [EMAIL PROTECTED] Parameters} instance into [EMAIL
PROTECTED] Properties}.</p>
+ *
+ * @return a <b>non null</b> [EMAIL PROTECTED] Properties} instance with
all parameters
+ * it was possible to convert into properties.
+ */
+ public Properties toProperties() {
+ Properties properties = new Properties();
+ Iterator iterator = this.keySet().iterator();
+ while (iterator.hasNext()) {
+ String name = (String)iterator.next();
+ String value = this.getString(name, null);
+ if (value != null) properties.put(name, value);
+ }
+ return(properties);
+ }
+
/*
====================================================================== */
/**