本文整理汇总了Java中org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl类的典型用法代码示例。如果您正苦于以下问题:Java XMLResourceImpl类的具体用法?Java XMLResourceImpl怎么用?Java XMLResourceImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMLResourceImpl类属于org.eclipse.emf.ecore.xmi.impl包,在下文中一共展示了XMLResourceImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
/** Load model to a resource. */
public static Resource load (String ontoumlPath) throws IOException
{
ResourceSet rset = new ResourceSetImpl();
rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put("mouml",new XMIResourceFactoryImpl());
rset.getPackageRegistry().put(OntoumlPackage.eNS_URI, OntoumlPackage.eINSTANCE);
File file = new File(ontoumlPath);
URI fileURI = URI.createFileURI(file.getAbsolutePath());
Resource resource = rset.createResource(fileURI);
/**Load options that significantly improved the performance of loading EMF Model instances*/
Map<Object,Object> loadOptions = ((XMLResourceImpl)resource).getDefaultLoadOptions();
//loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl());
//loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
resource.load(loadOptions);
return resource;
}
示例2: serialize
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
private String serialize(EObject eObject) {
ResourceImpl resource = new XMLResourceImpl();
resource.getContents().add(eObject);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
options.put(XMLResource.OPTION_DECLARE_XML, Boolean.FALSE);
try {
resource.save(baos, options);
return baos.toString();
} catch (IOException e) {
LogUtil.error(e);
}
return null;
}
示例3: getEObjectListFromResponse
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
/**
* converts an response's inputstream to a list of EObjects, for example: List<ProjectInfo>, List<BranchInfo>, ...
* @param response
* @return
*/
private <T extends EObject> List<T> getEObjectListFromResponse(
final Response response) {
//create XMLResource and read the entity
ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
final String fileNameURI = "blabla";
final XMLResourceImpl resource = (XMLResourceImpl) resourceSetImpl.createResource(URI.createURI(fileNameURI));
final InputStream is = response.readEntity(InputStream.class);
List<T> eObjectList = new ArrayList<T>();
try {
//create the List<ProjectInfo> from the input stream
resource.doLoad(is, null);
for(Object o : resource.getContents()) {
eObjectList.add((T) o);
}
} catch (final IOException ex) {
System.err.println(ex.getMessage());
}
return eObjectList;
}
示例4: convertEObjectsToXmlIntoStreamingOutput
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
/**
* @param eObjects
* @return
*/
protected StreamingOutput convertEObjectsToXmlIntoStreamingOutput(
final Collection<? extends EObject> eObjects) {
// convert the list into XML and write it to a StreamingOutput
ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
final String fileNameURI = "blabla";
final XMLResourceImpl resource = (XMLResourceImpl) resourceSetImpl
.createResource(URI.createURI(fileNameURI));
for(EObject e : eObjects) {
EObject copy = EcoreUtil.copy(e); //neccessary because add() has side effects!
resource.getContents().add(copy);
}
final StreamingOutput streamingOutput = new StreamingOutput() {
public void write(OutputStream output) throws IOException,
WebApplicationException {
resource.doSave(output, null);
}
};
return streamingOutput;
}
示例5: convertEObjectsToXmlIntoStreamingOutput
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
/**
* @param eObjects
* @return
*/
public static StreamingOutput convertEObjectsToXmlIntoStreamingOutput(
final Collection<? extends EObject> eObjects) {
// convert the list into XML and write it to a StreamingOutput
ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
final String fileNameURI = "blabla";
final XMLResourceImpl resource = (XMLResourceImpl) resourceSetImpl
.createResource(URI.createURI(fileNameURI));
for(EObject e : eObjects) {
EObject copy = EcoreUtil.copy(e); //neccessary because add() has side effects!
resource.getContents().add(copy);
}
final StreamingOutput streamingOutput = new StreamingOutput() {
public void write(OutputStream output) throws IOException,
WebApplicationException {
resource.doSave(output, null);
}
};
return streamingOutput;
}
示例6: getEObjectListFromInputStream
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
/**
* converts an response's inputstream to a list of EObjects, for example: List<ProjectInfo>, List<BranchInfo>, ...
* @param
* @return
*/
public static <T extends EObject> List<T> getEObjectListFromInputStream(
final InputStream is) {
//create XMLResource and read the entity
ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
final String fileNameURI = "blabla";
final XMLResourceImpl resource = (XMLResourceImpl) resourceSetImpl.createResource(URI.createURI(fileNameURI));
List<T> eObjectList = new ArrayList<T>();
try {
//create the List<ProjectInfo> from the input stream
resource.doLoad(is, null);
for(Object o : resource.getContents()) {
eObjectList.add((T) o);
}
} catch (final IOException ex) {
System.err.println(ex.getMessage());
}
return eObjectList;
}
示例7: generateSample
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
public Resource generateSample() {
final String theGrammarFile = PLATFORM_RESOURCE + theSchema.eResource().getURI().toPlatformString(true);
final CMDocument cmDocument = createCMDocument(theGrammarFile, new String[2]);
setGrammarURI(theGrammarFile);
setCMDocument(cmDocument);
setRootElementName(root);
setBuildPolicy(BUILD_OPTIONAL_ELEMENTS | BUILD_FIRST_CHOICE | BUILD_FIRST_SUBSTITUTION | BUILD_TEXT_NODES);
// setOptionalElementDepthLimit(-1);
createNamespaceInfoList();
resolveSchemaLocations();
try {
this.createXMLDocument(toFile(xmlURI).getPath());
} catch (final Exception e) {
throw new RuntimeException("Failed to create the XML resource.", e);
}
return new XMLResourceImpl(xmlURI);
}
示例8: serialize
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
private String serialize(Marketplace rootElement) throws IOException {
Map<String, Object> saveOptions = new HashMap<String, Object>();
saveOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
// UTF-8 encoding is required per specification
saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8");
XMLResource resource = new XMLResourceImpl();
resource.getContents().add(rootElement);
StringWriter stringWriter = new StringWriter();
resource.save(new URIConverter.WriteableOutputStream(stringWriter, resource.getEncoding()), saveOptions);
return stringWriter.getBuffer().toString();
}
示例9: serialize
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
public static String serialize(Node rootElement) throws IOException {
Map<String, Object> saveOptions = new HashMap<String, Object>();
saveOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8");
XMLResource resource = new XMLResourceImpl();
resource.getContents().add(rootElement);
StringWriter stringWriter = new StringWriter();
resource.save(new URIConverter.WriteableOutputStream(stringWriter, resource.getEncoding()), saveOptions);
return stringWriter.getBuffer().toString();
}
示例10: setUp
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
ResourceSet resourceSet = new ResourceSetImpl();
Resource syntheticResource = new XMLResourceImpl(URI.createURI("http://synthetic.resource"));
resourceSet.getResources().add(syntheticResource);
typeProvider = new ClasspathTypeProvider(getClass().getClassLoader(), resourceSet, null, null);
}
示例11: setUp
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
resource = new XMLResourceImpl();
resource.setURI(URI.createURI("foo:/test"));
nameProvider = new IQualifiedNameProvider.AbstractImpl() {
@Override
public QualifiedName getFullyQualifiedName(EObject obj) {
if (obj instanceof ENamedElement)
return QualifiedName.create(((ENamedElement) obj).getName());
return null;
}
};
strategy = new DefaultResourceDescriptionStrategy();
strategy.setQualifiedNameProvider(nameProvider);
description = new DefaultResourceDescription(resource, strategy);
EcoreFactory f = EcoreFactory.eINSTANCE;
pack = f.createEPackage();
pack.setName("MyPackage");
eClass = f.createEClass();
eClass.setName("MyEClass");
dtype = f.createEDataType();
dtype.setName("MyDatatype");
pack.getEClassifiers().add(eClass);
pack.getEClassifiers().add(dtype);
resource.getContents().add(pack);
}
示例12: loadRefModel
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
public static Resource loadRefModel(String refontoumlpath) throws IOException
{
ResourceSet rset = new ResourceSetImpl();
rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put("refontouml",new RefOntoUMLResourceFactoryImpl());
rset.getPackageRegistry().put(RefOntoUML.RefOntoUMLPackage.eNS_URI, RefOntoUML.RefOntoUMLPackage.eINSTANCE);
File file = new File(refontoumlpath);
URI fileURI = URI.createFileURI(file.getAbsolutePath());
Resource resource = rset.createResource(fileURI);
/**Load options that significantly improved the performance of loading EMF Model instances*/
Map<Object,Object> loadOptions = ((XMLResourceImpl)resource).getDefaultLoadOptions();
loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl());
loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
resource.load(loadOptions);
return resource;
}
示例13: setup
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
@Before
public void setup() {
resourceSet = new ResourceSetImpl();
model = PatchTestFactory.eINSTANCE.createPatchTestModel();
model.setId("ID");
ResourceImpl testModelResource = new XMLResourceImpl(URI.createURI("http://model"));
testModelResource.getContents().add(model);
resourceSet.getResources().add(testModelResource);
if (showDebuggingOutput()) {
System.out.println("TEST: " + name.getMethodName());
}
}
示例14: deserialize
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
private EObject deserialize(String string) {
ByteArrayInputStream bais = new ByteArrayInputStream(string.getBytes());
XMLResourceImpl resource = new XMLResourceImpl(URI.createURI("http://patch"));
resourceSet.getResources().add(resource);
try {
resource.load(bais, null);
return resource.getContents().get(0);
} catch (IOException e) {
LogUtil.error(e);
}
return null;
}
示例15: getModelXML
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; //导入依赖的package包/类
private String getModelXML(EObject toCompare) {
try {
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
Resource res = new XMLResourceImpl(URI.createURI("dummyfile.xml"));
res.getContents().add(EcoreUtil.copy(toCompare));
res.save(oStream, null);
oStream.flush();
oStream.close();
String file = new String(oStream.toByteArray());
return file;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}