Listing of Source rappapi/server/CallClassTest.javapackage server;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import se.entra.phantom.rapp.RAPPElement;
import se.entra.phantom.rapp.RAPPCallClass;
import se.entra.phantom.server.rapp.CallClassInterface;
import se.entra.phantom.server.rapp.DefaultRemoteApplication;
import se.entra.phantom.server.rapp.RequestThread;
/**
* This class is called by the RAPP API in the NetPhantom Server
* from the TestAPI application.
*
* <p>Each time this CallClass action is about to start, a new
* instance of the class (that implements this interface) is
* created and called with the method <code>runAction</code>.
*
* @see se.entra.phantom.rapp.RAPPCallClass
* @see se.entra.phantom.server.rapp.DefaultRemoteApplication
* @see se.entra.phantom.server.rapp.RequestThread
*/
public class CallClassTest implements CallClassInterface
{
/**
* Runs the CallClass action.
*
* <p>The return value is a success flag. A failure indicates
* that the script must be halted after this action.
*
* <p>The action has to set it's own error code in the class
* and eventually also log the error/warning in the server log.
*
* @return true for success, false for failure.
*
* @see se.entra.phantom.server.rapp.RequestThread#setReply
* @see se.entra.phantom.server.rapp.RequestThread#setError
*/
public boolean runAction(DefaultRemoteApplication app,RequestThread requestThread,RAPPCallClass action)
{
// Get the request data (it might be null) and print it out.
Element request=action.getRequest();
if ( request==null )
System.out.println("#CallClassTest: No request data");
else
System.out.println("#CallClassTest: Request data = "+RAPPElement.getElementString(request));
// This code should normally do something meaningful, but
// as this is just a sample, create a "static" reply now.
// This reply is stored in an Element without a namespace.
Document document=requestThread.getDocument();
Element replyElement=document.createElement("myReplyData");
RAPPElement reply=new RAPPElement(replyElement,null);
reply.setAttribute("myReplyStringAttribute" ,"StringValue");
reply.setAttribute("myReplyIntegerAttribute",456);
reply.setAttribute("myReplyBooleanAttribute",true);
// Create "child 1" element.
RAPPElement child1=reply.createAppendedChild("myReplyChild1");
child1.setAttribute("myReplyChild1AttrA","attr A, child #1");
child1.setAttribute("myReplyChild1AttrB","attr B, child #1");
// Create "child 2" element.
RAPPElement child2=reply.createAppendedChild("myReplyChild2");
child2.setAttribute("myReplyChild2AttrA","attr A, child #2");
child2.setAttribute("myReplyChild2AttrB","attr B, child #2");
// Add a nested child to "child 1" element.
RAPPElement nestChild1=child1.createAppendedChild("myNestedReplyChild1");
nestChild1.setAttribute("myNestedReplyChild1AttrA","attr A, nested child #2");
nestChild1.setAttribute("myNestedReplyChild1AttrB","attr B, nested child #2");
Element nc1=nestChild1.getElement();
nc1.appendChild(document.createComment(" THIS IS THE NESTED CHILD 1 USER DATA TEXT DATA THAT FOLLOWS "));
nc1.appendChild(document.createTextNode("This is an XML text node\nthat can contain <any> data, but beware of whitespaces!"));
// Set the reply for the action.
action.setReplyData(replyElement);
// Return OK to continue processing.
return true;
}
}