public void documentReady(DOMEvent evt)
throws XbeansException {
try {
URL receiver = new URL (getRemoteURL ());
URLConnection receiverConnection = receiver.openConnection();
receiverConnection.setDoOutput(true);
//向发送者打开一个输出流然后发送文本形式的XML数据
OutputStream out = receiverConnection.getOutputStream();
DOMWriter writer = new DOMWriter();
writer.setPRintWriter(new PrintWriter(out));
writer.documentReady(
new com.ibm.xml.XPk4j.dom.DOMEvent( this,evt.getDocument()));
out.close(); // 为结果打开一个输入流
BufferedReader in = New BufferedReader(
new InputStreamReader(receiverConnection.getInputStream()));
// 处理结果:"OK" 表示成功;"Exception" 表示输入流串行化异常
...
in.close();
} catch (Throwable e) {
e.printStackTrace(System.err);
}
}
import org.xbeans.communication.stdio.receiver.*;
public class receiverMain {
static Bean theReceiver = new Bean();
public static void main(String[] args) {
theReceiver.receiveDocument();
}
}
DOMParser parser = new DOMParser(); // 构造解析器
try { // 调用解析器
parser.parse(new InputSource(System.in));
} catch (Throwable e) {
throw new XbeansException("","receiver","io error parsing incoming document",
"io error parsing incoming document "+e);
}
//将文档传向下一个bean
DOMListener.documentReady(new DOMEvent(this,parser.getDocument()));
public void documentReady(DOMEvent evt) throws XbeansException {
if (DOMListener==null) {
try {
DOMListener = (DOMListener)Naming.lookup(getReceiverName());
} catch (Exception e) {
throw new XbeansException( evt.getDocument().getNodeName(),
"sender", "error oBTaining remote receiver",
"The name may be wrong or the network may be down.");
}
}
DOMListener.documentReady(evt); }
public void setReceiverName(String newName) {
try {
if (receiverName!=null) Naming.unbind(receiverName);
receiverName = newName;
Naming.rebind(receiverName, this );
} catch( Exception e ) {
System.out.println( e );
}
}
public void documentReady(Document incomingDocument)
throws RemoteException, XbeansException {
if (DOMListener==null) {
throw new XbeansException(incomingDocument.getNodeName(),"rmiReceiver",
"next component not established", "The component needs to be configured.");
}
DOMListener.documentReady(new DOMEvent(this,incomingDocument));
}
exception RemoteReceiverException {
string remoteIdentifier;
string documentName;
string componentName;
string message;
string moreMessage;
};
typedef sequence byteArray;
interface XMLReceiver {
void documentReady(in byteArray serializedDocument)
raises(RemoteReceiverException);
};
public void documentReady(DOMEvent evt) throws XbeansException {
Document documentToSend = evt.getDocument();
try {
ByteArrayOutputStream bastream = new ByteArrayOutputStream();
ObjectOutputStream p = new ObjectOutputStream(bastream);
p.writeObject(documentToSend);
p.flush();
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init( new String[0],
System.getProperties());
XMLReceiver receiver = urlToObject(orb,getReceiverURL());
receiver.documentReady(bastream.toByteArray());
} catch (RemoteReceiverException rre) {
throw new XbeansException(rre.remoteIdentifier, rre.documentName,
rre.componentName, rre.message,rre.moreMessage);
} catch (Throwable e) {
throw new XbeansException("","sender", "error sending document "+e,
"error sending document "+e);
}
}
public void documentReady(byte[] serializedDocument)throws RemoteReceiverException {
// 反串行化字节流
ByteArrayInputStream bais = new ByteArrayInputStream(serializedDocument);
Document theDocument;
try {
ObjectInputStream ois = new ObjectInputStream(bais);
theDocument = (Document)ois.readObject();
} catch(Throwable e) {
throw new RemoteReceiverException(corbaName,"incoming document","receiver",
"error deserializing document","error deserializing document"+e);
}
try { //将文档传向监听者
local.DOMListener.documentReady(new DOMEvent(this,theDocument));
} catch (XbeansException xbe) {
throw new RemoteReceiverException( xbe.remoteIdentifier(),
xbe.documentName(),xbe.componentName(),
xbe.message(),xbe.moreMessage());
}
}
新闻热点
疑难解答