public Validate()
{
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("calender", new XMIResourceFactoryImpl());
ResourceSet rs = new ResourceSetImpl();
Resource r = rs.getResource(URI.createFileURI("model/mynew.calender"), true);
EObject root = r.getContents().get(0);
Iterator<EObject> i = r.getAllContents();
while(i.hasNext())
System.out.println(i.next());
}
java类org.eclipse.emf.ecore.resource.impl.ResourceSetImpl的实例源码
Validate.java 文件源码
项目:MBSE-Vacation-Manager
阅读 29
收藏 0
点赞 0
评论 0
GemocSequentialPropertyTester.java 文件源码
项目:gemoc-studio-modeldebugging
阅读 19
收藏 0
点赞 0
评论 0
protected boolean isModel(IAdaptable receiver){
IFile modelFile = (IFile)(receiver).getAdapter(IFile.class);
if(modelFile !=null){
ResourceSet rs = new ResourceSetImpl();
URI modelURI = URI.createURI("platform:/resource/"+modelFile.getFullPath().toString());
try{
Resource resource = rs.getResource(modelURI, true);
if (resource != null) {
return true;
}
} catch (Exception e){
// not a valid model, simply ignore
return false;
}
}
return false;
}
CreateDSAWizardContextActionDSAK3.java 文件源码
项目:gemoc-studio-modeldebugging
阅读 17
收藏 0
点赞 0
评论 0
private GenModel loadGenmodel(String path) {
try {
if (!EPackage.Registry.INSTANCE.containsKey(GenModelPackage.eNS_URI))
EPackage.Registry.INSTANCE.put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("genmodel", new XMIResourceFactoryImpl());
ResourceSet rs = new ResourceSetImpl();
URI uri = URI.createURI(path);
Resource pkg = rs.getResource(uri, true);
return (GenModel) pkg.getContents().get(0);
} catch (Exception e) {
// ...
}
return null;
}
CreateDSAProposal.java 文件源码
项目:gemoc-studio-modeldebugging
阅读 19
收藏 0
点赞 0
评论 0
private GenModel loadGenmodel(String path) {
try {
if (!EPackage.Registry.INSTANCE.containsKey(GenModelPackage.eNS_URI))
EPackage.Registry.INSTANCE.put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("genmodel", new XMIResourceFactoryImpl());
ResourceSet rs = new ResourceSetImpl();
URI uri = URI.createURI(path);
Resource pkg = rs.getResource(uri, true);
return (GenModel) pkg.getContents().get(0);
} catch (Exception e) {
// ...
}
return null;
}
ChartConfiguratorView.java 文件源码
项目:neoscada
阅读 27
收藏 0
点赞 0
评论 0
public void setChartConfiguration ( final Chart chart )
{
if ( chart == null )
{
this.viewer.setInput ( null );
}
else
{
if ( chart.eResource () == null )
{
final ResourceSetImpl rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createURI ( "urn:dummy" ) );
r.getContents ().add ( chart );
}
if ( chart.eResource ().getURI () == null )
{
chart.eResource ().setURI ( URI.createURI ( "urn:dummy" ) );
}
this.viewer.setInput ( chart.eResource () );
}
}
ChartHelper.java 文件源码
项目:neoscada
阅读 29
收藏 0
点赞 0
评论 0
public static Chart loadConfiguraton ( final String configurationUri )
{
if ( configurationUri == null || configurationUri.isEmpty () )
{
return null;
}
// load
ChartPackage.eINSTANCE.eClass ();
final ResourceSet resourceSet = new ResourceSetImpl ();
resourceSet.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "*", new XMIResourceFactoryImpl () ); //$NON-NLS-1$
final Resource resource = resourceSet.getResource ( URI.createURI ( configurationUri ), true );
for ( final EObject o : resource.getContents () )
{
if ( o instanceof Chart )
{
return (Chart)o;
}
}
return null;
}
DetailViewImpl.java 文件源码
项目:neoscada
阅读 25
收藏 0
点赞 0
评论 0
private void load ()
{
logger.info ( "Loading: {}", this.uri ); //$NON-NLS-1$
final ResourceSet resourceSet = new ResourceSetImpl ();
resourceSet.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "*", new XMIResourceFactoryImpl () ); //$NON-NLS-1$
final URI file = URI.createURI ( this.uri );
final Resource resource = resourceSet.getResource ( file, true );
for ( final EObject o : resource.getContents () )
{
if ( o instanceof View )
{
createView ( (View)o );
}
}
}
ArduinoDriverImpl.java 文件源码
项目:neoscada
阅读 17
收藏 0
点赞 0
评论 0
@Override
public Profile getProfile ()
{
if ( this.profile == null )
{
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createURI ( DEFAULT_URI ) );
try
{
r.load ( null );
}
catch ( final IOException e )
{
throw new RuntimeException ( e );
}
this.profile = (Profile)EcoreUtil.getObjectByType ( r.getContents (), ProfilePackage.Literals.PROFILE );
if ( this.profile == null )
{
throw new IllegalStateException ( String.format ( "Resource loaded from %s does not contain an object of type %s", DEFAULT_URI, Profile.class.getName () ) );
}
}
return this.profile;
}
ServerHostImpl.java 文件源码
项目:neoscada
阅读 26
收藏 0
点赞 0
评论 0
public Collection<? extends ServerDescriptor> startServer ( final URI exporterFileUri, final String locationLabel ) throws CoreException
{
final ResourceSetImpl resourceSet = new ResourceSetImpl ();
resourceSet.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "*", new ExporterResourceFactoryImpl () );
final Resource resource = resourceSet.createResource ( exporterFileUri );
try
{
resource.load ( null );
}
catch ( final IOException e )
{
throw new CoreException ( StatusHelper.convertStatus ( HivesPlugin.PLUGIN_ID, "Failed to load configuration", e ) );
}
final DocumentRoot root = (DocumentRoot)EcoreUtil.getObjectByType ( resource.getContents (), ExporterPackage.Literals.DOCUMENT_ROOT );
if ( root == null )
{
throw new CoreException ( new Status ( IStatus.ERROR, HivesPlugin.PLUGIN_ID, "Failed to locate exporter configuration in: " + exporterFileUri ) );
}
return startServer ( root, locationLabel );
}
ParserDriverImpl.java 文件源码
项目:neoscada
阅读 20
收藏 0
点赞 0
评论 0
/**
* @generated NOT
*/
@Override
public Profile getProfile ()
{
if ( this.profile == null )
{
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createURI ( DEFAULT_URI ), "org.eclipse.scada.configuration.world.osgi.profile" );
try
{
r.load ( null );
}
catch ( final IOException e )
{
throw new RuntimeException ( e );
}
this.profile = (Profile)EcoreUtil.getObjectByType ( r.getContents (), ProfilePackage.Literals.PROFILE );
if ( this.profile == null )
{
throw new IllegalStateException ( String.format ( "Resource loaded from %s does not contain an object of type %s", DEFAULT_URI, Profile.class.getName () ) );
}
}
return this.profile;
}
DriverApplicationImpl.java 文件源码
项目:neoscada
阅读 16
收藏 0
点赞 0
评论 0
/**
* @generated NOT
*/
@Override
public Profile getProfile ()
{
if ( this.profile == null )
{
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createURI ( DEFAULT_URI ), "org.eclipse.scada.configuration.world.osgi.profile" );
try
{
r.load ( null );
}
catch ( final IOException e )
{
throw new RuntimeException ( e );
}
this.profile = (Profile)EcoreUtil.getObjectByType ( r.getContents (), ProfilePackage.Literals.PROFILE );
if ( this.profile == null )
{
throw new IllegalStateException ( String.format ( "Resource loaded from %s does not contain an object of type %s", DEFAULT_URI, Profile.class.getName () ) );
}
}
return this.profile;
}
CommonPackageHandler.java 文件源码
项目:neoscada
阅读 16
收藏 0
点赞 0
评论 0
/**
* Inject the CA bootstrap property to the profile
*
* @param file
* the profile.xml file in the package target
* @throws IOException
*/
protected void patchProfile ( final String appName, final File file ) throws IOException
{
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createFileURI ( file.toString () ) );
r.load ( null );
final Profile profile = (Profile)EcoreUtil.getObjectByType ( r.getContents (), ProfilePackage.Literals.PROFILE );
Profiles.addSystemProperty ( profile, "org.eclipse.scada.ca.file.provisionJsonUrl", "file:///usr/share/eclipsescada/ca.bootstrap/bootstrap." + appName + ".json" );
r.save ( null );
}
ModelLoader.java 文件源码
项目:neoscada
阅读 24
收藏 0
点赞 0
评论 0
public T load ( final URI uri, final String contentTypeId ) throws IOException
{
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( uri, contentTypeId );
r.load ( null );
for ( final Object o : r.getContents () )
{
if ( this.clazz.isAssignableFrom ( o.getClass () ) )
{
return this.clazz.cast ( o );
}
}
throw new IllegalStateException ( String.format ( "Model %s does not contain an object of type %s", uri, this.clazz ) );
}
DaveDriverImpl.java 文件源码
项目:neoscada
阅读 18
收藏 0
点赞 0
评论 0
/**
* @generated NOT
*/
@Override
public Profile getProfile ()
{
if ( this.profile == null )
{
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createURI ( DEFAULT_URI ), "org.eclipse.scada.configuration.world.osgi.profile" );
try
{
r.load ( null );
}
catch ( final IOException e )
{
throw new RuntimeException ( e );
}
this.profile = (Profile)EcoreUtil.getObjectByType ( r.getContents (), ProfilePackage.Literals.PROFILE );
if ( this.profile == null )
{
throw new IllegalStateException ( String.format ( "Resource loaded from %s does not contain an object of type %s", DEFAULT_URI, Profile.class.getName () ) );
}
}
return this.profile;
}
ModbusDriverImpl.java 文件源码
项目:neoscada
阅读 19
收藏 0
点赞 0
评论 0
@Override
public Profile getProfile ()
{
if ( this.profile == null )
{
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createURI ( DEFAULT_URI ), "org.eclipse.scada.configuration.world.osgi.profile" );
try
{
r.load ( null );
}
catch ( final IOException e )
{
throw new RuntimeException ( e );
}
this.profile = (Profile)EcoreUtil.getObjectByType ( r.getContents (), ProfilePackage.Literals.PROFILE );
if ( this.profile == null )
{
throw new IllegalStateException ( String.format ( "Resource loaded from %s does not contain an object of type %s", DEFAULT_URI, Profile.class.getName () ) );
}
}
return this.profile;
}
DefaultValueArchiveServerImpl.java 文件源码
项目:neoscada
阅读 17
收藏 0
点赞 0
评论 0
@Override
public Profile getProfile ()
{
if ( this.profile == null )
{
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createURI ( DEFAULT_URI ), "org.eclipse.scada.configuration.world.osgi.profile" );
try
{
r.load ( null );
}
catch ( final IOException e )
{
throw new RuntimeException ( e );
}
this.profile = (Profile)EcoreUtil.getObjectByType ( r.getContents (), ProfilePackage.Literals.PROFILE );
if ( this.profile == null )
{
throw new IllegalStateException ( String.format ( "Resource loaded from %s does not contain an object of type %s", DEFAULT_URI, Profile.class.getName () ) );
}
}
return this.profile;
}
DefaultMasterServerImpl.java 文件源码
项目:neoscada
阅读 14
收藏 0
点赞 0
评论 0
@Override
public Profile getProfile ()
{
if ( this.profile == null )
{
final ResourceSet rs = new ResourceSetImpl ();
final Resource r = rs.createResource ( URI.createURI ( DEFAULT_URI ), "org.eclipse.scada.configuration.world.osgi.profile" );
try
{
r.load ( null );
}
catch ( final IOException e )
{
throw new RuntimeException ( e );
}
this.profile = (Profile)EcoreUtil.getObjectByType ( r.getContents (), ProfilePackage.Literals.PROFILE );
if ( this.profile == null )
{
throw new IllegalStateException ( String.format ( "Resource loaded from %s does not contain an object of type %s", DEFAULT_URI, Profile.class.getName () ) );
}
}
return this.profile;
}
Hive.java 文件源码
项目:neoscada
阅读 23
收藏 0
点赞 0
评论 0
private static RootType parse ( final URI uri ) throws IOException
{
final ResourceSet rs = new ResourceSetImpl ();
rs.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "*", new ConfigurationResourceFactoryImpl () );
final Resource r = rs.createResource ( uri );
r.load ( null );
final DocumentRoot doc = (DocumentRoot)EcoreUtil.getObjectByType ( r.getContents (), ConfigurationPackage.Literals.DOCUMENT_ROOT );
if ( doc == null )
{
return null;
}
else
{
return doc.getRoot ();
}
}
PrettyPrinter.java 文件源码
项目:greycat-idea-plugin
阅读 16
收藏 0
点赞 0
评论 0
protected ResourceSet getEcoreModel(File ecorefile) {
ResourceSetImpl rs = new ResourceSetImpl();
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
try {
URI fileUri = URI.createFileURI(ecorefile.getCanonicalPath());
Resource resource = rs.createResource(fileUri);
resource.load(null);
EcoreUtil.resolveAll(resource);
rs.getResources().add(resource);
EcoreUtil.resolveAll(rs);
} catch (IOException e) {
e.printStackTrace();
}
return rs;
}
EcoreResource.java 文件源码
项目:JavaGraph
阅读 19
收藏 0
点赞 0
评论 0
public EcoreResource(File typeTarget, File instanceTarget) {
this.m_resourceSet = new ResourceSetImpl();
this.m_resourceSet.getResourceFactoryRegistry()
.getExtensionToFactoryMap()
.put("*", new XMIResourceFactoryImpl());
this.m_typeFile = typeTarget;
this.m_instanceFile = instanceTarget;
if (this.m_typeFile == this.m_instanceFile || this.m_typeFile == null
|| this.m_instanceFile == null) {
this.relPath = "";
} else {
this.relPath =
groove.io.Util.getRelativePath(new File(this.m_instanceFile.getAbsoluteFile()
.getParent()), this.m_typeFile.getAbsoluteFile())
.toString();
}
}
ExtensionsManager.java 文件源码
项目:TOSCA-Studio
阅读 14
收藏 0
点赞 0
评论 0
public static void createExtendedTosca() {
ResourceSet resSet = new ResourceSetImpl();
URI modelURI = URI
.createURI("file:/C:/Users/schallit/workspace-tosca2/plugins/org.eclipse.cmf.occi.tosca.extended/model/extendedTosca.occie");
resource = resSet.createResource(modelURI);
Extension extension = OCCIFactory.eINSTANCE.createExtension();
extension.setDescription("Extended TOSCA");
extension.setScheme("http://org.occi/extendedTosca#");
extension.setName("extendedTosca");
Extension toscaExtension = OcciHelper.loadExtension("http://org.occi/tosca#");
extension.getImport().add(extensionsPerName.get("core"));
extension.getImport().add(extensionsPerName.get("infrastructure"));
extension.getImport().add(extensionsPerName.get("platform"));
extension.getImport().add(extensionsPerName.get("sla"));
extension.getImport().add(toscaExtension);
copy(toscaExtension);
extensionsPerName.replace("tosca", toscaExtension);
resource.getContents().add(extension);
extensionsPerName.put("extendedTosca", extension);
currentExtensionToBeBuild = extension;
}
ConfigManager.java 文件源码
项目:TOSCA-Studio
阅读 26
收藏 0
点赞 0
评论 0
public static void createConfiguration(String path) {
String name = convertPathToConfigName(path);
ResourceSet resSet = new ResourceSetImpl();
URI modelURI = URI
.createURI("file:/C:/Users/schallit/workspace-tosca2/plugins/org.eclipse.cmf.occi.tosca.examples/" + name + ".extendedTosca");
resource = resSet.createResource(modelURI);
Configuration configuration = OCCIFactory.eINSTANCE.createConfiguration();
configuration.getUse().add(OcciHelper.loadExtension("http://schemas.ogf.org/occi/core#"));
configuration.getUse().add(OcciHelper.loadExtension("http://schemas.ogf.org/occi/infrastructure#"));
configuration.getUse().add(OcciHelper.loadExtension("http://schemas.ogf.org/occi/platform#"));
configuration.getUse().add(OcciHelper.loadExtension("http://schemas.ogf.org/occi/sla#"));
configuration.getUse().add(OcciHelper.loadExtension("http://org.occi/tosca#"));
configuration.getUse().add(OcciHelper.loadExtension("http://org.occi/extendedTosca#"));
resource.getContents().add(configuration);
currentConfiguration = configuration;
}
EcoreUtilities.java 文件源码
项目:Tarski
阅读 22
收藏 0
点赞 0
评论 0
@SuppressWarnings({"unchecked", "rawtypes"})
public static void saveResources(final List<EObject> root, final URI uri) {
final ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMLResourceFactoryImpl());
final Resource resource = resourceSet.createResource(uri);
resource.getContents().addAll(root);
final Map options = new HashMap();
options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
try {
resource.save(options);
} catch (final IOException e) {
e.printStackTrace();
}
}
DesignerGeneratorAction.java 文件源码
项目:OCCI-Studio
阅读 21
收藏 0
点赞 0
评论 0
private IProject generateDesignProject(String occieLocation, String designName, String designProjectName,
final IProgressMonitor monitor) throws CoreException, IOException {
// Load the ecore file.
String ecoreLocation = occieLocation.replace(".occie", ".ecore");
URI ecoreURI = URI.createFileURI(ecoreLocation);
// Create a new resource set.
ResourceSet resourceSet = new ResourceSetImpl();
// Load the OCCI resource.
org.eclipse.emf.ecore.resource.Resource resource = resourceSet.getResource(ecoreURI, true);
// Return the first element.
EPackage ePackage = (EPackage) resource.getContents().get(0);
String extensionScheme = Occi2Ecore.convertEcoreNamespace2OcciScheme(ePackage.getNsURI());
// Register the ePackage to avoid an error when trying to open the generated
// .odesign file,
EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
URI occieURI = URI.createFileURI(occieLocation);
/*
* Create design project
*/
IProject project = DesignerGeneratorUtils.genDesignProject(designProjectName, designName, extensionScheme,
new ProgressMonitorDialog(shell));
/*
* Create design model
*/
org.eclipse.cmf.occi.core.gen.design.main.Generate generator = new org.eclipse.cmf.occi.core.gen.design.main.Generate(
occieURI, project.getFolder("description").getLocation().toFile(), new ArrayList<String>());
generator.doGenerate(BasicMonitor.toMonitor(monitor));
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
return project;
}
RegisterOCCIExtensionAction.java 文件源码
项目:OCCI-Studio
阅读 15
收藏 0
点赞 0
评论 0
/**
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
if (selection != null) {
IFile selectedFile = (IFile) ((IStructuredSelection) selection)
.getFirstElement();
// Use a platform:/resource/ URI
URI uri = URI.createPlatformResourceURI(selectedFile.getFullPath().toString(), true);
ResourceSet rs = new ResourceSetImpl();
Resource r = rs.getResource(uri, true);
Extension extension = (Extension) r.getContents().get(0);
OcciRegistry.getInstance().registerExtension(extension.getScheme(),
uri.toString());
closeOtherSessions(selectedFile.getProject());
MessageDialog.openInformation(shell,
Messages.RegisterExtensionAction_ExtRegistration,
Messages.RegisterExtensionAction_RegisteredExtension
+ extension.getScheme());
}
}
SurveyGenerator.java 文件源码
项目:SurveyDSL
阅读 14
收藏 0
点赞 0
评论 0
private static Survey loadSurveyModel(String modulePath) {
// Initialize the model
QueryITPackage.eINSTANCE.eClass();
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
m.put("ecore", new EcoreResourceFactoryImpl());
// Obtain a new resource set
ResourceSet resSet = new ResourceSetImpl();
// Get the resource
//Resource resource = resSet.getResource(URI.createFileURI(modulePath), true);
Resource resource = resSet.getResource(URI.createURI(modulePath), true);
// Get the first model element and cast it to the right type, in my
// example everything is included in this first node
Survey s = (Survey) resource.getContents().get(0);
return s;
}
WorkspaceUtil.java 文件源码
项目:termsuite-ui
阅读 15
收藏 0
点赞 0
评论 0
public static void saveResource(EObject emfObject, Path path) {
// Obtain a new resource set
ResourceSet resSet = new ResourceSetImpl();
Resource resource = resSet
.createResource(URI.createFileURI(path.toString()));
// Get the first model element and cast it to the right type, in my
// example everything is hierarchical included in this first node
// if (emfObject instanceof EPipeline) {
// resource.getContents().add(((EPipeline) emfObject).getTaggerConfig());
// }
resource.getContents().add(emfObject);
// now save the content.
Map<String, Object> options = Maps.newHashMap();
// options.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, false);
try {
resource.save(options);
} catch (IOException e) {
throw new TermSuiteException("Could not save resource " + emfObject.getClass().getSimpleName(), e);
}
}
LazyLinkingResourceTest.java 文件源码
项目:xtext-core
阅读 19
收藏 0
点赞 0
评论 0
@Test public void testResolveLazyCrossReferences_02() throws Exception {
with(lazyLinkingTestLangaugeSetup());
ResourceSetImpl rs = new ResourceSetImpl();
final Resource res1 = rs.createResource(URI.createURI("file1.lazylinkingtestlanguage"));
Resource res2 = rs.createResource(URI.createURI("file2.lazylinkingtestlanguage"));
res1.load(new StringInputStream("type Foo { } type Baz { Foo Bar prop; } }"), null);
res2.load(new StringInputStream("type Bar { }"), null);
res1.eAdapters().add(notificationAlert);
Model m = (Model) res1.getContents().get(0);
Type t = m.getTypes().get(1);
Property p = t.getProperties().get(0);
final InternalEList<Type> types = (InternalEList<Type>) p.getType();
assertEquals(2, types.size());
for (Iterator<Type> it = types.basicIterator(); it.hasNext();) {
final Type tt = it.next();
assertTrue(tt.eIsProxy());
}
((LazyLinkingResource) res1).resolveLazyCrossReferences(CancelIndicator.NullImpl);
assertFalse(types.basicGet(0).eIsProxy());
assertTrue(types.basicGet(1).eIsProxy());
res1.eAdapters().remove(notificationAlert);
EcoreUtil.resolveAll(res1);
assertFalse(types.basicGet(0).eIsProxy());
assertFalse(types.basicGet(1).eIsProxy());
}
MediniQVTFamiliesToPersonsConfig.java 文件源码
项目:benchmarx
阅读 19
收藏 0
点赞 0
评论 0
/**
* Allows to save the current state of the source and target models
*
* @param name : Filename
*/
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();
}
}
ResourceSetBasedResourceDescriptionsTest.java 文件源码
项目:xtext-core
阅读 21
收藏 0
点赞 0
评论 0
@Before
public void setUp() throws Exception {
resourceSet = new ResourceSetImpl();
IQualifiedNameProvider qualifiedNameProvider = new IQualifiedNameProvider.AbstractImpl() {
@Override
public QualifiedName getFullyQualifiedName(EObject obj) {
return QualifiedName.create(((ENamedElement) obj).getName());
}
@Override
public QualifiedName apply(EObject from) {
return QualifiedName.create(((ENamedElement) from).getName());
}
};
resourceDescriptionManager = new DefaultResourceDescriptionManager();
resourceDescriptionManager.setCache(IResourceScopeCache.NullImpl.INSTANCE);
DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
strategy.setQualifiedNameProvider(qualifiedNameProvider);
resourceDescriptionManager.setStrategy(strategy);
resDescs = new ResourceSetBasedResourceDescriptions();
resDescs.setContext(resourceSet);
resDescs.setRegistry(this);
container = new ResourceDescriptionsBasedContainer(resDescs);
}