Package org.apache.cocoon.components.language

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));
        }

        Class clazz = null;
        ArrayList dependecies = new ArrayList();

        String className = null;
        BufferedReader r = null;
        try {
            r = new BufferedReader(
                    (encoding == null)?
                    new FileReader(sourceFile):
                    new InputStreamReader(new FileInputStream(sourceFile), encoding));
            className = getMeta(r.readLine(), "extends");
            if (className == null) {
                throw new LanguageException("Can't load program - Signature is not found: "
                        + IOUtils.getFullFilename(sourceFile));
            }

            clazz = ClassUtils.loadClass(className);

            String line;
            while((line = getMeta(r.readLine(), "depends")) != null) {
                dependecies.add(line);
            }
        } catch (IOException e) {
            throw new LanguageException("Can't load program - Signature is not found: "
                    + IOUtils.getFullFilename(sourceFile));
        } catch (ClassNotFoundException e) {
            throw new LanguageException("Can't load program - Base class " + className + " is not found: "
                    + IOUtils.getFullFilename(sourceFile));
        } finally {
            if (r != null) try {
                r.close();
            } catch (IOException ignored) {
View Full Code Here


            throws LanguageException {
        try {
            this.classLoaderManager.addDirectory(baseDirectory);
            return this.classLoaderManager.loadClass(name.replace(File.separatorChar, '.'));
        } catch (Exception e) {
            throw new LanguageException("Could not load class for program '" + name + "' due to a " + e.getClass().getName() + ": " + e.getMessage());
        }
    }
View Full Code Here

                    message.append(error.getStartColumn());
                    message.append(": ");
                    message.append(error.getMessage());
                }

                throw new LanguageException(message.toString());
            }

        } catch (InstantiationException e) {
            getLogger().warn("Could not instantiate the compiler", e);
            throw new LanguageException("Could not instantiate the compiler: " + e.getMessage());
        } catch (IllegalAccessException e) {
            getLogger().warn("Could not access the compiler class", e);
            throw new LanguageException("Could not access the compiler class: " + e.getMessage());
        } catch (IOException e) {
            getLogger().warn("Error during compilation", e);
            throw new LanguageException("Error during compilation: " + e.getMessage());
        }
    }
View Full Code Here

    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));
        }

        Class clazz = null;
        ArrayList dependecies = new ArrayList();

        String className = null;
        BufferedReader r = null;
        try {
            r = new BufferedReader(new FileReader(sourceFile));
            className = getMeta(r.readLine(), "extends");
            if (className == null) {
                throw new LanguageException("Can't load program - Signature is not found: "
                        + IOUtils.getFullFilename(sourceFile));
            }

            clazz = ClassUtils.loadClass(className);

            String line;
            while((line = getMeta(r.readLine(), "depends")) != null) {
                dependecies.add(line);
            }
        } catch (IOException e) {
            throw new LanguageException("Can't load program - Signature is not found: "
                    + IOUtils.getFullFilename(sourceFile));
        } catch (ClassNotFoundException e) {
            throw new LanguageException("Can't load program - Base class " + className + " is not found: "
                    + IOUtils.getFullFilename(sourceFile));
        } finally {
            if (r != null) try {
                r.close();
            } catch (IOException ignored) {
View Full Code Here

        }

        // 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 {
            Object testInstance = 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

    public CompiledComponent instantiate(Program program) throws LanguageException {
        try {
            return program.newInstance();
        } catch (Exception e) {
            getLogger().warn("Could not instantiate program instance", e);
            throw new LanguageException("Could not instantiate program instance due to a " + e.getClass().getName() + ": " + e.getMessage());
        }
    }
View Full Code Here

      };

      compiler.main(args);
    } catch (Exception e) {
      getLogger().warn("JavascriptLanguage.compile", e);
      throw new LanguageException(e.getMessage());
    }
  }
View Full Code Here

      this.classLoaderManager.addDirectory(baseDirectory);
      return
        this.classLoaderManager.loadClass(name.replace(File.separatorChar, '.'));
    } catch (Exception e) {
      getLogger().warn("Could not load class for program '" + name + "'", e);
      throw new LanguageException("Could not load class for program '" + name + "' due to a " + e.getClass().getName() + ": " + e.getMessage());
    }
  }
View Full Code Here

          message.append(error.getStartColumn());
          message.append(": ");
          message.append(error.getMessage());
        }

        throw new LanguageException(message.toString());
      }

    } catch (InstantiationException e) {
      getLogger().warn("Could not instantiate the compiler", e);
      throw new LanguageException("Could not instantiate the compiler: " + e.getMessage());
    } catch (IllegalAccessException e) {
      getLogger().warn("Could not access the compiler class", e);
      throw new LanguageException("Could not access the compiler class: " + e.getMessage());
    } catch (IOException e) {
      getLogger().warn("Error during compilation", e);
      throw new LanguageException("Error during compilation: " + e.getMessage());
    }
  }
View Full Code Here

  public CompiledComponent instantiate(Class program) throws LanguageException {
    try {
      return (CompiledComponent) program.newInstance();
    } catch (Exception e) {
      getLogger().warn("Could not instantiate program instance", e);
      throw new LanguageException("Could not instantiate program instance due to a " + e.getClass().getName() + ": " + e.getMessage());
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.components.language.LanguageException

Copyright © 2018 www.massapicom. 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.