[3235] | 1 | /*
|
---|
| 2 | * Communicator.java
|
---|
| 3 | * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
|
---|
| 4 | *
|
---|
| 5 | * This program is free software; you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 8 | * (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program; if not, write to the Free Software
|
---|
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 18 | */
|
---|
[3222] | 19 | package org.greenstone.gsdl3.comms;
|
---|
| 20 |
|
---|
| 21 | import org.greenstone.gsdl3.core.ModuleInterface;
|
---|
| 22 | import org.greenstone.gsdl3.util.*;
|
---|
| 23 |
|
---|
| 24 | //XML packages
|
---|
[3502] | 25 | import org.w3c.dom.Element;
|
---|
[4035] | 26 | import org.w3c.dom.Node;
|
---|
[3222] | 27 |
|
---|
| 28 | /** Communicator - base class for Modules that talk via some protocol to other modules
|
---|
| 29 | *
|
---|
[3519] | 30 | * can be used by a MessageRouter - in this case set localSiteName
|
---|
| 31 | * can be used by any other module - in this case it has no local site - dont set localsiteName. the setting of localSiteName affects the handling of teh to and from fields in the message.
|
---|
[3235] | 32 | * @author <a href="mailto:[email protected]">Katherine Don</a>
|
---|
| 33 | * @version $Revision: 9824 $
|
---|
[3222] | 34 | */
|
---|
| 35 | abstract public class Communicator
|
---|
| 36 | implements ModuleInterface {
|
---|
| 37 |
|
---|
| 38 | /** name of local site */
|
---|
| 39 | protected String local_site_name_ = null;
|
---|
[3505] | 40 |
|
---|
[3222] | 41 | /** name of site to connect to */
|
---|
[3505] | 42 | protected String remote_site_name_=null;
|
---|
| 43 |
|
---|
[3222] | 44 | /** converter for String to DOM and vice versa */
|
---|
| 45 | protected XMLConverter converter_= null;
|
---|
| 46 |
|
---|
| 47 | public Communicator() {
|
---|
| 48 | converter_ = new XMLConverter();
|
---|
| 49 | }
|
---|
[9824] | 50 | public void cleanUp() {}
|
---|
[3505] | 51 |
|
---|
| 52 | public void setLocalSiteName(String name) {
|
---|
[3222] | 53 | local_site_name_ = name;
|
---|
| 54 | }
|
---|
[3505] | 55 | /** this should be done as part of configure */
|
---|
| 56 | public void setRemoteSiteName(String name) {
|
---|
| 57 | remote_site_name_ = name;
|
---|
[3222] | 58 | }
|
---|
[3505] | 59 | /** configures the Communicator using the <site> element */
|
---|
| 60 | abstract public boolean configure(Element site_elem);
|
---|
[3222] | 61 |
|
---|
[4035] | 62 | public String process(String xml_in) {
|
---|
| 63 | Element e = converter_.getDOM(xml_in).getDocumentElement();
|
---|
| 64 | Node result = process(e);
|
---|
| 65 | return converter_.getString(result);
|
---|
| 66 | }
|
---|
[3222] | 67 |
|
---|
[3502] | 68 | abstract public Element process(Element xml_in);
|
---|
[3222] | 69 | }
|
---|