Package net.sf.laja.exception

Examples of net.sf.laja.exception.InterpretationException


   
    Iterator<Object> argumentsIterator = arguments.iterator();
   
    for (String parameter : parameters) {
      if (!argumentsIterator.hasNext()) {
        throw new InterpretationException(source, indexInSource, "Missing argument in parameter list for macro '" + name + "'");
      }
      populatedArguments.set(parameter, argumentsIterator.next());
    }
    if (argumentsIterator.hasNext()) {
      throw new InterpretationException(source, indexInSource, "Too many arguments in parameter list for macro '" + name + "'");
    }
    localContext.setLocalVariables(populatedArguments);
  }
View Full Code Here


   
    Iterator<Data> argumentsIterator = arguments.iterator();

    for (String parameter : parameters) {
      if (!argumentsIterator.hasNext()) {
        throw new InterpretationException(source, indexInSource, "Missing argument in parameter list for macro '" + name + "'");
      }
      Data argument = argumentsIterator.next();
      if (argument.isLazy()) {
        populatedArguments.set(parameter, argument);
      } else {
        populatedArguments.set(parameter, argument.evaluate());
      }
    }
    if (argumentsIterator.hasNext()) {
      throw new InterpretationException(source, indexInSource, "Too many arguments in parameter list for macro '" + name + "'");
    }
    localContext.setLocalVariables(populatedArguments);
  }
View Full Code Here

    indexInSource = begin.getStartIndex();
  }
 
  public void setCurrentdir() {
    if (!(source instanceof FileSource)) {
      throw new InterpretationException(source, indexInSource, "The source must be of type " + FileSource.class.getName() + " when using $dir");
    }
    directory = getDirectory(getFilenamePath(((FileSource)source).getName()));
  }
View Full Code Here

    directory = getDirectory(getFilenamePath(((FileSource)source).getName()));
  }

  public void setParentDir() {
    if (!(source instanceof FileSource)) {
      throw new InterpretationException(source, indexInSource, "The source must be of type " + FileSource.class.getName() + " when using $dir");
    }
    directory = getParentDirectory(((FileSource)source).getName());
  }
View Full Code Here

        parentDir = currentDir.getParentFile();
      }
      if (parentDir != null) {
        path = parentDir.getCanonicalPath().replace('\\', '/');
      } else {
        throw new InterpretationException(source, indexInSource, "No parent directory exists: " + filename);
      }
    } catch (IOException e) {
      throw new InterpretationException(source, indexInSource, "Could not find path for parent directory of: " + filename);
    }
    return path;
  }
View Full Code Here

    File directory = new File(filename);
    String filenamePath = "";
    try {
      filenamePath = directory.getCanonicalPath();
    } catch (IOException e) {
      throw new InterpretationException(source, indexInSource, "Could not find path for: " + filename);
    }
   
    return  filenamePath.replace('\\', '/');
  }
View Full Code Here

  private void importTextFile(String filename) {
    try {
      String result = new FileReader().readFile(filename);
      templateTextWriter.write(result);
    } catch (IOException e) {
      throw new InterpretationException(source, indexInSource, "Could not import file: " + filename + ". Error: " + e.getMessage());
    }
  }
View Full Code Here

    if (groovyObject == null) {
      try {
        Class groovyClass = groovyClassLoader.parseClass(new File(filename));
        classes.addClass(groovyClass);
      } catch (Exception e) {
        throw new InterpretationException(source, indexInSource, "Could not import file: " + filename + ". Error: " + e.getMessage());
      }
    }
  }
View Full Code Here

  }
 
  public Object generate() {
    if (target.isNamespaceRef()) {
      // e.g: #set ($x = $y)
      throw new InterpretationException(source, indexInSource, "Not possible to set namespace variable $" + target.getNamespaceName());
    }
    if (target.isMethodRef()) {
      // e.g: #set (a() = 123)
      throw new InterpretationException(source, indexInSource, "Not possible to set a method, function or macro");
    }
    if (!target.hasAttributes()) {
      // e.g: #set (x = "1") or #set ($n.x = "1")
      data.setAttribute(target.getVariableName(), target.getSpecifiedContext(context));
    } else {
      // e.g: #set (x.a = "1") or #set ($n.x.a = "1") or #set (a.b.c.d = 1)
      AttributeRefs targetAttributeRefs = target.getAttributesRefs();
     
      AttributeRef targetAttributeRef = targetAttributeRefs.getLastAttribute();
      String targetAttributeName = targetAttributeRef.getName();
     
      Object targetObject = target.getContext().evaluate(target.getAttributeRef());
     
      if (targetObject == null) {
        throw new InterpretationException(source, indexInSource, "Can not set value, the target was null '" + target.getAttributeRef().getName() + "'");
      }

      targetAttributeRefs = targetAttributeRefs.createAttributesSkipLast();
     
      if (targetAttributeRefs.hasAttributes()) {
View Full Code Here

        attribute = primitive.evaluate();
      } else if (isNamespaceRef()) {
        String namespaceName = namespaceRef.getNamespaceName();
        MapContext namespaceContext = namespaces.getNamespaceContext(namespaceName);
        if (namespaceContext == null) {
          throw new InterpretationException(source, indexInSource, "Could not find namespace '" + namespaceName + "'");
        }
        attribute = namespaceContext.getMap();
      } else if (namespaceRef == null) {
        attribute = getResultFromCurrentOrDefaultNamespace();
      } else {
        attribute = getResultFromSpecifiedNamespace();
      }
    } catch (InterpretationException e) {
      throw e;
    } catch (Exception e) {
      throw new InterpretationException(source, indexInSource, e);
    }
    try {
      attribute = evaluateExceptionAndListIndex(attribute);
      return nextAttributeRefs.evaluateNextAttributes(getContext(), attribute);
    } catch (Exception e) {
      throw new InterpretationException(source, indexInSource, e);
    }
  }
View Full Code Here

TOP

Related Classes of net.sf.laja.exception.InterpretationException

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.