Examples of LanguageException


Examples of org.apache.cocoon.components.language.LanguageException

    public Program load(String filename, File baseDirectory, String encoding) throws LanguageException {

        // Does source file exist?
        File sourceFile = new File(baseDirectory, filename + "." + this.getSourceExtension());
        if (!sourceFile.exists()) {
            throw new LanguageException("Can't load program - File doesn't exist: " + IOUtils.getFullFilename(sourceFile));
        }
        if (!sourceFile.isFile()) {
            throw new LanguageException("Can't load program - File is not a normal file: " + IOUtils.getFullFilename(sourceFile));
        }
        if (!sourceFile.canRead()) {
            throw new LanguageException("Can't load program - File cannot be read: " + IOUtils.getFullFilename(sourceFile));
        }
        this.compile(filename, baseDirectory, encoding);
        if (this.deleteSources) {
            sourceFile.delete();
        }
        Class program = this.loadProgram(filename, baseDirectory);

        // Try to instantiate once to ensure there are no exceptions thrown in the constructor
        try {
            // Create and discard test instance
            program.newInstance();
        } catch(IllegalAccessException iae) {
            getLogger().debug("No public constructor for class " + program.getName());
        } catch(Exception e) {
            // Unload class and delete the object file, or it won't be recompiled
            // (leave the source file to allow examination).
            this.doUnload(program);
            new File(baseDirectory, filename + "." + this.getObjectExtension()).delete();

            String message = "Error while instantiating " + filename;
            getLogger().debug(message, e);
            throw new LanguageException(message, e);
        }

        if (program == null) {
            throw new LanguageException("Can't load program : " + baseDirectory.toString() + File.separator + filename);
        }

        return new JavaProgram(program);
    }
View Full Code Here
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.