Java 3D Desktop Environment旨在使用Java 3D来创建一个3D桌面环境。功能包括:分布式的应用程序
源代码在线查看: distributedevent.java
package org.j3de.events;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import java.security.PublicKey;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.SignatureException;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import org.j3de.security.SecurityFactory;
import org.j3de.exception.ExceptionHandler;
public final class DistributedEvent implements Serializable {
private PublicKey receiver;
private PublicKey sender;
private byte[] encodedEvent;
private byte[] signed;
private String classname;
public DistributedEvent(PublicKey receiver,
Class receiverApp,
Serializable event,
SecurityFactory securityFactory) throws DistributedEventCreationException {
this.receiver = receiver;
this.sender = securityFactory.getPublicKey();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out =
new ObjectOutputStream(
new CipherOutputStream(baos, securityFactory.getEncodingCipher()));
out.writeObject(event);
out.close();
Signature signature = securityFactory.getSignature();
signature.update(encodedEvent);
this.encodedEvent = baos.toByteArray();
this.signed = signature.sign();
this.classname = receiverApp.getName();
} catch (IOException e) {
throw new DistributedEventCreationException(e);
} catch (SignatureException e2) {
throw new DistributedEventCreationException(e2);
}
}
public PublicKey getReceiver() {
return receiver;
}
public PublicKey getSender() {
return sender;
}
public Object getEvent(SecurityFactory securityFactory)
throws DistributedEventCorruptedException, UnknownEventException {
try {
ByteArrayInputStream baos = new ByteArrayInputStream(encodedEvent);
ObjectInputStream in =
new ObjectInputStream(
new CipherInputStream(baos, securityFactory.getDecodingCipher()));
Object obj = in.readObject();
in.close();
return obj;
} catch (StreamCorruptedException e) {
throw new DistributedEventCorruptedException(e);
} catch (IOException e2) {
throw new DistributedEventCorruptedException(e2);
} catch (ClassNotFoundException e3) {
throw new UnknownEventException(e3.getMessage());
}
}
public boolean verify(SecurityFactory securityFactory) {
try {
Signature signature = securityFactory.getVerifySignature(sender);
signature.update(encodedEvent);
return signature.verify(signed);
} catch (SignatureException e) {
ExceptionHandler.handleException(e);
return false;
}
}
}