EXECUTION OF WORK FLOW REQUEST

 

                       

                                                 JAVA – XML PROJECT     

 

 

 

                                                  GROUP

 

                                      Chauhan, Anand Kumar

                                                   Ranganathan, Narayanan

                                                       Prabhu, Balkrishna

 

 

 

                       

                                                                   TO

                                                Dr. Lawrence Osborne

                        Chair, Department of Computer Science               

                              LAMAR UNIVERSITY, Beaumont TX - 77705          

 

 

 

 

 

Acknowledgement

 

 

We express our heartfelt gratitude to Dr.Lawrence Osborne, Chair, and Department of Computer Science at Lamar University Beaumont Texas – 77705 without whose encouragement guidance and support this project would not have been a success.  We also sincerely thank the members of the other group for their consistent and invaluable help.

 

                                                                                    Group:

                                                                                                Chauhan, Anand kumar

                                                                                                Ranganathan, Narayanan

Prabhu, Balkrishna


 

ABSTRACT

 

            EXECUTION OF WORKFLOW REQUEST – Java, Java API’s and XML

 

The objective of this project is to carry out intensive mathematical computations like finding the Newton Rap son’s method implemented Root of any given polynomial equation f (x). We also find the Local Maxima and the Local Minima if it exists for the same equation. Three different servers perform these three tasks. Messages between different servers are passed in the XML format. Each server uses different Java API’s to parse the XML document and do processing as desired.

 

            The Newton Raphson technique is a recursive method to get intercept of the given equation curve with the X-axis. The Maxima of the curve is the point where and increasing function just starts to decrease. i.e. Point Of Inflexion. Vice-versa Minima is the point at which a decreasing function just starts to increase. Further increasing function is a curve with a negative slope at any arbitrary point on the curve and a decreasing function is a curve with a positive slope.


INDEX

S. No.

                                Description

Page No.

1.

INTRODUCTION

5

2

OVERVIEW OF JAXP

7

3

WHY DOM AND NOT SAX

8

4

WHY XML - RPC

9

5

REGISTRY

10

6

WHY AWT AND SWING

11

7

ARCHITECTURE

13

8

INSTRUCTIONS TO RUN THE SOFTWARE

16

9

SECURITY MEASURES

17

10

LIST OF API’s

 

18

11

SOURCE CODE

19

12

CONCLUSION

60

 


INTRODUCTION

           

            This project is a communication model and a software tool, which performs user, defined tasks on different servers. A server is dedicated to performing a specific task. We have a client, which passes an equation to a host of servers. Each server successively processes the given equation, which in its transition from one server to the other gets either appended or changed so as to let the next server in the work flow act upon it.

            This procedure goes on till it gets to the report generator, which in turn sends the results back to the client.

            The client specifies the workflow, i.e. the order in which the tasks are to be executed. The controller understands this and only the servers that perform those tasks are put in the execution queue. The controlling server also maintains a registry which is basically a directory service giving references to the servers. All servers that are up and running are registered in to this registry.

            The model was successfully able to perform all various aspects mentioned above in an efficient and transparent manner.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DISTRIBUTED API’s

 

 

 

 

 

 


 

OVERVIEW OF JAXP 

 

Java API for XML Parsing (JAXP) is a Java-standard, parser-independent API for XML. It makes it easier to process XML data with application written in Java programming language. JAXP leverages parser standards SAX (Simple API for XML Parsing) and DOM (DOCUMENT OBJECT MODULE).

            Designed to be flexible, JAXP allows to use and XML compliant parser from within the application using the pluggability layer, which allows plugging an implementation, either a SAX or DOM.

 

 

USES OF JAXP     

 

·        Flexibility in accessing data either serially or randomly in memory.

·        Insert or Remove object from an object tree that represents XML data.

·        Apply XSLT transforms


 

 WHY DOM AND NOT SAX ?     

 

The DOM API provides a standardized, versatile view of a document’s contents. By supporting the DOM API, a program not only allows its data to be manipulated by other routines, but also does so in a way that allows those manipulations to be reused with other DOMs, or to take advantage of solutions already written for those DOMs. This interoperability also allows programmers who invest in learning to use the DOM calls to apply those skills to other DOMs.

            The Document Object Model API, defined by the W3C DOM working group is a set of interfaces for building an object representation in the form of a tree, of a parsed XML document. Once a DOM is built its easy to manipulate with the DOM methods. Thus with DOM parser you can build an object representation of the document and manipulate it in memory, adding a new element or deleting an existing one.

            One of the main advantage of DOM is that it is easy able to delete, add, or change an element (as long as the document is still valid), change its content or add, delete or change an attribute. Although DOM tree can occupy large amount of memory, the DOM API includes common tree-manipulation functions.

 

                       


WHY  XML – RPC ?

 

            XML-RPC is actually a specific flavor of Remote Procedure Calls. It is a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet. It makes it possible to write application in the java programming language that uses XML to make remote procedure calls. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned. It provides a way to handle simple creation of hooks in to your application and its services

            XML-RPC implementations that span all operating systems, programming languages, dynamic and static environments, open source and commercial, for Perl, Python, Java, Frontier, C/C++, Lisp, PHP, Microsoft .NET, Rebol, Real Basic, Tcl, Delphi, WebObjects and Zope. 

            XML-RPC, in particular, is very much in the Unix spirit. It's deliberately minimalist but nevertheless quite powerful, offering a way for the vast majority of RPC applications that can get by passing around Boolean, integer, float, string data types to do their thing in a way that is lightweight and easy to understand and monitor. This simple type ontology acts as a valuable check on interface complexity.

            XML-RPC, in particular, is very much in the Unix spirit. It's deliberately minimalist but nevertheless quite powerful, offering a way for the vast majority of RPC applications that can get by passing around boolean, integer, float, string datatypes to do their thing in a way that is lightweight and easy to understand and monitor. This simple type ontology acts as a valuable check on interface complexity. It is the better choice for application that wish to avoid the complexities of SOAP messaging.

REGISTRY   

 

            The registry is basically defined as yellow pages because they contain listings of all the services that different servers offer. Registries are becoming an interestingly important component because they allow different services to collaborate with each other in a loosely coupled way. Thus upon a request from a client the controller which actually maintains the registry checks which services have been registered to do a particulate task. The controller also receives the order in which the task has to be performed and sees that the data is sent to the respective servers in the order specified.

            The Registry thus maintains the hostname, port number and the service offered by a particular server in order to send the data. Thus when a particular server did not register it to the controller then it cannot send the data to that server for processing and thus it tells the client that particular service cannot be provided.


 

 WHY Java AWT AND Java SWING ?

 

 

The abstract window kit (AWT) contains numerous classes and methods that allow to create and manage stand-alone windows that run in a GUI environment.

Swing is a set of classes that provides more powerful and flexible components than that are possible by AWT .  For instance the GUI for the client has a tabbed pane, which is one of the component classes in the Java Swing.  
 

 

 

 

 

 

 

 

                             ARCHITECTURE
 ARCHITECTURE

The project mainly circles around Java API’s and XML documents and how they process the users request. The Java APIs play a vital role parsing the document and appending the necessary results to the documents.

 

SERVER

There are about 6 Servers which works on the given client’s document namely 

                                   

Each server is assigned a particular tasks and it parses the client’s request which is basically a XML document. All the servers act on XML documents and pass around XML documents to the  respective server after they finish their processing. At each server the server appends a tag, i.e Result at the end of the XML document.

 

           

