Package railo.transformer.library.function

Examples of railo.transformer.library.function.FunctionLibFunction


        }
        throw new TemplateException(data.cfml,"invalid name for a function");
      }
     
      if(!data.isCFC && !data.isInterface){
        FunctionLibFunction flf = getFLF(data,id);
        if(flf!=null && flf.getClazz()!=CFFunction.class)throw new TemplateException(data.cfml,"The name ["+id+"] is already used by a built in Function");
      }
      return closurePart(data, id,access,rtnType,line,false);
  }
View Full Code Here


    Map<Key, FunctionLibFunction> match = matches.get(type);
    if(match!=null) return match;
   
    FunctionLib[] flds = ((ConfigWebImpl)pc.getConfig()).getFLDs();
    Iterator<FunctionLibFunction> it;
    FunctionLibFunction f;
    match=new HashMap<Collection.Key,FunctionLibFunction>();
    for(int i=0;i<flds.length;i++){
       it = flds[i].getFunctions().values().iterator();
       while(it.hasNext()){
         f = it.next();
         if(f.getMemberName()!=null && f.getMemberType()==type && f.getArgType()==FunctionLibFunction.ARG_FIX) {
           match.put(KeyImpl.getInstance(f.getMemberName()),f);
         }
       }
    }
    matches.put(type, match);
    return match;
