本文整理汇总了Java中org.javarosa.model.xform.DataModelSerializer类的典型用法代码示例。如果您正苦于以下问题:Java DataModelSerializer类的具体用法?Java DataModelSerializer怎么用?Java DataModelSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataModelSerializer类属于org.javarosa.model.xform包,在下文中一共展示了DataModelSerializer类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializeElements
import org.javarosa.model.xform.DataModelSerializer; //导入依赖的package包/类
private static void serializeElements(XPathNodeset nodeset, OutputStream output) throws IOException {
KXmlSerializer serializer = new KXmlSerializer();
try {
serializer.setOutput(output, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
DataModelSerializer s = new DataModelSerializer(serializer);
DataInstance instance = nodeset.getInstance();
Vector<TreeReference> refs = nodeset.getReferences();
for (TreeReference ref : refs) {
AbstractTreeElement treeElement = instance.resolveReference(ref);
s.serialize(treeElement);
}
}
示例2: printInstance
import org.javarosa.model.xform.DataModelSerializer; //导入依赖的package包/类
public static void printInstance(String instanceRef) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataModelSerializer s = new DataModelSerializer(bos, new CommCareInstanceInitializer(CommCareStatic.appStringCache));
s.serialize(new ExternalDataInstance(instanceRef, "instance"), null);
System.out.println(new String(bos.toByteArray()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例3: startRecovery
import org.javarosa.model.xform.DataModelSerializer; //导入依赖的package包/类
/**
* The recovery process comes in three phases. First, reporting to the server all of the cases that
* currently live on the phone (so the server can compare to its current state).
*
* Next, the full restore data is retrieved from the server and stored locally to ensure that the db
* can be recovered. Then local storage is cleared of data, and
*/
private void startRecovery() {
//Make a streaming message (the db is likely be too big to store in memory)
TransportMessage message = new StreamingHTTPMessage(this.getSubmitUrl()) {
public void _writeBody(OutputStream os) throws IOException {
//TODO: This is just the casedb, we actually want
DataModelSerializer s = new DataModelSerializer(os, new CommCareInstanceInitializer(CommCareStatic.appStringCache));
s.serialize(new ExternalDataInstance("jr://instance/casedb/report" + "/" + syncToken + "/" + stateHash,"casedb"), null);
}
};
listener.statusUpdate(CommCareOTARestoreListener.RESTORE_RECOVER_SEND);
try {
message = TransportService.sendBlocking(message);
} catch (TransportException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(message.isSuccess()) {
//The server is now informed of our current state, time for the tricky part,
this.recoveryMode = true;
initURI(null, null);
//TODO: Set a flag somewhere (sync token perhaps) that we're in recovery mode
this.startOtaProcess();
} else {
listener.promptRetry("restore.recover.fail");
}
}
示例4: serialize
import org.javarosa.model.xform.DataModelSerializer; //导入依赖的package包/类
public void serialize() throws IOException {
s.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
s.startDocument("UTF-8", null);
s.startTag(XMLNS, "mockup");
if(mockup.getDate() != null || mockup.getInstances() != null) {
s.startTag(XMLNS, "context");
if(mockup.getDate() != null){
s.startTag(XMLNS, "date");
s.text(DateUtils.formatDate(mockup.getDate(), DateUtils.FORMAT_ISO8601));
s.endTag(XMLNS, "date");
}
Hashtable<String, FormInstance> instances = mockup.getInstances();
for(Enumeration en = instances.keys() ; en.hasMoreElements() ;) {
String key = (String)en.nextElement();
DataInstance theInstance = instances.get(key);
s.startTag(XMLNS, "instance");
s.attribute(null, "src", key);
DataModelSerializer dms = new DataModelSerializer(s);
dms.serialize(theInstance, null);
s.endTag(XMLNS, "instance");
}
s.endTag(XMLNS, "context");
}
s.endTag(XMLNS, "mockup");
s.endDocument();
}
示例5: printExternalInstance
import org.javarosa.model.xform.DataModelSerializer; //导入依赖的package包/类
private void printExternalInstance(PrintStream out, String instanceRef) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataModelSerializer s = new DataModelSerializer(bos, mIIF);
s.serialize(new ExternalDataInstance(instanceRef, "instance"), null);
out.println(XmlUtil.getPrettyXml(bos.toByteArray()));
} catch (IOException e) {
e.printStackTrace();
out.println("Error Serializing XForm Data! " + e.getMessage());
}
}
示例6: serializeCaseInstanceFromSandbox
import org.javarosa.model.xform.DataModelSerializer; //导入依赖的package包/类
private static byte[] serializeCaseInstanceFromSandbox(MockUserDataSandbox sandbox) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataModelSerializer s = new DataModelSerializer(bos, new TestInstanceInitializer(sandbox));
s.serialize(new ExternalDataInstance(CaseTestUtils.CASE_INSTANCE, CaseInstanceTreeElement.MODEL_NAME), null);
return bos.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
}
示例7: getFixtureForId
import org.javarosa.model.xform.DataModelSerializer; //导入依赖的package包/类
/**
* Return a cursor to the fixture associated with this id
*/
private Cursor getFixtureForId(String instanceId) {
MatrixCursor retCursor = new MatrixCursor(new String[]{FixtureDataAPI.MetadataColumns._ID, FixtureDataAPI.MetadataColumns.FIXTURE_ID, "content"});
IStorageUtilityIndexed<FormInstance> userFixtureStorage = CommCareApplication.instance().getUserStorage("fixture", FormInstance.class);
for (IStorageIterator<FormInstance> userFixtures = userFixtureStorage.iterate(); userFixtures.hasMore(); ) {
try {
FormInstance fi = userFixtures.nextRecord();
String currentInstanceId = fi.getInstanceId();
if (instanceId.equals(currentInstanceId)) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataModelSerializer s = new DataModelSerializer(bos, new AndroidInstanceInitializer(null));
s.serialize(fi, fi.getRoot().getRef());
String dump = new String(bos.toByteArray());
retCursor.addRow(new Object[]{fi.getID(), fi.getInstanceId(), dump});
}
} catch (IOException e) {
e.printStackTrace();
}
}
return retCursor;
}