CONTROLLER

            The controller is basically the first place where the client sends his/her equation along with work flow. The controller then maintains a list of all the services it has to provide for a particular client. Thus on a request the controller actually decides which server to call upon to do the required job. This is done by the controller by maintaining a Registry where it stores all the details about a particular server. Thus all servers are suppose to register in order to render the service.

 

CLIENT

            The client basically deals with the GUI and it specifies the equation for which either Roots or Maxima or Minima are to be found. It also specifies the order of work flow in which the work has to be don and waits for the server to process its data. After processing the data the  Report Generator sends the result back to the client.

 

REPORT GENERATOR

            The Report Generator is the last server that the controller specifies, i.e  when the all the tasks in the work flow are completed the controller asks the server to send the XML document to Report Generator where it reads the results and sends it to the client.





INSTRUCTIONS TO RUN THE SOFTWARE

 

 

1.      Run the controller hence enabling the registry.

2.      Run all the server programs successively

3.      Run the client

4.      Enter the equation

5.      Enter the order of the different tasks to be done i.e. Newton Raphson Root,  Maxima  and Minima

6.      Hit “GetRoots”


Security Measures :

      All the files that are sent across each server from the client are XML documents. Thus when passing these documents across a private key can be maintained by the document and a public key which is given to all the servers. Thus at each server when ever a document arrives a security check will be done comparing the public key and the private key. Thus a simple a security can be established.

 

 

 

 


LIST OF API’s

 

 

 


 

 

 

 

 

SOURCE CODE

import java.io.IOException;

import java.net.MalformedURLException;

import java.util.Vector;

 

import helma.xmlrpc.XmlRpc;

import helma.xmlrpc.XmlRpcClient;

import helma.xmlrpc.XmlRpcException;

import helma.xmlrpc.WebServer;

import java.io.IOException;

 

import java.io.*;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

//Client.java

 

class Network

{

                private String ControllerPortNumber="9007/";

                private String ControllerHostName="http://galaxy.lamar.edu:";

                private String ControllerHandler="Controller.";

 

                private String MyHostName="http://gandhi.lamar.edu:";

                private String MyPortNumber="9008/";

                private int ClientPortNumber=9008;

                private String MyHandler="ClientHandler";

                private String MyRequest="Request";

                private String XMLString;

 

                private Vector ControllerParams;

 

                public void MakeServer()

                {

                                try

                                {

                                                //start server on specified port

                                                System.out.println("Starting XML-RPC Client Side Server...");

                                                WebServer server=new WebServer(ClientPortNumber);

 

                                                //register the handler class

                                                server.addHandler(MyHandler,new ClientHandlerClass());

                                                System.out.println("Registered ClientHandler class to"+MyHandler);

 

                                                System.out.println("Now accepting requests...");

 

                                }

                                catch (IOException e)

                                {

                                                System.out.println("Make Server : IO Exception : "+e.getMessage());

                                }

                }

               

                public void getRoots(String s,String Task1,String Task2,String Task3)

                {

                                String t1=Task1;

                                String t2=Task2;

                                String t3=Task3;

                                XMLString="<?xml version=\"1.0\"?>";

//                              XMLString+="<!DOCTYPE EQUATION SYSTEM \"http://galaxy.lamar.edu/~anandc/ip/xml/dtd/data/data.1.dtd\">";

                                XMLString+="<EQUATION>";

                                XMLString+=s;

                                XMLString+="</EQUATION>";

//                              Create Request

                                ControllerParams=new Vector();

                                ControllerParams.addElement(MyHostName);

                                ControllerParams.addElement(MyPortNumber);

                                ControllerParams.addElement(MyHandler);

                                ControllerParams.addElement(XMLString);

                                ControllerParams.addElement(Task1);

                                ControllerParams.addElement(Task2);

                                ControllerParams.addElement(Task3);

 

                                try

                                {

//                                              specify the server

                                                XmlRpcClient ControllerClient=new XmlRpcClient(ControllerHostName+ControllerPortNumber);

 

//                                              Make a request and print the result

                                                ControllerClient.execute(ControllerHandler+MyRequest,ControllerParams);

                                }

                                catch (MalformedURLException e)

                                {

                                                System.out.println("getRoots : Incorrect URL for XML-RPC format : "+e.getMessage());

                                }

                                catch (XmlRpcException e)

                                {

                                                System.out.println("getRoots : XML-RPC Exception : "+e.getMessage());

                                }

                                catch (IOException e)

                                {

                                                System.out.println("getRoots : IO Exception : "+e.getMessage());

                                }

                }

}

 

//-----------------------------------------------------------------------------------------------------------------      

 

public class Client extends JFrame

{

                public static void main(String args[])

                {

                                Network NetworkObject=new Network();

                                NetworkObject.MakeServer();

 

                                Toolkit tk=Toolkit.getDefaultToolkit();

                                Dimension d=tk.getScreenSize();

                                int screenHeight=d.height;

                                int screenWidth=d.width;

                                               

                                Client nc;

                                nc=new Client();

                                nc.setBounds(screenHeight/5,screenWidth/5,900,300);

                                nc.setVisible(true);

                }

 

                public Client()

                {

                                addWindowListener

                                (              

                                                new WindowAdapter()

                                                {

                                                                public void windowClosing(WindowEvent e)

                                                                {

                                                                                System.exit(0);

                                                                }

                                                }

                                );

                                setTitle("X M L   W O R K F L O W   N E T W O R K   C L I E N T");

                                JTabbedPane jtp=new JTabbedPane();

                                jtp.addTab("Equation Config",new NewtonMethod());

                                jtp.addTab("Server Config",new ServerConfig());

                                jtp.addTab("Server Info",new ServerInfo());

                                jtp.addTab("Task Info",new TaskInfo());

                                jtp.addTab("Exit System",new ExitSystem());

                                getContentPane().add(jtp);

                }

}

 

class NewtonMethod extends JPanel implements ActionListener

{

                JPanel Line1=new JPanel();

                JPanel Line2=new JPanel();

                JPanel Line3=new JPanel();

 

                Box b=Box.createVerticalBox();

 

                int i;

                String TestString="";

                String Polynomial=" ";

                String SentPolynomial=" ";

                boolean Flag=false;

                boolean Error=false;

                String ErrorString;

                String EquationValue="anand ";

                String DisplayString=" ";         

 

                Choice CoefficentSign=new Choice();

                Choice Coefficent1=new Choice();

                Choice Coefficent2=new Choice();

                Choice Coefficent3=new Choice();

                Choice Coefficent4=new Choice();

 

                Choice ExponentSign=new Choice();

                Choice Exponent1=new Choice();

                Choice Exponent2=new Choice();

                Choice Exponent3=new Choice();

                Choice Exponent4=new Choice();

 

                Choice ConstantSign=new Choice();

                Choice Constant1=new Choice();

                Choice Constant2=new Choice();

                Choice Constant3=new Choice();

                Choice Constant4=new Choice();

 

                JLabel Label1=new JLabel("E N T E R   f(x)   F O R   E Q U A T I O N   f(x) = 0");              

                JPanel ServerConfig=new JPanel();

 

                JButton AppendTerm=new JButton("Append Term");

                JButton AppendConstant=new JButton("Append Constant");

                JButton GetRoots=new JButton("Get Roots");

                JButton Reset=new JButton("Reset Equation");

                JLabel EquationLabel=new JLabel("Equation : ");

                JTextField jtf=new JTextField(70);

               

                String OutputFileName;

                String InputFileName;

 

                String ToData;

