use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project InformationSystem by ObeoNetwork.
the class AbstractDatabaseCompareTest method createResource.
/**
* This will create a {@link Resource} given the model extension it is intended for and a ResourceSet.
*
* @param modelURI
* {@link org.eclipse.emf.common.util.URI URI} where the model is stored.
* @param resourceSet
* The {@link ResourceSet} to load the model in.
* @return The {@link Resource} given the model extension it is intended for.
*/
protected Resource createResource(URI modelURI, ResourceSet resourceSet) {
String fileExtension = modelURI.fileExtension();
if (fileExtension == null || fileExtension.length() == 0) {
fileExtension = Resource.Factory.Registry.DEFAULT_EXTENSION;
}
// First search the resource set for our resource factory
Resource.Factory.Registry registry = resourceSet.getResourceFactoryRegistry();
Object resourceFactory = registry.getExtensionToFactoryMap().get(fileExtension);
if (resourceFactory == null) {
// then the global registry
registry = Resource.Factory.Registry.INSTANCE;
resourceFactory = registry.getExtensionToFactoryMap().get(fileExtension);
if (resourceFactory != null) {
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension, resourceFactory);
} else {
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension, new XMIResourceFactoryImpl());
}
}
return resourceSet.createResource(modelURI);
}
use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project gemoc-studio by eclipse.
the class StandaloneSetup method doEMFRegistration.
public void doEMFRegistration() {
EPackage.Registry.INSTANCE.put(org.eclipse.gemoc.sample.legacyfsm.fsm.FsmPackage.eNS_URI, org.eclipse.gemoc.sample.legacyfsm.fsm.FsmPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap().put("melange", new MelangeResourceFactoryImpl());
}
use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project gemoc-studio by eclipse.
the class DslStandaloneSetupGenerated method createInjectorAndDoEMFRegistration.
@Override
public Injector createInjectorAndDoEMFRegistration() {
// register default ePackages
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtextbin", new BinaryGrammarResourceFactoryImpl());
if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI))
EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE);
Injector injector = createInjector();
register(injector);
return injector;
}
use of org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl in project gemoc-studio by eclipse.
the class GexpressionsExample method main.
/**
* <!-- begin-user-doc -->
* Load all the argument file paths or URIs as instances of the model.
* <!-- end-user-doc -->
* @param args the file paths or URIs.
* @generated
*/
public static void main(String[] args) {
// Create a resource set to hold the resources.
//
ResourceSet resourceSet = new ResourceSetImpl();
// Register the appropriate resource factory to handle all file extensions.
//
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
// Register the package to ensure it is available during loading.
//
resourceSet.getPackageRegistry().put(GexpressionsPackage.eNS_URI, GexpressionsPackage.eINSTANCE);
//
if (args.length == 0) {
System.out.println("Enter a list of file paths or URIs that have content like this:");
try {
Resource resource = resourceSet.createResource(URI.createURI("http:///My.gexpressions"));
GProgram root = GexpressionsFactory.eINSTANCE.createGProgram();
resource.getContents().add(root);
resource.save(System.out, null);
} catch (IOException exception) {
exception.printStackTrace();
}
} else {
//
for (int i = 0; i < args.length; ++i) {
// Construct the URI for the instance file.
// The argument is treated as a file path only if it denotes an existing file.
// Otherwise, it's directly treated as a URL.
//
File file = new File(args[i]);
URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()) : URI.createURI(args[i]);
try {
// Demand load resource for this file.
//
Resource resource = resourceSet.getResource(uri, true);
System.out.println("Loaded " + uri);
//
for (EObject eObject : resource.getContents()) {
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
if (diagnostic.getSeverity() != Diagnostic.OK) {
printDiagnostic(diagnostic, "");
}
}
} catch (RuntimeException exception) {
System.out.println("Problem loading " + uri);
exception.printStackTrace();
}
}
}
}
Aggregations