1 16 package rmitest; 17 18 import java.io.IOException; 20 import java.io.StringReader; 21 22 import java.rmi.Naming; 24 import java.rmi.RemoteException; 25 import java.rmi.NotBoundException; 26 27 import org.xml.sax.InputSource; 29 import org.xml.sax.SAXException; 30 31 import org.apache.cocoon.ProcessingException; 33 import org.apache.cocoon.generation.ComposerGenerator; 34 35 import org.apache.avalon.framework.parameters.Parameters; 38 import org.apache.avalon.framework.parameters.ParameterException; 39 import org.apache.avalon.framework.component.ComponentException; 40 41 import org.apache.excalibur.xml.sax.SAXParser; 43 44 96 public class RMIGenerator extends ComposerGenerator { 97 98 105 public void generate () throws IOException, SAXException, ProcessingException { 106 String host; 107 108 try { 110 host = parameters.getParameter("host"); 111 if (host == "") { 113 throw new ParameterException("The parameter 'host' may not be the empty string"); 114 } 115 } catch (ParameterException pe) { 116 throw new ProcessingException("Parameter 'host' not specified",pe); 118 } 119 120 String bindname; 121 122 try { 124 bindname = parameters.getParameter("bindname"); 125 if (bindname == "") { 127 throw new ParameterException("The parameter 'bindname' may not be the empty string"); 128 } 129 } catch (ParameterException pe) { 130 throw new ProcessingException("Parameter 'bindname' not specified",pe); 132 } 133 134 String port = ""; 135 try { 137 port = parameters.getParameter("port"); 138 port = ":" + port; 139 } catch (ParameterException pe) { 140 port = ""; 143 } 144 145 try { 146 ServerFunctions obj = (ServerFunctions)Naming.lookup("//" + host + port + "/" + bindname); 147 String message = ""; 148 149 if (this.source == null) { 152 message = obj.sayHello(); 153 } else { 154 message = obj.getResource(this.source); 155 } 156 157 SAXParser parser = null; 158 parser = (SAXParser)this.manager.lookup(SAXParser.ROLE); 159 InputSource inputSource = new InputSource(new StringReader(message)); 160 parser.parse(inputSource,super.xmlConsumer); 161 } catch (NotBoundException nbe) { 162 throw new ProcessingException("Error looking up the RMI application server",nbe); 163 } catch (ComponentException ce) { 164 throw new ProcessingException("Error obtaining a SAXParser",ce); 165 } 166 } 167 } 168 169 | Popular Tags |