View Full Code Here

    return match;
  }
 
  public static Object call(PageContext pc, Object coll,Collection.Key methodName, Object[] args, short type, String strType) throws PageException {
    Map<Key, FunctionLibFunction> members = getMembers(pc, type);
    FunctionLibFunction member=members.get(methodName);
   
    if(member!=null){
      List<FunctionLibFunctionArg> _args = member.getArg();
      FunctionLibFunctionArg arg;
      if(args.length<_args.size()){
        ArrayList<Ref> refs=new ArrayList<Ref>();
        refs.add(new Casting(strType,type,coll));
        for(int y=0;y<args.length;y++){
View Full Code Here

    throw new ExpressionException("No matching function member ["+methodName+"] found, available function members are ["+railo.runtime.type.util.ListUtil.sort(CollectionUtil.getKeyList(members.keySet().iterator(), ","),"textnocase","asc",",")+"]");
  }

  public static Object callWithNamedValues(PageContext pc,Object coll, Collection.Key methodName, Struct args,short type, String strType) throws PageException {
    Map<Key, FunctionLibFunction> members = getMembers(pc, type);
    FunctionLibFunction member=members.get(methodName);
   
    if(member!=null){
      List<FunctionLibFunctionArg> _args = member.getArg();
      FunctionLibFunctionArg arg;
      if(args.size()<_args.size()){
        Object val;
        ArrayList<Ref> refs=new ArrayList<Ref>();
        arg=_args.get(0);
        refs.add(new Casting(arg.getTypeAsString(),arg.getType(),new LFunctionValue(new LString(arg.getName()),coll)));
        for(int y=1;y<_args.size();y++){
          arg = _args.get(y);
         
          // match by name
          val = args.get(arg.getName(),null);
         
          //match by alias
          if(val==null) {
            String alias=arg.getAlias();
            if(!StringUtil.isEmpty(alias,true)) {
              String[] aliases = railo.runtime.type.util.ListUtil.trimItems(railo.runtime.type.util.ListUtil.listToStringArray(alias,','));
              for(int x=0;x<aliases.length;x++){
                val = args.get(aliases[x],null);
                if(val!=null) break;
              }
            }
          }
         
          if(val==null) {
            if(arg.getRequired()) {
              throw new ExpressionException("missing required argument ["+arg.getName()+"] for member function call ["+member.getMemberName()+"]");
            }
          }
          else{
            refs.add(new Casting(arg.getTypeAsString(),arg.getType(),new LFunctionValue(new LString(arg.getName()),val)));
            //refs.add(new LFunctionValue(new LString(arg.getName()),new Casting(pc,arg.getTypeAsString(),arg.getType(),val)));
View Full Code Here

        //}
       
  }
 
  public static void checkFunctionName(String name, FunctionLib[] flibs) throws EvaluatorException {
    FunctionLibFunction flf;
    for (int i = 0; i < flibs.length; i++) {
      flf = flibs[i].getFunction(name);
      if(flf!=null && flf.getClazz()!=CFFunction.class) {
        throw new EvaluatorException("The name ["+name+"] is already used by a built in Function");
      }
    }
  }
View Full Code Here

 
  protected  abstract Function closurePart(ExprData data, String id, int access, String rtnType, Position line,boolean closure) throws TemplateException;

 
  protected FunctionLibFunction getFLF(ExprData data,String name) {
    FunctionLibFunction flf=null;
    for (int i = 0; i < data.flibs.length; i++) {
      flf = data.flibs[i].getFunction(name);
      if (flf != null)
        break;
    }
View Full Code Here

    boolean checkLibrary)
    throws TemplateException {

    // get Function Library
    checkLibrary=checkLibrary && data.flibs!=null;
    FunctionLibFunction flf = null;
    if (checkLibrary) {
      if(!(name instanceof Literal))
        throw new TemplateException(data.cfml,"syntax error"); // should never happen!
     
      for (int i = 0; i < data.flibs.length; i++) {
        flf = data.flibs[i].getFunction(((Literal)name).getString());
        if (flf != null)break;
      }
      if (flf == null) {
        checkLibrary = false;
      }
    }
    // Element Function
    FunctionMember fm;
    if(checkLibrary) {
      BIF bif=new BIF(name,flf);
      bif.setArgType(flf.getArgType());
      bif.setClass(flf.getClazz());
      bif.setReturnType(flf.getReturnTypeAsString());
      fm=bif;
     
      if(flf.getArgType()== FunctionLibFunction.ARG_DYNAMIC && flf.hasDefaultValues()){
            ArrayList<FunctionLibFunctionArg> args = flf.getArg();
        Iterator<FunctionLibFunctionArg> it = args.iterator();
            FunctionLibFunctionArg arg;
            while(it.hasNext()){
              arg=it.next();
              if(arg.getDefaultValue()!=null)
                bif.addArgument(
                    new NamedArgument(
                        LitString.toExprString(arg.getName()),
                        LitString.toExprString(arg.getDefaultValue()),
                        arg.getTypeAsString(),false
                        ));
            }
      }
    }
    else {
      fm = new UDF(name);
    }
   
   
   

    // Function Attributes
    ArrayList<FunctionLibFunctionArg> arrFuncLibAtt = null;
    int libLen = 0;
    if (checkLibrary) {
      arrFuncLibAtt = flf.getArg();
      libLen = arrFuncLibAtt.size();
    }
    int count = 0;
    do {
      data.cfml.next();
            comments(data);

      // finish
      if (count==0 && data.cfml.isCurrent(')'))
        break;

      // too many Attributes
      boolean isDynamic=false;
      int max=-1;
      if(checkLibrary) {
        isDynamic=flf.getArgType()==FunctionLibFunction.ARG_DYNAMIC;
        max=flf.getArgMax();
      // Dynamic
        if(isDynamic) {
          if(max!=-1 && max <= count)
            throw new TemplateException(
              data.cfml,
              "too many Attributes in function [" + ASMUtil.display(name) + "]");
        }
      // Fix
        else {
          if(libLen <= count){
           
            TemplateException te = new TemplateException(
              data.cfml,
              "too many Attributes in function call [" + ASMUtil.display(name) + "]");
            UDFUtil.addFunctionDoc(te, flf);
            throw te;
          }
        }
       
      }
     
      //Argument arg;
      if (checkLibrary && !isDynamic) {
        // current attribues from library
        FunctionLibFunctionArg funcLibAtt =arrFuncLibAtt.get(count);
        fm.addArgument(functionArgument(data,funcLibAtt.getTypeAsString(),false))
      }
      else {
        fm.addArgument(functionArgument(data,false));
      }

            comments(data);
      count++;
      if (data.cfml.isCurrent(')'))
        break;
    }
    while (data.cfml.isCurrent(','));

    // end with ) ??   
    if (!data.cfml.forwardIfCurrent(')'))
      throw new TemplateException(
        data.cfml,
        "Invalid Syntax Closing [)] for function ["
          + ASMUtil.display(name)
          + "] not found");

    // check min attributes
    if (checkLibrary && flf.getArgMin() > count){
      TemplateException te = new TemplateException(
        data.cfml,
        "too few attributes in function [" + ASMUtil.display(name) + "]");
      if(flf.getArgType()==FunctionLibFunction.ARG_FIX) UDFUtil.addFunctionDoc(te, flf);
      throw te;
    }

        comments(data);
       
        // evaluator
        if(checkLibrary && flf.hasTteClass()){
          flf.getEvaluator().evaluate((BIF) fm, flf);
        }
       
    return fm;
  }
View Full Code Here

    */
    private Ref startElement(String name) throws PageException {
       
        // check function
        if (cfml.isCurrent('(')) {
            FunctionLibFunction function = fld.getFunction(name);
            Ref[] arguments = functionArg(name,true, function,')');
          //print.out(name+":"+(function!=null));
            if(function!=null) return new BIFCall(function,arguments);

            Ref ref = new railo.runtime.interpreter.ref.var.Scope(Scope.SCOPE_UNDEFINED);
View Full Code Here

      }
    }
    cfml.removeSpace();
       
        if (cfml.isCurrent('(')) {
          FunctionLibFunction function = fld.getFunction("_createComponent");
            Ref[] arguments = functionArg("_createComponent",true, function,')');
            Ref[] args=new Ref[arguments.length+1];
            for(int i=0;i<arguments.length;i++){
              args[i]=arguments[i];
            }
View Full Code Here

   
    public void createFunction(FunctionLib fl,String filename) {
      //PageSource ps = functionMapping.getPageSource(filename);
     
      String name=toName(filename);//filename.substring(0,filename.length()-(getCFMLExtensions().length()+1));
        FunctionLibFunction flf = new FunctionLibFunction(fl);
      flf.setArgType(FunctionLibFunction.ARG_DYNAMIC);
      flf.setCls("railo.runtime.functions.system.CFFunction");
      flf.setName(name);
      flf.setReturn("object");
      FunctionLibFunctionArg arg = new FunctionLibFunctionArg(flf);
        arg.setName("__filename");
        arg.setRequired(true);
        arg.setType("string");
        arg.setHidden(true);
        arg.setDefaultValue(filename);
        flf.setArg(arg);
       
        arg = new FunctionLibFunctionArg(flf);
        arg.setName("__name");
        arg.setRequired(true);
        arg.setHidden(true);
        arg.setType("string");
        arg.setDefaultValue(name);
        flf.setArg(arg);
       
        arg = new FunctionLibFunctionArg(flf);
        arg.setName("__isweb");
        arg.setRequired(true);
        arg.setHidden(true);
        arg.setType("boolean");
        arg.setDefaultValue(this instanceof ConfigWeb?"true":"false");
        flf.setArg(arg);
     
     
     
      fl.setFunction(flf);
    }
View Full Code Here

TOP

Related Classes of railo.transformer.library.function.FunctionLibFunction

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.