public void saveModels(String name) {
ResourceSet set = new ResourceSetImpl();
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
URI srcURI = URI.createFileURI(RESULTPATH + "/" + name + "Family.xmi");
URI trgURI = URI.createFileURI(RESULTPATH + "/" + name + "Person.xmi");
Resource resSource = set.createResource(srcURI);
Resource resTarget = set.createResource(trgURI);
EObject colSource = EcoreUtil.copy(getSourceModel());
EObject colTarget = EcoreUtil.copy(getTargetModel());
resSource.getContents().add(colSource);
resTarget.getContents().add(colTarget);
try {
resSource.save(null);
resTarget.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}
java类org.eclipse.emf.ecore.resource.impl.ResourceSetImpl的实例源码
EMoflonFamiliesToPersons.java 文件源码
项目:benchmarx
阅读 19
收藏 0
点赞 0
评论 0
ProgramPerformanceAnalyser.java 文件源码
项目:haetae
阅读 13
收藏 0
点赞 0
评论 0
public void visit(EOLModule program)
{
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
Resource resource = resourceSet.createResource(URI.createFileURI(new File("test.xmi").getAbsolutePath()));
resource.getContents().add(program);
model = new InMemoryEmfModel("EOL", program.eResource(), EolPackage.eINSTANCE);
try {
matchSelectPatterOne(program);
matchSelectPatterTwo(program);
matchSelectPatterThree(program);
matchSelectPatterFour(program);
matchSelectPatterFive(program);
} catch (Exception e) {
e.printStackTrace();
}
}
NewChildTest.java 文件源码
项目:library-training
阅读 20
收藏 0
点赞 0
评论 0
/**
* Check that referenced element type are in the registry
*/
@Test
public void checkMenuNewChildElementTypeIdRefs() {
URI createPlatformPluginURI = URI.createPlatformPluginURI(NEW_CHILD_MENU_PATH, true);
ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
Resource resource = resourceSetImpl.getResource(createPlatformPluginURI, true);
TreeIterator<EObject> allContents = resource.getAllContents();
while (allContents.hasNext()) {
EObject eObject = (EObject) allContents.next();
if (eObject instanceof CreationMenu) {
String iconPath = ((CreationMenu) eObject).getIcon();
if (iconPath != null && !"".equals(iconPath)){
try {
Assert.assertNotNull("The icon "+iconPath+" can't be found", FileLocator.find(new URL(iconPath)));
} catch (MalformedURLException e) {
Assert.fail("The new child menu is refering to a malformed url "+iconPath);
}
}
}
}
}
ExtendedLanguageConfig.java 文件源码
项目:dsl-devkit
阅读 15
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
* <p>
* Registers all EPackages (transitively) referenced by registered GenModels prior to calling {@link LanguageConfig#setUri(String)}.
*/
@Override
public void setUri(final String uri) {
ResourceSet rs = new ResourceSetImpl();
Set<URI> result = Sets.newHashSet();
@SuppressWarnings("deprecation")
Map<String, URI> genModelLocationMap = EcorePlugin.getEPackageNsURIToGenModelLocationMap();
for (Map.Entry<String, URI> entry : genModelLocationMap.entrySet()) {
Resource resource = GenModelAccess.getGenModelResource(null, entry.getKey(), rs);
if (resource != null) {
for (EObject model : resource.getContents()) {
if (model instanceof GenModel) {
GenModel genModel = (GenModel) model;
result.addAll(getReferencedEPackages(genModel));
}
}
}
}
for (URI u : result) {
addLoadedResource(u.toString());
}
super.setUri(uri);
}
CheckResourceUtil.java 文件源码
项目:dsl-devkit
阅读 17
收藏 0
点赞 0
评论 0
/**
* Gets all available grammars.
* <p>
* The result contains no null entries.
* </p>
*
* @return an iterator over all grammars in the workspace followed by all those in the registry.
*/
private Iterable<Grammar> allGrammars() {
final ResourceSet resourceSetForResolve = new ResourceSetImpl();
final Function<IEObjectDescription, Grammar> description2GrammarTransform = new Function<IEObjectDescription, Grammar>() {
@Override
public Grammar apply(final IEObjectDescription desc) {
EObject obj = desc.getEObjectOrProxy();
if (obj != null && obj.eIsProxy()) {
obj = EcoreUtil.resolve(obj, resourceSetForResolve);
}
if (obj instanceof Grammar && !obj.eIsProxy()) {
return (Grammar) obj;
} else {
return null;
}
}
};
final Iterable<IEObjectDescription> grammarDescriptorsFromIndex = Access.getIResourceDescriptions().get().getExportedObjectsByType(XtextPackage.Literals.GRAMMAR);
return Iterables.concat(Iterables.filter(Iterables.transform(grammarDescriptorsFromIndex, description2GrammarTransform), Predicates.notNull()), allGrammarsFromRegistry());
}
ServerWithAuthentication.java 文件源码
项目:M2Doc
阅读 15
收藏 0
点赞 0
评论 0
@BeforeClass
public static void startCDOServer() throws IOException, CommitException {
server = new CDOServer(true);
server.start();
IConnector connector = M2DocCDOUtils
.getConnector(CDOServer.PROTOCOL + "://" + CDOServer.IP + ":" + CDOServer.PORT);
CDOSession session = M2DocCDOUtils.openSession(connector, CDOServer.REPOSITORY_NAME, CDOServer.USER_NAME,
CDOServer.PASSWORD);
final CDOTransaction transaction = M2DocCDOUtils.openTransaction(session);
final CDOResource resource = transaction.createResource("anydsl.ecore");
final ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
final Resource anyDSLResource = resourceSet.getResource(URI.createFileURI("resources/anydsl.ecore"), true);
resource.getContents().addAll(anyDSLResource.getContents());
resource.save(null);
transaction.commit();
transaction.close();
session.close();
connector.close();
if (!EMFPlugin.IS_ECLIPSE_RUNNING) {
ConfigurationProviderService.getInstance().register(CONFIGURATION_PROVIDER);
M2DocUtils.registerServicesConfigurator(SERVICES_CONFIGURATOR_DESCRIPTOR);
}
}
CustomClassAwareEcoreGenerator.java 文件源码
项目:dsl-devkit
阅读 21
收藏 0
点赞 0
评论 0
/**
* Registers the given source-paths in the generator.
*/
@Override
public void preInvoke() {
ResourceSet resSet = new ResourceSetImpl();
Resource resource = resSet.getResource(URI.createURI(genModel), true);
for (EObject obj : resource.getContents()) {
if (obj instanceof GenModel) {
GenModel model = (GenModel) obj;
addSourcePathForPlugin(model.getModelPluginID());
for (GenPackage usedPackage : model.getUsedGenPackages()) {
addSourcePathForPlugin(usedPackage.getGenModel().getModelPluginID());
}
}
}
LOGGER.info("Registered source path to discover custom classes: " + Joiner.on(", ").join(this.srcPaths));
}
SimpleNameScopeProviderTest.java 文件源码
项目:xtext-core
阅读 18
收藏 0
点赞 0
评论 0
@Test public void testGetAllContents() throws Exception {
SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter();
ResourceSetImpl rs = new ResourceSetImpl();
rs.setURIConverter(models);
models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type Foo");
models.addModel("bar.importuritestlanguage", "type A type B type C");
Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);
IScope scope = getScopeProvider().getScope(((Main)resource.getContents().get(0)).getTypes().get(0), ImportedURIPackage.Literals.TYPE__EXTENDS);
HashSet<IEObjectDescription> set = Sets.newHashSet(scope.getAllElements());
assertEquals(4,set.size());
}
ResourceRepositoryImpl.java 文件源码
项目:Vitruv
阅读 15
收藏 0
点赞 0
评论 0
public ResourceRepositoryImpl(final File folder, final VitruvDomainRepository metamodelRepository,
final ClassLoader classLoader) {
this.metamodelRepository = metamodelRepository;
this.folder = folder;
this.resourceSet = new ResourceSetImpl();
ResourceSetUtil.addExistingFactoriesToResourceSet(this.resourceSet);
this.modelInstances = new HashMap<VURI, ModelInstance>();
this.fileSystemHelper = new FileSystemHelper(this.folder);
initializeUuidProviderAndResolver();
this.domainToRecorder = new HashMap<VitruvDomain, AtomicEmfChangeRecorder>();
initializeCorrespondenceModel();
loadVURIsOfVSMUModelInstances();
}
Models.java 文件源码
项目:Vitruv
阅读 29
收藏 0
点赞 0
评论 0
public static Resource loadModel(URL modelURL) {
ResourceSet resSet = new ResourceSetImpl();
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());
EcoreResourceFactoryImpl ecoreResFact = new EcoreResourceFactoryImpl();
URI fileName = BasicTestCase.getURI(modelURL);
LOGGER.info("Trying to load " + fileName);
Resource ecoreRes = ecoreResFact.createResource(fileName);
try {
ecoreRes.load(null);
} catch (IOException e) {
fail("Could not load " + Files.EXAMPLEMODEL_ECORE.getFile() + ". Reason: " + e);
}
resSet.getResources().add(ecoreRes);
return ecoreRes;
}