                String FromData;

 

                public void InputStringToFile()

                {

                                try

                                {

                                                FileOutputStream f=new FileOutputStream(InputFileName);

                                                PrintStream p=new PrintStream(f);

                                                p.println(FromData);

                                                p.close();

                                }

                                catch (Exception e)

                                {

                                                System.out.println(e);

                                }

                }

 

                public NewtonMethod()

                {

                                FromData="NO";

 

                                InputFileName="Task1.status";              

                                InputStringToFile();

 

                                InputFileName="Task2.status";              

                                InputStringToFile();

 

                                InputFileName="Task3.status";              

                                InputStringToFile();

               

                                Line1.add(Label1);

                               

                                JLabel CoefficentLabel=new JLabel("Coefficent");

                                Line2.add(CoefficentLabel);

                                CoefficentSign.add("+");

                                CoefficentSign.add("-");

                                Line2.add(CoefficentSign);

                                CoefficentSign.setVisible(true);

                                for(i=0;i<10;Coefficent1.add(""+i),i++);

                                Line2.add(Coefficent1);

                                for(i=0;i<10;Coefficent2.add(""+i),i++);

                                Line2.add(Coefficent2);

                                for(i=0;i<10;Coefficent3.add(""+i),i++);

                                Line2.add(Coefficent3);

                                for(i=0;i<10;Coefficent4.add(""+i),i++);

                                Line2.add(Coefficent4);

 

                                JLabel ExponentLabel=new JLabel("Exponent");

                                Line2.add(ExponentLabel);

                                ExponentSign.add("+");

                                ExponentSign.add("-");

                                Line2.add(ExponentSign);

                                for(i=0;i<10;Exponent1.add(""+i),i++);

                                Line2.add(Exponent1);

                                for(i=0;i<10;Exponent2.add(""+i),i++);

                                Line2.add(Exponent2);

                                for(i=0;i<10;Exponent3.add(""+i),i++);

                                Line2.add(Exponent3);

                                for(i=0;i<10;Exponent4.add(""+i),i++);

                                Line2.add(Exponent4);

 

                                Line3.add(jtf);

 

                                AppendTerm.addActionListener(this);

                                GetRoots.addActionListener(this);

                                Reset.addActionListener(this);

                                ServerConfig.add(AppendTerm);

                                ServerConfig.add(GetRoots);

                                ServerConfig.add(Reset);

 

                                b.add(Line1);

                                b.add(Line2);

                                b.add(Line3);

                                b.add(ServerConfig);

                                add(b,"Center");

                }

 

                public void FileToOutputString()

                {

                                ToData="";

                                try

                                {

                                                FileInputStream f=new FileInputStream(OutputFileName);

                                                int i=0;

                                                while(i!=-1)             

                                                {

                                                                i=f.read();

                                                                ToData+=(char)i;

                                                }

 

                                                f.close();

                                }

                                catch (Exception e)

                                {

                                                System.out.println(e);

                                }

                }

 

                public void actionPerformed(ActionEvent ae)

                {

                                String s1;

                                String s2;

                                String s3;

                                String Task1;

                                String Task2;

                                String Task3;

 

                                OutputFileName="Task1.status";

                                FileToOutputString();

                                s1=ToData;

                               

                                OutputFileName="Task2.status";

                                FileToOutputString();

                                s2=ToData;

 

                                OutputFileName="Task3.status";

                                FileToOutputString();

                                s3=ToData;

 

                                TestString=ae.getActionCommand();

                                if(TestString.equals("Append Term"))

                                {

                                                DisplayString=Polynomial;

                                                getTermString();

                                                DisplayString=Polynomial;

                                                Flag=true;

                                }

                                else if(TestString.equals("Get Roots"))

                                {

                                                if((s1.equals("NO"))&&(s2.equals("NO"))&&(s2.equals("NO")))

                                                {

                                                                ErrorString="No Task Selected, Please Select a Task First";

                                                                Flag=false;

                                                }

                                                try

                                                {

                                                                if(Flag)

                                                                {

                                                                                FromData="NO";

 

                                                                                InputFileName="Task1.status";

                                                                                InputStringToFile();

 

                                                                                InputFileName="Task2.status";

                                                                                InputStringToFile();

 

                                                                                InputFileName="Task3.status";

                                                                                InputStringToFile();

                                                                               

                                                                                Flag=false;

                                                                                DisplayString="R E Q U E S T   ";

                                                                                DisplayString+="S E N T   T O   ";

                                                                                DisplayString+="T H E   C O N T R O L L E R";

                                                                                Network NetworkObject=new Network();

 

                                                                                OutputFileName="Task1.order";

                                                                                FileToOutputString();

                                                                                Task1=ToData.substring(0,ToData.length()-1);

                                                                                System.out.println("Task 1 : "+Task1);

 

                                                                                OutputFileName="Task2.order";

                                                                                FileToOutputString();

                                                                                Task2=ToData.substring(0,ToData.length()-1);

                                                                                System.out.println("Task 2 : "+Task2);

 

                                                                                OutputFileName="Task3.order";

                                                                                FileToOutputString();

                                                                                Task3=ToData.substring(0,ToData.length()-1);

                                                                                System.out.println("Task 3 : "+Task3);

 

                                                                                DisplayString=SentPolynomial;               

                                                                                NetworkObject.getRoots(SentPolynomial,Task1,Task2,Task3);

                                                                }

                                                                else

                                                                {

                                                                                ErrorString="Equation Should Have Atleast 1 Term, Reset Equation and Redo it";

                                                                }

                                                }

                                                catch (Exception e)

                                                {

                                                                jtf.setText("This Exception Occurred : "+e);

                                                }

                                }

                                else if(TestString.equals("Reset Equation"))

                                {

                                                Flag=false;

                                                DisplayString=" ";

                                                ErrorString=" ";

                                                Polynomial=" ";

                                                SentPolynomial=" ";

                                                jtf.setText(" ");

                                }

                                if(!Flag)

                                {

                                                jtf.setText(ErrorString);

                                                ErrorString=" ";

                                                DisplayString=" ";

                                                Polynomial=" ";

                                                SentPolynomial=" ";

                                }

                                else

                                {

                                                jtf.setText(DisplayString);

                                }

                                repaint();

                }

 

                public void getTermString()

                {

                                Polynomial+=CoefficentSign.getSelectedItem();

                                Polynomial+=Coefficent1.getSelectedItem();

                                Polynomial+=Coefficent2.getSelectedItem();

                                Polynomial+=Coefficent3.getSelectedItem();

                                Polynomial+=Coefficent4.getSelectedItem();

 

                                Polynomial+=" X ^";              

                                Polynomial+=ExponentSign.getSelectedItem();

                                Polynomial+=Exponent1.getSelectedItem();

                                Polynomial+=Exponent2.getSelectedItem();

                                Polynomial+=Exponent3.getSelectedItem();

                                Polynomial+=Exponent4.getSelectedItem();

 

                                SentPolynomial+=CoefficentSign.getSelectedItem();

                                SentPolynomial+=":";

                                SentPolynomial+=Coefficent1.getSelectedItem();

                                SentPolynomial+=Coefficent2.getSelectedItem();

                                SentPolynomial+=Coefficent3.getSelectedItem();

                                SentPolynomial+=Coefficent4.getSelectedItem();

                                SentPolynomial+=":";

 

                                SentPolynomial+=ExponentSign.getSelectedItem();

                                SentPolynomial+=":";

                                SentPolynomial+=Exponent1.getSelectedItem();

                                SentPolynomial+=Exponent2.getSelectedItem();

                                SentPolynomial+=Exponent3.getSelectedItem();

                                SentPolynomial+=Exponent4.getSelectedItem();

                                SentPolynomial+=":";

                }

}

 

class ExitSystem extends JPanel implements ActionListener

{

                JButton Yes=new JButton("Yes");

                JLabel ExitLabel=new JLabel("Are You Sure, You Want to Exit ?");

 

                JPanel Head1=new JPanel();

                JPanel Head2=new JPanel();

               

                Box b=Box.createVerticalBox();

                public ExitSystem()

                {

                                Yes.addActionListener(this);

 

                                Head1.add(ExitLabel);

                                Head2.add(Yes);

 

                                b.add(Head1);

                                b.add(Head2);

 

                                add(b,"South");

                }

 

                public void actionPerformed(ActionEvent ae)

                {

                                String Str;

                                Str=ae.getActionCommand();

                                if(Str.equals("Yes"))

                                {

                                                System.exit(0);

                                }

                }

}

 

class ServerConfig extends JPanel implements ActionListener

{

                JLabel myHeading=new JLabel("Select The Tasks to Be Done (Specifed in Task Info)");

               

                JCheckBox Task1=new JCheckBox("");

                JCheckBox Task2=new JCheckBox("");

                JCheckBox Task3=new JCheckBox("");

 

                JButton Task1Button=new JButton("Roots");

                JButton Task2Button=new JButton("Maxima");

                JButton Task3Button=new JButton("Minima");

               

                JButton ResetChoice=new JButton("Reset");

 

                JPanel Heading=new JPanel();

                JPanel Choices=new JPanel();

                JPanel ResetButton=new JPanel();

 

                Box b=Box.createVerticalBox();

 

                JPanel Line1=new JPanel();

                JPanel Line2=new JPanel();

                JPanel Line3=new JPanel();

 

                String InputFileName;

                String FromData;

               

                int Counter=0;

 

                public ServerConfig()

                {

                                FromData="NONE";

                               

                                InputFileName="Task1.order";

                                InputStringToFile();

               

                                InputFileName="Task2.order";

                                InputStringToFile();

 

                                InputFileName="Task3.order";

                                InputStringToFile();

 

                                Heading.add(myHeading);

                                Line1.add(Task1);

                                Line1.add(Task1Button);

                                Line1.add(Task2);

                                Line1.add(Task2Button);

                                Line1.add(Task3);

                                Line1.add(Task3Button);

 

                                ResetButton.add(ResetChoice);

               

                                b.add(Heading);

                                b.add(Line1);

                                b.add(Line2);

                                b.add(Line3);

                                ResetChoice.addActionListener(this);

                                Task1Button.addActionListener(this);

                                Task2Button.addActionListener(this);

                                Task3Button.addActionListener(this);

                                b.add(ResetButton);

                                add(b,"Center");

                }

 

                public void actionPerformed(ActionEvent ae)

                {

                                boolean Flag;

                                String Str;

                                Str=ae.getActionCommand();

                                StoreState();

                                if((Str.equals("Reset")))

                                {

                                                Flag=false;

                                }

                                else

                                {

                                                Flag=true;

                                }

                                if(Counter<4)

                                {

                                                if(Flag)

                                                {

                                                                Counter++;

                                                                if(Counter==1)

                                                                {

                                                                                InputFileName="Task1.order";

                                                                }

                                                                else if(Counter==2)

                                                                {

                                                                                InputFileName="Task2.order";

                                                                }

                                                                else if(Counter==3)

                                                                {

                                                                                InputFileName="Task3.order";

                                                                }

                                                                FromData=Str;

                                                                InputStringToFile();

                                                }

                                }

                                else

                                {

                                                Counter=0;

                                }

                                if(Str.equals("Reset"))

                                {

                                                UnCheckAll();        

                                }

                                if(Str.equals("Roots"))

                                {

                                                Task1.setSelected(true);

                                }             

                                else if(Str.equals("Maxima"))

                                {

                                                Task2.setSelected(true);

                                }             

                                else if(Str.equals("Minima"))

                                {

                                                Task3.setSelected(true);

                                }             

                                repaint();

                }

 

                public void UnCheckAll()

                {

                                String FromData="NONE";

//                              MyremoveAllElements();

                                Task1.setSelected(false);

                                Task2.setSelected(false);

                                Task3.setSelected(false);

                                InputFileName="Task1.status";

                                InputStringToFile();

                                InputFileName="Task2.status";

                                InputStringToFile();

                                InputFileName="Task3.status";

                                InputStringToFile();

                                Counter=0;

                }

 

                public void StoreState()

                {

                                if(Task1.isSelected())

                                {

                                                InputFileName="Task1.status";

                                                FromData="YES";

                                                InputStringToFile();

                                }                             

                                else

                                {

                                                InputFileName="Task1.status";

                                                FromData="NO";

                                                InputStringToFile();

                                }

                                if(Task2.isSelected())

                                {

                                                InputFileName="Task2.status";

                                                FromData="YES";

                                                InputStringToFile();

                                }                             

                                else

                                {

                                                InputFileName="Task2.status";

                                                FromData="NO";

                                                InputStringToFile();

                                }

                                if(Task3.isSelected())

                                {

                                                InputFileName="Task3.status";

                                                FromData="YES";

                                                InputStringToFile();

                                }                             

                                else

                                {

                                                InputFileName="Task3.status";

                                                FromData="NO";

                                                InputStringToFile();

                                }

                               

                }

 

                public void InputStringToFile()

                {

                                try

                                {

                                                FileOutputStream f=new FileOutputStream(InputFileName);

                                                PrintStream p=new PrintStream(f);

                                                p.println(FromData);

                                                p.close();

                                }

                                catch (Exception e)

                                {

                                                System.out.println(e);

                                }

                }

}

 

class ServerInfo extends JPanel

{

                String s="CONTROLLER : Cordinates Client Server Interaction, RPC Server Running on galaxy.lamar.edu Port : 9007";

                JLabel Label1=new JLabel("XML-RPC Server1 Does Task1, Runs on carnap.lamar.edu Port 9001");

                JLabel Label2=new JLabel("XML-RPC Server2 Does Task2, Runs on church.lamar.edu Port 9002");

                JLabel Label3=new JLabel("XML-RPC Server3 Does Task3, Runs on turing.lamar.edu Port 9003");

                JLabel Label4=new JLabel("XML-RPC Server4 Does Task4, Runs on bose.lamar.edu Port 9004");

                JLabel Label5=new JLabel("XML-RPC Server5 Does Task5, Runs on post.lamar.edu Port 9005");

                JLabel Label6=new JLabel("XML-RPC Server6 Does Task6, Runs on russell.lamar.edu Port 9006");

 

                JLabel ControllerLabel=new JLabel(s);

                JLabel ClientLabel=new JLabel("CLIENT : This User Input GUI");

 

                JPanel Heading1=new JPanel();

                JPanel Heading2=new JPanel();

                JPanel Heading3=new JPanel();

                JPanel Heading4=new JPanel();

                JPanel Heading5=new JPanel();

                JPanel Heading6=new JPanel();

 

                JPanel HeadingController=new JPanel();

                JPanel HeadingClient=new JPanel();

 

                Box b=Box.createVerticalBox();

 

                public ServerInfo()

