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;
}
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);
}
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;
}
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);
}
}
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);
}
Aggregations