Java 类org.apache.velocity.util.introspection.Info 实例源码

项目:oap    文件:Uberspector.java   
public VelPropertyGet getPropertyGet( Object object, String name, Info i ) throws Exception {
    VelPropertyGet getter = super.getPropertyGet( object, name, i );
    try {
        getter.getMethodName();
        return getter;
    } catch( NullPointerException notfound ) {
        final Field field = object.getClass().getField( name );
        if( field != null ) {
            AbstractExecutor executor = new AbstractExecutor() {
                public Object execute( Object o ) throws IllegalAccessException {
                    return field.get( o );
                }
            };
            return new VelGetterImpl( executor );
        }
    }
    return null;
}
项目:TeachingKidsProgramming.Source.Java    文件:TestableUberspect.java   
public static Iterator<?> getStandardIterator(Object obj, Info i)
{
  if (obj.getClass().isArray())
  {
    return new ArrayIterator(obj);
  }
  else if (obj instanceof Collection)
  {
    return ((Collection<?>) obj).iterator();
  }
  else if (obj instanceof Map)
  {
    return ((Map<?, ?>) obj).values().iterator();
  }
  else if (obj instanceof Iterator)
  {
    return ((Iterator<?>) obj);
  }
  else if (obj instanceof Enumeration) { return new EnumerationIterator((Enumeration<?>) obj); }
  throw new VelocityParsingError("Could not determine type of iterator in " + "#foreach loop ", i);
}
项目:TeachingKidsProgramming.Source.Java    文件:TestableUberspect.java   
@Override
public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception
{
  AbstractExecutor executor;
  if (obj == null) { throw new VelocityParsingError("tried " + getPropertyText("null", identifier), i); }
  Class<?> type = obj.getClass();
  // trying getFoo()
  executor = new PropertyExecutor(log, introspectorWithLog, type, identifier);
  if (!executor.isAlive())
  {
    // trying get("foo")
    executor = new GetExecutor(log, introspectorWithLog, type, identifier);
  }
  if (!executor.isAlive())
  {
    // trying isFoo()
    executor = new BooleanPropertyExecutor(log, introspectorWithLog, type, identifier);
  }
  if (!executor.isAlive()) { throw new VelocityParsingError("Did not find "
      + getPropertyText(obj.getClass().getName(), identifier), i); }
  return new VelGetterImpl(executor);
}
项目:velocity-scripting    文件:InDirective.java   
@Override
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) {
  super.init(rs, context, node);
  final int n = node.jjtGetNumChildren() - 1;
  for (int i = 1; i < n; i++) {
    Node child = node.jjtGetChild(i);
    if (i == 1) {
      if (child.getType() == ParserTreeConstants.JJTREFERENCE) {
        this.var = ((ASTReference) child).getRootString();
      }
      else {
        throw new TemplateInitException("Syntax error", getTemplateName(), getLine(), getColumn());
      }
    }
    else if (child.getType() == ParserTreeConstants.JJTSTRINGLITERAL) {
      String value = (String) ((ASTStringLiteral) child).value(context);
      if (i == 2) {
        this.column = value;
      }
    }
    else {
      throw new TemplateInitException("Syntax error", getTemplateName(), getLine(), getColumn());
    }
  }
  this.uberInfo = new Info(this.getTemplateName(), getLine(), getColumn());
}
项目:ApprovalTests.Java    文件:TestableUberspect.java   
/***********************************************************************/
public static Iterator getStandardIterator(Object obj, Info i)
{
  if (obj.getClass().isArray())
  {
    return new ArrayIterator(obj);
  }
  else if (obj instanceof Collection)
  {
    return ((Collection) obj).iterator();
  }
  else if (obj instanceof Map)
  {
    return ((Map) obj).values().iterator();
  }
  else if (obj instanceof Iterator)
  {
    return ((Iterator) obj);
  }
  else if (obj instanceof Enumeration) { return new EnumerationIterator((Enumeration) obj); }
  throw new VelocityParsingError("Could not determine type of iterator in " + "#foreach loop ", i);
}
项目:ApprovalTests.Java    文件:TestableUberspect.java   
/***********************************************************************/
public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i) throws Exception
{
  if (obj == null) 
  { 
    if(beKindToNulls)
    {
      return null;
    } 
    else 
    {
      throw new VelocityParsingError("tried " + getMethodText("null", methodName, args), i); 
    }
  }     
  Method m = introspector.getMethod(obj.getClass(), methodName, args);
  if (m == null) { throw new VelocityParsingError("Method " + getMethodText(obj.getClass().getName(), methodName, args) + " does not exist.", i); }
  return new VelMethodImpl(m);
}
项目:ApprovalTests.Java    文件:TestableUberspect.java   
/***********************************************************************/
public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception
{
  AbstractExecutor executor;
  if (obj == null) { throw new VelocityParsingError("tried " + getPropertyText("null", identifier), i); }
  Class<? extends Object> claz = obj.getClass();
  // trying getFoo()
  executor = new PropertyExecutor(log, introspectorWithLog, claz, identifier);
  if (!executor.isAlive())
  {
    // trying  get("foo")
    executor = new GetExecutor(log, introspectorWithLog, claz, identifier);
  }
  if (!executor.isAlive())
  {
    // trying  isFoo()
    executor = new BooleanPropertyExecutor(log, introspectorWithLog, claz, identifier);
  }
  if (!executor.isAlive()) { throw new VelocityParsingError("Did not find " + getPropertyText(obj.getClass().getName(), identifier), i); }
  return new VelGetterImpl(executor);
}
项目:jannocessor    文件:VelocityEventHandler.java   
@Override
public boolean invalidSetMethod(Context context, String leftreference,
        String rightreference, Info info) {
    logger.error("Invalid write: {left:{}, right:{}, template:{}}",
            new Object[] { leftreference, rightreference, info });
    return false;
}
项目:jannocessor    文件:VelocityEventHandler.java   
@Override
public Object invalidMethod(Context context, String reference,
        Object object, String method, Info info) {
    logger.error(
            "Invalid method: {ref:{}, obj:{}, method:{}, template:{}}",
            new Object[] { reference, object, method, info });
    return null;
}
项目:TeachingKidsProgramming.Source.Java    文件:TestableUberspect.java   
@Override
public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i) throws Exception
{
  if (obj == null) { throw new VelocityParsingError("tried " + getMethodText("null", methodName, args), i); }
  Method m = introspector.getMethod(obj.getClass(), methodName, args);
  if (m == null) { throw new VelocityParsingError("Method "
      + getMethodText(obj.getClass().getName(), methodName, args) + " does not exist.", i); }
  return new VelMethodImpl(m);
}
项目:velocity-scripting    文件:RepeatDirective.java   
@Override
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) {
  super.init(rs, context, node);
  final int n = node.jjtGetNumChildren() - 1;
  for (int i = 1; i < n; i++) {
    Node child = node.jjtGetChild(i);
    if (i == 1) {
      if (child.getType() == ParserTreeConstants.JJTREFERENCE) {
        this.var = ((ASTReference) child).getRootString();
      } else {
        throw new TemplateInitException("Syntax error", getTemplateName(), getLine(), getColumn());
      }
    } else if (child.getType() == ParserTreeConstants.JJTSTRINGLITERAL) {
      String value = (String) ((ASTStringLiteral)child).value(context);
      switch (i) {
        case 2:
          this.separator = value;
          break;
        case 3:
          this.open = value;
          break;
        case 4:
          this.close = value;
          break;
        default:
          break;
      }
    } else {
      throw new TemplateInitException("Syntax error", getTemplateName(), getLine(), getColumn());
    }
  }
  this.uberInfo = new Info(this.getTemplateName(), getLine(), getColumn());
}
项目:ApprovalTests.Java    文件:VelocityInfoTest.java   
/***********************************************************************/
private void assertInfoEqual(Info i, String name, int line, int column)
{
  assertEquals("Template Name", name, i.getTemplateName());
  assertEquals("Template Line", line, i.getLine());
  assertEquals("Template Column", column, i.getColumn());
}
项目:ApprovalTests.Java    文件:VelocityInfoTest.java   
/***********************************************************************/
public Info getInfoFor(String velocity)
{
  try
  {
    VelocityParser.parseString(velocity, this);
    fail("Testable Uberspect Should have thrown an error");
    throw new Error("Shouldn't be able to reach this point");
  }
  catch (VelocityParsingError t)
  {
    return t.getInfo();
  }
}
项目:jannocessor    文件:VelocityEventHandler.java   
@Override
public Object invalidGetMethod(Context context, String reference,
        Object object, String property, Info info) {
    return null;
}
项目:TeachingKidsProgramming.Source.Java    文件:TestableUberspect.java   
@Override
public Iterator<?> getIterator(Object obj, Info i) throws Exception
{
  return getStandardIterator(obj, i);
}
项目:TeachingKidsProgramming.Source.Java    文件:VelocityParsingError.java   
public VelocityParsingError(String message, Info info)
{
  this.message = message;
  this.info = info;
}
项目:TeachingKidsProgramming.Source.Java    文件:VelocityParsingError.java   
public static String getInfoText(Info i)
{
  return " at [" + i.getLine() + "," + i.getColumn() + "]" + " in template " + i.getTemplateName();
}
项目:ApprovalTests.Java    文件:TestableUberspect.java   
/***********************************************************************/
public Iterator getIterator(Object obj, Info i) throws Exception
{
  return getStandardIterator(obj, i);
}
项目:ApprovalTests.Java    文件:VelocityParsingError.java   
public VelocityParsingError(String message, Info info)
{
  this.message = message;
  this.info = info;
}
项目:ApprovalTests.Java    文件:VelocityParsingError.java   
/***********************************************************************/
public static String getInfoText(Info i)
{
  return " at [" + i.getLine() + "," + i.getColumn() + "]" + " in template " + i.getTemplateName();
}
项目:ApprovalTests.Java    文件:VelocityParsingError.java   
public Info getInfo()
{
  return info;
}
项目:ApprovalTests.Java    文件:VelocityInfoTest.java   
/***********************************************************************/
public void testInfoForField() throws Exception
{
  Info i = getInfoFor("$main.unknownField");
  assertInfoEqual(i, "$main.unknownField", 1, 7);
}
项目:ApprovalTests.Java    文件:VelocityInfoTest.java   
/***********************************************************************/
public void testInfoForMethod()
{
  Info i = getInfoFor("$main.unknownMethod()");
  assertInfoEqual(i, "$main.unknownMethod()", 1, 7);
}