Search in sources :

Example 1 with XMIResource

use of org.eclipse.emf.ecore.xmi.XMIResource in project tdi-studio-se by Talend.

the class AutoUpdateRelationsMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    try {
        RelationshipItemBuilder.getInstance().addOrUpdateItem(item, true);
        // release the memory when gc
        if (item instanceof ProcessItem) {
            Resource processResource = ((ProcessItem) item).getProcess().eResource();
            Resource propertyResource = item.eResource();
            if (processResource != null && processResource.isLoaded() && (processResource instanceof XMIResource)) {
                propertyResource.unload();
                processResource.unload();
                rM.resourceSet.getResources().remove(propertyResource);
                rM.resourceSet.getResources().remove(processResource);
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(new Exception("Error in item:" + item.getProperty().getLabel(), e));
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) Resource(org.eclipse.emf.ecore.resource.Resource) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource)

Example 2 with XMIResource

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

the class UserdataMapper method getDeserializedModuleFromDescriptionAsString.

/**
 * <b>ONLY INTENDED FOR TESTS OR DEBUGGING. DON'T USE IN PRODUCTION CODE.</b>
 * <p>
 * Same as {@link #getDeserializedModuleFromDescription(IEObjectDescription, URI)}, but always returns the module as
 * an XMI-serialized string.
 */
public static String getDeserializedModuleFromDescriptionAsString(IEObjectDescription eObjectDescription, URI uri) throws IOException {
    final TModule module = getDeserializedModuleFromDescription(eObjectDescription, uri);
    final XMIResource resourceForUserData = new XMIResourceImpl(uri);
    resourceForUserData.getContents().add(module);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    resourceForUserData.save(baos, getOptions(uri, false));
    return baos.toString(TRANSFORMATION_CHARSET_NAME);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) TModule(org.eclipse.n4js.ts.types.TModule) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)

Example 3 with XMIResource

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

the class UserdataMapper method createUserData.

/**
 * Serializes an exported script (or other {@link EObject}) stored in given resource content at index 1, and stores
 * that in a map under key {@link #USERDATA_KEY_SERIALIZED_SCRIPT}.
 */
public static Map<String, String> createUserData(final TModule exportedModule) throws IOException, UnsupportedEncodingException {
    if (exportedModule.isPreLinkingPhase()) {
        throw new AssertionError("Module may not be from the preLinkingPhase");
    }
    // TODO GH-230 consider disallowing serializing reconciled modules to index with fail-fast
    // if (exportedModule.isReconciled()) {
    // throw new IllegalArgumentException("module must not be reconciled");
    // }
    final Resource originalResourceUncasted = exportedModule.eResource();
    if (!(originalResourceUncasted instanceof N4JSResource)) {
        throw new IllegalArgumentException("module must be contained in an N4JSResource");
    }
    final N4JSResource originalResource = (N4JSResource) originalResourceUncasted;
    // resolve resource (i.e. resolve lazy cross-references, resolve DeferredTypeRefs, etc.)
    originalResource.performPostProcessing();
    if (EcoreUtilN4.hasUnresolvedProxies(exportedModule) || TypeUtils.containsDeferredTypeRefs(exportedModule)) {
        // leads to an unresolvable proxy in the TModule)
        return createTimestampUserData(exportedModule);
    }
    // add copy -- EObjects can only be contained in a single resource, and
    // we do not want to mess up the original resource
    URI resourceURI = originalResource.getURI();
    XMIResource resourceForUserData = new XMIResourceImpl(resourceURI);
    resourceForUserData.getContents().add(TypeUtils.copyWithProxies(exportedModule));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    resourceForUserData.save(baos, getOptions(resourceURI, BINARY));
    String serializedScript = BINARY ? XMLTypeFactory.eINSTANCE.convertBase64Binary(baos.toByteArray()) : baos.toString(TRANSFORMATION_CHARSET_NAME);
    final HashMap<String, String> ret = new HashMap<>();
    ret.put(USERDATA_KEY_SERIALIZED_SCRIPT, serializedScript);
    ret.put(N4JSResourceDescriptionStrategy.MAIN_MODULE_KEY, Boolean.toString(exportedModule.isMainModule()));
    // required to trigger rebuilds even if only minor changes happened to the content.
    if (exportedModule.isStaticPolyfillModule()) {
        final String contentHash = Integer.toHexString(originalResource.getParseResult().getRootNode().hashCode());
        ret.put(USERDATA_KEY_STATIC_POLYFILL_CONTENTHASH, contentHash);
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) URI(org.eclipse.emf.common.util.URI) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)

Example 4 with XMIResource

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

the class DirtyStateListener method resourceSetChanged.

