Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public final class ResourceSetOptions {

private static final String INSTALL_DERIVED_STATE = "com.avaloq.tools.ddk.xtext.resource.ResourceSetOptions.installDerivedState";
private static final String SKIP_MODEL = "com.avaloq.tools.ddk.xtext.resource.ResourceSetOptions.skipModel";

private ResourceSetOptions() {
// utility class
Expand Down Expand Up @@ -52,4 +53,12 @@ public static void setInstallDerivedState(final @NonNull ResourceSet resourceSet
resourceSet.getLoadOptions().put(INSTALL_DERIVED_STATE, installDerivedState);
}

public static boolean skipModel(final @NonNull ResourceSet resourceSet) {
Object object = resourceSet.getLoadOptions().get(SKIP_MODEL);
return object != null && (boolean) object; // default is false
}

public static void setSkipModel(final @NonNull ResourceSet resourceSet, final @Nullable Boolean skipModel) {
resourceSet.getLoadOptions().put(SKIP_MODEL, skipModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl.Container;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
Expand Down Expand Up @@ -123,8 +125,6 @@ public void loadResource(final Resource resource) throws IOException {
if (uri != null && uri.isHierarchical() && !uri.isRelative()) {
baseURI = uri;
}
boolean installDerivedState = ResourceSetOptions.installDerivedState(resourceSet); // must be read before readCompressedInt, see HACK comment inside
// readCompressedInt
int size = readCompressedInt();
if (!installDerivedState && size == 2) { // the InfererenceContainer is always in the second slot
size--;
Expand Down Expand Up @@ -153,6 +153,8 @@ public void loadResource(final Resource resource) throws IOException {
private final ITraceSet traceSet;

private ResourceLoadMode mode;
private boolean installDerivedState;
private boolean skipModel;

public DirectLinkingResourceStorageLoadable(final InputStream in, final boolean loadNodeModel, final boolean splitContents, final ITraceSet traceSet) {
super(in, loadNodeModel);
Expand Down Expand Up @@ -182,6 +184,8 @@ public void loadIntoResource(final StorageAwareResource resource, final Resource
throw new IllegalArgumentException("Incompatible resource load mode: " + loadMode.instruction(Constituent.RESOURCE)); //$NON-NLS-1$
}
this.mode = loadMode;
this.installDerivedState = ResourceSetOptions.installDerivedState(resource.getResourceSet());
this.skipModel = ResourceSetOptions.skipModel(resource.getResourceSet());
traceSet.started(ResourceLoadStorageEvent.class, resource.getURI(), loadMode);
try {
super.loadIntoResource(resource);
Expand Down Expand Up @@ -223,7 +227,12 @@ protected void loadEntries(final StorageAwareResource resource, final ZipInputSt
LOG.warn("Proxying of resource contents is not supported: " + resource.getURI()); //$NON-NLS-1$
// fall through
case LOAD:
readContents(resource, new NonLockingBufferInputStream(zipIn));
if (!skipModel) {
readContents(resource, new NonLockingBufferInputStream(zipIn));
} else {
// TODO I need to put something in the resource. Don't want to get into proxying yet (might have to).
addFakeModel(resource);
}
break;
}

Expand Down Expand Up @@ -286,6 +295,15 @@ protected void loadEntries(final StorageAwareResource resource, final ZipInputSt
}
}

private void addFakeModel(final StorageAwareResource resource) {
InternalEObject[] values = new InternalEObject[] {new Container()};
BasicEList<InternalEObject> internalEObjectList = new BasicEList<InternalEObject>(); // NOPMD LooseCoupling
internalEObjectList.setData(1, values);
@SuppressWarnings("unchecked")
InternalEList<InternalEObject> internalEObjects = (InternalEList<InternalEObject>) (InternalEList<?>) resource.getContents();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about adding subclassed BasicEList which throws an UnsoportedOperationException in all operations? That way we are sure that we are not getting wrong results because we access a partially loaded resource.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's not going to work: this list is returned from Resource.getContents(), the inference container is contained in it

internalEObjects.addAllUnique(internalEObjectList);
}

/**
* Read the node model from the given input stream.
*
Expand Down