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


Java TreeElement.getMult方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: checkDuplicateNodesAreRepeatable

import org.javarosa.core.model.instance.TreeElement; //导入方法依赖的package包/类
private static void checkDuplicateNodesAreRepeatable (TreeElement node) {
	int mult = node.getMult();
	if (mult > 0) { //repeated node
		if (!node.isRepeatable()) {
			System.out.println("Warning: repeated nodes [" + node.getName() + "] detected that have no repeat binding in the form; DO NOT bind questions to these nodes or their children!");
			//we could do a more comprehensive safety check in the future
		}
	}

	for (int i = 0; i < node.getNumChildren(); i++) {
		checkDuplicateNodesAreRepeatable(node.getChildAt(i));
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:14,代码来源:XFormParser.java

示例5: schemizeInstance

import org.javarosa.core.model.instance.TreeElement; //导入方法依赖的package包/类
private static Element schemizeInstance (TreeElement node) {
	String name = node.getName();
	boolean terminal = node.isLeaf();
	boolean repeatable = node.isRepeatable();

	if (repeatable && node.getMult() != TreeReference.INDEX_TEMPLATE) {
		return null;
	}

	Element e = new Element();
	e.setName("element");
	e.setAttribute(null, "name", name);
	e.setAttribute(null, "minOccurs", "0"); //technically only needed if node has a 'relevant' attribute bound to it, but no easy way to tell
	if (repeatable) {
		e.setAttribute(null, "maxOccurs", "unbounded");
	}

	if (!terminal) {
		Element ct = new Element();
		ct.setName("complexType");
		e.addChild(Node.ELEMENT, ct);

		Element seq = new Element();
		seq.setName("sequence");
		ct.addChild(Node.ELEMENT, seq);

		for (int i = 0; i < node.getNumChildren(); i++) {
			Element child = schemizeInstance((TreeElement)node.getChildAt(i));
			if (child != null) {
				seq.addChild(Node.ELEMENT, child);
			}
		}
	} else {
		String type;

		switch (node.getDataType()) {
		case Constants.DATATYPE_NULL:
		case Constants.DATATYPE_TEXT:
			type = "string";
			break;
		case Constants.DATATYPE_INTEGER: type = "integer"; break;
		case Constants.DATATYPE_LONG: type = "long"; break;
		case Constants.DATATYPE_DECIMAL: type = "decimal"; break;
		case Constants.DATATYPE_BOOLEAN: type = "boolean"; break;
		case Constants.DATATYPE_DATE: type = "date"; break;
		case Constants.DATATYPE_DATE_TIME: type = "dateTime"; break;
		case Constants.DATATYPE_TIME: type = "time"; break;
		case Constants.DATATYPE_CHOICE:
		case Constants.DATATYPE_CHOICE_LIST:
			type = (String)choiceTypeMapping.get(node);
			if (type == null) {
				System.err.println("can't find choices for select-type question [" + node.getName() + "]");
			}
			break;
		case Constants.DATATYPE_GEOPOINT: type = "jr:geopoint"; break;
		case Constants.DATATYPE_GEOSHAPE: type = "jr:geoshape"; break;
		case Constants.DATATYPE_GEOTRACE: type = "jr:geotrace"; break;
		default:
			type = null;
			System.err.println("unrecognized type [" + node.getDataType() + ";" + node.getName() + "]");
			break;
		}

		if (type != null) {
			e.setAttribute(null, "type", type);
		}
	}

	return e;
}
 
开发者ID:medic,项目名称:javarosa,代码行数:71,代码来源:InstanceSchema.java

示例6: serializeNode

import org.javarosa.core.model.instance.TreeElement; //导入方法依赖的package包/类
public String serializeNode(TreeElement instanceNode) {
	StringBuilder b = new StringBuilder();
	// don't serialize template nodes or non-relevant nodes
	if (!instanceNode.isRelevant()
			|| instanceNode.getMult() == TreeReference.INDEX_TEMPLATE)
		return null;

	if (instanceNode.getValue() != null) {
		Object serializedAnswer = serializer.serializeAnswerData(
				instanceNode.getValue(), instanceNode.getDataType());

		if (serializedAnswer instanceof Element) {
			// DON"T handle this.
			throw new RuntimeException("Can't handle serialized output for"
					+ instanceNode.getValue().toString() + ", "
					+ serializedAnswer);
		} else if (serializedAnswer instanceof String) {
			Element e = new Element();
			e.addChild(Node.TEXT, (String) serializedAnswer);

			String tag = instanceNode.getAttributeValue("", "tag");
			if ( tag != null ) {
				b.append(tag);
			}
			else {
				String name = instanceNode.getName();
				if ( name != null ) {
					b.append(name);
				}
			}
			b.append(delimiter);

			for (int k = 0; k < e.getChildCount(); k++) {
				b.append(e.getChild(k).toString().replace("\\", "\\\\").replace(delimiter, "\\" + delimiter));
				b.append(delimiter);
			}

		} else {
			throw new RuntimeException("Can't handle serialized output for"
					+ instanceNode.getValue().toString() + ", "
					+ serializedAnswer);
		}

		if (serializer.containsExternalData(instanceNode.getValue())
				.booleanValue()) {
			IDataPointer[] pointer = serializer
					.retrieveExternalDataPointer(instanceNode.getValue());
			for (int i = 0; i < pointer.length; ++i) {
				dataPointers.add(pointer[i]);
			}
		}
	}
	return b.toString();
}
 
开发者ID:medic,项目名称:javarosa,代码行数:55,代码来源:SMSSerializingVisitor.java


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