Changeset 3502


Ignore:
Timestamp:
2002-10-29T15:31:12+13:00 (22 years ago)
Author:
kjdon
Message:

process now uses Elements instead of Nodes

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java

    r3498 r3502  
    215215    Element e = doc.getDocumentElement();
    216216   
    217     Node res = process(e);
     217    Element res = process(e);
    218218    return converter_.getString(res);
    219219   
     
    223223     *
    224224     */
    225     public Node process(Node xml_in) {
    226 
    227     // xml_in should always be an Element - should check this
    228     Element xml = (Element)xml_in;
    229     String to = xml.getAttribute("to");
     225    public Element process(Element message) {
     226
     227    String to = message.getAttribute("to");
    230228
    231229    // the cluster name should be first, check, then remove
     
    233231    if (clustername.equals(cluster_name_)){
    234232        to = GSPath.removeFirstLink(to);
    235         xml.setAttribute("to", to);
     233        message.setAttribute("to", to);
    236234    } else {
    237235        System.out.println("ServiceCluster error: cluster name wrong! was "+clustername+" should have been "+cluster_name_);
     
    240238
    241239    if (to.equals("")) { // this command is for me
    242         String type = xml.getAttribute("type");
     240        String type = message.getAttribute("type");
    243241        if (type.equals("describe")) {
    244242        // create a response with the description inside it
     
    250248        } else {
    251249        System.out.println("ServiceCluster: error, cant handle request:");
    252         System.out.println(converter_.getString(xml));
     250        System.out.println(converter_.getString(message));
    253251        return null;
    254252        }
     
    258256       
    259257        if (service_map_.containsKey(service)) {
    260         return ((ModuleInterface)service_map_.get(service)).process(xml);
     258        return ((ModuleInterface)service_map_.get(service)).process(message);
    261259        } else {
    262         System.err.println("ServiceCluster: non-existant service, "+service+", specified, in:\n"+converter_.getString(xml));
     260        System.err.println("ServiceCluster: non-existant service, "+service+", specified, in:\n"+converter_.getString(message));
    263261        return null;
    264262        }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/comms/Communicator.java

    r3235 r3502  
    2323
    2424//XML packages
    25 import org.w3c.dom.Node;
     25import org.w3c.dom.Element;
    2626
    2727/** Communicator - base class for Modules that talk via some protocol to other modules
     
    6767    abstract public String process(String xml_in);
    6868
    69     abstract public Node process(Node xml_in);
     69    abstract public Element process(Element xml_in);
    7070}
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/comms/SOAPCommunicator.java

    r3462 r3502  
    7373
    7474    // put this into Communicator??
    75     public Node process(Node xml_in) {
     75    public Element process(Element xml_in) {
    7676    // needs to catch SOAPException, MalformedURLException
    7777    try {
     
    149149   
    150150    public String process(String xml_in) {
    151     Node n = converter_.getDOM(xml_in).getDocumentElement();
    152     Node result = process(n);
    153     if (result == null) {
    154         return "";
    155     }
     151    Element e = converter_.getDOM(xml_in).getDocumentElement();
     152    Node result = process(e);
    156153    return converter_.getString(result);   
    157154    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/MessageRouter.java

    r3485 r3502  
    173173    Document doc = converter_.getDOM(xml_in);
    174174   
    175     Node result = process(doc);
     175    Element result = process(doc.getDocumentElement());
    176176    return converter_.getString(result);
    177177    }
    178178   
    179179    /**
    180      * Process an XML request - as a DOM model node
    181      * the Node may be an Element or a Document
     180     * Process an XML request - as a DOM Element
    182181     *
    183182     * @param xml_in the message to process - should be <message>
    184183     * @return the response - contains any error messages
    185      * @see Node
    186      * @see Document
    187184     * @see Element
    188185     */
    189     public Node process(Node xml_in) {
    190    
    191     // check if Element or Document - we want to deal with Elements
    192     Element message=null;
    193     short node_type = xml_in.getNodeType();
    194     if (node_type == Node.DOCUMENT_NODE) {
    195         message = ((Document)xml_in).getDocumentElement();
    196     } else if (node_type == Node.ELEMENT_NODE) {
    197         message = (Element)xml_in;
    198     } else {
    199         System.err.println("MessageRouter:process: invalid Node type");
    200     }
    201 
     186    public Element process(Element message) {
     187   
    202188    // check that its a correct message tag
    203189    if (!message.getTagName().equals(GSDL_MESSAGE_NAME)) {
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/ModuleInterface.java

    r3235 r3502  
    1919package org.greenstone.gsdl3.core;
    2020   
    21 import org.w3c.dom.Node;                                               
     21import org.w3c.dom.Element;                                               
    2222
    2323/**
    24  * Module interface for all components/modules in greenstone.
     24 * interface for all modules in greenstone.
    2525 *
    2626 * all components talk via a process method - in its simplest form,
    2727 * it takes a String of XML, and returns a String of XML
    2828 *
    29  * Java modules also implement a convenience process method -
    30  * uses DOM Nodes instead of Strings - avoids parsing the XML at each module
     29 * the more efficient process method uses DOM Element Nodes instead
     30 * of Strings - this avoids parsing the XML at each module
    3131 *
    3232 * @author <a href="mailto:[email protected]">Katherine Don</a>
     
    4545
    4646  /**
    47    * Process an XML request - as a DOM model node
    48    * the Node may be an Element or a Document
     47   * Process an XML request - as a DOM model Element
    4948   *
    50    * @param in the request to process
     49   * @param xml_in the request to process
    5150   * @return the response - contains any error messages
    52    * @see org.w3c.dom.Node
    53    * @see org.w3c.dom.Document
    5451   * @see org.w3c.dom.Element
    5552   */
    56     abstract public Node process(Node xml_in);
    57     //abstract public XMLConverter process(XMLConverter out);
     53    abstract public Element process(Element xml_in);
    5854}   
    5955                                                                           
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java

    r3486 r3502  
    157157    }
    158158
    159     public Node process(Node xml_in) {
     159    public Element process(Element xml_in) {
    160160    return xml_in; // for now
    161161
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ModuleWrapper.java

    r3251 r3502  
    2828import org.apache.xindice.xml.TextWriter;
    2929import org.w3c.dom.Document;
     30import org.w3c.dom.Element;
    3031import org.w3c.dom.Node;
    3132import org.w3c.dom.Node;                                               
     
    212213
    213214  /**
    214    * Process an XML request - as a DOM model node
    215    * the Node may be an Element or a Document
     215   * Process an XML request - as a DOM Element
    216216   *
    217217   * @param in the request to process
    218218   * @return the response - contains any error messages
    219    * @see org.w3c.dom.Node
    220    * @see org.w3c.dom.Document
    221219   * @see org.w3c.dom.Element
    222220   */
    223   public Node process(Node xmlIn) {
     221  public Element process(Element xmlIn) {
    224222    throw new Error("Not implmented yet. Should be faked by stringizing the node.");
    225223  }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ServicesImpl.java

    r3492 r3502  
    124124    Document doc = converter_.getDOM(xml_in);
    125125   
    126     Node res = process(doc);
     126    Element res = process(doc.getDocumentElement());
    127127    return converter_.getString(res);
    128128   
     
    137137     * @see Element
    138138     */
    139     public Node process(Node xml_in) {
    140 
    141     // check if request is Element or Document - we want to work
    142     // with an Element
    143     Element request=null;
    144 
    145     short node_type = xml_in.getNodeType();
    146     if (node_type == Node.DOCUMENT_NODE) {
    147         request = ((Document)xml_in).getDocumentElement();
    148     } else if (node_type == Node.ELEMENT_NODE) {
    149         request = (Element)xml_in;
    150     } else {
    151         System.err.println("ServicesImpl:process error: input should be an Element or Document!");
    152     }
     139    public Element process(Element request) {
    153140
    154141    String req = request.getNodeName();
Note: See TracChangeset for help on using the changeset viewer.