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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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 ();
            }
        } );
    }
}
 
Example 41
Project: gemoc-studio-modeldebugging   File: GemocSourceLocator.java   Source Code and License 5 votes vote down vote up
@Override
public String getEditorId(IEditorInput input, Object element) {
	if (element instanceof EObject) {
		EObject eObject = (EObject) element;
		Resource r = eObject.eResource();
		if (r instanceof XtextResource) {
			return ((XtextResource) r).getLanguageName();
		}
	}
	 
	//Default
	ISourcePresentation presentation = getPresentation();
	return presentation.getEditorId(input, element);
}
 
Example 42
Project: n4js   File: BuiltInTypeScope.java   Source Code and License 5 votes vote down vote up
@Override
protected void buildMap(Resource resource, Map<QualifiedName, IEObjectDescription> elements) {
	TypeDefs typeDefinitions = (TypeDefs) resource.getContents().get(0);
	for (Type type : typeDefinitions.getTypes()) {
		if (!(type instanceof VirtualBaseType)) {
			IEObjectDescription description = EObjectDescription.create(type.getName(), type);
			elements.put(description.getName(), description);
		}
	}
}
 
Example 43
Project: neoscada   File: MemoryManagerXMLProcessor.java   Source Code and License 5 votes vote down vote up
/**
 * Register for "*" and "xml" file extensions the MemoryManagerResourceFactoryImpl factory.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
protected Map<String, Resource.Factory> getRegistrations ()
{
    if ( registrations == null )
    {
        super.getRegistrations ();
        registrations.put ( XML_EXTENSION, new MemoryManagerResourceFactoryImpl () );
        registrations.put ( STAR_EXTENSION, new MemoryManagerResourceFactoryImpl () );
    }
    return registrations;
}
 
Example 44
Project: Saturn   File: DocumentumResourceXMLProcessor.java   Source Code and License 5 votes vote down vote up
/**
 * Register for "*" and "xml" file extensions the DocumentumResourceResourceFactoryImpl factory.
 * <!-- begin-user-doc
 * --> <!-- end-user-doc -->
 * @generated
 */
@Override
protected Map<String, Resource.Factory> getRegistrations()
{
  if (registrations == null)
  {
    super.getRegistrations();
    registrations.put(XML_EXTENSION, new DocumentumResourceResourceFactoryImpl());
    registrations.put(STAR_EXTENSION, new DocumentumResourceResourceFactoryImpl());
  }
  return registrations;
}
 
Example 45
Project: gemoc-studio   File: FsmEditor.java   Source Code and License 5 votes vote down vote up
/**
 * Handles what to do with changed resources on activation.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void handleChangedResources() {
	if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) {
		if (isDirty()) {
			changedResources.addAll(editingDomain.getResourceSet().getResources());
		}
		editingDomain.getCommandStack().flush();

		updateProblemIndication = false;
		for (Resource resource : changedResources) {
			if (resource.isLoaded()) {
				resource.unload();
				try {
					resource.load(Collections.EMPTY_MAP);
				}
				catch (IOException exception) {
					if (!resourceToDiagnosticMap.containsKey(resource)) {
						resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
					}
				}
			}
		}

		if (AdapterFactoryEditingDomain.isStale(editorSelection)) {
			setSelection(StructuredSelection.EMPTY);
		}

		updateProblemIndication = true;
		updateProblemIndication();
	}
}
 
Example 46
Project: gemoc-studio   File: FsmEditor.java   Source Code and License 5 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) {
	boolean hasErrors = !resource.getErrors().isEmpty();
	if (hasErrors || !resource.getWarnings().isEmpty()) {
		BasicDiagnostic basicDiagnostic =
			new BasicDiagnostic
				(hasErrors ? Diagnostic.ERROR : Diagnostic.WARNING,
				 "org.eclipse.gemoc.sample.legacyfsm.fsm.model.editor",
				 0,
				 getString("_UI_CreateModelError_message", resource.getURI()),
				 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.gemoc.sample.legacyfsm.fsm.model.editor",
				 0,
				 getString("_UI_CreateModelError_message", resource.getURI()),
				 new Object[] { exception });
	}
	else {
		return Diagnostic.OK_INSTANCE;
	}
}
 
Example 47
Project: Saturn   File: DatacompareModuleXMLProcessor.java   Source Code and License 5 votes vote down vote up
/**
 * Register for "*" and "xml" file extensions the DatacompareModuleResourceFactoryImpl factory.
 * <!-- begin-user-doc
 * --> <!-- end-user-doc -->
 * @generated
 */
