Package com.rescripter.resources

Source Code of com.rescripter.resources.WorkspaceScriptLoader

package com.rescripter.resources;

import java.io.IOException;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;

import com.rescripter.script.ScriptRunner;
import com.rescripter.script.ScriptStack;

public class WorkspaceScriptLoader implements ScriptLoader {

    private final ScriptRunner scriptRunner;
    private final IFile location;
    private final ScriptStack scriptStack;
    private final FileContentsReader fileReader;

    public WorkspaceScriptLoader(IFile location,
                   ScriptRunner scriptRunner,
                   ScriptStack scriptStack,
                   FileContentsReader fileReader) {
      this.location = location;
        this.scriptRunner = scriptRunner;
    this.scriptStack = scriptStack;
    this.fileReader = fileReader;
    }
   
    public void file(String filename) throws IOException, CoreException {
        IContainer container = location.getParent();
        IFile file = container.getFile(new Path(filename.trim()));
        if (!file.exists()) {
            throw new IOException("Failed to find file '" + file.getLocation().toString()+"'");
        }

        String contents = fileReader.getContents(file.getContents());
       
        scriptStack.push(new WorkspaceScriptLoader(file, scriptRunner, scriptStack, fileReader));
        scriptRunner.run(contents, file.getFullPath().toPortableString());
        scriptStack.pop();
    }

  public IFile getCurrentLocation() {
    return location;
  }

  public String toString() {
    return "a workspace script loader";
  }
}
TOP

Related Classes of com.rescripter.resources.WorkspaceScriptLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.