public void resourceSetChanged(ResourceSetChangeEvent event) {
    List<URI> remainingURIs = Lists.newArrayList(uri2dirtyResource.keySet());
    for (Resource currentResource : event.getEditingDomain().getResourceSet().getResources()) {
        if (currentResource instanceof XMIResource) {
            XMIResource resource = (XMIResource) currentResource;
            remainingURIs.remove(resource.getURI());
            IDirtyResource dirtyResource = uri2dirtyResource.get(resource.getURI());
            if (resource.isModified()) {
                if (dirtyResource == null) {
                    createAndRegisterDirtyState(resource);
                }
            } else {
                if (dirtyResource != null) {
                    uri2dirtyResource.remove(resource.getURI());
                    dirtyStateManager.discardDirtyState(dirtyResource);
                }
            }
        }
    }
    for (URI remainingURI : remainingURIs) {
        IDirtyResource dirtyResource = uri2dirtyResource.get(remainingURI);
        dirtyStateManager.discardDirtyState(dirtyResource);
        uri2dirtyResource.remove(remainingURI);
    }
}
Also used : IDirtyResource(org.eclipse.xtext.ui.editor.IDirtyResource) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) Resource(org.eclipse.emf.ecore.resource.Resource) IDirtyResource(org.eclipse.xtext.ui.editor.IDirtyResource) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) URI(org.eclipse.emf.common.util.URI)

Example 5 with XMIResource

use of org.eclipse.emf.ecore.xmi.XMIResource in project tdq-studio-se by Talend.

the class DQReferenceMerger method addInTarget.

/*
     * override this method to fix a specail case: when add a catalog on database server,this new one can't be added in
     * local db connection
     */
@Override
protected void addInTarget(ReferenceChange diff, boolean rightToLeft) {
    final Match match = diff.getMatch();
    final EObject expectedContainer;
    if (rightToLeft) {
        expectedContainer = match.getLeft();
    } else {
        expectedContainer = match.getRight();
    }
    if (expectedContainer == null) {
        // one of the "required" diffs should have created our container.
        return;
    }
    final Comparison comparison = match.getComparison();
    final EReference reference = diff.getReference();
    final EObject expectedValue;
    final Match valueMatch = comparison.getMatch(diff.getValue());
    if (valueMatch == null) {
        // This is an out of scope value.
        if (diff.getValue().eIsProxy()) {
            // Copy the proxy
            expectedValue = EcoreUtil.copy(diff.getValue());
        } else {
            // Use the same value.
            expectedValue = diff.getValue();
        }
    } else if (rightToLeft) {
        if (reference.isContainment()) {
            expectedValue = createCopy(diff.getValue());
            valueMatch.setLeft(expectedValue);
        } else {
            // qiongli: when I add catalog on remote server,test on reload, should replace "valueMatch.getLeft()"
            // with "valueMatch.getRight()" at here.
            // expectedValue = valueMatch.getLeft();
            expectedValue = valueMatch.getRight();
            // qiongli: remove the newest DataManage from the right Catalog or Schema,avoid a missing
            // "datamanage herf=" "
            Catalog catlog = SwitchHelpers.CATALOG_SWITCH.doSwitch(expectedValue);
            Schema schema = SwitchHelpers.SCHEMA_SWITCH.doSwitch(expectedValue);
            if (catlog != null) {
                EList<DataManager> dataManager = catlog.getDataManager();
                dataManager.clear();
            } else if (schema != null) {
                EList<DataManager> dataManager = schema.getDataManager();
                dataManager.clear();
            }
        }
    } else {
        if (reference.isContainment()) {
            expectedValue = createCopy(diff.getValue());
            valueMatch.setRight(expectedValue);
        } else {
            expectedValue = valueMatch.getLeft();
        }
    }
    // We have the container, reference and value. We need to know the insertion index.
    if (reference.isMany()) {
        final int insertionIndex = findInsertionIndex(comparison, diff, rightToLeft);
        final List<EObject> targetList = (List<EObject>) safeEGet(expectedContainer, reference);
        addAt(targetList, expectedValue, insertionIndex);
    } else {
        safeESet(expectedContainer, reference, expectedValue);
    }
    if (reference.isContainment()) {
        // Copy XMI ID when applicable.
        final Resource initialResource = diff.getValue().eResource();
        final Resource targetResource = expectedValue.eResource();
        if (initialResource instanceof XMIResource && targetResource instanceof XMIResource) {
            ((XMIResource) targetResource).setID(expectedValue, ((XMIResource) initialResource).getID(diff.getValue()));
        }
    }
// no need to check this for DQ items,
// checkImpliedDiffsOrdering(diff, rightToLeft);
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) Resource(org.eclipse.emf.ecore.resource.Resource) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) Catalog(orgomg.cwm.resource.relational.Catalog) Match(org.eclipse.emf.compare.Match) EList(org.eclipse.emf.common.util.EList) Comparison(org.eclipse.emf.compare.Comparison) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) EReference(org.eclipse.emf.ecore.EReference)

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