📄 testbean.java
字号:
/* * SchoolEJB - CyberDemia's library of EJBs for educational related services. * Copyright (C) 2003 CyberDemia Research and Services * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * See the COPYING file located in the top-level-directory of * the archive of this library for complete text of license. */package com.cyberdemia.school;import javax.ejb.*;import java.util.*;/** * TestBean models a test consisting of one or more questions. * * @ejb.bean name="TestBean" * type="CMP" * view-type="local" * schema="Test" * cmp-version="2.x" * primkey-field="id" * local-jndi-name="ejb/LocalTest" * * @ejb.util generate="physical" * @ejb.interface local-class="com.cyberdemia.school.LocalTest" local-extends="javax.ejb.EJBLocalObject" * @ejb.home local-class="com.cyberdemia.school.LocalTestHome" local-extends="javax.ejb.EJBLocalHome" * @ejb.persistence table-name="Test" * * @ejb.finder signature="java.util.Collection findAll()" * query="SELECT DISTINCT OBJECT(t) FROM Test t" * * @ejb.finder signature="java.util.Collection findAllActive()" * query="SELECT DISTINCT OBJECT(t) FROM Test t WHERE t.active=true" * * @jboss.method-attributes pattern="get*" read-only="true" * @jboss.method-attributes pattern="is*" read-only="true" * @jboss.method-attributes pattern="has*" read-only="true" * * * @author Alexander Yap * @version $Revision: 1.5 $ at $Date: 2004/05/10 15:29:37 $ by $Author: alexycyap $ * */public abstract class TestBean extends AbstractActivity{ /** * Default passing percentage. */ public static final double PASSING_PERCENTAGE=50.0; /** * Gets Collection of all questions (LocalQuestion interfaces) associated with this test. * * @ejb.interface-method * @ejb.relation name="test-questions" role-name="test-has-questions" target-ejb="QuestionBean" target-role-name="questions-belongs-to-test" * * @return Collection of LocalQuestion interfaces. */ public abstract Collection getQuestions(); /** * Sets Collection of all questions (LocalQuestion interfaces) associated with this test. * * @ejb.interface-method * * @param quesCol Collection of LocalQuestion interfaces. */ public abstract void setQuestions(Collection quesCol); /** * Gets the score threshold in percentage for passing this test. * * @ejb.interface-method * @ejb.persistence * * @return Passing percentage, between 0 and 100. */ public abstract double getPassPercentage(); /** * Sets the score threshold in percentage for passing this test. * * @ejb.interface-method * * @param pass Passing percentage, between 0 and 100. */ public abstract void setPassPercentage(double pass); /** * Checks if this test should display all its questions simultaneously * in a single page or one question at a time. * * @ejb.interface-method * @ejb.persistence * * @return true if all questions should be displayed in a single page, false if only one question at a time. */ public abstract boolean getMultiQuestionsMode(); /** * Sets if this test should display all its questions simultaneously * in a single page or one question at a time. * * @ejb.interface-method * * @param mode true if all questions should be displayed in a single page, false if only one question at a time. */ public abstract void setMultiQuestionsMode(boolean mode); /** * Checks whether to suppress the feedback (whether the user answered the * question correctly) after each question is answered. If this * feedback is suppressed, the user should immediately go to the next * question without knowing if the answer was correct. * This setting only applies if MultiQuestionsMode is disabled. * * @ejb.interface-method * @ejb.persistence * * @return true to suppress the feedback, false to show the feedback after each question. * @see #isMultiQuestionsMode() */ public abstract boolean getSuppressQuestionFeedback(); /** * Sets whether to suppress the feedback (whether the user answered the * question correctly) after each question is answered. If this * feedback is suppressed, the user should immediately go to the next * question without knowing if the answer was correct. * This setting only applies if MultiQuestionsMode is disabled. * * @ejb.interface-method * * @param suppress true to suppress the feedback, false to show the feedback after each question. * @see #isMultiQuestionsMode() */ public abstract void setSuppressQuestionFeedback(boolean suppress); /** * Checks whether to suppress the feedback (which questions were answered correctly * or wrongly) at the completion of a test. * The client should also hide the test results in any review or historical * displays when this is enabled. * * @ejb.interface-method * @ejb.persistence * * @return true to suppress the feedback, false to show the feedback at the completion of a test. */ public abstract boolean getSuppressTestEndFeedback(); /** * Sets whether to suppress the feedback (which questions were answered correctly * or wrongly) at the end of a test. * * @ejb.interface-method * * @param suppress true to suppress the feedback, false to show the feedback at the end of a test. */ public abstract void setSuppressTestEndFeedback(boolean suppress); /** * Sets the allocated time limit (in seconds) for this test. * * @ejb.interface-method * * @param limit Time limit in seconds, or 0 (or negative) for no time limit. */ public abstract void setTimeLimitSeconds(int limit); /** * Gets the allocated time limit (in seconds) for this test. * * @ejb.interface-method * @ejb.persistence * * @return Time limit in seconds, or 0 (or negative) for no time limit. */ public abstract int getTimeLimitSeconds(); /** * Checks if this test has questions. * * @ejb.interface-method * * @return true if this test has questions, otherwise false. */ public boolean hasQuestions() { return !getQuestions().isEmpty(); } /** * Checks if this test should display all its questions simultaneously * in a single page or one question at a time. * * @ejb.interface-method * * @return true if all questions should be displayed in a single page, false if only one question at a time. */ public boolean isMultiQuestionsMode() { return getMultiQuestionsMode(); } /** * Checks whether to suppress the feedback (whether the user answered the * question correctly) after each question is answered. If this * feedback is suppressed, the user should immediately go to the next * question without knowing if the answer was correct. * This setting only applies if MultiQuestionsMode is disabled. * * @ejb.interface-method * * @return true to suppress the feedback, false to show the feedback after each question. * @see #isMultiQuestionsMode() */ public boolean isSuppressQuestionFeedback() { return getSuppressQuestionFeedback(); } /** * Checks whether to suppress the feedback (which questions were answered correctly * or wrongly) at the completion of a test. * The client should also hide the test results in any review or historical * displays when this is enabled. * * @ejb.interface-method * * @return true to suppress the feedback, false to show the feedback at the completion of a test. */ public boolean isSuppressTestEndFeedback() { return getSuppressTestEndFeedback(); } /** * Gets List of questions (LocalQuestion interfaces) associated with this test. * The number of questions returned is specified by <i>count</i> if * there are enough questions, otherwise its all the available questions. * The current implementation simply returns the first <i>count</i> * questions. * * @ejb.interface-method * * @param count Desired number of questions to return. * @return List of LocalQuestion interfaces. */ public List getQuestions(int count) { Iterator qIter = getQuestions().iterator(); List quesList = new ArrayList(); for (int qcnt=0; (qcnt<count) && qIter.hasNext(); qcnt++) { quesList.add( qIter.next() ); } return quesList; } /** * Adds question to this test. * * @ejb.interface-method * * @param ques Question to add. */ public void addQuestion( LocalQuestion ques ) { if (isActive()) { Collection quesCol = getQuestions(); if (!quesCol.contains(ques)) { quesCol.add(ques); ques.setAssignedToTest(true); } } } /** * Removes question from this test. * * @ejb.interface-method * * @param ques Question to remove. */ public void removeQuestion( LocalQuestion ques ) { Collection quesCol = getQuestions(); if (quesCol.contains(ques)) { ques.setAssignedToTest(false); quesCol.remove(ques); } } /** * Removes all questions from this test. * * @ejb.interface-method * */ public void removeAllQuestions() { Collection quesCol = getQuestions(); Iterator quesIter = quesCol.iterator(); while (quesIter.hasNext()) { LocalQuestion ques = (LocalQuestion)quesIter.next(); ques.setAssignedToTest(false); } quesCol.clear(); } /** * Actives this test, so that it may be editted and used. * This method may perform some checks first to ensure that this test * can be safely activated. * * @ejb.interface-method * * @return true if this test is activated, false if it is not (either a problem or it is already active) */ public boolean activate() { // Can always activate as long as it is currently inactive. if (!isActive()) { setActive(true); return true; } return false; } /** * Deactives this test, after which it may be considered to be logically removed * from the system. * This method may perform some checks first to ensure that this test * can be safely deactivated. * * @ejb.interface-method * * @return true if this test is deactivated, false if it is not (either a problem or it is already inactive) */ public boolean deactivate() { if (isActive() ) { setActive(false); return true; } return false; } //----------------------------- // Create methods. //----------------------------- /** * Creates an Test. * * @ejb.create-method view-type="local" */ public Integer ejbCreate( String name, String ownerHierId, double passPercentage, int timeLimitSecs, boolean multiQuesMode, boolean suppressQuesFeedback, boolean suppressTestEndFeedback ) throws CreateException { // Note : Unique ID is assigned by database auto-increment setName(name); setOwnerHierarchyId( ownerHierId); setPassPercentage( passPercentage ); setTimeLimitSeconds(timeLimitSecs); setActive(true); long nowMillis = System.currentTimeMillis(); setCreatedMillis( nowMillis ); setLastModifiedMillis(nowMillis); setMultiQuestionsMode(multiQuesMode); setSuppressQuestionFeedback(suppressQuesFeedback); setSuppressTestEndFeedback(suppressTestEndFeedback); m_owner = null; return null; } public void ejbPostCreate( String name, String ownerHierId, double passPercentage, int timeLimitSecs, boolean multiQuesMode, boolean suppressQuesFeedback, boolean suppressTestEndFeedback ) { // Nothing here } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -