Fixes npe and return type of auth.run()
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / commands / sp / AuthCommand.java
index 3167720..8869d83 100644 (file)
@@ -7,10 +7,13 @@ import com.indexdata.mkjsf.pazpar2.Pz2Service;
 import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;\r
 import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
 import com.indexdata.mkjsf.pazpar2.data.ResponseParser;\r
+import com.indexdata.mkjsf.pazpar2.data.sp.AuthResponse;\r
 import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject;\r
 \r
 /**\r
- * Authenticates a user against a Pazpar2 Service Proxy\r
+ * Represents a Service Proxy <code>auth</code> command, can be accessed by <code>pzreq.sp.auth</code> \r
+ * \r
+ * <p>Authenticates a user against a Pazpar2 Service Proxy</p>\r
  * \r
  * @author Niels Erik\r
  *\r
@@ -30,7 +33,7 @@ public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand {
     ClientCommandResponse response = (ClientCommandResponse) Pz2Service.get().getSearchClient().executeCommand(this);      \r
     String renamedResponse = renameResponseElement(response.getResponseString(), "auth");    \r
     response.setResponseToParse(renamedResponse);\r
-    SpResponseDataObject responseObject = (SpResponseDataObject) ResponseParser.getParser().getDataObject(response);    \r
+    AuthResponse responseObject = (AuthResponse) ResponseParser.getParser().getDataObject(response);    \r
     if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
       Pz2Service.get().getPzresp().put(getCommandName(), responseObject);\r
     }\r
@@ -40,33 +43,59 @@ public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand {
     return responseObject;\r
   }\r
   \r
+  /**\r
+   * Normalizes the response XML for the benefit of the SAX parser that creates data objects. \r
+   * <p>The parser expects responses to have document element names corresponding to the names of\r
+   * the commands that created the responses.</p>\r
+   * \r
+   * @param responseString\r
+   * @param newName\r
+   * @return\r
+   */\r
   private String renameResponseElement(String responseString, String newName) {\r
     responseString = responseString.replace("<response>", "<" + newName + ">");\r
     responseString = responseString.replace("</response>", "</" + newName + ">");\r
     return responseString;\r
   }\r
 \r
-  \r
+  /**\r
+   * Sets Service Proxy command parameter <code>action</code>. See Service Proxy documentation for details. \r
+   */\r
   public void setAction (String action) {\r
     setParameterInState(new CommandParameter("action","=",action));\r
   }  \r
   \r
+  /**\r
+   * Gets parameter value for <code>action</cod>\r
+   */\r
   public String getAction () {\r
     return getParameterValue("action");\r
   }\r
   \r
+  /**\r
+   * Sets Service Proxy command parameter <code>username</code>. See Service Proxy documentation for details. \r
+   */\r
   public void setUsername(String username) {\r
     setParameterInState(new CommandParameter("username","=",username));\r
   }\r
   \r
+  /**\r
+   * Gets parameter value for <code>username</cod>\r
+   */\r
   public String getUsername () {\r
     return getParameterValue("username");\r
   }\r
-  \r
+    \r
+  /**\r
+   * Sets Service Proxy command parameter <code>password</code>. See Service Proxy documentation for details. \r
+   */\r
   public void setPassword (String password) {\r
     setParameterInState(new CommandParameter("password","=",password));\r
   }\r
   \r
+  /**\r
+   * Gets parameter value for <code>password</cod>\r
+   */\r
   public String getPassword () {\r
     return getParameterValue("password");\r
   }\r