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


Java TreeElement.getChild方法代码示例

本文整理汇总了Java中org.javarosa.core.model.instance.TreeElement.getChild方法的典型用法代码示例。如果您正苦于以下问题:Java TreeElement.getChild方法的具体用法?Java TreeElement.getChild怎么用?Java TreeElement.getChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.javarosa.core.model.instance.TreeElement的用法示例。


在下文中一共展示了TreeElement.getChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeInvalidTemplates

import org.javarosa.core.model.instance.TreeElement; //导入方法依赖的package包/类
private boolean removeInvalidTemplates (TreeElement instanceNode, TreeElement repeatTreeNode, boolean templateAllowed) {
	int mult = instanceNode.getMult();
	boolean repeatable = (repeatTreeNode == null ? false : repeatTreeNode.isRepeatable());

	if (mult == TreeReference.INDEX_TEMPLATE) {
		if (!templateAllowed) {
			reporter.warning(XFormParserReporter.TYPE_INVALID_STRUCTURE, "Template nodes for sub-repeats must be located within the template node of the parent repeat; ignoring template... [" + instanceNode.getName() + "]", null);
			return true;
		} else if (!repeatable) {
			reporter.warning(XFormParserReporter.TYPE_INVALID_STRUCTURE, "Warning: template node found for ref that is not repeatable; ignoring... [" + instanceNode.getName() + "]", null);
			return true;
		}
	}

	if (repeatable && mult != TreeReference.INDEX_TEMPLATE)
		templateAllowed = false;

	for (int i = 0; i < instanceNode.getNumChildren(); i++) {
		TreeElement child = instanceNode.getChildAt(i);
		TreeElement rchild = (repeatTreeNode == null ? null : repeatTreeNode.getChild(child.getName(), 0));

		if (removeInvalidTemplates(child, rchild, templateAllowed)) {
			instanceNode.removeChildAt(i);
			i--;
		}
	}
	return false;
}
 
开发者ID:medic,项目名称:javarosa,代码行数:29,代码来源:XFormParser.java

示例2: verifyRepeatMemberBindings

import org.javarosa.core.model.instance.TreeElement; //导入方法依赖的package包/类
private void verifyRepeatMemberBindings (IFormElement fe, FormInstance instance, GroupDef parentRepeat) {
	if (fe.getChildren() == null)
		return;

	for (int i = 0; i < fe.getChildren().size(); i++) {
		IFormElement child = fe.getChildren().get(i);
		boolean isRepeat = (child instanceof GroupDef && ((GroupDef)child).getRepeat());

		//get bindings of current node and nearest enclosing repeat
		TreeReference repeatBind = (parentRepeat == null ? TreeReference.rootRef() : FormInstance.unpackReference(parentRepeat.getBind()));
		TreeReference childBind = FormInstance.unpackReference(child.getBind());

		//check if current binding is within scope of repeat binding
		if (!repeatBind.isParentOf(childBind, false)) {
			//catch <repeat nodeset="/a/b"><input ref="/a/c" /></repeat>: repeat question is not a child of the repeated node
			throw new XFormParseException("<repeat> member's binding [" + childBind.toString() + "] is not a descendant of <repeat> binding [" + repeatBind.toString() + "]!");
		} else if (repeatBind.equals(childBind) && isRepeat) {
			//catch <repeat nodeset="/a/b"><repeat nodeset="/a/b">...</repeat></repeat> (<repeat nodeset="/a/b"><input ref="/a/b" /></repeat> is ok)
			throw new XFormParseException("child <repeat>s [" + childBind.toString() + "] cannot bind to the same node as their parent <repeat>; only questions/groups can");
		}

		//check that, in the instance, current node is not within the scope of any closer repeat binding
		//build a list of all the node's instance ancestors
		List<TreeElement> repeatAncestry = new ArrayList<TreeElement>();
		TreeElement repeatNode = (repeatTree == null ? null : repeatTree.getRoot());
		if (repeatNode != null) {
			repeatAncestry.add(repeatNode);
			for (int j = 1; j < childBind.size(); j++) {
				repeatNode = repeatNode.getChild(childBind.getName(j), 0);
				if (repeatNode != null) {
					repeatAncestry.add(repeatNode);
				} else {
					break;
				}
			}
		}
		//check that no nodes between the parent repeat and the target are repeatable
		for (int k = repeatBind.size(); k < childBind.size(); k++) {
			TreeElement rChild = (k < repeatAncestry.size() ? repeatAncestry.get(k) : null);
			boolean repeatable = (rChild == null ? false : rChild.isRepeatable());
			if (repeatable && !(k == childBind.size() - 1 && isRepeat)) {
				//catch <repeat nodeset="/a/b"><input ref="/a/b/c/d" /></repeat>...<repeat nodeset="/a/b/c">...</repeat>:
				//  question's/group's/repeat's most immediate repeat parent in the instance is not its most immediate repeat parent in the form def
				throw new XFormParseException("<repeat> member's binding [" + childBind.toString() + "] is within the scope of a <repeat> that is not its closest containing <repeat>!");
			}
		}

		verifyRepeatMemberBindings(child, instance, (isRepeat ? (GroupDef)child : parentRepeat));
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:51,代码来源:XFormParser.java


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