⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boardbean.java

📁 用java编写的留言版
💻 JAVA
字号:
package com.bitterjava.bbs.ejb;

import java.rmi.RemoteException;
import java.security.Identity;
import java.util.Properties;
import javax.ejb.*;
/**
 * This is an Entity Bean class with CMP fields
 */
public class BoardBean implements EntityBean {
	private javax.ejb.EntityContext entityContext = null;
	public String name;
	private java.util.Vector threads;
	private ThreadHome threadHome = null;
	final static long serialVersionUID = 3206093459760846163L;

/**
 * This method was generated for supporting the associations.
 * @return java.util.Vector
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
protected java.util.Vector _getLinks() {
	java.util.Vector links = new java.util.Vector();
	return links;
}
/**
 * This method was generated for supporting the associations.
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
protected void _initLinks() {}
/**
 * This method was generated for supporting the associations.
 * @exception java.rmi.RemoteException The exception description.
 * @exception javax.ejb.RemoveException The exception description.
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
protected void _removeLinks() throws java.rmi.RemoteException, javax.ejb.RemoveException {
	java.util.Enumeration links = _getLinks().elements();
	while (links.hasMoreElements()) {
		try {
			((com.ibm.ivj.ejb.associations.interfaces.Link) (links.nextElement())).remove();
		}
		catch (javax.ejb.FinderException e) {} //Consume Finder error since I am going away
	}
}
/**
 * Insert the method's description here.
 * Creation date: (9/25/2001 1:41:20 PM)
 * @param threadName java.lang.String
 */
public int addThread(String threadName) throws RemoteException, CreateException {
	int nextID = 0;
	for (int i = 0; i < threads.size(); i++) {
		Thread thread = resolveThread(i);
		int threadID = thread.getThreadID();
		nextID = Math.max(nextID, threadID+1);
	}
	Thread newThread = getThreadHome().create(name, nextID);
	newThread.setName(threadName);
	threads.addElement(newThread);
	return nextID;
}
/**
 * ejbActivate method comment
 * @exception java.rmi.RemoteException The exception description.
 */
public void ejbActivate() throws java.rmi.RemoteException {
	_initLinks();
}
/**
 * ejbCreate method for a CMP entity bean
 * @param argName java.lang.String
 * @exception javax.ejb.CreateException The exception description.
 * @exception java.rmi.RemoteException The exception description.
 */
public void ejbCreate(java.lang.String argName) throws javax.ejb.CreateException, java.rmi.RemoteException {
	_initLinks();
	// All CMP fields should be initialized here.
	name = argName;
	threads = new java.util.Vector();
}
/**
 * ejbLoad method comment
 * @exception java.rmi.RemoteException The exception description.
 */
public void ejbLoad() throws java.rmi.RemoteException {
	_initLinks();

	try {
		threads = new java.util.Vector();
		java.util.Enumeration e = getThreadHome().findAllForBoard(name);
		while (e.hasMoreElements()) {
			threads.addElement(e.nextElement());
		}
	}
	catch (FinderException e) {
	}
	catch (NullPointerException e) {
	}
}
/**
 * ejbPassivate method comment
 * @exception java.rmi.RemoteException The exception description.
 */
public void ejbPassivate() throws java.rmi.RemoteException {}
/**
 * ejbPostCreate method for a CMP entity bean
 * @param argName java.lang.String
 * @exception java.rmi.RemoteException The exception description.
 */
public void ejbPostCreate(java.lang.String argName) throws java.rmi.RemoteException {}
/**
 * ejbRemove method comment
 * @exception java.rmi.RemoteException The exception description.
 * @exception javax.ejb.RemoveException The exception description.
 */
public void ejbRemove() throws java.rmi.RemoteException, javax.ejb.RemoveException {
	_removeLinks();
	removeAllThreads();
}
/**
 * ejbStore method comment
 * @exception java.rmi.RemoteException The exception description.
 */
public void ejbStore() throws java.rmi.RemoteException {}
/**
 * getEntityContext method comment
 * @return javax.ejb.EntityContext
 */
public javax.ejb.EntityContext getEntityContext() {
	return entityContext;
}
/**
 * Insert the method's description here.
 * Creation date: (9/25/2001 1:39:20 PM)
 * @return java.lang.String
 */
public String getName() {
	return name;
}
/**
 * Insert the method's description here.
 * Creation date: (9/25/2001 4:54:16 PM)
 * @return com.bitterjava.bbs.ejb.Thread
 * @param threadID int
 * @exception java.rmi.RemoteException The exception description.
 */
public Thread getThread(int threadID) throws java.rmi.RemoteException {
	Thread rcThread = null;
	for (int i = 0; i < threads.size(); i++) {
		Thread thisThread = resolveThread(i);
		if (thisThread.getThreadID() == threadID) {
			rcThread = thisThread;
			break;
		}
	}
	return rcThread;
}
/**
 * Insert the method's description here.
 * Creation date: (9/25/2001 1:03:26 PM)
 * @return com.bitterjava.bbs.ejb.ThreadHome
 * @exception java.rmi.RemoteException The exception description.
 */
private ThreadHome getThreadHome() {
	if (threadHome == null) {
		try {
			Properties env = entityContext.getEnvironment();
			String providerURL = env.getProperty("providerURL");
			String threadHomeName = env.getProperty("threadHomeName");
			String ctxFactory = env.getProperty("ctxFactory");
			
			Properties p = new Properties();
		
			p.put("java.naming.provider.url", providerURL);
			p.put("java.naming.factory.initial", ctxFactory);
			javax.naming.InitialContext ic  = new javax.naming.InitialContext(p);

			java.lang.Object homeObject = ic.lookup(threadHomeName);
			threadHome = (ThreadHome)javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object)homeObject, ThreadHome.class);
		}
		catch (Exception e) {
		}

	}
	return threadHome;
}
/**
 * Insert the method's description here.
 * Creation date: (9/25/2001 1:01:26 PM)
 * @return java.util.Collection
 */
