--- /dev/null
+package com.indexdata.mkjsf.pazpar2.commands;\r
+\r
+/**\r
+ * Represents a query parameter as it applies to the Pazpar2 search command\r
+ * \r
+ * <p>A query parameter can consist of a term value and/or one or more expressions \r
+ * separated by boolean operators.</p>\r
+ * \r
+ * <p>A complex query can be represented in the object as either one long string \r
+ * set by <code>setQuery(string)</code> or as a series of expressions set by \r
+ * <code>setQueryExpression(...)</code> (or a combination of the two). The difference\r
+ * between the two approaches would be the option of easily removing individual \r
+ * expressions again or otherwise treat them has separate entities in the UI.</p>\r
+ * \r
+ * @author Niels Erik\r
+ *\r
+ */\r
+public class QueryParameter extends CommandParameter {\r
+\r
+ private static final long serialVersionUID = -3649052232241100927L;\r
+ private String booleanOperator = "AND";\r
+\r
+ public QueryParameter(String name) {\r
+ super(name);\r
+ }\r
+\r
+ public QueryParameter(String name, String operator, String value,\r
+ Expression... expressions) {\r
+ super(name, operator, value, expressions);\r
+ }\r
+\r
+ public QueryParameter(String name, String operator, Expression... expressions) {\r
+ super(name, operator, expressions);\r
+ }\r
+\r
+ public QueryParameter(String name, String operator, String value) {\r
+ super(name, operator, value);\r
+ }\r
+\r
+ public QueryParameter(String name, String operator, int value) {\r
+ super(name, operator, value);\r
+ }\r
+ \r
+ public void setBooleanOperator (String operator) {\r
+ this.booleanOperator = operator;\r
+ }\r
+ \r
+ public String getValueWithExpressions () {\r
+ StringBuilder completeValue = new StringBuilder((value==null ? "" : value));\r
+ boolean first = true;\r
+ for (Expression expr : expressions) {\r
+ if (value == null && first) {\r
+ first = false;\r
+ completeValue.append(expr.toString());\r
+ } else {\r
+ completeValue.append(" "+booleanOperator+" " + expr.toString());\r
+ }\r
+ }\r
+ return completeValue.toString(); \r
+ } \r
+ \r
+ public QueryParameter copy() { \r
+ QueryParameter newParam = new QueryParameter(name);\r
+ newParam.value = this.value;\r
+ newParam.operator = this.operator;\r
+ newParam.booleanOperator = this.booleanOperator;\r
+ for (Expression expr : expressions) {\r
+ newParam.addExpression(expr.copy()); \r
+ }\r
+ return newParam;\r
+ }\r
+\r
+\r
+}\r