How do you write and advertise operators so they can be used in Ninja Paths?

There are essentially two things that an operator writer is responsible for.: While all the above should help in understanding the process of writing and advertising operators, the best way to understand fic these ideas in place is by studying the following example.
 

ENGLISH TO PIG-LATIN CONVERTER:

The following example converts from English text to PigLatin text:
 
 

CODE

// you start of by a bunch of imports. you have to import the path and the rmi packages.

package ninja.activeproxy.path.demo;
import java.io.*;
import java.net.*;
import java.rmi.*;
import ninja.activeproxy.path.*;

// The java class for our service has to extend Operator and implement the OperatorIF and SDSOperatorIF
public class EnglishToPigLatin extends Operator implements OperatorIF, SDSOperatorIF{

    public EnglishToPigLatin() throws RemoteException{
        super();
    }
 

// This is the meat of the code
    public void run() {

      // reader and writer are the input and output streams
     BufferedReader reader;
      BufferedWriter writer;
      String outs;

     // pathID is an identifier for the path that this operator belongs to
     Object pathId = getPathID(Thread.currentThread());

      if (pathId == null) System.out.println("pathId not found, EncodeOperator.");
 

      // instantiate the reader and writer streams
      reader = new BufferedReader(new InputStreamReader(getReader(pathId)));
      writer = new BufferedWriter(new OutputStreamWriter(getWriter(pathId)));

// What follows is the actual English-to-PigLatin Converter
       String s;
       boolean done = false;
       char first = ' ';
       boolean wordStart = true;
       while (!done) {
       try {
           // Read a line of input
           s = reader.readLine();
           System.out.println("Read: " + s);
           if (s == null) {
                   System.out.println("EC Socket closed.");
                   done = true;
           }
        outs = new String();
         // Do whatever you are supposed to do with it
        for (int i = 0; i < s.length(); i++ )
            {
              char c = s.charAt(i);
 
              if (Character.isLetterOrDigit(c)) {
                 if (wordStart) first = c;
                 else outs += c;
                 wordStart = false;
               } else {
                 if (!wordStart) {
                   outs += first;
                   outs += "ay";
                   wordStart = true;
                 }
                 outs += c;
               }
             }
           if (!wordStart) {
             outs += first;
             outs += "ay";
           }

          // write out your output, and remember to flush the stream
          writer.write(outs);
          writer.newLine();
          writer.flush();
          } catch (IOException e) {
             System.out.println("IOException in EncodeOperator." + e);
          }
        }
    }
 

    // This method is used to return an XML description of the operator to the SDS
    public String GetServiceDescriptor() {
      String descr = "";
      try {
        // This returns the contents of the xml file with the same name as the operator
       descr = getOperatorDescription();
 
      } catch (Exception e) {
      }
      System.out.println("Returning xml description: " + descr);
      return descr;
    }
 
 
 

XML Description


The corresponding XML description for the English to PigLatin Converter operator follows:

<?xml version="1.0"?>
<XMLDESCRIPTION>

<! this specifies that it is an operator and not a connector>
<OPERATOR>

<! specifies the unique id of this operator>
<UNIQUE_ID>ninja.activeproxy.path.demo.EnglishToPigLatin</UNIQUE_ID>

<! Input>
<OP_INPUT>

<! Network Information>
<NETWORKINFO>
<! you are not looking for a specific protocol>
<TYPE>GENERIC</TYPE>
<SUBTYPE>STREAM</SUBTYPE>
<! various parameters>
<CONNECTORNAME>NONE</CONNECTORNAME>
<ORDERED>YES</ORDERED>
<RELIABLE>YES</RELIABLE>
<LOWERBANDWIDTH>ANY</LOWERBANDWIDTH>
<HIGHERBANDWIDTH>ANY</HIGHERBANDWIDTH>
</NETWORKINFO>

<MEDIAINFO>
<TEXT>
<TEXTSTRUCTURALINFO></TEXTSTRUCURALINFO>
<TEXTSEMANTICINFO>
<TEXTUAL>
<LANG>ENGLISH</LANG>
</TEXTUAL>
</TEXTSEMANTICINFO>
</TEXT>
</MEDIAINFO>
</OP_INPUT>
 

<! similarly for the output>
<OP_OUTPUT>
<NETWORKINFO>
<TYPE>GENERIC</TYPE>
<SUBTYPE>STREAM</SUBTYPE>
<CONNECTORNAME>NONE</CONNECTORNAME>
<ORDERED>YES</ORDERED>
<RELIABLE>YES</RELIABLE>
<LOWERBANDWIDTH>ANY</LOWERBANDWIDTH>
<HIGHERBANDWIDTH>ANY</HIGHERBANDWIDTH>
</NETWORKINFO>
<MEDIAINFO>
<TEXT>
<TEXTSTRUCTURALINFO></TEXTSTRUCURALINFO>
<TEXTSEMANTICINFO>
<TEXTUAL>
<LANG>PIG LATIN</LANG>
</TEXTUAL>
</TEXTSEMANTICINFO>
</TEXT>
</MEDIAINFO>
</OP_OUTPUT>
</OPERATOR>
</XMLDESCRIPTION>
 
 
 

Questions/Comments?

Back to paths page