@Override
protected Map<String, Resource.Factory> getRegistrations()
{
  if (registrations == null)
  {
    super.getRegistrations();
    registrations.put(XML_EXTENSION, new DatacompareModuleResourceFactoryImpl());
    registrations.put(STAR_EXTENSION, new DatacompareModuleResourceFactoryImpl());
  }
  return registrations;
}
 
Example 48
Project: OCCI-Studio   File: ConverterUtils.java   Source Code and License 5 votes vote down vote up
public static void save(ResourceSet resourceSet, EObject rootElement, String path) throws IOException {
	Resource resource = resourceSet.createResource(URI.createURI(path));
	resource.getContents().add(rootElement);
	Map<String, String> options = new HashMap<String, String>();
	options.put(XMIResource.OPTION_ENCODING, "UTF-8");
	resource.save(options);
}
 
Example 49
Project: n4js   File: N4LanguageUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Same as {@link #getServiceForContext(URI, Class)}, but accepts any {@link EObject} contained in an Xtext language
 * resource. Returns <code>null</code> if the given context object is not contained in a {@link Resource}.
 */
public static <T> Optional<T> getServiceForContext(EObject context, Class<T> serviceType) {
	Objects.requireNonNull(context);
	Objects.requireNonNull(serviceType);
	final Resource res = context.eResource();
	final URI uri = res != null ? res.getURI() : null;
	return uri != null ? getServiceForContext(uri, serviceType) : Optional.empty();
}
 
Example 50
Project: time4sys   File: Time4sysEditor.java   Source Code and License 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 51
Project: org.xtext.dsl.restaurante   File: RestauranteStandaloneSetupGenerated.java   Source Code and License 5 votes vote down vote up
public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.xtext.org/dsl/restaurante/Restaurante")) {
		EPackage.Registry.INSTANCE.put("http://www.xtext.org/dsl/restaurante/Restaurante", RestaurantePackage.eINSTANCE);
	}
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("rest", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("rest", serviceProvider);
}
 
Example 52
Project: Saturn   File: SqlModuleXMLProcessor.java   Source Code and License 5 votes vote down vote up
/**
 * Register for "*" and "xml" file extensions the SqlModuleResourceFactoryImpl factory.
 * <!-- begin-user-doc --> <!--
 * end-user-doc -->
 * @generated
 */
@Override
protected Map<String, Resource.Factory> getRegistrations()
{
  if (registrations == null)
  {
    super.getRegistrations();
    registrations.put(XML_EXTENSION, new SqlModuleResourceFactoryImpl());
    registrations.put(STAR_EXTENSION, new SqlModuleResourceFactoryImpl());
  }
  return registrations;
}
 
Example 53
Project: neoscada   File: MemoryResourceFactoryImpl.java   Source Code and License 5 votes vote down vote up
/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource ( URI uri )
{
    Resource result = new MemoryResourceImpl ( uri );
    return result;
}
 
Example 54
Project: rest-modeling-framework   File: RamlResourceTest.java   Source Code and License 5 votes vote down vote up
@Ignore
@Test
public void apiViaHttp() {
    final URI uri = URI.createURI("http://localhost:5050/api-raml/");
    final Resource resource = fromUri(uri);
    resource.getContents();
    assertThat(resource).isNotNull();
}
 