                {

                                Heading1.add(Label1);

                                Heading2.add(Label2);

                                Heading3.add(Label3);

                                Heading4.add(Label4);

                                Heading5.add(Label5);

                                Heading6.add(Label6);

                                HeadingController.add(ControllerLabel);

                                HeadingClient.add(ClientLabel);

 

                                b.add(Heading1);

                                b.add(Heading2);

                                b.add(Heading3);

                                b.add(Heading4);

                                b.add(Heading5);

                                b.add(Heading6);

 

                                b.add(HeadingController);

                                b.add(HeadingClient);

 

                                add(b,"Center");

                }

}

               

 

class TaskInfo extends JPanel

{

                JLabel Label1=new JLabel("Task1 Done by Server1 : To ");

                JLabel Label2=new JLabel("Task2 Done by Server2 : To ");

                JLabel Label3=new JLabel("Task3 Done by Server3 : To ");

                JLabel Label4=new JLabel("Task4 Done by Server4 : To ");

                JLabel Label5=new JLabel("Task5 Done by Server5 : To ");

                JLabel Label6=new JLabel("Task6 Done by Server6 : To ");

 

                JPanel Heading1=new JPanel();

                JPanel Heading2=new JPanel();

                JPanel Heading3=new JPanel();

                JPanel Heading4=new JPanel();

                JPanel Heading5=new JPanel();

                JPanel Heading6=new JPanel();

 

                Box b=Box.createVerticalBox();

 

                public TaskInfo()

                {

                                Heading1.add(Label1);

                                Heading2.add(Label2);

                                Heading3.add(Label3);

                                Heading4.add(Label4);

                                Heading5.add(Label5);

                                Heading6.add(Label6);

 

                                b.add(Heading1);

                                b.add(Heading2);

                                b.add(Heading3);

                                b.add(Heading4);

                                b.add(Heading5);

                                b.add(Heading6);

 

                                add(b,"Center");

                }

}

 

import java.io.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

 

import java.io.IOException;

import java.net.MalformedURLException;

import java.util.Vector;

 

import helma.xmlrpc.XmlRpc;

import helma.xmlrpc.XmlRpcClient;

import helma.xmlrpc.XmlRpcException;

 

//ClientHandlerClass.java

public class ClientHandlerClass

{

                private String Var1;

                private String Var2;

                private String Var3;

                private String Var4;

                private String Var5;

                private String Var6;

                private String Var7;

                private String Var8;

                private String Var9;

 

                public void Result(String s1,String s2,String s3,String s4,String s5,String

                s6,String s7,String s8,String s9)

                {

                                Var1=s1;

                                Var2=s2;

                                Var3=s3;

                                Var4=s4;

                                Var5=s5;

                                Var6=s6;

                                Var7=s7;

                                Var8=s8;

                                Var9=s9;

                                ResultClass ResultObject=new ResultClass();

                                ResultObject.printResult(Var1,Var2,Var3,Var4,Var5,Var6,Var7,Var8,Var9);

                               

                                JFrame myJFrame=new ResultFrame(s9);

                                Toolkit tk=Toolkit.getDefaultToolkit();

                                Dimension d=tk.getScreenSize();

                                int screenHeight=d.height;

                                int screenWidth=d.width;

                                myJFrame.setBounds(screenHeight/2,screenWidth/2,900,100);

                                myJFrame.setTitle("R E S U L T S   D I S P L A Y   W I N D O W");

                                myJFrame.show();

                }

}

 

class ResultFrame extends JFrame implements ActionListener

{

                private String Data="DEFAULT_DATA";

                private JTextField jtf;

                private JPanel jp;

                private Box b;

 

                public ResultFrame(String s)

                {

                                Data=s;

                                b=Box.createVerticalBox();

 

                                jtf=new JTextField(850);

                                b.add(jtf);

 

                                JButton jb=new JButton("Close");

                                jb.addActionListener(this);      

                                b.add(jb);

 

                                getContentPane().add(b);

                                jtf.setText(Data);

                                repaint();

                }

 

                public void actionPerformed(ActionEvent ev)

                {

                                this.hide();   

                }

}

 

 

class ResultClass

{

                                public void printResult(String s1,String s2,String s3,String s4,String

                                s5,String s6,String s7,String s8,String s9)

                                {

                                                System.out.println("RESULT_OK");

                                                System.out.println("From : "+s1+s2+s3+s4);

                                                System.out.println("To : "+s5+s6+s7+s8);

                                                System.out.println("Data : "+s9);

                                }

}

 

 

 

import java.io.*;

import java.io.IOException;

import java.net.MalformedURLException;

 

import helma.xmlrpc.XmlRpc;

import helma.xmlrpc.XmlRpcClient;

import helma.xmlrpc.XmlRpcException;

import helma.xmlrpc.WebServer;

import java.io.IOException;

 

//Controller.java

public class Controller

{

                public static void main(String args[])

                {

                                int ControllerPort=9007;

                                try

                                {

                                                //start server on specified port

                                                System.out.println("Starting XML-RPC Server...");

                                                WebServer server=new WebServer(ControllerPort);

 

                                                //register the handler class

                                                server.addHandler("Controller",new Handler());

                                                System.out.println("Registered Handler class to \"Controller\"");

 

                                                System.out.println("Now accepting requests...");

                                }

                                catch (IOException e)

                                {

                                                System.out.println("Could not start server: "+e.getMessage());

                                }

                }

}

 

                                                               

 

 

import java.io.*;

import java.io.IOException;

import java.net.MalformedURLException;

import java.util.Vector;

 

import helma.xmlrpc.XmlRpc;

import helma.xmlrpc.XmlRpcClient;

import helma.xmlrpc.XmlRpcException;

//Handler.java

 

public class Handler

{

                private static int RegistrationNumber=-1;

                private static String TaskList[]=new String[3];

                private static int NumberOfTasks;

                private static int NumberOfTasksDone;

 

                private static String RegisterTask[]=new String[6];

                private static String RegisterHostName[]=new String[6];

                private static String RegisterPortNumber[]=new String[6];

                private static String RegisterHandler[]=new String[6];

                private static String RegisterRequest[]=new String[6];

 

                private String ClientHostName;

                private String ClientPortNumber;

                private String ClientHandler;

                private String ClientRequest;

 

                private String GeneratorHostName="http://russell.lamar.edu:";

                private String GeneratorPortNumber="9006";

                private String GeneratorHandler="Server6Handler";

                private String GeneratorRequest="Request6";

 

                private String NextHostName="http://church.lamar.edu:";

                private String NextPortNumber="9002";

                private String NextHandler="Server2Handler.";

                private String NextRequest="Request2";

 

                private String MyHostName="http://galaxy.lamar.edu:";

                private String MyPortNumber="9007/";

                private String MyHandler="Controller.";

                private String MyRequest="Request";

 

                private String FirstHostName="http://carnap.lamar.edu:";

                private String FirstPortNumber="9001/";

                private String FirstHandler="Server1Handler.";

                private String FirstRequest="Request1";

                private String FirstData="";

 

                private String ToHostName;

                private String ToPortNumber;

                private String ToHandler;

                private String ToRequest;

 

                private String NextHost[]=new String[4];

 

                private String PreviousRequest;

                private Vector NextParams;

 

                private String InputFileName="./data.0.xml";

                private String OutputFileName="./data.1.xml";

 

                private String ToData;

                private String FromData;

 

                int HostIndex;

 

                public void Register(String HostName,String PortNumber,String HandlerName,String RegisterString,String Task)

                {

//                              RegisterClass RegisterObject=new RegisterClass();

//                              RegisterObject.RegisterIt(HostName,PortNumber,HandlerName,RegisterString);

                                System.out.println("REGISTER_OK"+HostName+PortNumber+HandlerName+RegisterString);

 

                                RegistrationNumber++;

                                RegisterTask[RegistrationNumber]=Task;

                                RegisterHostName[RegistrationNumber]=HostName;

                                RegisterPortNumber[RegistrationNumber]=PortNumber;

                                RegisterHandler[RegistrationNumber]=HandlerName;

                                RegisterRequest[RegistrationNumber]=RegisterString;

                }

 

                public void getNumberOfTasks()

                {

                                int Nones=0;

                                int i;

                                for(i=0;i<3;i++)

                                {

                                                System.out.println("Task List of"+i+TaskList[i]);

                                                if(TaskList[i].trim().equals("NONE"))

                                                {

                                                                Nones++;

                                                }

                                }

                                NumberOfTasks=3-Nones;

                }

 

                public String [] getNextHost(String HostName,String PortNumber,String

                Handler,String Request)

                {

                                int i;

                                int NextIndex;

                                if(!PortNumber.equals("9002"))

                                {

                                                NumberOfTasksDone++;

                                }

                                if(NumberOfTasksDone==NumberOfTasks)

                                {

                                                NextHost[0]=GeneratorHostName;

                                                NextHost[1]=GeneratorPortNumber;

                                                NextHost[2]=GeneratorHandler;

                                                NextHost[3]=GeneratorRequest;

                                }

                                else

                                {

                                                NextIndex=getNextIndex();

                                                System.out.println("NextIndex="+NextIndex);

                                                NextHost[0]=RegisterHostName[NextIndex];

                                                NextHost[1]=RegisterPortNumber[NextIndex];

                                                NextHost[2]=RegisterHandler[NextIndex];

                                                NextHost[3]=RegisterRequest[NextIndex];

                                }

                                return NextHost;

                }

 

                public int getNextIndex()

                {

                                int thisIndex=0;

                                for(int i=0;i<6;i++)

                                {

                                                if(TaskList[NumberOfTasksDone].equals(RegisterTask[i]))

                                                {

                                                                thisIndex=i;

                                                }

                                }

                                return thisIndex;

                }

 

                public void Request(String HostName,String PortNumber,String HandlerName,String DataString,

                                String Task1,String Task2,String Task3)

                throws Exception

                {

 

                                NumberOfTasksDone=0;

                                TaskList[0]=Task1;

                                TaskList[1]=Task2;

                                TaskList[2]=Task3;

                                System.out.println("Tasks : "+Task1+Task2+Task3);

                                getNumberOfTasks();

 

                                System.out.println("Number of Tasks = "+NumberOfTasks);

                               

                                ClientHostName=HostName;

                                ClientPortNumber=PortNumber;

                                ClientHandler=HandlerName;

                                FromData=DataString;

 

                                TaskList[0]=Task1;

                                TaskList[1]=Task2;

                                TaskList[2]=Task3;

 

//                              RequestClass RequestObject=new RequestClass();

//                              RequestObject.RequestIt(HostName,PortNumber,HandlerName,DataString);

/*

                                FromHostName=s1;

                                FromPortNumber=s2;

                                FromHandler=s3;

                                FromData=s4;

*/

 

                                //Create Request

                                NextParams=new Vector();

                                NextParams.addElement(MyHostName);

                                NextParams.addElement(MyPortNumber);

                                NextParams.addElement(MyHandler);

                                NextParams.addElement(MyRequest);

                                NextParams.addElement(NextHostName);

                                NextParams.addElement(NextPortNumber);

                                NextParams.addElement(NextHandler);

                                NextParams.addElement(NextRequest);

                                NextParams.addElement(ToData);

               

                                InputStringToFile();

                                Process();

                                FileToOutputString();

                                ToData=ToData.trim();

               

                                ToHostName="http://carnap.lamar.edu:";

                                ToPortNumber="9001/";

                                ToHandler="Server1Handler.";

                                ToRequest="Request1";

 

                                System.out.println("HEAD");

                                System.out.println("My Host : "+MyHostName);

                                System.out.println("MyPort Number : "+MyPortNumber);

                                System.out.println("MyHandler : "+MyHandler);

                                System.out.println("MyRequest : "+MyRequest);

                                System.out.println("NextHostName : "+NextHostName);

                                System.out.println("NextPortNumber : "+NextPortNumber);

                                System.out.println("NextHandler : "+NextHandler);

                                System.out.println("NextRequest : "+NextRequest);

                                System.out.println("ToData : "+ToData);

                                System.out.println("ToHostName : "+ToHostName);

                                System.out.println("ToPortNumber : "+ToPortNumber);

                                System.out.println("ToRequest : "+ToRequest);

                                System.out.println("To Handler : "+ToHandler);

                                System.out.println("FOOT");

 

                                System.out.println("REQUEST_OK");

                                System.out.println("From : "+MyHostName+MyPortNumber+MyHandler+MyRequest);

                                System.out.println("To : "+ToHostName+ToPortNumber+ToHandler+ToRequest);

                                System.out.println("Data : "+ToData);

 

                                try

                                {

                                                //specify the server

                                                XmlRpcClient NextClient=new XmlRpcClient(ToHostName+ToPortNumber);

                                                System.out.println("client creadted...");

 

                                                //Make a request

                                                NextClient.execute(ToHandler+ToRequest,NextParams);

                                                System.out.println("Execute Attempted...");

 

                                }

                                catch (MalformedURLException e)

                                {

                                                System.out.println("Incorrect URL for XML-RPC format : "+e.getMessage());

                                }

                                catch (XmlRpcException e)

                                {

                                                System.out.println("XML-RPC Exception : "+e.getMessage());

                                }

                                catch (IOException e)

                                {

                                                System.out.println("IO Exception : "+e.getMessage());

                                }

 

                }

/*

                public void Result(String HostName,String PortNumber,String HandlerName,String RegisterString)

                {

                                RegisterClass RegisterObject=new RegisterClass();

                                RegisterObject.RegisterIt(HostName,PortNumber,HandlerName,RegisterString);

                }

*/

 

                public void InputStringToFile()

                {

                                try

                                {

                                                FileOutputStream f=new FileOutputStream(InputFileName);

                                                PrintStream p=new PrintStream(f);

                                                p.println(FromData);

                                                p.close();

                                }

                                catch (Exception e)

                                {

                                                System.out.println(e);

                                }

                }

 

                public void FileToOutputString()

                {

                                String tmp;

                                try

                                {

                                                FileInputStream f=new FileInputStream(OutputFileName);

                                                int i=0;    

                                                while(i!=-1)             

                                                {

                                                                i=f.read();

                                                                ToData+=(char)i;

                                                }

 

                                                tmp=ToData;

                                                ToData=tmp.substring(0,tmp.length()-1);

 

                                                tmp=ToData;

                                                ToData=tmp.substring(4,tmp.length());

 

                                                f.close();

                                }

                                catch (Exception e)

                                {

                                                System.out.println(e);

                                }

                }

 

                public void Process()

                {

                                CopyFile();

                }

 

                public void CopyFile()

                {

                                                try

                                                {

                                                                int c;

                                                                File inputFile=new File(InputFileName);

                                                                File outputFile=new File(OutputFileName);

                                                               

                                                                FileReader in=new FileReader(inputFile);

                                                                FileWriter out=new FileWriter(outputFile);

 

                                                                while((c=in.read())!=-1)

                                                                                                out.write(c);

                                                                in.close();

                                                                out.close();

                                                }

                                                catch (Exception e)

                                                {

                                                                System.out.println(e);

                                                }

 

                }

}

                                               

 

