File resources (EMF Resource)

MOFScript provides simple integration with EMF Resources, which allow for getting the resource of an EObject, manipulating its contents, and storing the resource.

Obtaining the resource of an EObject

The resource associated with en EObject is obtained using the _eResource() operation.

Example

uml.Model::main () { var resource:ecore.EResource = self._eResource(); // ... }

Getting the contents of a Resource

The contents of a resource get be obtained using the getContents() operations. It returns a list of EObjects. This list can be manipulated by standard list operations (addOrg, add, remove, removeAt, removeAll...)

Example

var contents:List = resource.getContents()

Removing an element from a resource

contents.removeAt(3)

Adding an element to a resource

var profile:mdl.ProfileApplication = new mdl.ProfileApplication(isStrict=false) resource..addOrg(profile) or resource.getContents().addOrg(profile)

Storing a resource

A Resource is stored by invoking the store() operation on the resource.

Storing the resource using the original URI

resource.store()

Storing the resource with a new URI

resource.store("/home/mofscript/newResource.uml")