Example 55
Project: OCCI-Studio   File: InfrastructureEditor.java   Source Code and License 5 votes vote down vote up
/**
 * Handles what to do with changed resources on activation.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void handleChangedResources() {
	if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) {
		if (isDirty()) {
			changedResources.addAll(editingDomain.getResourceSet().getResources());
		}
		editingDomain.getCommandStack().flush();

		updateProblemIndication = false;
		for (Resource resource : changedResources) {
			if (resource.isLoaded()) {
				resource.unload();
				try {
					resource.load(Collections.EMPTY_MAP);
				}
				catch (IOException exception) {
					if (!resourceToDiagnosticMap.containsKey(resource)) {
						resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
					}
				}
			}
		}

		if (AdapterFactoryEditingDomain.isStale(editorSelection)) {
			setSelection(StructuredSelection.EMPTY);
		}

		updateProblemIndication = true;
		updateProblemIndication();
	}
}
 
Example 56
Project: gw4e.project   File: DSLPoliciesStandaloneSetupGenerated.java   Source Code and License 5 votes vote down vote up
public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.gw4e/dsl/DSLPolicies")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.gw4e/dsl/DSLPolicies", DSLPoliciesPackage.eINSTANCE);
	}
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("policies", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("policies", serviceProvider);
}
 
Example 57
Project: OCCI-Studio   File: DesignServices.java   Source Code and License 5 votes vote down vote up
public void importExtension(Extension extension) {
	Shell shell = Display.getCurrent().getActiveShell();
	Session session = SessionManager.INSTANCE.getSession(extension);
	LoadExtensionDialog dialog = new LoadExtensionDialog(shell, session.getTransactionalEditingDomain());
	dialog.open();

	for (URI uri : dialog.getURIs()) {
		session.addSemanticResource(uri, new NullProgressMonitor());
		Resource resource = session.getTransactionalEditingDomain().getResourceSet().getResource(uri, true);
		if (!resource.getContents().isEmpty() && (resource.getContents().get(0) instanceof Extension)
				&& !extension.getImport().contains(resource.getContents().get(0))) {
			extension.getImport().add((Extension) resource.getContents().get(0));
		}
	}
}
 
Example 58
Project: n4js   File: N4HeadlessCompiler.java   Source Code and License 5 votes vote down vote up
/**
 * Collects all resources belonging to the given project and adds them to the given resource set.
 *
 * @param markedProject
 *            the project being loaded
 * @param resourceSet
 *            the resource set to load the resources into
 * @param recorder
 *            the progress recorder
 */
private void collectResources(MarkedProject markedProject, ResourceSet resourceSet,
		N4ProgressStateRecorder recorder) {

	markedProject.clearResources();

	for (IN4JSSourceContainer container : markedProject.project.getSourceContainers()) {
		// Conditionally filter test resources if not desired
		if (shouldLoadSourceContainer(container)) {
			if (logger.isCreateDebugOutput()) {
				logger.debug("Collecting resources from source container " + container.getLocation());
			}

			Iterables.filter(container, uri -> shouldLoadResource(uri)).forEach(uri -> {
				Resource resource = resourceSet.createResource(uri);
				if (resource != null) {
					if (logger.isCreateDebugOutput()) {
						logger.debug("  Creating resource " + resource.getURI());
					}

					markedProject.resources.add(resource);

					if (container.isExternal()) {
						markedProject.externalResources.add(resource);
					}

					if (container.isTest()) {
						markedProject.testResources.add(resource);
					}
				} else {
					recorder.markFailedCreateResource(uri);
					logger.warn("  Could not create resource for " + uri);
				}
			});
		}
	}
}
 
Example 59
Project: neoscada   File: InfrastructureEditor.java   Source Code and License 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 ();
            }
        } );
    }
}
 
Example 60
Project: time4sys   File: LibraryEditor.java   Source Code and License 5 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) {
	boolean hasErrors = !resource.getErrors().isEmpty();
	if (hasErrors || !resource.getWarnings().isEmpty()) {
		BasicDiagnostic basicDiagnostic =
			new BasicDiagnostic
				(hasErrors ? Diagnostic.ERROR : Diagnostic.WARNING,
				 "org.polarsys.time4sys.library.editor",
				 0,
				 getString("_UI_CreateModelError_message", resource.getURI()),
				 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.polarsys.time4sys.library.editor",
				 0,
				 getString("_UI_CreateModelError_message", resource.getURI()),
				 new Object[] { exception });
	}
	else {
		return Diagnostic.OK_INSTANCE;
	}
}