📄 bean.java
字号:
/*
Copyright (c) 1999 Bruce Martin, a contributor to the Xbean project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// A simple minded sender bean to transport XML using Java serialization and
// CORBA to a compatible receiver bean.
package org.xbeans.communication.corba.sender;
import org.xbeans.*;
import org.xbeans.communication.corba.*;
import org.w3c.dom.Document;
import java.io.*;
public class Bean implements DOMListener {
private String receiverId;
public Bean() {
}
// DomListener method
// Simply uses the Java serialization mechanism to create a byte array
// for the incoming document and sends the byte array to the receiver
// via a CORBA call designed to mimic DomListener.
//
// The receiver is found by using the VisiBroker bind() call.
// The identifier passed to the bind() call is specified as a property.
//
// Note that for this to work, the receiver must have the same implementation
// of the DOM. Otherwise, the deserialization into dom objects at the receiver
// side will fail.
public void documentReady(DOMEvent evt) throws XbeansException {
Document documentToSend = evt.getDocument();
if (documentToSend==null) throw new XbeansException(
"",
"sender",
"sender invoked without a document",
"sender invoked without a document"
);
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 = XMLReceiverHelper.bind(orb,getReceiverId());
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 setReceiverId(String newReceiverId) {
receiverId = newReceiverId;
}
public String getReceiverId() {
return receiverId;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -