Java Code Examples for org.eclipse.emf.ecore.resource.Resource

The following are top voted examples for showing how to use org.eclipse.emf.ecore.resource.Resource. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: neoscada   File: ArduinoDriverImpl.java   View source code 7 votes vote down vote up
@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;
}
 
Example 2
Project: gemoc-studio   File: EMFResource.java   View source code 6 votes vote down vote up
/**
 * Getting an IFile from an EMF Resource
 * 
 * @param eObject
 * @return
 */
public static IFile getIFile(Resource res) {
	URI uri = res.getURI();
	String filePath = uri.toPlatformString(true);
	IFile ifile = ResourcesPlugin.getWorkspace().getRoot()
			.getFile(new Path(filePath));
	return ifile;
}
 
Example 3
Project: ttc2017smartGrids   File: Task2PackageImpl.java   View source code 6 votes vote down vote up
/**
 * Laods the package and any sub-packages from their serialized form.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void loadPackage() {
	if (isLoaded)
		return;
	isLoaded = true;

	URL url = getClass().getResource(packageFilename);
	if (url == null) {
		throw new RuntimeException("Missing serialized package: " + packageFilename);
	}
	URI uri = URI.createURI(url.toString());
	Resource resource = new EcoreResourceFactoryImpl().createResource(uri);
	try {
		resource.load(null);
	} catch (IOException exception) {
		throw new WrappedException(exception);
	}
	initializeFromLoadedEPackage(this, (EPackage) resource.getContents().get(0));
	createResource(eNS_URI);
}
 
Example 4
Project: neoscada   File: ItemEditor.java   View source code 6 votes vote down vote up
/**
 * Returns a diagnostic describing the errors and warnings listed in the resource
 * and the specified exception (if any).
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public Diagnostic analyzeResourceProblems ( Resource resource, Exception exception )
{
    if ( !resource.getErrors ().isEmpty () || !resource.getWarnings ().isEmpty () )
    {
        BasicDiagnostic basicDiagnostic =
                new BasicDiagnostic
                ( Diagnostic.ERROR, "org.eclipse.scada.configuration.item.editor", //$NON-NLS-1$
                        0,
                        getString ( "_UI_CreateModelError_message", resource.getURI () ), //$NON-NLS-1$
                        new Object[] { exception == null ? (Object)resource : exception } );
        basicDiagnostic.merge ( EcoreUtil.computeDiagnostic ( resource, true ) );
        return basicDiagnostic;
    }
    else if ( exception != null )
    {
        return new BasicDiagnostic ( Diagnostic.ERROR, "org.eclipse.scada.configuration.item.editor", //$NON-NLS-1$
                0,
                getString ( "_UI_CreateModelError_message", resource.getURI () ), //$NON-NLS-1$
                new Object[] { exception } );
    }
    else
    {
        return Diagnostic.OK_INSTANCE;
    }
}
 
Example 5
Project: OCCI-Studio   File: OCCIEditor.java   View source code 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel() {
	URI resourceURI = EditUIUtil.getURI(getEditorInput(), editingDomain.getResourceSet().getURIConverter());
	Exception exception = null;
	Resource resource = null;
	try {
		// Load the resource through the editing domain.
		//
		resource = editingDomain.getResourceSet().getResource(resourceURI, true);
	}
	catch (Exception e) {
		exception = e;
		resource = editingDomain.getResourceSet().getResource(resourceURI, false);
	}

	Diagnostic diagnostic = analyzeResourceProblems(resource, exception);
	if (diagnostic.getSeverity() != Diagnostic.OK) {
		resourceToDiagnosticMap.put(resource,  analyzeResourceProblems(resource, exception));
	}
	editingDomain.getResourceSet().eAdapters().add(problemIndicationAdapter);
}
 
Example 6
Project: neoscada   File: CommonPackageHandler.java   View source code 6 votes vote down vote up
/**
 * 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 );
}
 
Example 7
Project: neoscada   File: Hive.java   View source code 6 votes vote down vote up
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 ();
    }
}
 
Example 8
Project: OCCI-Studio   File: SlaEditor.java   View source code 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel() {
	URI resourceURI = EditUIUtil.getURI(getEditorInput(), editingDomain.getResourceSet().getURIConverter());
	Exception exception = null;
	Resource resource = null;
	try {
		// Load the resource through the editing domain.
		//
		resource = editingDomain.getResourceSet().getResource(resourceURI, true);
	}
	catch (Exception e) {
		exception = e;
		resource = editingDomain.getResourceSet().getResource(resourceURI, false);
	}

	Diagnostic diagnostic = analyzeResourceProblems(resource, exception);
	if (diagnostic.getSeverity() != Diagnostic.OK) {
		resourceToDiagnosticMap.put(resource,  analyzeResourceProblems(resource, exception));
	}
	editingDomain.getResourceSet().eAdapters().add(problemIndicationAdapter);
}
 
Example 9
Project: solidity-ide   File: SolidityImportedNamespaceAwareLocalScopeProvider.java   View source code 6 votes vote down vote up
protected IScope getResourceScope(Resource res, EReference reference) {
	if (reference == TypesPackage.Literals.COMPLEX_TYPE__SUPER_TYPES)
		return super.getResourceScope(res, reference);
	EObject context = res.getContents().get(0);
	IScope globalScope = getGlobalScope(res, reference);
	List<ImportNormalizer> normalizers = getSuperTypeImports(res, reference);
	if (!normalizers.isEmpty()) {
		globalScope = createImportScope(globalScope, normalizers, null, reference.getEReferenceType(),
				isIgnoreCase(reference));
	}
	return getResourceScope(globalScope, context, reference);
}
 
Example 10
Project: neoscada   File: ChartResourceFactoryImpl.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource ( URI uri )
{
    XMLResource result = new ChartResourceImpl ( uri );
    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE );
    result.getDefaultLoadOptions ().put ( XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE );

    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE );

    result.getDefaultLoadOptions ().put ( XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE );
    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE );

    result.getDefaultLoadOptions ().put ( XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE );
    return result;
}
 
Example 11
Project: Saturn   File: SqlModuleResourceFactoryImpl.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri)
{
  XMLResource result = new SqlModuleResourceImpl(uri);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
  result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

  result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
  return result;
}
 
Example 12
Project: Saturn   File: SqliteResourceResourceFactoryImpl.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri)
{
  XMLResource result = new SqliteResourceResourceImpl(uri);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
  result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

  result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
  return result;
}
 
Example 13
Project: Saturn   File: ReferenceModuleResourceFactoryImpl.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri)
{
  XMLResource result = new ReferenceModuleResourceImpl(uri);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
  result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

  result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
  return result;
}
 
Example 14
Project: OCCI-Studio   File: CrtpEditor.java   View source code 6 votes vote down vote up
@Override
public void notifyChanged(Notification notification) {
	if (notification.getNotifier() instanceof Resource) {
		switch (notification.getFeatureID(Resource.class)) {
			case Resource.RESOURCE__IS_LOADED:
			case Resource.RESOURCE__ERRORS:
			case Resource.RESOURCE__WARNINGS: {
				Resource resource = (Resource)notification.getNotifier();
				Diagnostic diagnostic = analyzeResourceProblems(resource, null);
				if (diagnostic.getSeverity() != Diagnostic.OK) {
					resourceToDiagnosticMap.put(resource, diagnostic);
				}
				else {
					resourceToDiagnosticMap.remove(resource);
				}
				dispatchUpdateProblemIndication();
				break;
			}
		}
	}
	else {
		super.notifyChanged(notification);
	}
}
 
Example 15
Project: Saturn   File: DataSetResourceResourceFactoryImpl.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri)
{
  XMLResource result = new DataSetResourceResourceImpl(uri);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
  result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

  result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
  return result;
}
 
Example 16
Project: n4js   File: XpectN4JSES5TranspilerHelper.java   View source code 6 votes vote down vote up
/**
 * @return the resources retrieved from the Xpect resource set configuration
 */
@Override
public List<Resource> getResources() {
	final List<Resource> configuredResources = newArrayList();
	if (configuredResourceSet != null) {
		for (ResourceFactory factory : configuredResourceSet.getFactories()) {
			if (factory instanceof org.eclipse.xpect.xtext.lib.setup.emf.Resource) {
				org.eclipse.xpect.xtext.lib.setup.emf.Resource res = (org.eclipse.xpect.xtext.lib.setup.emf.Resource) factory;
				try {
					if (fileSetupCtx != null) {
						Resource createdRes = res.create(fileSetupCtx, resourceSet);
						configuredResources.add(createdRes);
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	return configuredResources;
}
 
Example 17
Project: Saturn   File: QueryResourceResourceFactoryImpl.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri)
{
  XMLResource result = new QueryResourceResourceImpl(uri);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
  result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

  result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
  return result;
}
 
Example 18
Project: OCCI-Studio   File: InfrastructureEditor.java   View source code 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel() {
	URI resourceURI = EditUIUtil.getURI(getEditorInput(), editingDomain.getResourceSet().getURIConverter());
	Exception exception = null;
	Resource resource = null;
	try {
		// Load the resource through the editing domain.
		//
		resource = editingDomain.getResourceSet().getResource(resourceURI, true);
	}
	catch (Exception e) {
		exception = e;
		resource = editingDomain.getResourceSet().getResource(resourceURI, false);
	}

	Diagnostic diagnostic = analyzeResourceProblems(resource, exception);
	if (diagnostic.getSeverity() != Diagnostic.OK) {
		resourceToDiagnosticMap.put(resource,  analyzeResourceProblems(resource, exception));
	}
	editingDomain.getResourceSet().eAdapters().add(problemIndicationAdapter);
}
 
Example 19
Project: neoscada   File: ConfigurationResourceFactoryImpl.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource ( URI uri )
{
    XMLResource result = new ConfigurationResourceImpl ( uri );
    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE );
    result.getDefaultLoadOptions ().put ( XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE );

    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE );

    result.getDefaultLoadOptions ().put ( XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE );
    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE );

    result.getDefaultLoadOptions ().put ( XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE );
    return result;
}
 
Example 20
Project: neoscada   File: ProfileResourceFactoryImpl.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
@Override
public Resource createResource ( final URI uri )
{
    final XMLResource result = new ProfileResourceImpl ( uri );

    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE );
    result.getDefaultLoadOptions ().put ( XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE );

    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE );

    result.getDefaultLoadOptions ().put ( XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE );
    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE );

    result.getDefaultLoadOptions ().put ( XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE );

    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_URI_HANDLER, new URIHandlerImpl.PlatformSchemeAware () );

    return result;
}
 
Example 21
Project: Saturn   File: XSplitModuleResourceFactoryImpl.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri)
{
  XMLResource result = new XSplitModuleResourceImpl(uri);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
  result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

  result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
  return result;
}
 
Example 22
Project: rest-modeling-framework   File: IncludeTest.java   View source code 6 votes vote down vote up
@Test
public void load() throws IOException {
    final Resource resource = fromClasspath("/data-type-include.raml");
    assertThat(resource.getErrors()).hasSize(0);

    final Library library = getRootObject(resource);
    final EList<AnyType> types = library.getTypes();

    assertThat(types).hasSize(1);
    assertThat(types.get(0)).isInstanceOf(ObjectType.class);

    final ObjectType personType = (ObjectType) types.get(0);

    assertThat(personType.getName()).isEqualTo("Person");
    assertThat(personType.getDisplayName()).isEqualTo("Person");
    assertThat(personType.getProperties()).hasSize(1);

    final Property ageProperty = personType.getProperties().get(0);

    assertThat(ageProperty.getName()).isEqualTo("age");
    assertThat(ageProperty.getType().getName()).isEqualTo("integer");
}
 
Example 23
Project: smarthome-cep-demonstrator   File: SmarthomeEditor.java   View source code 6 votes vote down vote up
@Override
public void notifyChanged(Notification notification) {
	if (notification.getNotifier() instanceof Resource) {
		switch (notification.getFeatureID(Resource.class)) {
			case Resource.RESOURCE__IS_LOADED:
			case Resource.RESOURCE__ERRORS:
			case Resource.RESOURCE__WARNINGS: {
				Resource resource = (Resource)notification.getNotifier();
				Diagnostic diagnostic = analyzeResourceProblems(resource, null);
				if (diagnostic.getSeverity() != Diagnostic.OK) {
					resourceToDiagnosticMap.put(resource, diagnostic);
				}
				else {
					resourceToDiagnosticMap.remove(resource);
				}
				dispatchUpdateProblemIndication();
				break;
			}
		}
	}
	else {
		super.notifyChanged(notification);
	}
}
 
Example 24
Project: rest-modeling-framework   File: TypedFragmentTest.java   View source code 6 votes vote down vote up
@Test
public void dataType() throws IOException {
    final Resource resource = fromClasspath("/includes/data-type-fragment.raml");
    final ObjectType objectType = getRootObject(resource);

    assertThat(objectType.getName())
            .as("Name of a typed fragment")
            .isNull();

    assertThat(objectType.getDisplayName()).isEqualTo("Person");

    final EList<Property> properties = objectType.getProperties();
    assertThat(properties)
            .hasSize(1);

    final Property nameProperty = properties.get(0);
    assertThat(nameProperty.getName())
            .isEqualTo("age");
    assertThat(nameProperty.getType().getName())
            .isEqualTo("integer");
}
 
