当前位置: 首页>>代码示例>>Java>>正文


Java InvalidReferenceException类代码示例

本文整理汇总了Java中org.javarosa.core.model.instance.InvalidReferenceException的典型用法代码示例。如果您正苦于以下问题:Java InvalidReferenceException类的具体用法?Java InvalidReferenceException怎么用?Java InvalidReferenceException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InvalidReferenceException类属于org.javarosa.core.model.instance包,在下文中一共展示了InvalidReferenceException类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createNewRepeat

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的package包/类
public void createNewRepeat(FormIndex index) throws InvalidReferenceException {
    TreeReference repeatContextRef = getChildInstanceRef(index);
    TreeElement template = mainInstance.getTemplate(repeatContextRef);

    mainInstance.copyNode(template, repeatContextRef);

    preloadInstance(mainInstance.resolveReference(repeatContextRef));

    // Fire jr-insert events before "calculate"s
    triggeredDuringInsert.removeAllElements();
    actionController.triggerActionsFromEvent(Action.EVENT_JR_INSERT, this, repeatContextRef, this);

    // trigger conditions that depend on the creation of this new node
    triggerTriggerables(repeatContextRef);

    // trigger conditions for the node (and sub-nodes)
    initTriggerablesRootedBy(repeatContextRef, triggeredDuringInsert);
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:19,代码来源:FormDef.java

示例2: createModelIfBelowMaxCount

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的package包/类
private static void createModelIfBelowMaxCount(FormIndex index, FormDef form, int fullcount) {
    TreeReference ref = form.getChildInstanceRef(index);
    TreeElement element = form.getMainInstance().resolveReference(ref);
    if (element == null) {
        int instanceIndexOfDeepestRepeat = index.getLastRepeatInstanceIndex();
        if (instanceIndexOfDeepestRepeat == -1) {
            throw new RuntimeException("Attempting to expand a repeat for a form index where no repeats were present: " + index);
        }
        if (instanceIndexOfDeepestRepeat < fullcount) {
            try {
                form.createNewRepeat(index);
            } catch (InvalidReferenceException ire) {
                ire.printStackTrace();
                throw new RuntimeException("Invalid Reference while creating new repeat!" + ire.getMessage());
            }
        }
    }
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:19,代码来源:FormEntryModel.java

示例3: createNewRepeat

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的package包/类
public void createNewRepeat(FormIndex index) throws InvalidReferenceException {
    TreeReference repeatContextRef = getChildInstanceRef(index);
    TreeElement template = mainInstance.getTemplate(repeatContextRef);

    mainInstance.copyNode(template, repeatContextRef);

    // Fire jr-insert events before "calculate"s
    triggeredDuringInsert.removeAllElements();
    actionController.triggerActionsFromEvent(Action.EVENT_JR_INSERT, this, repeatContextRef, this);

    // trigger conditions that depend on the creation of this new node
    triggerTriggerables(repeatContextRef);

    // trigger conditions for the node (and sub-nodes)
    initTriggerablesRootedBy(repeatContextRef, triggeredDuringInsert);
}
 
开发者ID:dimagi,项目名称:commcare-core,代码行数:17,代码来源:FormDef.java

示例4: answerQuestion

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的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;
     }
 }
 
开发者ID:medic,项目名称:javarosa,代码行数:38,代码来源:FormEntryController.java

示例5: newRepeat

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的package包/类
/**
 * Creates a new repeated instance of the group referenced by the specified
 * FormIndex.
 *
 * @param questionIndex
 */
