本文整理汇总了Java中org.javarosa.core.model.QuestionDef.isComplex方法的典型用法代码示例。如果您正苦于以下问题:Java QuestionDef.isComplex方法的具体用法?Java QuestionDef.isComplex怎么用?Java QuestionDef.isComplex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.javarosa.core.model.QuestionDef
的用法示例。
在下文中一共展示了QuestionDef.isComplex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: answerQuestion
import org.javarosa.core.model.QuestionDef; //导入方法依赖的package包/类
/**
* Attempts to save the answer at the specified FormIndex into the
* datamodel.
*
* @param index
* @param data
* @return OK if save was successful, error if a constraint was violated.
*/
public int answerQuestion(FormIndex index, IAnswerData data, boolean midSurvey) {
QuestionDef q = model.getQuestionPrompt(index).getQuestion();
if (model.getEvent(index) != FormEntryController.EVENT_QUESTION) {
throw new RuntimeException("Non-Question object at the form index.");
}
TreeElement element = model.getTreeElement(index);
boolean complexQuestion = q.isComplex();
boolean hasConstraints = false;
if (element.isRequired() && data == null) {
return ANSWER_REQUIRED_BUT_EMPTY;
} else if (!complexQuestion && !model.getForm().evaluateConstraint(index.getReference(), data)) {
return ANSWER_CONSTRAINT_VIOLATED;
} else if (!complexQuestion) {
commitAnswer(element, index, data, midSurvey);
return ANSWER_OK;
} else if (complexQuestion && hasConstraints) {
//TODO: itemsets: don't currently evaluate constraints for itemset/copy -- haven't figured out how handle it yet
throw new RuntimeException("Itemsets do not currently evaluate constraints. Your constraint will not work, please remove it before proceeding.");
} else {
try {
model.getForm().copyItemsetAnswer(q, element, data, midSurvey);
} catch (InvalidReferenceException ire) {
ire.printStackTrace();
throw new RuntimeException("Invalid reference while copying itemset answer: " + ire.getMessage());
}
return ANSWER_OK;
}
}
示例2: checkQuestionConstraint
import org.javarosa.core.model.QuestionDef; //导入方法依赖的package包/类
public int checkQuestionConstraint(IAnswerData data) {
FormIndex index = model.getFormIndex();
QuestionDef q = model.getQuestionPrompt(index).getQuestion();
if (model.getEvent(index) != FormEntryController.EVENT_QUESTION) {
throw new RuntimeException("Non-Question object at the form index.");
}
TreeElement element = model.getTreeElement(index);
if (element.isRequired() && data == null) {
return ANSWER_REQUIRED_BUT_EMPTY;
}
// A question is complex when it has a copy tag that needs to be
// evaluated by copying in the correct xml subtree. XXX: The code to
// answer complex questions is incomplete, but luckily this feature is
// rarely used.
boolean complexQuestion = q.isComplex();
if (complexQuestion) {
// TODO PLM: unsure how to check constraints of 'complex' questions
return ANSWER_OK;
} else {
if (!model.getForm().evaluateConstraint(index.getReference(), data)) {
// constraint checking failed
return ANSWER_CONSTRAINT_VIOLATED;
}
return ANSWER_OK;
}
}
示例3: answerQuestion
import org.javarosa.core.model.QuestionDef; //导入方法依赖的package包/类
/**
* Attempts to save the answer at the specified FormIndex into the
* datamodel.
*
* @return OK if save was successful, error if a constraint was violated.
*/
public int answerQuestion(FormIndex index, IAnswerData data) {
QuestionDef q = model.getQuestionPrompt(index).getQuestion();
if (model.getEvent(index) != FormEntryController.EVENT_QUESTION) {
throw new RuntimeException("Non-Question object at the form index.");
}
TreeElement element = model.getTreeElement(index);
// A question is complex when it has a copy tag that needs to be
// evaluated by copying in the correct xml subtree. XXX: The code to
// answer complex questions is incomplete, but luckily this feature is
// rarely used.
boolean complexQuestion = q.isComplex();
boolean hasConstraints = false;
if (element.isRequired() && data == null) {
return ANSWER_REQUIRED_BUT_EMPTY;
}
if (complexQuestion) {
if (hasConstraints) {
//TODO: itemsets: don't currently evaluate constraints for
//itemset/copy -- haven't figured out how handle it yet
throw new RuntimeException("Itemsets do not currently evaluate constraints. Your constraint will not work, please remove it before proceeding.");
} else {
try {
model.getForm().copyItemsetAnswer(q, element, data);
} catch (InvalidReferenceException ire) {
ire.printStackTrace();
throw new RuntimeException("Invalid reference while copying itemset answer: " + ire.getMessage());
}
q.getActionController().triggerActionsFromEvent(Action.EVENT_QUESTION_VALUE_CHANGED, model.getForm());
return ANSWER_OK;
}
} else {
if (!model.getForm().evaluateConstraint(index.getReference(), data)) {
// constraint checking failed
return ANSWER_CONSTRAINT_VIOLATED;
}
commitAnswer(element, index, data);
q.getActionController().triggerActionsFromEvent(Action.EVENT_QUESTION_VALUE_CHANGED, model.getForm());
return ANSWER_OK;
}
}