blob: d75b15fab16f65a49c4f96b5f55a0acd86effc9d [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010, 2018 Willink Transformations and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* E.D.Willink - initial API and implementation
*******************************************************************************/
package org.eclipse.ocl.examples.build.utilities;
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.mwe.core.WorkflowContext;
import org.eclipse.emf.mwe.core.issues.Issues;
import org.eclipse.emf.mwe.core.lib.WorkflowComponentWithModelSlot;
import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
/**
* Reads a specified <tt>uri</tt> into a designated <tt>modelSlot</tt>.
*/
public class ResourceReader extends WorkflowComponentWithModelSlot
{
private Logger log = Logger.getLogger(getClass());
private ResourceSet resourceSet = null;
protected String uri;
public ResourceSet getResourceSet() {
if (resourceSet == null) {
resourceSet = new ResourceSetImpl();
}
return resourceSet;
}
public String getUri() {
return uri;
}
@Override
public void invokeInternal(WorkflowContext ctx, ProgressMonitor arg1, Issues arg2) {
URI fileURI = URI.createPlatformResourceURI(uri, true);
log.info("Reading '" + fileURI + "'");
ResourceSet resourceSet = getResourceSet();
Resource resource = resourceSet.getResource(fileURI, true);
EcoreUtil.resolveAll(resource);
// System.out.println("ResolvedAll " + resource.getClass().getName() + "@" + Integer.toHexString(resource.hashCode()) + " " + resource.getURI());
ResourceUtils.checkResource(resource);
EcoreUtil.resolveAll(resourceSet);
ResourceUtils.checkResourceSet(resourceSet);
ctx.set(getModelSlot(), resource);
}
public void setResourceSet(ResourceSet resourceSet) {
this.resourceSet = resourceSet;
}
public void setUri(String uri) {
this.uri = uri;
}
}