• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TreeElement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: extractFormParameters

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
/**
 * Extract the form id, version and uiVersion.
 *
 * @param rootElement
 *          - the tree element that is the root submission.
 * @param defaultFormIdValue
 *          - used if no "id" attribute found. This should already be
 *          slash-substituted.
 * @return
 */
private XFormParameters extractFormParameters(TreeElement rootElement, String defaultFormIdValue) {

  String formIdValue = null;
  String versionString = rootElement.getAttributeValue(null, "version");

  // search for the "id" attribute
  for (int i = 0; i < rootElement.getAttributeCount(); i++) {
    String name = rootElement.getAttributeName(i);
    if (name.equals(ParserConsts.FORM_ID_ATTRIBUTE_NAME)) {
      formIdValue = rootElement.getAttributeValue(i);
      formIdValue = formIdValue.replaceAll(ParserConsts.FORWARD_SLASH,
          ParserConsts.FORWARD_SLASH_SUBSTITUTION);
      break;
    }
  }

  return new XFormParameters((formIdValue == null) ? defaultFormIdValue : formIdValue,
      versionString);
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:30,代码来源:BaseFormParserForJavaRosa.java


示例2: FormInstanceValidator

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
public FormInstanceValidator(InputStream formInput, InputStream instanceInput) throws Exception {
		theForm = XFormUtils.getFormFromInputStream(formInput);
		
		savedModel = XFormParser.restoreDataModel(instanceInput, null);
        TreeElement templateRoot = theForm.getInstance().getRoot().deepCopy(true);

        //sanity check instance names before loading
        if (!savedModel.getRoot().getName().equals(templateRoot.getName()) || savedModel.getRoot().getMult() != 0) {
			System.out.println("Instance model name does not match xform instance name.");
			System.out.println("Instance: " + savedModel.getName() + " Xform: " + templateRoot.getName());
			System.exit(1);
        }
        
        model = new FormEntryModel(theForm);
        controller = new FormEntryController(model);

        
        //Populate XForm Model 
//        TreeReference tr = TreeReference.rootRef();
//        tr.add(templateRoot.getName(), TreeReference.INDEX_UNBOUND);
//        templateRoot.populate(savedRoot, f);
//
//        f.getInstance().setRoot(templateRoot);
	}
 
开发者ID:medic,项目名称:javarosa,代码行数:25,代码来源:FormInstanceValidator.java


示例3: isIndexReadonly

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
/**
 * @param index
 * @return true if the element at the specified index is read only
 */
public boolean isIndexReadonly(FormIndex index) {
    if (index.isBeginningOfFormIndex() || index.isEndOfFormIndex())
        return true;

    TreeReference ref = form.getChildInstanceRef(index);
    boolean isAskNewRepeat = (getEvent(index) == FormEntryController.EVENT_PROMPT_NEW_REPEAT ||
    						  getEvent(index) == FormEntryController.EVENT_REPEAT_JUNCTURE);

    if (isAskNewRepeat) {
        return false;
    } else {
        TreeElement node = form.getMainInstance().resolveReference(ref);
        return !node.isEnabled();
    }
}
 
开发者ID:medic,项目名称:javarosa,代码行数:20,代码来源:FormEntryModel.java


示例4: setRepeatNextMultiplicity

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
private boolean setRepeatNextMultiplicity(List<IFormElement> elements, List<Integer> multiplicities) {
	// find out if node is repeatable
	TreeReference nodeRef = form.getChildInstanceRef(elements, multiplicities);
	TreeElement node = form.getMainInstance().resolveReference(nodeRef);
	if (node == null || node.isRepeatable()) { // node == null if there are no
		// instances of the repeat
		int mult;
		if (node == null) {
			mult = 0; // no repeats; next is 0
		} else {
			String name = node.getName();
			TreeElement parentNode = form.getMainInstance().resolveReference(nodeRef.getParentRef());
			mult = parentNode.getChildMultiplicity(name);
		}
		multiplicities.set(multiplicities.size() - 1, Integer.valueOf(repeatStructure == REPEAT_STRUCTURE_NON_LINEAR ? TreeReference.INDEX_REPEAT_JUNCTURE : mult));
		return true;
	} else {
		return false;
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:21,代码来源:FormEntryModel.java


示例5: attachBind

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
private static void attachBind(TreeElement node, DataBinding bind) {
	node.setDataType(bind.getDataType());

	if (bind.relevancyCondition == null) {
		node.setRelevant(bind.relevantAbsolute);
	}
	if (bind.requiredCondition == null) {
		node.setRequired(bind.requiredAbsolute);
	}
	if (bind.readonlyCondition == null) {
		node.setEnabled(!bind.readonlyAbsolute);
	}
	if (bind.constraint != null) {
		node.setConstraint(new Constraint(bind.constraint, bind.constraintMessage));
	}

	node.setPreloadHandler(bind.getPreload());
	node.setPreloadParams(bind.getPreloadParams());
	node.setBindAttributes(bind.getAdditionalAttributes());
}
 
开发者ID:medic,项目名称:javarosa,代码行数:21,代码来源:XFormParser.java


示例6: loadXmlInstance

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
/**
 * Load a compatible xml instance into FormDef f
 *
 * call before f.initialize()!
 */
public static void loadXmlInstance(FormDef f, Document xmlInst) {
       TreeElement savedRoot = XFormParser.restoreDataModel(xmlInst, null).getRoot();
       TreeElement templateRoot = f.getMainInstance().getRoot().deepCopy(true);

       // weak check for matching forms
       // TODO: should check that namespaces match?
    if (!savedRoot.getName().equals(templateRoot.getName()) || savedRoot.getMult() != 0) {
    	throw new RuntimeException("Saved form instance does not match template form definition");
    }

    // populate the data model
    TreeReference tr = TreeReference.rootRef();
    tr.add(templateRoot.getName(), TreeReference.INDEX_UNBOUND);
    templateRoot.populate(savedRoot, f);

    // populated model to current form
    f.getMainInstance().setRoot(templateRoot);

    // if the new instance is inserted into the formdef before f.initialize() is called, this
    // locale refresh is unnecessary
    //   Localizer loc = f.getLocalizer();
    //   if (loc != null) {
    //       f.localeChanged(loc.getLocale(), loc);
    //	 }
}
 
开发者ID:medic,项目名称:javarosa,代码行数:31,代码来源:XFormParser.java


示例7: applyControlProperties

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
private void applyControlProperties (FormInstance instance) {
	for (int h = 0; h < 2; h++) {
        List<TreeReference> selectRefs = (h == 0 ? selectOnes : selectMultis);
		int type = (h == 0 ? Constants.DATATYPE_CHOICE : Constants.DATATYPE_CHOICE_LIST);

		for (int i = 0; i < selectRefs.size(); i++) {
			TreeReference ref = selectRefs.get(i);
           List<TreeReference> nodes = new EvaluationContext(instance).expandReference(ref, true);
			for (int j = 0; j < nodes.size(); j++) {
				TreeElement node = instance.resolveReference(nodes.get(j));
				if (node.getDataType() == Constants.DATATYPE_CHOICE || node.getDataType() == Constants.DATATYPE_CHOICE_LIST) {
					//do nothing
				} else if (node.getDataType() == Constants.DATATYPE_NULL || node.getDataType() == Constants.DATATYPE_TEXT) {
					node.setDataType(type);
				} else {
					reporter.warning(XFormParserReporter.TYPE_INVALID_STRUCTURE,
							"Select question " + ref.toString() + " appears to have data type that is incompatible with selection", null);
				}
			}
		}
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:23,代码来源:XFormParser.java


示例8: createRepeatGroup

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
@Override
public void createRepeatGroup(FormInstance mainInstance,
		EvaluationContext evalContext, TreeReference createRef,
		TreeElement parentElement, TreeElement createdElement) {

	// trigger conditions that depend on the creation of this new node
	Set<QuickTriggerable> qtSet1 = triggerTriggerables(mainInstance,
			evalContext, createRef, true, new HashSet<QuickTriggerable>(0));
	publishSummary("Created (phase 1)", createRef, qtSet1);

	// initialize conditions for the node (and sub-nodes)
	Set<QuickTriggerable> qtSet2 = initializeTriggerables(mainInstance,
			evalContext, createRef, true, new HashSet<QuickTriggerable>(0));
	publishSummary("Created (phase 2)", createRef, qtSet2);

	Set<QuickTriggerable> alreadyEvaluated = new HashSet<QuickTriggerable>(
			qtSet1);
	alreadyEvaluated.addAll(qtSet2);

	evaluateChildrenTriggerables(mainInstance, evalContext, createdElement,
			true, true, alreadyEvaluated);
}
 
开发者ID:medic,项目名称:javarosa,代码行数:23,代码来源:Fast2014DagImpl.java


示例9: evaluateChildrenTriggerables

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
private void evaluateChildrenTriggerables(FormInstance mainInstance,
		EvaluationContext evalContext, TreeElement newNode,
		boolean createdOrDeleted, boolean midSurvey,
		Set<QuickTriggerable> alreadyEvaluated) {
	// iterate into the group children and evaluate any triggerables that
	// depend one them, if they are not already calculated.
	int numChildren = newNode.getNumChildren();
	for (int i = 0; i < numChildren; i++) {
		TreeReference anchorRef = newNode.getChildAt(i).getRef();
		Set<QuickTriggerable> childTriggerables = triggerTriggerables(
				mainInstance, evalContext, anchorRef,
				  midSurvey, alreadyEvaluated);
		publishSummary((createdOrDeleted ? "Created" : "Deleted"),
				anchorRef, childTriggerables);
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:17,代码来源:Fast2014DagImpl.java


示例10: addChildrenOfReference

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
/**
 * This is a utility method to get all of the references of a node. It can
 * be replaced when we support dependent XPath Steps (IE: /path/to//)
 */
public void addChildrenOfReference(FormInstance mainInstance,
		EvaluationContext evalContext, TreeReference original,
		Set<TreeReference> toAdd, boolean expandRepeatables) {
	// original has already been added to the 'toAdd' list.

	TreeElement repeatTemplate = expandRepeatables ? mainInstance
			.getTemplatePath(original) : null;
	if (repeatTemplate != null) {
		for (int i = 0; i < repeatTemplate.getNumChildren(); ++i) {
			TreeElement child = repeatTemplate.getChildAt(i);
			toAdd.add(child.getRef().genericize());
			addChildrenOfElement(mainInstance, evalContext, child, toAdd, expandRepeatables);
		}
	} else {
		List<TreeReference> refSet = evalContext
				.expandReference(original);
		for (TreeReference ref : refSet) {
			addChildrenOfElement(mainInstance, evalContext, evalContext.resolveReference(ref),
					toAdd, expandRepeatables);
		}
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:27,代码来源:Fast2014DagImpl.java


示例11: createRepeatGroup

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
@Override
public void createRepeatGroup(FormInstance mainInstance,
      EvaluationContext evalContext, TreeReference createRef,
      TreeElement parentElement, TreeElement createdElement) {

   // trigger conditions that depend on the creation of this new node
   Set<QuickTriggerable> qtSet1 = triggerTriggerables(mainInstance,
         evalContext, createRef, new HashSet<QuickTriggerable>(0));
   publishSummary("Created (phase 1)", createRef, qtSet1);

   // initialize conditions for the node (and sub-nodes)
   Set<QuickTriggerable> qtSet2 = initializeTriggerables(mainInstance,
         evalContext, createRef, new HashSet<QuickTriggerable>(0));
   publishSummary("Created (phase 2)", createRef, qtSet2);

   Set<QuickTriggerable> alreadyEvaluated = new HashSet<QuickTriggerable>(
         qtSet1);
   alreadyEvaluated.addAll(qtSet2);

   evaluateChildrenTriggerables(mainInstance, evalContext,
         createdElement, true, alreadyEvaluated);
}
 
开发者ID:medic,项目名称:javarosa,代码行数:23,代码来源:Safe2014DagImpl.java


示例12: copyItemsetAnswer

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
@Override
public void copyItemsetAnswer(FormInstance mainInstance,
      EvaluationContext evalContext, TreeReference copyRef,
      TreeElement copyToElement, boolean midSurvey) {

   TreeReference targetRef = copyToElement.getRef();

   Set<QuickTriggerable> qtSet1 = triggerTriggerables(mainInstance,
         evalContext, copyRef,
         new HashSet<QuickTriggerable>(0));// trigger conditions that
                                    // depend on the creation of
                                    // these new nodes
   publishSummary("Copied itemset answer (phase 1)", targetRef, qtSet1);

   Set<QuickTriggerable> qtSet2 = initializeTriggerables(mainInstance,
         evalContext, copyRef,
         new HashSet<QuickTriggerable>(0));// initialize conditions for
                                    // the node (and sub-nodes)
   publishSummary("Copied itemset answer (phase 2)", targetRef, qtSet2);
   // not 100% sure this will work since destRef is ambiguous as the last
   // step, but i think it's supposed to work
}
 
开发者ID:medic,项目名称:javarosa,代码行数:23,代码来源:Safe2014DagImpl.java


示例13: addChildrenOfReference

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
/**
 * This is a utility method to get all of the references of a node. It can
 * be replaced when we support dependent XPath Steps (IE: /path/to//)
 */
private void addChildrenOfReference(FormInstance mainInstance,
      EvaluationContext evalContext, TreeReference original,
      Set<TreeReference> toAdd, boolean expandRepeatables) {
   // original has already been added to the 'toAdd' list.

   TreeElement repeatTemplate = expandRepeatables ? mainInstance
         .getTemplatePath(original) : null;
   if (repeatTemplate != null) {
      for (int i = 0; i < repeatTemplate.getNumChildren(); ++i) {
         TreeElement child = repeatTemplate.getChildAt(i);
         toAdd.add(child.getRef().genericize());
         addChildrenOfElement(mainInstance, evalContext, child, toAdd,
               expandRepeatables);
      }
   } else {
      List<TreeReference> refSet = evalContext.expandReference(original);
      for (TreeReference ref : refSet) {
         addChildrenOfElement(mainInstance, evalContext,
               evalContext.resolveReference(ref), toAdd,
               expandRepeatables);
      }
   }
}
 
开发者ID:medic,项目名称:javarosa,代码行数:28,代码来源:Safe2014DagImpl.java


示例14: checkRepeatsForTemplate

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
private static void checkRepeatsForTemplate (TreeElement repeatTreeNode, TreeReference ref, FormInstance instance, List<TreeReference> missing) {
	String name = repeatTreeNode.getName();
	int mult = (repeatTreeNode.isRepeatable() ? TreeReference.INDEX_TEMPLATE : 0);
	ref = ref.extendRef(name, mult);

	if (repeatTreeNode.isRepeatable()) {
		TreeElement template = instance.resolveReference(ref);
		if (template == null) {
			missing.add(ref);
		}
	}

	for (int i = 0; i < repeatTreeNode.getNumChildren(); i++) {
		checkRepeatsForTemplate(repeatTreeNode.getChildAt(i), ref, instance, missing);
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:17,代码来源:XFormParser.java


示例15: checkHomogeneity

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
private void checkHomogeneity (FormInstance instance) {
     List<TreeReference> refs = getRepeatableRefs();
	for (int i = 0; i < refs.size(); i++) {
		TreeReference ref = refs.get(i);
		TreeElement template = null;
        List<TreeReference> nodes = new EvaluationContext(instance).expandReference(ref);
		for (int j = 0; j < nodes.size(); j++) {
			TreeReference nref = nodes.get(j);
			TreeElement node = instance.resolveReference(nref);
			if (node == null) //don't crash on '/'... invalid repeat binding will be caught later
				continue;

			if (template == null)
				template = instance.getTemplate(nref);

			if (!FormInstance.isHomogeneous(template, node)) {
				reporter.warning(XFormParserReporter.TYPE_INVALID_STRUCTURE, "Not all repeated nodes for a given repeat binding [" + nref.toString() + "] are homogeneous! This will cause serious problems!", null);
			}
		}
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:22,代码来源:XFormParser.java


示例16: importData

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
public boolean importData(File instanceFile, FormEntryController fec) {
  publishProgress(Collect.getInstance().getString(R.string.survey_loading_reading_data_message));

  // convert files into a byte array
  byte[] fileBytes = FileUtils.getFileAsBytes(instanceFile);

  // get the root of the saved and template instances
  TreeElement savedRoot = XFormParser.restoreDataModel(fileBytes, null).getRoot();
  TreeElement templateRoot = fec.getModel().getForm().getInstance().getRoot().deepCopy(true);

  // weak check for matching forms
  if (!savedRoot.getName().equals(templateRoot.getName()) || savedRoot.getMult() != 0) {
    Log.e(t, "Saved form instance does not match template form definition");
    return false;
  } else {
    // populate the data model
    TreeReference tr = TreeReference.rootRef();
    tr.add(templateRoot.getName(), TreeReference.INDEX_UNBOUND);

    // Here we set the Collect's implementation of the IAnswerResolver.
    // We set it back to the default after select choices have been populated.
    XFormParser.setAnswerResolver(new ExternalAnswerResolver());
    templateRoot.populate(savedRoot, fec.getModel().getForm());
    XFormParser.setAnswerResolver(new DefaultAnswerResolver());

    // populated model to current form
    fec.getModel().getForm().getInstance().setRoot(templateRoot);

    // fix any language issues
    // :
    // http://bitbucket.org/javarosa/main/issue/5/itext-n-appearing-in-restored-instances
    if (fec.getModel().getLanguages() != null) {
      fec.getModel().getForm()
          .localeChanged(fec.getModel().getLanguage(), fec.getModel().getForm().getLocalizer());
    }

    return true;

  }
}
 
开发者ID:Last-Mile-Health,项目名称:ODK-Liberia,代码行数:41,代码来源:FormLoaderTask.java


示例17: findDepthFirst

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
/**
 * Traverse the submission looking for the first matching tag in depth-first order.
 *
 * @param parent
 * @param name
 * @return
 */
private TreeElement findDepthFirst(TreeElement parent, String name) {
    int len = parent.getNumChildren();
    for ( int i = 0; i < len ; ++i ) {
        TreeElement e = parent.getChildAt(i);
        if ( name.equals(e.getName()) ) {
            return e;
        } else if ( e.getNumChildren() != 0 ) {
            TreeElement v = findDepthFirst(e, name);
            if ( v != null ) return v;
        }
    }
    return null;
}
 
开发者ID:Last-Mile-Health,项目名称:ODK-Liberia,代码行数:21,代码来源:FormController.java


示例18: getVariableValue

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
public static IAnswerData getVariableValue(String variableName,
                                           FormDef formDef) {
    TreeElement element = findChildForName(formDef.getInstance().getRoot(), variableName);
    if (element != null) {
        return element.getValue();
    }
    return null;
}
 
开发者ID:Last-Mile-Health,项目名称:ODK-Liberia,代码行数:9,代码来源:FormsUtils.java


示例19: findChildForNameRecursive

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
private static TreeElement findChildForNameRecursive(TreeElement element,
                                                     String[] names,
                                                     int index) {
    if (element.getName().equals(names[index])) {
        if (++index >= names.length) {
            return element;
        }
        TreeElement foundElement = findFirstChildForName(element, names[index]);
        if (foundElement != null) {
            return findChildForNameRecursive(foundElement, names, index);
        }
    }
    return null;
}
 
开发者ID:Last-Mile-Health,项目名称:ODK-Liberia,代码行数:15,代码来源:FormsUtils.java


示例20: findFirstChildForName

import org.javarosa.core.model.instance.TreeElement; //导入依赖的package包/类
public static TreeElement findFirstChildForName(TreeElement element,
                                                String name) {
    List<TreeElement> elements = element.getChildrenWithName(name);
    if (elements.size() > 0) {
        return elements.get(0);
    }
    return null;
}
 
开发者ID:Last-Mile-Health,项目名称:ODK-Liberia,代码行数:9,代码来源:FormsUtils.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NetcdfDataset类代码示例发布时间:2022-05-22
下一篇:
Java ApplicationACLMapProto类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap