perfsonar-dev - nmwg: r217 - trunk/nmwg/java/org/ggf/ns/nmwg/tools/passivetracefile/v2_0
Subject: perfsonar development work
List archive
- From:
- To: ,
- Subject: nmwg: r217 - trunk/nmwg/java/org/ggf/ns/nmwg/tools/passivetracefile/v2_0
- Date: Tue, 27 Mar 2007 06:35:56 -0400
Author: uros
Date: 2007-03-27 06:35:55 -0400 (Tue, 27 Mar 2007)
New Revision: 217
Modified:
trunk/nmwg/java/org/ggf/ns/nmwg/tools/passivetracefile/v2_0/Parameters.java
Log:
Allow other params also.
Modified:
trunk/nmwg/java/org/ggf/ns/nmwg/tools/passivetracefile/v2_0/Parameters.java
===================================================================
---
trunk/nmwg/java/org/ggf/ns/nmwg/tools/passivetracefile/v2_0/Parameters.java
2007-03-26 13:20:01 UTC (rev 216)
+++
trunk/nmwg/java/org/ggf/ns/nmwg/tools/passivetracefile/v2_0/Parameters.java
2007-03-27 10:35:55 UTC (rev 217)
@@ -36,17 +36,18 @@
* Construct a set of allowedParameterNames
*/
private static final String allowedParameterNames[] = {
- "flow_h_filter",
- "flow_s_type",
- "flow_s_thre",
- "flow_p_filter",
- "characteristics",
- "granularity",
- "start_time",
- "end_time"
+ "^flow_h_filter$",
+ "^flow_s_type$",
+ "^flow_s_thre$",
+ "^flow_p_filter$",
+ "^characteristics$",
+ "^granularity$",
+ "^start_time$",
+ "^end_time$",
+ "^auth\\.username$",
+ "^auth\\.password$",
+ "^anon.*$"
};
- private static final Set<String> allowedParameterNamesSet =
- new HashSet<String>(Arrays.asList(allowedParameterNames));
// ---------------------------------- constructors
@@ -78,13 +79,14 @@
if (! name.equals("")) {
- if (allowedParameterNamesSet.contains(name)) {
+ if (isParameterValid(name)) {
Parameter p = new Parameter();
p = (Parameter)parameterMap.get(name);
return p;
} else {
System.err.println("Error: " + getFileName() + "
'getParameterByName(String)' "
- + "Parameter's name value must be one of: " +
allowedParameterNamesSet);
+ + "Parameter's name value ("
+ + name + ") must be one of: " +
allowedParameterNamesAsString());
return null;
}
}
@@ -103,7 +105,7 @@
public void addParameter(Parameter newParameter) {
if (newParameter != null) {
- if
(allowedParameterNamesSet.contains(newParameter.getParameterName())) {
+ if (isParameterValid(newParameter.getParameterName())) {
if (getParameterByName(newParameter.getParameterName()) !=
null) {
System.err.println("Error: " + getFileName()
+ " 'setParameter(Parameter)' Duplicate parameter
name: "
@@ -112,8 +114,10 @@
}
parameterMap.put(newParameter.getParameterName(),
newParameter);
} else {
- System.err.println("Error: " + getFileName() + "
'addParameter(Parameter)' Parameter's name value must be one of:"
- + allowedParameterNamesSet);
+ System.err.println("Error: " + getFileName()
+ + " 'addParameter(Parameter)' Parameter's name value
("
+ + newParameter.getParameterName() + ") must be one
of:"
+ + allowedParameterNamesAsString());
return;
}
} else {
@@ -138,6 +142,45 @@
addParameter(p);
}
-
+
+ /**
+ * Check, whether given string matches one of the regular expressions in
+ * allowedParameterNames
+ *
+ * @param parameter
+ * @return true if match is found, false otherwise
+ */
+ private boolean isParameterValid(String parameter) {
+
+ for (String regex : allowedParameterNames) {
+
+ if (parameter.matches(regex)) return true;
+
+ }
+
+ return false;
+
+ }
+
+
+ /**
+ * Return comma separated list of allowedParameterNames enclosed in
+ * square brackets
+ *
+ * @return comma separeted list of allowedParameterNames enclosed in
+ * square brackets
+ */
+ private String allowedParameterNamesAsString() {
+
+ StringBuilder sb = new StringBuilder("[");
+
+ for (String s : allowedParameterNames)
+ sb.append(s).append(", ");
+ if (sb.length() > 2) sb.delete(sb.length() - 2, sb.length());
+ sb.append("]");
+
+ return sb.toString();
+
+ }
}
- nmwg: r217 - trunk/nmwg/java/org/ggf/ns/nmwg/tools/passivetracefile/v2_0, svnlog, 03/27/2007
Archive powered by MHonArc 2.6.16.