public java.util.Collection getThreads() {
	return threads;
}
/**
 * Insert the method's description here.
 * Creation date: (9/26/2001 10:26:49 PM)
 * @exception java.rmi.RemoteException The exception description.
 * @exception javax.ejb.RemoveException The exception description.
 */
public void removeAllThreads() throws java.rmi.RemoteException, javax.ejb.RemoveException {
	for (int i = 0; i < threads.size(); i++) {
		Thread thisThread = resolveThread(i);
		thisThread.remove();
	}
	threads = new java.util.Vector();
}
/**
 * Insert the method's description here.
 * Creation date: (9/25/2001 1:48:53 PM)
 * @param thread com.bitterjava.bbs.ejb.Thread
 */
public void removeThread(Thread thread) throws RemoteException, RemoveException {
	for (int i = 0; i < threads.size(); i++) {
		Thread thisThread = resolveThread(i);
		if (thisThread.isIdentical(thread)) {
			threads.remove(i);
			thisThread.remove();
			break;
		}
	}
}
/**
 * Insert the method's description here.
 * Creation date: (9/27/2001 9:56:47 AM)
 * @return com.bitterjava.bbs.ejb.Thread
 * @param threadIndex int
 */
private Thread resolveThread(int threadIndex) {
	java.lang.Object o = threads.elementAt(threadIndex);
	Thread threadEjb = (Thread)javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object)o, Thread.class);
	return threadEjb;
}
/**
 * setEntityContext method comment
 * @param ctx javax.ejb.EntityContext
 * @exception java.rmi.RemoteException The exception description.
 */
public void setEntityContext(javax.ejb.EntityContext ctx) throws java.rmi.RemoteException {
	entityContext = ctx;
}
/**
 * unsetEntityContext method comment
 * @exception java.rmi.RemoteException The exception description.
 */
public void unsetEntityContext() throws java.rmi.RemoteException {
	entityContext = null;
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -