下面列出了怎么用org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl的API类实例代码及写法,或者点击链接到github查看源代码。
public static String getSkriptXml( Model pModel )
{
Resource.Factory.Registry lRegistry = Resource.Factory.Registry.INSTANCE;
Map<String,Object> lMap = lRegistry.getExtensionToFactoryMap();
lMap.put( "xml", new XMLResourceFactoryImpl() );
ResourceSet lResourceSet = new ResourceSetImpl();
Resource lResource = lResourceSet.createResource( URI.createFileURI( "*.xml" ) );
((XMLResource)lResource).getDefaultSaveOptions();
lResource.getContents().add( pModel );
try
{
ByteArrayOutputStream lByteArrayOutputStream = new ByteArrayOutputStream();
lResource.save( lByteArrayOutputStream, Collections.EMPTY_MAP );
return new String( lByteArrayOutputStream.toByteArray() );
}
catch( IOException e )
{
throw new RuntimeException( e );
}
}
@SuppressWarnings( "unchecked" )
public T loadModelXml( String pFilename, String pNamespaceUri, EPackage pEPackage )
{
EPackage.Registry.INSTANCE.put( pNamespaceUri, pEPackage );
Resource.Factory.Registry lRegistry = Resource.Factory.Registry.INSTANCE;
Map<String, Object> lMap = lRegistry.getExtensionToFactoryMap();
lMap.put( "xml", new XMLResourceFactoryImpl() );
ResourceSet lResourceSet = new ResourceSetImpl();
Resource lResource = lResourceSet.createResource( URI.createFileURI( pFilename ) );
((XMLResource) lResource).getDefaultSaveOptions();
try
{
lResource.load( Collections.EMPTY_MAP );
}
catch( IOException e )
{
throw new RuntimeException( e );
}
return (T) lResource.getContents().get( 0 );
}
private void doSave ( final String file ) throws IOException
{
final ResourceSet rs = new ResourceSetImpl ();
rs.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "*", new XMLResourceFactoryImpl () ); //$NON-NLS-1$
final URI fileUri = URI.createFileURI ( file );
final Resource resource = rs.createResource ( fileUri );
resource.getContents ().add ( this.chart );
final Map<Object, Object> options = new HashMap<Object, Object> ();
// options.put ( XMIResource., value )
resource.save ( options );
}
public void writeEMF(String fileName) {
ResourceSet metaResourceSet = new ResourceSetImpl();
metaResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMLResourceFactoryImpl());
URI resUri = URI.createURI(fileName);
Resource metaResource = metaResourceSet.createResource(resUri);
metaResource.getContents().add(schemaPack);
try {
metaResource.save(null);
} catch (Exception e) {
LOGGER.error("", e);
}
}
public void writeEMF(String fileName) {
ResourceSet metaResourceSet = new ResourceSetImpl();
metaResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMLResourceFactoryImpl());
URI resUri = URI.createURI(fileName);
Resource metaResource = metaResourceSet.createResource(resUri);
metaResource.getContents().add(ePackage);
try {
metaResource.save(null);
} catch (Exception e) {
e.printStackTrace();
}
}