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

📄 jlisttestcdbeantask.java

📁 主要是对串口驱动的的一些控制源码!!! 在下载javacomm20-win32.zip后就可以使用。
💻 JAVA
字号:
/**
 * $Log: JListTestCDBeanTask.java,v $
 * Revision 1.3  2003/03/12 14:57:14  willaxt
 * adjusted to new exception handling of communication exceptions
 * adjusted to call getPanel() because member of super class is no longer public
 *
 * Revision 1.2  2003/02/07 11:31:07  mwulff
 * no message
 *
 * Revision 1.1  2003/02/02 12:50:52  mwulff
 * initial version
 *
 */
package de.fhm.jkf.test.cl;

import java.util.Collection;
import java.util.Iterator;

import de.fhm.jkf.comm.cl.JKFFactory;
import de.fhm.jkf.comm.cl.ObjectFactory;
import de.fhm.jkf.gui.CommunicationTask;
import de.fhm.jkf.gui.JKFView;
import de.fhm.jkf.test.clsv.LocalCD;

/**
 * <br><br><center><table border="1" width="80%"><hr>
 * <strong><a href="http://jkf.sourceforge.net">The JKF Project</a></strong>
 * <p>
 * Copyright (C) 2002 by Marten Wulff
 * <p>
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * <p>
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * <p>
 * You should have received a copy of the <a href="http://www.gnu.org/copyleft/lesser.html">
 * GNU Lesser General Public License</a> along with this library; if not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA  02111-1307  USA
 * <hr></table></center>
 * 
 * @author		marten wulff
 * @version 	1.0
 */
public class JListTestCDBeanTask extends CommunicationTask {

	private StringBuffer result = new StringBuffer();
	private final String jndiName = "bean/CD";

	/**
	 * Constructor for JListTestCDBeanTask.
	 * @param panel
	 */
	public JListTestCDBeanTask(JKFView panel) {
		super(panel);
	}

	/* (non-Javadoc)
	 * @see de.fhm.jkf.gui.CommunicationTask#doPresentation()
	 */
	public void doPresentation() {
		JListTestTO o = new JListTestTO();
		o.setText(result.toString());

		try {
			this.getPanel().setTransferObject(o);
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

	/* (non-Javadoc)
	 * @see de.fhm.jkf.gui.CommunicationTask#doQuery()
	 */
	public void doQuery() {

		ObjectFactory factory = JKFFactory.instance().getFactory();

		result.append(
			"\n\n******************** "
				+ this.getClass().getName()
				+ " ***************************\n");

		Object[] param = new Object[5];

		LocalCD cd1 = null;
		LocalCD cd2 = null;
		LocalCD cd3 = null;
		LocalCD cd4 = null;

		// first step is creating some entity beans

		result.append("========== Creating EJBs ==========\n");

		try {
			param[0] = new Integer(1);
			param[1] = new String("classic");
			param[2] = new String("Verdi best of");
			param[3] = new Float(25.95);
			param[4] = new String("Verdi");
			cd1 = (LocalCD) factory.createEJB(LocalCD.class, param, jndiName);
		} catch (Exception ex) {
			result.append("Couldn't create Bean 1!: " + ex.getMessage() + "\n");
		}

		try {
			param[0] = new Integer(2);
			param[1] = new String("classic");
			param[2] = new String("Verdi second best of");
			param[3] = new Float(33.85);
			param[4] = new String("Verdi");
			cd2 = (LocalCD) factory.createEJB(LocalCD.class, param, jndiName);

		} catch (Exception ex) {
			result.append("Couldn't create Bean 2!: " + ex.getMessage() + "\n");
		}

		result.append("========== EJBs creation done ==========\n");

		// now let's find the created entity beans by its primary key
		try {
			result.append(
				"========== Finding EJB by primary key (id = 1) ==========\n");
			param = new Object[1];
			param[0] = new Integer(1);

			cd3 =
				(LocalCD) factory.findByPrimaryKey(
					LocalCD.class,
					param,
					jndiName);

			result.append("Entity Bean found:\n");
			result.append("ID: " + cd3.getId() + "\n");
			result.append("Title: " + cd3.getTitle() + "\n");
			result.append("Price: " + cd3.getPrice() + "\n");
			result.append("Artist: " + cd3.getArtist() + "\n");
			result.append("Genre: " + cd3.getGenre() + "\n");

		} catch (Exception ex) {
			result.append("Error finding EJB 1!:" + ex.getMessage() + "\n");
			ex.printStackTrace();
		}

		try {
			result.append(
				"========== Finding EJB by primary key (id = 2) ==========\n");
			param[0] = new Integer(2);
			cd4 =
				(LocalCD) factory.findByPrimaryKey(
					LocalCD.class,
					param,
					jndiName);

			result.append("Entity Bean found:\n");
			result.append("ID: " + cd4.getId() + "\n");
			result.append("Title: " + cd4.getTitle() + "\n");
			result.append("Price: " + cd4.getPrice() + "\n");
			result.append("Artist: " + cd4.getArtist() + "\n");
			result.append("Genre: " + cd4.getGenre() + "\n");

		} catch (Exception ex) {
			result.append("Couldn't find EJB 2!: " + ex.getMessage() + "\n");
		}

		try {
			result.append("========== Finding classic cds ==========\n");
			param[0] = new String("classic");
			// find by genre
			Collection cds =
				factory.findByXXX(
					LocalCD.class,
					param,
					jndiName,
					"findByGenre");
			Iterator it = cds.iterator();
			LocalCD cd = null;
			while (it.hasNext()) {
				cd = (LocalCD) it.next();

				result.append("ID: " + cd.getId() + "\n");
				result.append("Title: " + cd.getTitle() + "\n");
				result.append("Price: " + cd.getPrice() + "\n");
				result.append("Artist: " + cd.getArtist() + "\n");
				result.append("Genre: " + cd.getGenre() + "\n");

			}
		} catch (Exception ex) {
			result.append("Couldn't find Beans !!!\n");
		}

		// deleting the created bean
		result.append("========== Deleting EJBs ==========\n");
		try {
			if (cd1 != null) {
				cd1.remove();
			} else {
				cd3.remove();
			}
		} catch (Exception ex) {
			result.append("Error removing EJB: " + ex.getMessage() + "\n");
		}

		try {
			if (cd2 != null) {
				cd2.remove();
			} else {
				cd4.remove();
			}
		} catch (Exception ex) {
			result.append("Error removing EJB: " + ex.getMessage() + "\n");
		}

		result.append("========== EJBs deleted ==========\n");

	}

	/* (non-Javadoc)
	 * @see de.fhm.jkf.thread.cl.InterruptableTask#interrupt()
	 */
	public void interrupt() {
	}
}

⌨️ 快捷键说明

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