Example 25
Project: neoscada   File: InfrastructureEditor.java   View source code 6 votes vote down vote up
/**
 * This returns whether something has been persisted to the URI of the specified resource.
 * The implementation uses the URI converter from the editor's resource set to try to open an input stream.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected boolean isPersisted ( Resource resource )
{
    boolean result = false;
    try
    {
        InputStream stream = editingDomain.getResourceSet ().getURIConverter ().createInputStream ( resource.getURI () );
        if ( stream != null )
        {
            result = true;
            stream.close ();
        }
    }
    catch ( IOException e )
    {
        // Ignore
    }
    return result;
}
 
Example 26
Project: OCCI-Studio   File: OCCIEditor.java   View source code 6 votes vote down vote up
@Override
public void notifyChanged(Notification notification) {
	if (notification.getNotifier() instanceof Resource) {
		switch (notification.getFeatureID(Resource.class)) {
			case Resource.RESOURCE__IS_LOADED:
			case Resource.RESOURCE__ERRORS:
			case Resource.RESOURCE__WARNINGS: {
				Resource resource = (Resource)notification.getNotifier();
				Diagnostic diagnostic = analyzeResourceProblems(resource, null);
				if (diagnostic.getSeverity() != Diagnostic.OK) {
					resourceToDiagnosticMap.put(resource, diagnostic);
				}
				else {
					resourceToDiagnosticMap.remove(resource);
				}
				dispatchUpdateProblemIndication();
				break;
			}
		}
	}
	else {
		super.notifyChanged(notification);
	}
}
 
Example 27
Project: neoscada   File: ModbusDriverImpl.java   View source code 6 votes vote down vote up
@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;
}
 
Example 28
Project: OCCI-Studio   File: MonitoringEditor.java   View source code 6 votes vote down vote up
/**
 * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void createModel() {
	URI resourceURI = EditUIUtil.getURI(getEditorInput(), editingDomain.getResourceSet().getURIConverter());
	Exception exception = null;
	Resource resource = null;
	try {
		// Load the resource through the editing domain.
		//
		resource = editingDomain.getResourceSet().getResource(resourceURI, true);
	}
	catch (Exception e) {
		exception = e;
		resource = editingDomain.getResourceSet().getResource(resourceURI, false);
	}

	Diagnostic diagnostic = analyzeResourceProblems(resource, exception);
	if (diagnostic.getSeverity() != Diagnostic.OK) {
		resourceToDiagnosticMap.put(resource,  analyzeResourceProblems(resource, exception));
	}
	editingDomain.getResourceSet().eAdapters().add(problemIndicationAdapter);
}
 
Example 29
Project: Saturn   File: SaturnReportResourceFactoryImpl.java   View source code 6 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri)
{
  XMLResource result = new SaturnReportResourceImpl(uri);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
  result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

  result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
  result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

  result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
  return result;
}
 
Example 30
Project: neoscada   File: ChartEditor.java   View source code 6 votes vote down vote up
/**
 * This returns whether something has been persisted to the URI of the
 * specified resource.
 * The implementation uses the URI converter from the editor's resource set
 * to try to open an input stream.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated
 */
protected boolean isPersisted ( final Resource resource )
{
    boolean result = false;
    try
    {
        final InputStream stream = this.editingDomain.getResourceSet ()
                .getURIConverter ().createInputStream ( resource.getURI () );
        if ( stream != null )
        {
            result = true;
            stream.close ();
        }
    }
    catch ( final IOException e )
    {
        // Ignore
    }
    return result;
}
 
Example 31
Project: rgse.ttc17.emoflon.tgg   File: Task1PackageImpl.java   View source code 6 votes vote down vote up
/**
 * Laods the package and any sub-packages from their serialized form.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void loadPackage() {
	if (isLoaded)
		return;
	isLoaded = true;

	URL url = getClass().getResource(packageFilename);
	if (url == null) {
		throw new RuntimeException("Missing serialized package: " + packageFilename);
	}
	URI uri = URI.createURI(url.toString());
	Resource resource = new EcoreResourceFactoryImpl().createResource(uri);
	try {
		resource.load(null);
	} catch (IOException exception) {
		throw new WrappedException(exception);
	}
	initializeFromLoadedEPackage(this, (EPackage) resource.getContents().get(0));
	createResource(eNS_URI);
}
 
Example 32
Project: n4js   File: N4MFStandaloneSetupGenerated.java   View source code 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("n4mf", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("n4mf", serviceProvider);
}
 
Example 33
Project: gemoc-studio   File: StandaloneSetup.java   View source code 5 votes vote down vote up
public void doEMFRegistration() {
  EPackage.Registry.INSTANCE.put(
  	org.eclipse.gemoc.sample.legacyfsm.fsm.FsmPackage.eNS_URI,
  	org.eclipse.gemoc.sample.legacyfsm.fsm.FsmPackage.eINSTANCE
  );
  
  Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
  	"*",
  	new XMIResourceFactoryImpl()
  );
  Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap().put(
  	"melange",
  	new MelangeResourceFactoryImpl()
  );
}
 
Example 34
Project: ttc2017smartGrids   File: GlueModelCreator.java   View source code 5 votes vote down vote up
private static HashSet<MMXU> getAllMMXU(Resource resource) {
	HashSet<MMXU> mmxus = new HashSet<MMXU>();
	TreeIterator<EObject> iterator = resource.getAllContents();
	while (iterator.hasNext()) {
		EObject eOb = iterator.next();
		if (eOb instanceof MMXU) {
			MMXU asset = (MMXU) eOb;
			mmxus.add(asset);
		}
	}
	return mmxus;
}
 
Example 35
Project: Tarski   File: ModelIO.java   View source code 5 votes vote down vote up
public void write(final URI uri, final T obj) {
  final Resource resource = this.getResourceSet().createResource(uri);

  resource.getContents().add(obj);

  final HashMap<Object, Object> options = new HashMap<>();
  try {
    resource.save(options);
  } catch (final IOException e) {
    e.printStackTrace();
  }
}
 
Example 36
Project: neoscada   File: WorldResourceFactoryImpl.java   View source code 5 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
@Override
public Resource createResource ( final URI uri )
{
    final XMIResource result = new WorldResourceImpl ( uri );

    result.getDefaultSaveOptions ().put ( XMLResource.OPTION_URI_HANDLER, new URIHandlerImpl.PlatformSchemeAware () );

    return result;
}
 
Example 37
Project: n4js   File: EagerResourceSetBasedResourceDescriptions.java   View source code 5 votes vote down vote up
private Map<URI, IResourceDescription> getDescriptionsMap() {
	Descriptions descriptions = getDescriptions(getResourceSet());
	if (descriptions == null) {
		descriptions = new Descriptions();
		getResourceSet().eAdapters().add(descriptions);
		List<Resource> list = new ArrayList<>(getResourceSet().getResources());
		for (Resource resource : list) {
			IResourceDescription description = computeResourceDescription(resource.getURI());
			if (description != null) {
				descriptions.map.put(resource.getURI(), description);
			}
		}
	}
	return descriptions.map;
}
 
Example 38
Project: rest-modeling-framework   File: RamlTckTest.java   View source code 5 votes vote down vote up
@Test
@UseDataProvider("allTckRamlFiles")
public void tckFilesParse(final File f) throws IOException, TckParseException {
    final Resource resource;
    final URI fileURI = URI.createURI(f.toURI().toString());
    try {
        resource = fromUri(fileURI);
    } catch (Exception e) {
        throw new TckParseException(fileURI.toString(), e);
    }
    assertThat(resource).isInstanceOf(Resource.class)
            .overridingErrorMessage("Failed to parse: " + f.toString());
}
 
Example 39
Project: time4sys   File: GrmEditor.java   View source code 5 votes vote down vote up
@Override
public void notifyChanged(Notification notification) {
	if (notification.getNotifier() instanceof Resource) {
		switch (notification.getFeatureID(Resource.class)) {
			case Resource.RESOURCE__IS_LOADED:
			case Resource.RESOURCE__ERRORS:
			case Resource.RESOURCE__WARNINGS: {
				Resource resource = (Resource)notification.getNotifier();
				Diagnostic diagnostic = analyzeResourceProblems(resource, null);
				if (diagnostic.getSeverity() != Diagnostic.OK) {
					resourceToDiagnosticMap.put(resource, diagnostic);
				}
				else {
					resourceToDiagnosticMap.remove(resource);
				}

				if (updateProblemIndication) {
					getSite().getShell().getDisplay().asyncExec
						(new Runnable() {
							 public void run() {
								 updateProblemIndication();
							 }
						 });
				}
				break;
			}
		}
	}
	else {
		super.notifyChanged(notification);
	}
}
 
Example 40
Project: neoscada   File: ComponentEditor.java   View source code 5 votes vote down vote up
@Override
protected void unsetTarget ( Resource target )
{
    basicUnsetTarget ( target );
    resourceToDiagnosticMap.remove ( target );
    if ( updateProblemIndication )
    {
        getSite ().getShell ().getDisplay ().asyncExec ( new Runnable () {
            public void run ()
            {
                updateProblemIndication ();
            }
        } );
    }
}