Quote: |
[template T2(file : FL)] .... [/template] Wouldn't that do the trick? |
[let model : OclAny = loadModel(c.oclAsType(ecore::EObject), 'filename.xml')] [if (model.oclIsUndefined())] Cannot load model from file !!! [else] Model is defined !!! [/if] [/let]
Quote: |
!ENTRY org.eclipse.ocl 4 10 2010-12-10 10:44:40.914 !MESSAGE ERROR in (visitOperationCallExp): (null) !STACK 0 org.eclipse.acceleo.engine.AcceleoEvaluationException at org.eclipse.acceleo.engine.internal.environment.AcceleoLibra ryOperationVisitor.invoke(AcceleoLibraryOperationVisitor.jav a:926) at org.eclipse.acceleo.engine.internal.environment.AcceleoLibra ryOperationVisitor.callNonStandardOperation(AcceleoLibraryOp erationVisitor.java:119) at org.eclipse.acceleo.engine.internal.environment.AcceleoEvalu ationEnvironment.callOperation(AcceleoEvaluationEnvironment. java:167) at org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.callOperati on(EcoreEvaluationEnvironment.java:1) at org.eclipse.ocl.EvaluationVisitorImpl.visitOperationCallExp( EvaluationVisitorImpl.java:193) |
org.eclipse.core.internal.resources.ResourceException: Resource 'xxxxx' does not exist
rs.getResource(uri, true);
Resource res = rs.getResources().get(0); IProject iProject = getWorkspaceRoot().getFile(new Path(res.getURI().toString())).getProject();
public static URI getURI(EObject eObject){ Resource res = eObject.eResource(); if (res!= null) return eObject.eResource().getURI(); return null } public static IFile GetFile(EObject eObject){ URI u = getURI(eObject); if (u!= null){ if (u is a file URI) then return a Ifile ?? } }
private static IWorkspaceRoot getWorkspaceRoot() throws Exception { if (workspaceRoot==null){ workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); if (workspaceRoot==null) throw new Exception("No workspace defined, running outside of eclipse is forbidden"); } return workspaceRoot; } private static URI getWorkspaceURI() throws Exception { if (workspaceURI==null){ workspaceURI = URI.createFileURI(getWorkspaceRoot().getLocationURI().getPath() + "/"); } return workspaceURI; } public static EObject loadModel(EObject current, String filePath) throws Exception { ResourceSet rs = current.eResource().getResourceSet(); Resource res = current.eResource(); if (res != null){ URI u = res.getURI().deresolve(getWorkspaceURI()); return loadModel(rs, filePath, u.segment(0).toString()); } return null; } public static EObject loadModel(ResourceSet rs, String filePath, String project) { URI uri = URI.createURI(uriString, true); Resource res = rs.getResource(uri, true); if (res != null && res.getErrors().isEmpty()) { if (!res.getContents().isEmpty()) { return res.getContents().get(0); } } return null; }