⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vmproxyarg.java

📁 velocity 的脚本语言的全部代码集合
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                     */
                
                    retObject = context.get( singleLevelRef );
                }
                else
                {
                    /*
                     *  I need to let the AST produce it for me.
                     */

                    retObject = nodeTree.execute( null, context);
                }
            }
            else if( type == ParserTreeConstants.JJTOBJECTARRAY )
            {
                retObject = nodeTree.value( context );
            }
            else if ( type == ParserTreeConstants.JJTINTEGERRANGE)
            {
                retObject = nodeTree.value( context );    
            }
            else if( type == ParserTreeConstants.JJTTRUE )
            {
                retObject = staticObject;
            }
            else if ( type == ParserTreeConstants.JJTFALSE )
            {
                retObject = staticObject;
            }
            else if ( type == ParserTreeConstants.JJTSTRINGLITERAL )
            {
                retObject =  nodeTree.value( context );
            }
            else if ( type == ParserTreeConstants.JJTNUMBERLITERAL )
            {
                retObject = staticObject;
            }
            else if ( type == ParserTreeConstants.JJTTEXT )
            {
                /*
                 *  this really shouldn't happen.  text is just a thowaway arg for #foreach()
                 */
                           
                try 
                {
                    StringWriter writer =new StringWriter();
                    nodeTree.render( context, writer );
                    
                    retObject = writer;
                }
                catch (Exception e )
                {
                    rsvc.error("VMProxyArg.getObject() : error rendering reference : " + e );
                }
            }
            else if( type ==  GENERALSTATIC )
            {
                retObject = staticObject;
            }
            else
            {
                rsvc.error("Unsupported VM arg type : VM arg = " + callerReference +" type = " + type + "( VMProxyArg.getObject() )");
            }
            
            return retObject;
        }
        catch( MethodInvocationException mie )
        {
            /*
             *  not ideal, but otherwise we propogate out to the 
             *  VMContext, and the Context interface's put/get 
             *  don't throw. So this is a the best compromise
             *  I can think of
             */
            
            rsvc.error("VMProxyArg.getObject() : method invocation error getting value : " + mie );
            
            return null;
        }
    }

    /**
     *  does the housekeeping upon creationg.  If a dynamic type
     *  it needs to make an AST for further get()/set() operations
     *  Anything else is constant.
     */
    private void setup()
    {
        switch( type ) {

        case ParserTreeConstants.JJTINTEGERRANGE :
        case ParserTreeConstants.JJTREFERENCE :
        case ParserTreeConstants.JJTOBJECTARRAY :
        case ParserTreeConstants.JJTSTRINGLITERAL :
        case ParserTreeConstants.JJTTEXT :
            {
                /*
                 *  dynamic types, just render
                 */
                
                constant = false;

                try
                {
                    /*
                     *  fakie : wrap in  directive to get the parser to treat our args as args
                     *   it doesn't matter that #include() can't take all these types, because we 
                     *   just want the parser to consider our arg as a Directive/VM arg rather than
                     *   as if inline in schmoo
                     */

                    String buff ="#include(" + callerReference + " ) ";

                    //ByteArrayInputStream inStream = new ByteArrayInputStream( buff.getBytes() );

                    BufferedReader br = new BufferedReader( new StringReader( buff ) );

                    nodeTree = rsvc.parse(br, "VMProxyArg:" + callerReference, true);

                    /*
                     *  now, our tree really is the first DirectiveArg(), and only one
                     */

                    nodeTree = (SimpleNode) nodeTree.jjtGetChild(0).jjtGetChild(0);

                    /*
                     * sanity check
                     */

                    if ( nodeTree != null && nodeTree.getType() != type )
                    {
                        rsvc.error( "VMProxyArg.setup() : programmer error : type doesn't match node type.");
                    }

                    /*
                     *  init.  be a good citizen and give it an ICA
                     */

                    InternalContextAdapter ica
                            = new InternalContextAdapterImpl(new VelocityContext());

                    ica.pushCurrentTemplateName("VMProxyArg : "
                            + ParserTreeConstants.jjtNodeName[type]);

                    nodeTree.init(ica, rsvc);
                } 
                catch ( Exception e ) 
                {
                    rsvc.error("VMProxyArg.setup() : exception " + callerReference + 
                                  " : "  + StringUtils.stackTrace(e));
                }

                break;
            }
            
        case ParserTreeConstants.JJTTRUE :
            {
                constant = true;
                staticObject = new  Boolean(true);
                break;
            }

        case ParserTreeConstants.JJTFALSE :
            {
                constant = true;
                staticObject =  new Boolean(false);
                break;
            }

        case ParserTreeConstants.JJTNUMBERLITERAL :
            {
                constant = true;
                staticObject = new Integer(callerReference);
                break;
            }

      case ParserTreeConstants.JJTWORD :
          {
              /*
               *  this is technically an error...
               */

              rsvc.error("Unsupported arg type : " + callerReference
                            + "  You most likely intended to call a VM with a string literal, so enclose with ' or \" characters. (VMProxyArg.setup())");
              constant = true;
              staticObject = new String( callerReference );

              break;
          }
 
        default :
            {
                 rsvc.error(" VMProxyArg.setup() : unsupported type : " 
                                    + callerReference  );
            }
        }
    }

    /*
     * CODE FOR ALTERNATE IMPL : please ignore.  I will remove when confortable with current.
     */

    /**
     *  not used in current impl
     *
     *  Constructor for alternate impl where VelProxy class would make new
     *  VMProxyArg objects, and use this contructor to avoid reparsing the 
     *  reference args
     *
     *  that impl also had the VMProxyArg carry it's context
     */
    public VMProxyArg( VMProxyArg model, InternalContextAdapter c )
    {
        usercontext = c;
        contextReference = model.getContextReference();
        callerReference = model.getCallerReference();
        nodeTree = model.getNodeTree();
        staticObject = model.getStaticObject();
        type = model.getType();

       if( nodeTree != null)
            numTreeChildren = nodeTree.jjtGetNumChildren();

        if ( type == ParserTreeConstants.JJTREFERENCE )
        {
            if ( numTreeChildren == 0)
            {
                /*
                 *  use the reference node to do this...
                 */
                singleLevelRef = ((ASTReference) nodeTree).getRootString();
            }
        }
    }
  
    public String getCallerReference()
    {
        return callerReference;
    }

    public String getContextReference()
    {
        return contextReference;
    }

    public SimpleNode getNodeTree()
    {
        return nodeTree;
    }

    public Object getStaticObject()
    {
        return staticObject;
    }

    public int getType()
    {
        return type;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -