Javadoc
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / commands / Pazpar2Command.java
index 7c0ec74..82ac066 100644 (file)
@@ -16,6 +16,21 @@ import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;
 import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
 import com.indexdata.mkjsf.pazpar2.data.Responses;\r
 \r
+/**\r
+ * Represents a generic Pazpar2 or Service Proxy command with all its current parameters, and has\r
+ * methods for executing the command against the currently selected Pazpar2 service</p>\r
+ * <p>Being an abstract class it only has generic methods for getting and setting parameters. \r
+ * Implementing classes are supposed to create named getters and setters for convenient access\r
+ * to parameters from the UI.</p> \r
+ * <p>Parameters can be set with or without notifying the state manager.<p>\r
+ * \r
+ * <p><i>Note: Internally the application has to be able to set parameters without state changes \r
+ * - for instance to avoid eternal feedback when copying parameter from one state to the next. A \r
+ * setting from the UI should spawn a new search state however.</i></p>   \r
+ * \r
+ * @author Niels Erik\r
+ *\r
+ */\r
 public abstract class Pazpar2Command implements Serializable  {\r
   \r
   private static Logger logger = Logger.getLogger(Pazpar2Command.class);\r
@@ -34,17 +49,42 @@ public abstract class Pazpar2Command implements Serializable  {
     this.name = name;    \r
   }\r
       \r
+  /**\r
+   * Commands must implement this method to provide a completely detached, deep clone of \r
+   * themselves.\r
+   * \r
+   * The clone is needed by the state manager to transfer commands with current setting \r
+   * from one state to the next.\r
+   * \r
+   * Whenever a non-standard attribute is added to a command class, the copy method must \r
+   * be updated to ensure that the new attribute is brought over as well. \r
+   *   \r
+   * @return a Pazpar2 command of the given type\r
+   */\r
   public abstract Pazpar2Command copy ();\r
           \r
   public String getCommandName() {\r
     return name;\r
   }\r
   \r
+  /**\r
+   * Executes the command with the currently selected parameters against \r
+   * the currently selected Pazpar2 service\r
+   * \r
+   * @return Response data object based on the Pazpar2 service response. \r
+   */\r
   public ResponseDataObject run() {    \r
     return run(Pz2Service.get().getSearchClient(),\r
                Pz2Service.get().getPzresp());\r
   }\r
   \r
+  /**\r
+   * Executes the commands with the currently selected parameters, while adding\r
+   * the parameters provided in the vararg\r
+   * @param parameters A list of parameters on the form [key=value]\r
+   * \r
+   * @return Response data object based on the Pazpar2 service response\r
+   */\r
   public ResponseDataObject runWith(String... parameters) {\r
     for (String parameter : parameters) {\r
       StringTokenizer tokenizer = new StringTokenizer(parameter,"=");\r
@@ -55,11 +95,35 @@ public abstract class Pazpar2Command implements Serializable  {
     }\r
     return run();\r
   }\r
-  \r
+\r
   /**\r
-   * For running the command in a thread. Client and Responses must be \r
-   * provided because at this point the CDI bean cannot be retrieved \r
-   * from within a thread.\r
+   * Executes the commands with the currently selected parameters, while adding\r
+   * the parameters provided in the 'delimiter'-separated String.\r
+   * \r
+   * Note: This is for Glassfish/JBoss support. With Tomcat7 the method \r
+   *       runWith(String... parameters) can be used directly from EL \r
+   *       with a vararg \r
+   *  \r
+   * @param parameters A list of parameters separated by 'delimiter'\r
+   * @param delimiter The separator character of the String 'parameters' \r
+   * \r
+   * @return Response data object based on the Pazpar2 service response\r
+   */\r
+  public ResponseDataObject runWith2(String parameters, String delimiter) {    \r
+    StringTokenizer params = new StringTokenizer(parameters,delimiter);\r
+    String[] vararg = new String[params.countTokens()];\r
+    int i=0;\r
+    while (params.hasMoreTokens()) {\r
+      vararg[i++] = params.nextToken();\r
+    }\r
+    return runWith(vararg);\r
+  }\r
+    \r
+  /**\r
+   * Executes the command in a thread.  \r
+   * \r
+   * Note: Client and Responses must be provided because at this point \r
+   * CDI beans cannot be retrieved from within a thread.\r
    * \r
    * @param client\r
    * @param pzresp\r
@@ -75,7 +139,13 @@ public abstract class Pazpar2Command implements Serializable  {
     return responseObject;    \r
   }\r
   \r
-    \r
+   \r
+  /**\r
+   * Sets a parameter on this command and notifies the state manager\r
+   * about the change\r
+   * \r
+   * @param parameter \r
+   */\r
   public void setParameter (CommandParameter parameter) {\r
     Pazpar2Command copy = this.copy();\r
     logger.trace(name + " command: setting parameter [" + parameter.getName() + "=" + parameter.getValueWithExpressions() + "]");\r
@@ -83,6 +153,12 @@ public abstract class Pazpar2Command implements Serializable  {
     checkInState(copy);\r
   }\r
   \r
+  /**\r
+   * Sets multiple parameters on the command and notifies the state\r
+   * manager -- once -- about the change\r
+   * \r
+   * @param params \r
+   */\r
   public void setParameters (CommandParameter... params) {\r
     Pazpar2Command copy = this.copy();\r
     for (CommandParameter param : params) {\r
@@ -92,39 +168,86 @@ public abstract class Pazpar2Command implements Serializable  {
     checkInState(copy);\r
   }\r
   \r
+  /**\r
+   * Sets multiple parameters on this command without notifying the state manager. \r
+   * Typically used when one parameter setting should automatically trigger\r
+   * other parameters to be reset to defaults etc. Intended to avoid \r
+   * useless proliferation of states  \r
+   * \r
+   * @param params\r
+   */\r
   public void setParametersInState (CommandParameter... params) {    \r
     for (CommandParameter param : params) {\r
       logger.trace(name + " command: setting parameter [" + param.getName() + "=" + param.getValueWithExpressions() + "] silently");\r
       parameters.put(param.getName(),param);\r
     }    \r
   }\r
-    \r
+  \r
+  /**\r
+   * Sets a parameter on this command without notifying the state manager. \r
+   * Typically used when one parameter setting should automatically trigger\r
+   * other parameters to be reset to defaults etc. Intended to avoid \r
+   * useless proliferation of states  \r
+   * \r
+   * @param parameter\r
+   */    \r
   public void setParameterInState (CommandParameter parameter) {\r
     logger.trace(name + " command: setting parameter [" + parameter.getName() + "=" + parameter.getValueWithExpressions() + "] silently");\r
     parameters.put(parameter.getName(),parameter);    \r
   }\r
   \r
   \r
+  /**\r
+   * Retrieves a command parameter by parameter name\r
+   * \r
+   * @param name of the parameter\r
+   * @return CommandParameter\r
+   */\r
   public CommandParameter getParameter (String name) {\r
     return parameters.get(name);\r
   }\r
   \r
+  /**\r
+   * Removes a parameter completely and notifies the state manager\r
+   * about the change\r
+   * \r
+   * @param name of the parameter to remove\r
+   */\r
   public void removeParameter (String name) {\r
     Pazpar2Command copy = this.copy();\r
     copy.parameters.remove(name);\r
     checkInState(copy);\r
   }\r
   \r
+  /**\r
+   * Removes multiple parameters completely and notifies the state manager\r
+   * -- once -- about the change\r
+   * \r
+   * @param name of the parameter to remove\r
+   */  \r
   public void removeParameters() {\r
     Pazpar2Command copy = this.copy();\r
     copy.parameters = new HashMap<String,CommandParameter>();\r
     checkInState(copy);\r
   }\r
   \r
+  \r
+  /**\r
+   * Removes all parameters without notifying the state manager. For instance\r
+   * used in case of change of Pazpar2 service or renewed login to a service.\r
+   *  \r
+   */\r
   public void removeParametersInState() {\r
     parameters = new HashMap<String,CommandParameter>();    \r
   }\r
   \r
+  /**\r
+   * Adds an expression to an ordered list of expressions on a given parameter\r
+   * and notifies the state manager of the change\r
+   * \r
+   * @param parameterName name of the parameter to add the expression to\r
+   * @param expression\r
+   */\r
   public void addExpression(String parameterName, Expression expression) {\r
     Pazpar2Command copy = this.copy();\r
     copy.getParameter(parameterName).addExpression(expression);\r
@@ -201,9 +324,11 @@ public abstract class Pazpar2Command implements Serializable  {
     return getParameter(parameterName)==null ? "" : getParameter(parameterName).getValueWithExpressions();    \r
   }\r
 \r
+  /*\r
   public String getUrlEncodedParameterValue(String parameterName) {\r
     return getParameter(parameterName).getEncodedQueryString();\r
   }\r
+  */\r
   \r
   public void setSession (String sessionId) {\r
     setParameter(new CommandParameter("session","=",sessionId));\r
@@ -213,15 +338,32 @@ public abstract class Pazpar2Command implements Serializable  {
     return getParameterValue("session");\r
   } \r
   \r
-  private void checkInState(Pazpar2Command command) {\r
+  /**\r
+   * Notifies the state manager that this command changed a parameter\r
+   * \r
+   * @param command\r
+   */\r
+  protected void checkInState(Pazpar2Command command) {\r
     Pz2Service.get().getStateMgr().checkIn(command);\r
   }\r
-  \r
-  public String navigateTo (String target) {\r
-    return target;\r
-  }\r
-  \r
+    \r
+  /**\r
+   * Implementing classes must provide their Service Proxy \r
+   * extension command if any extension parameters exists, \r
+   * or -- just to be polite -- 'this' if there is no\r
+   * Service Proxy extension to the given command.\r
+   * @return\r
+   */\r
   public abstract ServiceProxyCommand getSp();\r
-   \r
+     \r
+  /**\r
+   * Here implementing commands publish whether they only \r
+   * apply to the Service Proxy or can be executed \r
+   * against straight Pazpar2 as well. This is convenient for a \r
+   * UI that switches between service types either \r
+   * deployment time or run time.\r
+   *   \r
+   * @return false if the command applies to straight Pazpar2\r
+   */\r
   public abstract boolean spOnly();  \r
 }\r