public void newRepeat(FormIndex questionIndex) {
	try{
		model.getForm().createNewRepeat(questionIndex);
	} catch(InvalidReferenceException ire) {
		throw new RuntimeException("Invalid reference while copying itemset answer: " + ire.getMessage());
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:14,代码来源:FormEntryController.java

示例6: createModelIfNecessary

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的package包/类
/**
 * For the current index: Checks whether the index represents a node which
 * should exist given a non-interactive repeat, along with a count for that
 * repeat which is beneath the dynamic level specified.
 *
 * If this index does represent such a node, the new model for the repeat is
 * created behind the scenes and the index for the initial question is
 * returned.
 *
 * Note: This method will not prevent the addition of new repeat elements in
 * the interface, it will merely use the xforms repeat hint to create new
 * nodes that are assumed to exist
 *
 * @param index The index to be evaluated as to whether the underlying model is
 *        hinted to exist
 */
private void createModelIfNecessary(FormIndex index) {
    if (index.isInForm()) {
        IFormElement e = getForm().getChild(index);
        if (e instanceof GroupDef) {
            GroupDef g = (GroupDef) e;
            if (g.getRepeat() && g.getCountReference() != null) {
            	// Lu Gram: repeat count XPath needs to be contextualized for nested repeat groups
            	TreeReference countRef = FormInstance.unpackReference(g.getCountReference());
            	TreeReference contextualized = countRef.contextualize(index.getReference());
                IAnswerData count = getForm().getMainInstance().resolveReference(contextualized).getValue();
                if (count != null) {
                    long fullcount = ((Integer) count.getValue()).intValue();
                    TreeReference ref = getForm().getChildInstanceRef(index);
                    TreeElement element = getForm().getMainInstance().resolveReference(ref);
                    if (element == null) {
                        if (index.getTerminal().getInstanceIndex() < fullcount) {

                          try {
                            getForm().createNewRepeat(index);
                          } catch (InvalidReferenceException ire) {
                            ire.printStackTrace();
                            throw new RuntimeException("Invalid Reference while creting new repeat!" + ire.getMessage());
                          }
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:medic,项目名称:javarosa,代码行数:47,代码来源:FormEntryModel.java

示例7: createMissingTemplates

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的package包/类
private void createMissingTemplates (FormInstance instance, List<TreeReference> missingTemplates) {
	//it is VERY important that the missing template refs are listed in depth-first or breadth-first order... namely, that
	//every ref is listed after a ref that could be its parent. checkRepeatsForTemplate currently behaves this way
	for (int i = 0; i < missingTemplates.size(); i++) {
		TreeReference templRef = missingTemplates.get(i);
		TreeReference firstMatch;

		//make template ref generic and choose first matching node
		TreeReference ref = templRef.clone();
		for (int j = 0; j < ref.size(); j++) {
			ref.setMultiplicity(j, TreeReference.INDEX_UNBOUND);
		}
        List<TreeReference> nodes = new EvaluationContext(instance).expandReference(ref);
		if (nodes.size() == 0) {
			//binding error; not a single node matches the repeat binding; will be reported later
			continue;
		} else {
			firstMatch = nodes.get(0);
		}

		try {
			instance.copyNode(firstMatch, templRef);
		} catch (InvalidReferenceException e) {
			reporter.warning(XFormParserReporter.TYPE_INVALID_STRUCTURE, "Could not create a default repeat template; this is almost certainly a homogeneity error! Your form will not work! (Failed on " + templRef.toString() + ")", null);
		}
		trimRepeatChildren(instance.resolveReference(templRef));
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:29,代码来源:XFormParser.java

示例8: newRepeat

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的package包/类
/**
 * Creates a new repeated instance of the group referenced by the specified
 * FormIndex.
 */
public void newRepeat(FormIndex questionIndex) {
    try {
        model.getForm().createNewRepeat(questionIndex);
        formEntrySession.addNewRepeat(questionIndex);
    } catch (InvalidReferenceException ire) {
        throw new RuntimeException("Invalid reference while copying itemset answer: " + ire.getMessage());
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:13,代码来源:FormEntryController.java

示例9: createModelIfNecessary

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的package包/类
/**
 * For the current index: Checks whether the index represents a node which
 * should exist given a non-interactive repeat, along with a count for that
 * repeat which is beneath the dynamic level specified.
 *
 * If this index does represent such a node, the new model for the repeat is
 * created behind the scenes and the index for the initial question is
 * returned.
 *
 * Note: This method will not prevent the addition of new repeat elements in
 * the interface, it will merely use the xforms repeat hint to create new
 * nodes that are assumed to exist
 *
 * @param index To be evaluated as to whether the underlying model is
 *              hinted to exist
 */
public void createModelIfNecessary(FormIndex index) {
    if (index.isInForm()) {
        IFormElement e = getForm().getChild(index);
        if (e instanceof GroupDef) {
            GroupDef g = (GroupDef)e;
            if (g.getRepeat() && g.getCountReference() != null) {
                IAnswerData count = getForm().getMainInstance().resolveReference(g.getConextualizedCountReference(index.getReference())).getValue();
                if (count != null) {
                    int fullcount = -1;
                    try {
                        fullcount = ((Integer)new IntegerData().cast(count.uncast()).getValue()).intValue();
                    } catch (IllegalArgumentException iae) {
                        throw new RuntimeException("The repeat count value \"" + count.uncast().getString() + "\" at " + g.getConextualizedCountReference(index.getReference()).toString() + " must be a number!");
                    }
                    TreeReference ref = getForm().getChildInstanceRef(index);
                    TreeElement element = getForm().getMainInstance().resolveReference(ref);
                    if (element == null) {
                        if (index.getInstanceIndex() < fullcount) {
                            try {
                                getForm().createNewRepeat(index);
                            } catch (InvalidReferenceException ire) {
                                ire.printStackTrace();
                                throw new RuntimeException("Invalid Reference while creating new repeat!" + ire.getMessage());
                            }
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:48,代码来源:FormEntryModel.java

示例10: createMissingTemplates

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的package包/类
private void createMissingTemplates(FormInstance instance, Vector<TreeReference> missingTemplates) {
    //it is VERY important that the missing template refs are listed in depth-first or breadth-first order... namely, that
    //every ref is listed after a ref that could be its parent. checkRepeatsForTemplate currently behaves this way
    for (int i = 0; i < missingTemplates.size(); i++) {
        TreeReference templRef = missingTemplates.elementAt(i);
        TreeReference firstMatch;

        //make template ref generic and choose first matching node
        TreeReference ref = templRef.clone();
        for (int j = 0; j < ref.size(); j++) {
            ref.setMultiplicity(j, TreeReference.INDEX_UNBOUND);
        }
        Vector<TreeReference> nodes = new EvaluationContext(instance).expandReference(ref);
        if (nodes.size() == 0) {
            //binding error; not a single node matches the repeat binding; will be reported later
            continue;
        } else {
            firstMatch = nodes.elementAt(0);
        }

        try {
            instance.copyNode(firstMatch, templRef);
        } catch (InvalidReferenceException e) {
            reporter.warning(XFormParserReporter.TYPE_INVALID_STRUCTURE, "Could not create a default repeat template; this is almost certainly a homogeneity error! Your form will not work! (Failed on " + templRef.toString() + ")", null);
        }
        trimRepeatChildren(instance.resolveReference(templRef));
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:29,代码来源:XFormParser.java

示例11: answerQuestion

import org.javarosa.core.model.instance.InvalidReferenceException; //导入依赖的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;
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:53,代码来源:FormEntryController.java


注:本文中的org.javarosa.core.model.instance.InvalidReferenceException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。