本文整理匯總了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();
}
}