📄 vmproxyarg.java
字号:
{
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.JJTINTEGERLITERAL )
{
retObject = staticObject;
}
else if ( type == ParserTreeConstants.JJTFLOATINGPOINTLITERAL )
{
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;
}
/**
* pass through application level runtime exceptions
*/
catch( RuntimeException e )
{
throw e;
}
catch (Exception e )
{
log.error("VMProxyArg.getObject() : error rendering reference", e);
}
}
else if( type == GENERALSTATIC )
{
retObject = staticObject;
}
else
{
log.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
*/
log.error("VMProxyArg.getObject() : method invocation error getting value", mie);
throw mie;
}
}
/**
* 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.JJTMAP :
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)
{
if(nodeTree.getType() != type)
{
log.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);
}
}
/**
* pass through application level runtime exceptions
*/
catch( RuntimeException e )
{
throw e;
}
catch ( Exception e )
{
log.error("VMProxyArg.setup() : exception " +
callerReference, e);
}
break;
}
case ParserTreeConstants.JJTTRUE :
{
constant = true;
staticObject = Boolean.TRUE;
break;
}
case ParserTreeConstants.JJTFALSE :
{
constant = true;
staticObject = Boolean.FALSE;
break;
}
case ParserTreeConstants.JJTINTEGERLITERAL :
{
constant = true;
staticObject = new Integer(callerReference);
break;
}
case ParserTreeConstants.JJTFLOATINGPOINTLITERAL :
{
constant = true;
staticObject = new Double(callerReference);
break;
}
case ParserTreeConstants.JJTWORD :
{
/*
* this is technically an error...
*/
log.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 = callerReference;
break;
}
default :
{
log.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.
* @param model
* @param c
*/
public VMProxyArg( VMProxyArg model, InternalContextAdapter 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();
}
}
}
/**
* @return The caller reference.
*/
public String getCallerReference()
{
return callerReference;
}
/**
* @return The context reference.
*/
public String getContextReference()
{
return contextReference;
}
/**
* @return The node tree.
*/
public SimpleNode getNodeTree()
{
return nodeTree;
}
/**
* @return The static object.
*/
public Object getStaticObject()
{
return staticObject;
}
/**
* @return The type.
*/
public int getType()
{
return type;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -