本文整理汇总了Java中org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl.createResource方法的典型用法代码示例。如果您正苦于以下问题:Java XMIResourceFactoryImpl.createResource方法的具体用法?Java XMIResourceFactoryImpl.createResource怎么用?Java XMIResourceFactoryImpl.createResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl
的用法示例。
在下文中一共展示了XMIResourceFactoryImpl.createResource方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadSample
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; //导入方法依赖的package包/类
/**
* Loads the sample saved in the given file.
*
* @param graphEditor the graph editor in which the loaded model will be set
*/
private void loadSample(final String file, final GraphEditor graphEditor) {
final String samplePath = getClass().getResource(file).toExternalForm();
final URI fileUri = URI.createURI(samplePath);
final XMIResourceFactoryImpl resourceFactory = new XMIResourceFactoryImpl();
final Resource resource = resourceFactory.createResource(fileUri);
try {
resource.load(Collections.EMPTY_MAP);
} catch (final IOException e) {
e.printStackTrace();
}
if (!resource.getContents().isEmpty() && resource.getContents().get(0) instanceof GModel) {
final GModel model = (GModel) resource.getContents().get(0);
graphEditor.setModel(model);
}
}
示例2: saveModel
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; //导入方法依赖的package包/类
/**
* Saves the graph editor's model state in the given file.
*
* @param file the {@link File} the model state will be saved in
* @param model the {@link GModel} to be saved
*/
private void saveModel(final File file, final GModel model) {
String absolutePath = file.getAbsolutePath();
if (!absolutePath.endsWith(FILE_EXTENSION)) {
absolutePath += FILE_EXTENSION;
}
final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model);
final URI fileUri = URI.createFileURI(absolutePath);
final XMIResourceFactoryImpl resourceFactory = new XMIResourceFactoryImpl();
final Resource resource = resourceFactory.createResource(fileUri);
resource.getContents().add(model);
try {
resource.save(Collections.EMPTY_MAP);
} catch (final IOException e) {
e.printStackTrace();
}
editingDomain.getResourceSet().getResources().clear();
editingDomain.getResourceSet().getResources().add(resource);
initialDirectory = file.getParentFile();
}
示例3: loadModel
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; //导入方法依赖的package包/类
/**
* Loads the model from the given file and sets it in the given graph editor.
*
* @param file the {@link File} to be loaded
* @param graphEditor the {@link GraphEditor} in which the loaded model will be set
*/
private void loadModel(final File file, final GraphEditor graphEditor) {
final URI fileUri = URI.createFileURI(file.getAbsolutePath());
final XMIResourceFactoryImpl resourceFactory = new XMIResourceFactoryImpl();
final Resource resource = resourceFactory.createResource(fileUri);
try {
resource.load(Collections.EMPTY_MAP);
} catch (final IOException e) {
e.printStackTrace();
}
if (!resource.getContents().isEmpty() && resource.getContents().get(0) instanceof GModel) {
final GModel model = (GModel) resource.getContents().get(0);
graphEditor.setModel(model);
}
initialDirectory = file.getParentFile();
}
示例4: createModel
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; //导入方法依赖的package包/类
/**
* Creates a new dummy model instance from a test file.
*
* @return a new dummy {@link GModel} instance from a test file
*/
public static GModel createModel() {
// Need to instantiate this to make metamodel available in unit tests.
@SuppressWarnings("unused")
final ModelPackage packageInstance = ModelPackage.eINSTANCE;
final String testFilePath = DummyDataFactory.class.getResource(TEST_FILE).toExternalForm();
final URI fileUri = URI.createURI(testFilePath);
final XMIResourceFactoryImpl resourceFactory = new XMIResourceFactoryImpl();
final Resource resource = resourceFactory.createResource(fileUri);
try {
resource.load(Collections.EMPTY_MAP);
} catch (final IOException e) {
e.printStackTrace();
}
if (!resource.getContents().isEmpty() && resource.getContents().get(0) instanceof GModel) {
return (GModel) resource.getContents().get(0);
} else {
return null;
}
}
示例5: createModel
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; //导入方法依赖的package包/类
/**
* Creates a new dummy model instance from a test file.
*
* @return a new dummy {@link GModel} instance from a test file
*/
public static GModel createModel() {
// Need to instantiate this to make metamodel available in unit tests.
@SuppressWarnings("unused")
final GraphPackage packageInstance = GraphPackage.eINSTANCE;
final String testFilePath = DummyDataFactory.class.getResource(TEST_FILE).toExternalForm();
final URI fileUri = URI.createURI(testFilePath);
final XMIResourceFactoryImpl resourceFactory = new XMIResourceFactoryImpl();
final Resource resource = resourceFactory.createResource(fileUri);
try {
resource.load(Collections.EMPTY_MAP);
} catch (final IOException e) {
e.printStackTrace();
}
if (!resource.getContents().isEmpty() && resource.getContents().get(0) instanceof GModel) {
return (GModel) resource.getContents().get(0);
} else {
return null;
}
}
示例6: inputChanged
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; //导入方法依赖的package包/类
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
ModelPackage modelPackage = ModelFactory.eINSTANCE.getModelPackage();
ResourceSetImpl resourceSetI = new ResourceSetImpl();
resourceSetI.getPackageRegistry().put(modelPackage.getNsURI(),
modelPackage);
XMIResourceFactoryImpl c = new XMIResourceFactoryImpl();
resource = c.createResource(URI.createURI(newInput.toString()));
try {
resource.load(null);
} catch (IOException e) {
e.printStackTrace();
}
}