try {
// Create a Sofa (using old APIs for now)
SofaID_impl id = new SofaID_impl();
id.setSofaID("EnglishDocument");
SofaFS es = this.cas.createSofa(id, "text");
// Initial View is #1!!!
assertTrue(2 == es.getSofaRef());
// Set the document text
es.setLocalSofaData("this beer is good");
// Test Multiple Sofas across XCAS serialization
XCASSerializer ser = new XCASSerializer(this.cas.getTypeSystem());
OutputStream outputXCAS = new FileOutputStream("Sofa.xcas");
XMLSerializer xmlSer = new XMLSerializer(outputXCAS);
try {
ser.serialize(cas, xmlSer.getContentHandler());
outputXCAS.close();
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
// Deserialize XCAS
this.cas.reset();
InputStream inputXCAS = new FileInputStream("Sofa.xcas");
try {
XCASDeserializer.deserialize(inputXCAS, cas, false);
inputXCAS.close();
} catch (SAXException e2) {
e2.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
// Add a new Sofa
// SofaID_impl gid = new SofaID_impl();
// gid.setSofaID("GermanDocument");
// SofaFS gs = ((CASImpl)cas).createSofa(gid,"text");
CAS gerTcas =this.cas.createView("GermanDocument");
assertTrue(gerTcas.getViewName().equals("GermanDocument"));
SofaFS gs = gerTcas.getSofa();
assertTrue(gs != null);
assertTrue(3 == gs.getSofaRef());
// Set the document text
// gs.setLocalSofaData("das bier ist gut");
gerTcas.setDocumentText("das bier ist gut");
// Test multiple Sofas across binary serialization
CASSerializer cs = Serialization.serializeNoMetaData(cas);
cas = Serialization.createCAS(casMgr, cs);
// Add a new Sofa
// SofaID_impl fid = new SofaID_impl();
// fid.setSofaID("FrenchDocument");
// SofaFS fs = ((CASImpl)cas).createSofa(fid, "text");
CAS frT =this.cas.createView("FrenchDocument");
assertTrue(frT.getViewName().equals("FrenchDocument"));
SofaFS fs = frT.getSofa();
assertTrue(fs != null);
assertTrue(4 == fs.getSofaRef());
// Test multiple Sofas across blob serialization
ByteArrayOutputStream fos = new ByteArrayOutputStream();
Serialization.serializeCAS(cas, fos);
this.cas.reset();