Search in sources :

Example 11 with XMIResource

use of org.eclipse.emf.ecore.xmi.XMIResource in project InformationSystem by ObeoNetwork.

the class DatabaseResourceFactoryImpl method createResource.

@Override
public Resource createResource(URI uri) {
    XMIResource resource = new DatabaseResourceImpl(uri);
    Map<Object, Object> saveOptions = resource.getDefaultSaveOptions();
    saveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE, Boolean.TRUE);
    saveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE, lookupTable);
    Map<Object, Object> loadOptions = resource.getDefaultLoadOptions();
    loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE);
    loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
    loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE);
    loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, parserPool);
    loadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, nameToFeatureMap);
    return resource;
}
Also used : XMIResource(org.eclipse.emf.ecore.xmi.XMIResource)

Example 12 with XMIResource

use of org.eclipse.emf.ecore.xmi.XMIResource in project xtext-core by eclipse.

the class InjectableValidatorTest method testWrongResource.

@Test
public void testWrongResource() throws Exception {
    Main main = LangATestLanguageFactory.eINSTANCE.createMain();
    XMIResource xmiResource = new XMIResourceImpl();
    xmiResource.getContents().add(main);
    assertTrue(languageSpecificValidator.validate(main, new BasicDiagnostic(), null));
    assertTrue(languageSpecificValidator.validate(main, new BasicDiagnostic(), context));
    context.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, xtextResource.getLanguageName());
    assertFalse(languageSpecificValidator.validate(main, new BasicDiagnostic(), context));
    context.clear();
    assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), null));
    assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), context));
    context.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, xtextResource.getLanguageName());
    assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), context));
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) Test(org.junit.Test)

Example 13 with XMIResource

use of org.eclipse.emf.ecore.xmi.XMIResource in project n4js by eclipse.

the class UserdataMapper method getDeserializedModuleFromDescription.

/**
 * Reads the TModule stored in the given IEObjectDescription.
 */
public static TModule getDeserializedModuleFromDescription(IEObjectDescription eObjectDescription, URI uri) {
    final String serializedData = eObjectDescription.getUserData(USERDATA_KEY_SERIALIZED_SCRIPT);
    if (Strings.isNullOrEmpty(serializedData)) {
        return null;
    }
    final XMIResource xres = new XMIResourceImpl(uri);
    try {
        final boolean binary = !serializedData.startsWith("<");
        final ByteArrayInputStream bais = new ByteArrayInputStream(binary ? XMLTypeFactory.eINSTANCE.createBase64Binary(serializedData) : serializedData.getBytes(TRANSFORMATION_CHARSET_NAME));
        xres.load(bais, getOptions(uri, binary));
    } catch (Exception e) {
        // $NON-NLS-1$
        LOGGER.warn("error deserializing module from IEObjectDescription: " + uri);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("error deserializing module from IEObjectDescription=" + eObjectDescription + ": " + uri, // $NON-NLS-1$
            e);
        }
        // IDE, so the format could be out of date (after an update of the IDE))
        return null;
    }
    final List<EObject> contents = xres.getContents();
    if (contents.isEmpty() || !(contents.get(0) instanceof TModule)) {
        return null;
    }
    final TModule module = (TModule) contents.get(0);
    xres.getContents().clear();
    return module;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) EObject(org.eclipse.emf.ecore.EObject) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) TModule(org.eclipse.n4js.ts.types.TModule) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 14 with XMIResource

use of org.eclipse.emf.ecore.xmi.XMIResource in project InformationSystem by ObeoNetwork.

the class ToolkitsResourceFactoryImpl method createResource.

/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
@Override
public Resource createResource(URI uri) {
    XMIResource result = new ToolkitsResourceImpl(uri);
    Map<Object, Object> saveOptions = result.getDefaultSaveOptions();
    saveOptions.put(XMLResource.OPTION_URI_HANDLER, new URIHandlerImpl.PlatformSchemeAware());
    saveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE, Boolean.TRUE);
    saveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE, lookupTable);
    Map<Object, Object> loadOptions = result.getDefaultLoadOptions();
    loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE);
    loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
    loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE);
    loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, parserPool);
    loadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, nameToFeatureMap);
    return result;
}
Also used : URIHandlerImpl(org.eclipse.emf.ecore.xmi.impl.URIHandlerImpl) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource)

Example 15 with XMIResource

use of org.eclipse.emf.ecore.xmi.XMIResource in project InformationSystem by ObeoNetwork.

the class ScaffoldResourceFactoryImpl method createResource.

/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
@Override
public Resource createResource(URI uri) {
    XMIResource resource = new ScaffoldResourceImpl(uri);
    Map<Object, Object> saveOptions = resource.getDefaultSaveOptions();
    saveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE, Boolean.TRUE);
    saveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE, lookupTable);
    saveOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    saveOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    Map<Object, Object> loadOptions = resource.getDefaultLoadOptions();
    loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE);
    loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
    loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE);
    loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, parserPool);
    loadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, nameToFeatureMap);
    loadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    loadOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    return resource;
}
Also used : XMIResource(org.eclipse.emf.ecore.xmi.XMIResource)

Aggregations

XMIResource (org.eclipse.emf.ecore.xmi.XMIResource)15 URIHandlerImpl (org.eclipse.emf.ecore.xmi.impl.URIHandlerImpl)5 Resource (org.eclipse.emf.ecore.resource.Resource)4 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 URI (org.eclipse.emf.common.util.URI)2 EObject (org.eclipse.emf.ecore.EObject)2 TModule (org.eclipse.n4js.ts.types.TModule)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 EList (org.eclipse.emf.common.util.EList)1 Comparison (org.eclipse.emf.compare.Comparison)1 Match (org.eclipse.emf.compare.Match)1 EReference (org.eclipse.emf.ecore.EReference)1 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)1 Main (org.eclipse.xtext.linking.langATestLanguage.Main)1