📄 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.
*/
// The bean receives a byte array from a sender.
// The byte array is the Java serialized form of an XML/DOM document. The
// implementation of the DOM document must be compatible at both the sender and
// the receiver. Once the byte array is received and deserialized into a functioning
// DOM document, it is passed on to the next DOMListener.
// The receiver bean is a CORBA object. The bean is exported
// to VisiBroker using the corbaName property as it's identifier.
// This sender/receiver pair is suitable for use inside of an enterprise.
// The sender bean uses the simple-minded VisiBroker bind() mechanism to
// locate the receiver. Furthermore, the implementations
// do not address any of the issues that would need to be addressed over the
// internet, such as security.
package org.xbeans.communication.corba.receiver;
import org.xbeans.*;
import org.xbeans.communication.corba.*;
import org.w3c.dom.Document;
import java.io.*;
public class Bean extends _XMLReceiverImplBase
implements DOMSource, Runnable {
private Bean delegate=null;
private Bean local=null;
private DOMListener DOMListener;
private String receiverId;
private static org.omg.CORBA.BOA boa=null;
private static org.omg.CORBA.ORB orb=null;
// Two beans are necessary in order to support setting the name as a property
// The local bean is instantiated with a null constructor and all of the properties
// are set on the local bean. When the corbaName property is set, the corba
// delegate bean is created and exported using the corbaName name.
// The constructor for the local instance
public Bean() {
}
// This constructor is for the corba delegate bean
public Bean(String cname, Bean _local) {
super(cname);
local=_local;
}
// DomSource methods
/** Sets the target listener for the DOM events. */
public void setDOMListener(DOMListener newDomListener) {
DOMListener = newDomListener;
}
/** Returns the target listener for the DOM events. */
public DOMListener getDOMListener(){
return DOMListener;
}
// XMLReceiver method in the IDL
public void documentReady(byte[] serializedDocument) throws RemoteReceiverException {
if (local.DOMListener==null) {
throw new RemoteReceiverException(
receiverId,
"incoming document",
"receiver",
"next component not established",
"The component needs to be configured."
);
}
// Deserialize the byte stream.
ByteArrayInputStream bais = new ByteArrayInputStream(serializedDocument);
Document theDocument;
try {
ObjectInputStream ois = new ObjectInputStream(bais);
theDocument = (Document)ois.readObject();
} catch(Throwable e) {
throw new RemoteReceiverException(
receiverId,
"incoming document",
"receiver",
"error deserializing document",
"error deserializing document"+e
);
}
// Pass on the document to the listeners
DOMEvent evt = new DOMEvent(this,theDocument);
try {
local.DOMListener.documentReady(evt);
} catch (XbeansException xbe) {
throw new RemoteReceiverException(
xbe.remoteIdentifier(),
xbe.documentName(),
xbe.componentName(),
xbe.message(),
xbe.moreMessage()
);
}
}
// Once the receiverId property is set, a delegate bean is created to
// provide distributed object services for receiving DOM documents
public void setReceiverId(String newReceiverId) {
receiverId = newReceiverId;
if (orb==null) {
orb = com.visigenic.vbroker.orb.ORB.init((String[]) null, System.getProperties());
boa = ((com.visigenic.vbroker.orb.ORB)orb).BOA_init();
}
delegate = new Bean(receiverId,this);
boa.obj_is_ready(delegate);
(new Thread(delegate)).start();
}
public void run() {
boa.impl_is_ready();
}
public String getReceiverId() {
return receiverId;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -