Return-Path: Delivered-To: apmail-ws-axis-cvs-archive@www.apache.org Received: (qmail 25061 invoked from network); 3 Jun 2005 09:19:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Jun 2005 09:19:54 -0000 Received: (qmail 51755 invoked by uid 500); 3 Jun 2005 09:19:52 -0000 Delivered-To: apmail-ws-axis-cvs-archive@ws.apache.org Received: (qmail 51693 invoked by uid 500); 3 Jun 2005 09:19:52 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 51680 invoked by uid 99); 3 Jun 2005 09:19:51 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 03 Jun 2005 02:19:47 -0700 Received: (qmail 24096 invoked by uid 65534); 3 Jun 2005 09:19:30 -0000 Message-ID: <20050603091930.24095.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r179755 - in /webservices/axis/trunk/java/modules/samples/src/sample/google/spellcheck: ./ AsyncPanel.java FormModel.java Observer.java SuggestionForm.java SyncPanel.java Date: Fri, 03 Jun 2005 09:19:29 -0000 To: axis-cvs@ws.apache.org From: ajith@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: ajith Date: Fri Jun 3 02:19:28 2005 New Revision: 179755 URL: http://svn.apache.org/viewcvs?rev=3D179755&view=3Drev Log: Adding the google spellcheck sample. Still needs some work to get it proper= ly running Added: webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/ webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/AsyncPanel.java webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/FormModel.java webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/Observer.java webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/SuggestionForm.java webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/SyncPanel.java Added: webservices/axis/trunk/java/modules/samples/src/sample/google/spellc= heck/AsyncPanel.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samp= les/src/sample/google/spellcheck/AsyncPanel.java?rev=3D179755&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/AsyncPanel.java (added) +++ webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/AsyncPanel.java Fri Jun 3 02:19:28 2005 @@ -0,0 +1,72 @@ +package sample.google.spellcheck; + +import org.apache.axis.clientapi.Call; +import org.apache.axis.engine.AxisFault; +import org.apache.axis.addressing.EndpointReference; +import org.apache.axis.addressing.AddressingConstants; +import org.apache.axis.soap.SOAPEnvelope; + +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.stream.XMLStreamException; +import javax.swing.*; +import java.net.MalformedURLException; +import java.net.URL; +import java.awt.event.KeyListener; +import java.awt.event.KeyEvent; +import java.awt.*; + +/** + * class sample.google.spellcheck.AsyncPanel + * This Impements its own GUI of the Asynchronous Client and it updates th= e string after getting the response to textarea + * @author Nadana Gunarathna + * + */ +public class AsyncPanel extends javax.swing.JPanel implements Observer,Key= Listener{ + FormModel formModel; + javax.swing.JTextArea textAreaget; + javax.swing.JTextArea textAreaset; + public AsyncPanel() + { + formModel =3D new FormModel(this); + textAreaget =3D new javax.swing.JTextArea(15,10); + textAreaset =3D new javax.swing.JTextArea(15,10); + JScrollPane scrollPaneGet =3D new JScrollPane(textAreaget); + JScrollPane scrollPaneSet =3D new JScrollPane(textAreaset); + setPreferredSize(new Dimension(450, 460)); + + textAreaget.setText("Enter a String"); + textAreaget.addKeyListener(this); + + + this.add(scrollPaneGet,BorderLayout.NORTH); + this.add(scrollPaneSet,BorderLayout.SOUTH); + + + } + public void update(String suggestion) + { + textAreaset.setText(suggestion); + + // put the suggestion string in the reaponse box along with the mi= sspelt word + } + + + public void keyPressed(KeyEvent e) { + //To change body of implemented methods use File | Settings | File= Templates. + int key=3De.getKeyChar(); + if((key=3D=3D32)||(key=3D=3D10)){ + String suggesion=3DtextAreaget.getText().trim(); + //suggesion.trim(); + formModel.doAsyncSpellingSuggestion(suggesion); + } + } + + public void keyReleased(KeyEvent e) { + //To change body of implemented methods use File | Settings | File= Templates. + } + + public void keyTyped(KeyEvent e) { + //To change body of implemented methods use File | Settings | File= Templates. + } +} Added: webservices/axis/trunk/java/modules/samples/src/sample/google/spellc= heck/FormModel.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samp= les/src/sample/google/spellcheck/FormModel.java?rev=3D179755&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/FormModel.java (added) +++ webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/FormModel.java Fri Jun 3 02:19:28 2005 @@ -0,0 +1,171 @@ +package sample.google.spellcheck; + +import org.apache.axis.soap.SOAPFactory; +import org.apache.axis.soap.SOAPEnvelope; +import org.apache.axis.om.OMAbstractFactory; +import org.apache.axis.om.OMNamespace; +import org.apache.axis.om.OMElement; +import org.apache.axis.clientapi.AsyncResult; +import org.apache.axis.clientapi.Call; +import org.apache.axis.clientapi.Callback; +import org.apache.axis.engine.AxisFault; +import org.apache.axis.addressing.EndpointReference; +import org.apache.axis.addressing.AddressingConstants; + +import javax.xml.stream.XMLStreamWriter; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.namespace.QName; +import java.net.URL; +import java.net.MalformedURLException; + +/** + * class sample.google.spellcheck.FormModel + * This is the Impementation of the Asynchronous Client + * @author Nadana Gunarathna + * + */ +public class FormModel extends Callback { + + Observer observer; + public FormModel(Observer observer) + { + this.observer =3D observer; + } + + private OMElement getElement(String word){ + SOAPFactory omfactory=3DOMAbstractFactory.getSOAP11Factory(); + OMNamespace opN =3D omfactory.createOMNamespace("urn:GoogleSearch"= ,"ns1"); + OMNamespace emptyNs=3Domfactory.createOMNamespace("", null); + + OMElement method =3D omfactory.createOMElement("doSpellingSuggesti= on", opN); + //reqEnv.getBody().addChild(method); + method.addAttribute("soapenv:encodingStyle","http://schemas.xmlsoa= p=2Eorg/soap/encoding/",null); + OMElement value1 =3D omfactory.createOMElement("key",emptyNs); + OMElement value2=3Domfactory.createOMElement("phrase",emptyNs); + value1.addAttribute("xsi:type","xsd:string",null); + value2.addAttribute("xsi:type","xsd:string",null); + value1.addChild(omfactory.createText(value1, "wzdxGcZQFHJ71w7IgCj5= ddQGLmODsP9g")); + value2.addChild(omfactory.createText(value2,word)); + method.addChild(value2); + method.addChild(value1); + return method; + } + + private SOAPEnvelope getEnvelope(String word) + { + SOAPFactory omfactory=3DOMAbstractFactory.getSOAP11Factory(); + SOAPEnvelope reqEnv=3Domfactory.getDefaultEnvelope(); + OMNamespace emptyNs=3Domfactory.createOMNamespace("", null); + OMNamespace xsi =3D reqEnv.declareNamespace("http://www.w3.org/199= 9/XMLSchema-instance","xsi"); + OMNamespace xsd =3D reqEnv.declareNamespace("http://www.w3.org/199= 9/XMLSchema","xsd"); + OMNamespace opN =3D reqEnv.declareNamespace("urn:GoogleSearch","ns= 1"); + OMElement method =3D omfactory.createOMElement("doSpellingSuggesti= on", opN); + reqEnv.getBody().addChild(method); + method.addAttribute("soapenv:encodingStyle","http://schemas.xmlsoa= p=2Eorg/soap/encoding/",null); + OMElement value1 =3D omfactory.createOMElement("key",emptyNs); + OMElement value2=3Domfactory.createOMElement("phrase",emptyNs); + value1.addAttribute("xsi:type","xsd:string",null); + value2.addAttribute("xsi:type","xsd:string",null); + value1.addChild(omfactory.createText(value1, "wzdxGcZQFHJ71w7IgCj5= ddQGLmODsP9g")); + value2.addChild(omfactory.createText(value2,word)); + method.addChild(value2); + method.addChild(value1); + return reqEnv; + + } + public void doAsyncSpellingSuggestion(String word) + { + OMElement requestElement =3D getElement(word); + System.out.println("Initializing the Client Call...."); + Call call =3D null; + try { + call =3D new Call(); + } catch (AxisFault axisFault) { + axisFault.printStackTrace(); //To change body of catch statem= ent use File | Settings | File Templates. + } + System.out.println("Setting the Endpointreference "); + URL url =3D null; + try { +// url =3D new URL("http","127.0.0.1",8080,"/search/beta2"); + url =3D new URL("http","api.google.com","/search/beta2"); + } catch (MalformedURLException e) { + + e.printStackTrace(); + System.exit(0); + } + + call.setTo(new EndpointReference(AddressingConstants.WSA_TO, url.t= oString())); + //call.invokeNonBlocking("doGoogleSpellingSugg",requestEnvelop, ne= w ClientCallbackHandler(parent)); + try { + call.invokeNonBlocking("doGoogleSpellingSugg",requestElement,t= his); + } catch (AxisFault axisFault) { + axisFault.printStackTrace(); //To change body of catch statem= ent use File | Settings | File Templates. + } + + } + public void doSyncSpellingSuggestion(String word) + { + SOAPEnvelope response=3Dnull; + SOAPEnvelope requestEnvelope =3D getEnvelope(word); + System.out.println("Initializing the Client Call...."); + Call call =3D null; + try { + call =3D new Call(); + } catch (AxisFault axisFault) { + axisFault.printStackTrace(); //To change body of catch statem= ent use File | Settings | File Templates. + } + System.out.println("Setting the Endpointreference "); + URL url =3D null; + try { + url =3D new URL("http","api.google.com","/search/beta2"); + } catch (MalformedURLException e) { + + e.printStackTrace(); + System.exit(0); + } + + call.setTo(new EndpointReference(AddressingConstants.WSA_TO, url.t= oString())); + try { + response=3D(SOAPEnvelope)call.invokeBlocking("doGoogleSpelling= Sugg",requestEnvelope); + } catch (AxisFault axisFault) { + axisFault.printStackTrace(); //To change body of catch statem= ent use File | Settings | File Templates. + } + + + this.getResponse(response); + } + public String getResponse(SOAPEnvelope responseEnvelope){ + //////////////////////////////////////////// + try { + XMLStreamWriter writer =3D XMLOutputFactory.newInstance().crea= teXMLStreamWriter(System.out); + responseEnvelope.serialize(writer); + writer.flush(); + } catch (XMLStreamException e) { + e.printStackTrace(); //To change body of catch statement use = File | Settings | File Templates. + } + + //////////////////////////////////////////// + QName qName1 =3D new QName("urn:GoogleSearch", "doSpellingSuggesti= onResponse"); + QName qName2 =3D new QName("urn:GoogleSearch", "return"); + OMElement returnvalue1 =3D responseEnvelope.getBody().getFirstChil= dWithName(qName1); + OMElement val =3D returnvalue1.getFirstChildWithName(qName2); + org.apache.axis.om.OMNode omtext =3D val.getFirstChild(); + String sugession =3D null; + sugession =3D ((org.apache.axis.om.OMText) omtext).getText(); + this.observer.update(sugession); + + return sugession; + } + + public void onComplete(AsyncResult asyncResult) { + String sugession =3D getResponse(asyncResult.getResponseEnvelope()= ); + this.observer.update(sugession); + //To change body of implemented methods use File | Settings | File= Templates. + + } + + public void reportError(Exception e) { + //To change body of implemented methods use File | Settings | File= Templates. + } +} Added: webservices/axis/trunk/java/modules/samples/src/sample/google/spellc= heck/Observer.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samp= les/src/sample/google/spellcheck/Observer.java?rev=3D179755&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/Observer.java (added) +++ webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/Observer.java Fri Jun 3 02:19:28 2005 @@ -0,0 +1,14 @@ +package sample.google.spellcheck; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; + +/** + * interface sample.google.spellcheck.Observer + * @author Nadana Gunarathna + * + */ +public interface Observer { + public void update(String suggestion); + } Added: webservices/axis/trunk/java/modules/samples/src/sample/google/spellc= heck/SuggestionForm.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samp= les/src/sample/google/spellcheck/SuggestionForm.java?rev=3D179755&view=3Dau= to =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/SuggestionForm.java (added) +++ webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/SuggestionForm.java Fri Jun 3 02:19:28 2005 @@ -0,0 +1,56 @@ +package sample.google.spellcheck; + +import sample.google.spellcheck.AsyncPanel; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * class sample.google.spellcheck.SuggestionForm + * This is the implementation of the GUI + * @author Nadana Gunarathna + * + */ +public class SuggestionForm extends javax.swing.JFrame implements ActionLi= stener { + AsyncPanel asyncPanel; + SyncPanel syncPanel; + + public SuggestionForm() throws HeadlessException { + asyncPanel =3D new AsyncPanel(); + syncPanel =3D new SyncPanel(); + JMenuBar menuBar; + //Create the menu bar. + menuBar =3D new JMenuBar(); + JMenu mainMenu =3D new JMenu("Select"); + + mainMenu.setMnemonic(KeyEvent.VK_A); + + JMenuItem syncMenuItem =3D new JMenuItem("Sync Call", KeyEvent.VK_= T); + syncMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, = ActionEvent.ALT_MASK)); + + syncMenuItem.addActionListener(this); + mainMenu.add(syncMenuItem); + + this.setJMenuBar(menuBar); + menuBar.add(mainMenu); + //this.getContentPane().add(menuBar); + + //this.getContentPane().add(syncPanel); + this.getContentPane().add(asyncPanel); + } + + public static void main(String[] args) { + SuggestionForm form =3D new SuggestionForm(); + form.setSize(800, 800); + form.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + form.pack(); + form.show(); + } + + public void actionPerformed(ActionEvent e) { + //To change body of implemented methods use File | Settings | File= Templates. + } +} Added: webservices/axis/trunk/java/modules/samples/src/sample/google/spellc= heck/SyncPanel.java URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samp= les/src/sample/google/spellcheck/SyncPanel.java?rev=3D179755&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/SyncPanel.java (added) +++ webservices/axis/trunk/java/modules/samples/src/sample/google/spellchec= k/SyncPanel.java Fri Jun 3 02:19:28 2005 @@ -0,0 +1,61 @@ +package sample.google.spellcheck; + +import sample.google.spellcheck.FormModel; +import sample.google.spellcheck.Observer; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +/** + * class sample.google.spellcheck.SyncPanel + * This Impements its own GUI of the Synchronous Client and it send the SO= AP request after the mouse event. + * @author Nadana Gunarathna + * + */ +public class SyncPanel extends javax.swing.JPanel implements Observer, Act= ionListener{ + FormModel formModel; + javax.swing.JTextField tFieldget; + javax.swing.JTextField tFieldset; + javax.swing.JButton button; + public SyncPanel() + { + formModel =3D new FormModel(this); + tFieldget =3D new javax.swing.JTextField(10); + tFieldset =3D new javax.swing.JTextField(10); + button=3Dnew javax.swing.JButton("Send"); + JScrollPane scrollPaneget =3D new JScrollPane(tFieldget); + JScrollPane scrollPaneset =3D new JScrollPane(tFieldset); + + setPreferredSize(new Dimension(150, 150)); + + tFieldget.setText("Enter a String"); + + this.add(tFieldget,BorderLayout.CENTER ); + this.add(scrollPaneget,BorderLayout.CENTER); + this.add(button); + this.add(tFieldset ,BorderLayout.CENTER); + this.add(scrollPaneset,BorderLayout.CENTER); + //this.setLayout(new GridLayout(0,1)); + button.addActionListener(this); + + } + public void update(String suggestion) + { + tFieldset.setText(suggestion); // put the suggestion s= tring in the reaponse box along with the misspelt word + } + + + public void actionPerformed(ActionEvent e) { + String str=3DtFieldget.getText().trim(); + formModel.doSyncSpellingSuggestion(str); + //formModel.getResponse(); + } + + + +} + +