import java.util.Vector;

import helma.xmlrpc.WebServer;

import helma.xmlrpc.XmlRpc;

import helma.xmlrpc.XmlRpcClient;

import helma.xmlrpc.XmlRpcException;

 

//Server1.java

public class Server1

{

                public static void main(String args[])

                {

                                String ControllerHostName="http://galaxy.lamar.edu:";

                                String ControllerPortNumber="9007";

                                String ControllerHandler="Controller.";

 

                                String MyHostName="http://carnap.lamar.edu:";

                                String MyPortNumber="9001";

                                String MyHandler="Server1Handler";

                                String MyRequest="Register";

                                String MyTask="Task1";

 

                                Vector ControllerParams=new Vector();

                                ControllerParams.addElement(MyHostName);

                                ControllerParams.addElement(MyPortNumber);

                                ControllerParams.addElement(MyHandler);

                                ControllerParams.addElement(MyRequest);

                                ControllerParams.addElement(MyTask);

 

                                try

                                {

                                                //specify the server (Controller)

                                                XmlRpcClient NextClient=new XmlRpcClient(ControllerHostName+ControllerPortNumber);

 

                                                //Make a Registration

                                                NextClient.execute(ControllerHandler+MyRequest,ControllerParams);

 

                                                //start server on specified port

                                                System.out.println("Starting XML-RPC Server...");

                                                WebServer server=new WebServer(Integer.parseInt(MyPortNumber));

 

                                                //register the handler class

                                                server.addHandler(MyHandler,new Request1Handler());

                                                System.out.println("Registered Request1Handler class to "+MyHandler);

 

                                                System.out.println("Now accepting requests...");

                                }

                                catch (Exception e)

                                {

                                                System.out.println("Could not start server: "+e.getMessage());

                                }

                }

}

               

 

import javax.xml.parsers.*;

import org.xml.sax.*;

import org.w3c.dom.*;

import javax.xml.transform.*;

import javax.xml.transform.dom.*;

import javax.xml.transform.stream.*;

import java.util.StringTokenizer;

 

import java.io.*;

import java.io.IOException;

import java.net.MalformedURLException;

import java.util.Vector;

 

import helma.xmlrpc.XmlRpc;

import helma.xmlrpc.XmlRpcClient;

import helma.xmlrpc.XmlRpcException;

 

//Request1Handler.java

public class Request1Handler

{

 

                private String MyHostName="http://carnap.lamar.edu:";

                private String MyPortNumber="9001/";

                private String MyHandler="Server1Handler.";

                private String MyRequest="Request1";

 

                private String FromHostName;

                private String FromPortNumber;

                private String FromHandler;

                private String FromRequest;

                private String FromData;

 

                private String ToHostName;

                private String ToPortNumber;

                private String ToHandler;

                private String ToRequest;

                private String ToData;

 

                private String PreviousRequest;

                private Vector NextParams;

 

                private String InputFileName="./data.1.xml";

                private String OutputFileName="./data.2.xml";

 

               

                static Document document;

 

                public void Request1(String s1,String s2,String s3,String s4,

         String s5,String s6,String s7,String s8,String s9)

                {

                                System.out.println("inside server1");

                                FromHostName=s1;

                                FromPortNumber=s2;

                                FromHandler=s3;

                                FromRequest=s4;

                                FromData=s9;

 

                                ToHostName=s5;

                                ToPortNumber=s6;

                                ToHandler=s7;

                                ToRequest=s8;

                               

                                InputStringToFile();

                                Process();

                                FileToOutputString();

 

                                System.out.println("REQUEST_OK");

                                System.out.println("From : "+MyHostName+MyPortNumber+MyHandler+MyRequest);

                                System.out.println("To : "+ToHostName+ToPortNumber+ToHandler+ToRequest);

                                System.out.println("Data : "+ToData);

 

                                //Create Request

                                NextParams=new Vector();

                                NextParams.addElement(MyHostName);

                                NextParams.addElement(MyPortNumber);

                                NextParams.addElement(MyHandler);

                                NextParams.addElement(MyRequest);

                                NextParams.addElement(ToData);

 

                                try

                                {

                                                //specify the server

                                                XmlRpcClient NextClient=new XmlRpcClient(ToHostName+ToPortNumber);

 

                                                //Make a request and print the result

                                                NextClient.execute(ToHandler+ToRequest,NextParams);

                                }

                                catch (MalformedURLException e)

                                {

                                                System.out.println("Incorrect URL for XML-RPC format : "+e.getMessage());

                                }

                                catch (XmlRpcException e)

                                {

                                                System.out.println("XML-RPC Exception : "+e.getMessage());

                                }

                                catch (IOException e)

                                {

                                                System.out.println("IO Exception : "+e.getMessage());

                                }

                }

 

                public void InputStringToFile()

                {

                                try

                                {

                                                FileOutputStream f=new FileOutputStream(InputFileName);

                                                PrintStream p=new PrintStream(f);

                                                p.println(FromData);

                                                p.close();

                                }

                                catch (Exception e)

                                {

                                                System.out.println(e);

                                }

                }

 

                public void FileToOutputString()

                {

                                String tmp;

                                try

                                {

                                                FileInputStream f=new FileInputStream(OutputFileName);

                                                int i=0;

                                                while(i!=-1)             

                                                {

                                                                i=f.read();

                                                                ToData+=(char)i;

                                                }

 

                                                tmp=ToData;

                                                ToData=tmp.substring(0,tmp.length()-1);

 

                                                tmp=ToData;

                                                ToData=tmp.substring(4,tmp.length());

 

               

                                                f.close();

                                }

                                catch (Exception e)

                                {

                                                System.out.println(e);

                                }

                }

 

                public void Process()

                {

//                              ToData=FromData+"Controller:";

 

                                String input, coeff, power;

                                input = "";

                                try

                                {

                                                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

                                                DocumentBuilder builder = factory.newDocumentBuilder();

                                                Document document = builder.parse("data.1.xml");

  

                                                NodeList equNode = document.getElementsByTagName("EQUATION");

 

                                                int terms = equNode.getLength();

                                                int j=0;

                                                for(int i=0; i<terms ; i++)

                                                {

                                                                Node thisTerm = equNode.item(i);

                                                                Node equ = thisTerm.getFirstChild();

                                                                try

                                                                {

                                                                                if(equ instanceof Text)

                                                                                input = equ.getNodeValue();

                                                                                System.out.println("the input is " + input);

                                                                }

                                                                catch(Exception e)

                                                                {

                                                                                System.out.println("Please check you coefficient tag. The value must be numerical.");

                                                                }

   

                                                                // StringTokenizer st = new StringTokenizer(input,"=");

                                                                StringTokenizer stk = new StringTokenizer(input,":");

                                                                //StringTokenizer stc = new StringTokenizer(st.nextToken(),":");

 

                                                                while(stk.hasMoreTokens())

                                                                {

                                                                                coeff = stk.nextToken() + stk.nextToken();

                                                                                power = stk.nextToken() + stk.nextToken();

                 

                                                                                //Node equation = document.getDocumentElement();

                                                                                Node termNode = document.createElement("TERM");

                                                                                Text termValue = document.createTextNode(""+coeff+" "+power);

 

                                                                                termNode.appendChild(termValue);

                                                                                if(j==0)

                                                                                {

                                                                                                thisTerm.replaceChild(termNode, equ);

                                                                                                j++;     

                                                                                }

                                                                                else

                                                                                {

                                                                                                thisTerm.appendChild(termNode);

                                                                                }

                                                                                TransformerFactory transFactory = TransformerFactory.newInstance();

                                                Transformer transformer = transFactory.newTransformer();

 

                                                DOMSource source = new DOMSource(document);

 

                                                                File newXML = new File("data.2.xml");

                                                                FileOutputStream os = new FileOutputStream(newXML);

                                                                StreamResult result = new StreamResult(os);

                                                                transformer.transform(source,result);

                                                }//while()

                                }//for()

                                }

                                catch (Exception e)

                                {

                                                System.out.println(e);

                                }

                }//Process()

}

 

 

import java.io.IOException;

import java.net.MalformedURLException;

import java.util.Vector;

 

import helma.xmlrpc.WebServer;

import helma.xmlrpc.XmlRpc;

import helma.xmlrpc.XmlRpcClient;

import helma.xmlrpc.XmlRpcException;

 

//Server2.java

public class Server2

{

                public static void main(String args[])

                {

                                String ControllerHostName="http://galaxy.lamar.edu:";

                                String ControllerPortNumber="9007";

                                String ControllerHandler="Controller.";

 

                                String MyHostName="http://church.lamar.edu:";

                                String MyPortNumber="9002";

                                String MyHandler="Server2Handler";

                                String MyRequest="Register";

                                String MyTask="Task2";

 

                                Vector ControllerParams=new Vector();

                                ControllerParams.addElement(MyHostName);

                                ControllerParams.addElement(MyPortNumber);

                                ControllerParams.addElement(MyHandler);

                                ControllerParams.addElement(MyRequest);

                                ControllerParams.addElement(MyTask);

 

                                try

                                {

                                                //specify the server (Controller)

                                                XmlRpcClient NextClient=new XmlRpcClient(ControllerHostName+ControllerPortNumber);

 

                                                //Make a Registration

                                                NextClient.execute(ControllerHandler+MyRequest,ControllerParams);

 

                                                //start server on specified port

                                                System.out.println("Starting XML-RPC Server...");

                                                WebServer server=new WebServer(Integer.parseInt(MyPortNumber));

 

                                                //register the handler class

                                                server.addHandler(MyHandler,new Request2Handler());

                                                System.out.println("Registered Request2Handler class to "+MyHandler);

 

                                                System.out.println("Now accepting requests...");

                                }

                                catch (Exception e)

                                {

                                                System.out.println("Could not start server: "+e.getMessage());

                                }

                }

}

               

                                               

 

 

import javax.xml.parsers.*;

import org.xml.sax.*;

import org.w3c.dom.*;

import javax.xml.transform.*;

import javax.xml.transform.dom.*;

import javax.xml.transform.stream.*;

import java.util.StringTokenizer;

 

import java.io.*;

import java.io.IOException;

import java.net.MalformedURLException;

import java.util.Vector;

 

import helma.xmlrpc.XmlRpc;

import helma.xmlrpc.XmlRpcClient;

import helma.xmlrpc.XmlRpcException;

 

//Request2Handler.java

public class Request2Handler

{

 

                private String ControllerHostName="http://galaxy.lamar.edu:";

                private String ControllerPortNumber="9007/";

                private String ControllerHandler="Handler.";

                private String ControllerRequest="getNextHost";

 

                private String MyHostName="http://church.lamar.edu:";

                private String MyPortNumber="9002/";

                private String MyHandler="Server2Handler.";

                private String MyRequest="Request2";

 

                private String FromHostName;

                private String FromPortNumber;

                private String FromHandler;

                private String FromRequest;

                private String FromData;

 

                private String ToHostName;

                private String ToPortNumber;

                private String ToHandler;

                private String ToRequest;

                private String ToData;

               

                private String NextHost[]=new String[4];

 

                private String PreviousRequest;

                private Vector ToParams=new Vector();

 

                private String InputFileName="./data.2.xml";

                private String OutputFileName="./data.3.xml";

 

                static Document document;

 

                public void Request2(String FromHostName,String FromPortNumber,String FromHandlerName,String FromRequestString,String data)

                {

                                this.FromHostName=FromHostName;

                                this.FromPortNumber=FromPortNumber;

                                this.FromHandler=FromHandlerName;

                                this.FromRequest=FromRequestString;

                                FromData=data;

                                ToHostName=ControllerHostName;

                                ToPortNumber=ControllerPortNumber;

                                ToHandler=ControllerHandler;

                                ToRequest=ControllerRequest;

                               

                                InputStringToFile();

                                Process();

                                FileToOutputString();

                               

                                System.out.println("REQUEST_OK");

                                System.out.println("From : "+MyHostName+MyPortNumber+MyHandler+MyRequest);

                                System.out.println("To : "+ToHostName+ToPortNumber+ToHandler+ToRequest+ToData);

                                System.out.println("Data : "+ToData);

 

                                //Create Request

 

 

                                ToParams.addElement(MyHostName);

                                ToParams.addElement(MyPortNumber);

                                ToParams.addElement(MyHandler);

                                ToParams.addElement(MyRequest);

               

                                try

                                {

                                                //specify the server

                                                XmlRpcClient NextClient=new XmlRpcClient(ToHostName+ToPortNumber);

 

                                                //Make a request and print the result

                                                NextHost=(String [])NextClient.execute(ToHandler+ToRequest,ToParams);

                                }

                                catch (MalformedURLException e)

                                {

                                                System.out.println("Incorrect URL for XML-RPC format : "+e.getMessage());

                                }

                                catch (XmlRpcException e)

                                {

                                                System.out.println("XML-RPC Exception : "+e.getMessage());

                                }

                                catch (IOException e)

                                {

                                                System.out.println("IO Exception : "+e.getMessage());

                                }

                               

                                ToHostName=NextHost[0];

                                ToPortNumber=NextHost[1];

                                ToHandler=NextHost[2];

                                ToRequest=NextHost[3];

                                ToParams.addElement(MyHostName);

                                ToParams.addElement(MyPortNumber);

                                ToParams.addElement(ToHandler);

                                ToParams.addElement(ToRequest);

                                ToParams.addElement(ToData);

                               

                                System.out.println("Next Host"+NextHost[0]);

                                System.out.println("Next port"+NextHost[1]);

                                System.out.println("Handler "+NextHost[2]);

                                System.out.println("Request "+NextHost[3]);

                                try

                                {

                                                //specify the server

                                                XmlRpcClient NextClient=new XmlRpcClient(ToHostName+ToPortNumber);

 

                                                //Make a request and print the result

                                                NextHost=(String [])NextClient.execute(ToHandler+ToRequest,ToParams);

                                }

                                catch (MalformedURLException e)

                                {

                                                System.out.println("Incorrect URL for XML-RPC format : "+e.getMessage());

                                }

                                catch (XmlRpcException e)

                                {

                                                System.out.println("XML-RPC Exception : "+e.getMessage());

                                }

                                catch (IOException e)

                                {

                                                System.out.println("IO Exception : "+e.getMessage());

                                }

 

                }

               

                public void InputStringToFile()

                {

                                try

                                {

                                                FileOutputStream f=new FileOutputStream(InputFileName);

                                                PrintStream p=new PrintStream(f);

                                                p.println(FromData);

                                                p.close();

                                }

                                catch (Exception e)

                                {

                                                System.out.println(e);