org.apache.velocity.util.introspection.Introspector Java Examples

The following examples show how to use org.apache.velocity.util.introspection.Introspector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VelTools66TestCase.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
public void testVelTools66()
        throws Exception
{
    /* the testcase is obsolete in JDK 8, as SystemManager.checkMemberAccess is not anymore called
     * by Class.getMethods() */

    int javaVersion = Integer.parseInt(System.getProperty("java.version").split("\\.")[1]);
    if (javaVersion >= 8)
    {
        return;
    }

    Method verifyMethod = TestInterface.class.getMethod("getTestValue");

    RuntimeInstance ri = new RuntimeInstance();
    log = new TestLogger(false, false);
    Introspector introspector = new Introspector(log);

    Method testMethod = introspector.getMethod(TestObject.class, "getTestValue", new Object[0]);
    assertNotNull(testMethod);
    assertEquals("Method object does not match!", verifyMethod, testMethod);
}
 
Example #2
Source File: PropertyExecutor.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 * @param log
 * @param introspector
 * @param clazz
 * @param property
 * @param wrapArray
 * @since 1.5
 */
public PropertyExecutor(final Logger log, final Introspector introspector,
        final Class clazz, final String property, final boolean wrapArray)
{
    this.log = log;
    this.introspector = introspector;
    this.wrapArray = wrapArray;

    // Don't allow passing in the empty string or null because
    // it will either fail with a StringIndexOutOfBounds error
    // or the introspector will get confused.
    if (StringUtils.isNotEmpty(property))
    {
        discover(clazz, property);
    }
}
 
Example #3
Source File: GetExecutor.java    From velocity-engine with Apache License 2.0 6 votes vote down vote up
/**
 * @param log
 * @param introspector
 * @param clazz
 * @param property
 * @since 1.5
 */
public GetExecutor(final Logger log, final Introspector introspector,
        final Class clazz, final String property)
{
    this.log = log;
    this.introspector = introspector;

    // If you passed in null as property, we don't use the value
    // for parameter lookup. Instead we just look for get() without
    // any parameters.
    //
    // In any other case, the following condition will set up an array
    // for looking up get(String) on the class.

    if (property != null)
    {
        this.params = new Object[] { property };
    }
    discover(clazz);
}
 
Example #4
Source File: WebappUberspector.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
/**
 * init method
 */
@Override
public void init()
{
    super.init();

    // we need our own introspector since the inner one is hidden by the Uberspect interface
    introspector = new Introspector(log);
}
 
Example #5
Source File: Introspector2TestCase.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
public void testIntrospector()
        throws Exception
{
    Velocity.setProperty(
	Velocity.RUNTIME_LOG_INSTANCE, new TestLogger());

    Velocity.init();

    Method method;
    String result;
    Tester t = new Tester();

    Object[] params = { new Foo(), new Foo() };

    Introspector introspector = new Introspector(log);

    method = introspector
        .getMethod( Tester.class, "find", params );

    if ( method == null)
        fail("Returned method was null");

    result = (String) method.invoke( t, params);

    if ( !result.equals( "Bar-Bar" ) )
    {
        fail("Should have gotten 'Bar-Bar' : received '" + result + "'");
    }

    /*
     *  now test for failure due to ambiguity
     */

    method = introspector
        .getMethod( Tester2.class, "find", params );

    if ( method != null)
        fail("Introspector shouldn't have found a method as it's ambiguous.");
}
 
Example #6
Source File: PublicFieldExecutor.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @param log
 * @param introspector
 * @param clazz
 * @param property
 * @since 1.5
 */
public PublicFieldExecutor(final Logger log, final Introspector introspector,
        final Class clazz, final String property)
{
    this.log = log;
    this.introspector = introspector;

    // Don't allow passing in the empty string or null because
    // it will either fail with a StringIndexOutOfBounds error
    // or the introspector will get confused.
    if (StringUtils.isNotEmpty(property))
    {
        discover(clazz, property);
    }
}
 
Example #7
Source File: SetPublicFieldExecutor.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @param log
 * @param introspector
 * @param clazz
 * @param property
 * @param arg
 */
public SetPublicFieldExecutor(final Logger log, final Introspector introspector,
        final Class clazz, final String property, final Object arg)
{
    this.log = log;
    this.introspector = introspector;

    // Don't allow passing in the empty string or null because
    // it will either fail with a StringIndexOutOfBounds error
    // or the introspector will get confused.
    if (StringUtils.isNotEmpty(property))
    {
        discover(clazz, property, arg);
    }
}
 
Example #8
Source File: PutExecutor.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @param log
 * @param introspector
 * @param clazz
 * @param arg
 * @param property
 */
public PutExecutor(final Logger log, final Introspector introspector,
        final Class clazz, final Object arg, final String property)
{
    this.log = log;
    this.introspector = introspector;
    this.property = property;

    discover(clazz, arg);
}
 
Example #9
Source File: SetPropertyExecutor.java    From velocity-engine with Apache License 2.0 5 votes vote down vote up
/**
 * @param log
 * @param introspector
 * @param clazz
 * @param property
 * @param arg
 */
public SetPropertyExecutor(final Logger log, final Introspector introspector,
        final Class clazz, final String property, final Object arg)
{
    this.log = log;
    this.introspector = introspector;

    // Don't allow passing in the empty string or null because
    // it will either fail with a StringIndexOutOfBounds error
    // or the introspector will get confused.
    if (StringUtils.isNotEmpty(property))
    {
        discover(clazz, property, arg);
    }
}
 
Example #10
Source File: WebappUberspector.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
/**
 * @param log logger
 * @param introspector introspector instance
 * @param clazz target class
 * @param arg value to set
 * @param property property name
 */
public SetAttributeExecutor(final Logger log, final Introspector introspector,
        final Class clazz, final Object arg, final String property)
{
    this.log = log;
    this.introspector = introspector;
    this.property = property;

    discover(clazz, arg);
}
 
Example #11
Source File: WebappUberspector.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
/**
 * @param log logger
 * @param introspector introspector instance
 * @param clazz class name
 * @param property property name
 */
public GetAttributeExecutor(final Logger log, final Introspector introspector,
        final Class clazz, final String property)
{
    this.log = log;
    this.introspector = introspector;
    this.params = new Object[] { property };

    discover(clazz);
}
 
Example #12
Source File: TestableUberspect.java    From ApprovalTests.Java with Apache License 2.0 5 votes vote down vote up
@Override
public void setLog(Log log)
{
  introspector = new IntrospectorBase(log)
  {
  };
  introspectorWithLog = new Introspector(log);
  this.log = log;
}
 
Example #13
Source File: PropertyExecutor.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
/**
 * @return The current introspector.
 * @since 1.5
 */
protected Introspector getIntrospector()
{
    return this.introspector;
}
 
Example #14
Source File: SetPropertyExecutor.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
/**
 * @return The current introspector.
 */
protected Introspector getIntrospector()
{
    return this.introspector;
}
 
Example #15
Source File: SetPublicFieldExecutor.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
/**
 * @return The current introspector.
 */
protected Introspector getIntrospector()
{
    return this.introspector;
}
 
Example #16
Source File: PublicFieldExecutor.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
/**
 * @return The current introspector.
 * @since 1.5
 */
protected Introspector getIntrospector()
{
    return this.introspector;
}
 
Example #17
Source File: Introspector3TestCase.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
public void testSimple()
    throws Exception
{
    Method method;
    String result;

    MethodProvider mp = new MethodProvider();

    /*
     * string integer
     */

    Object[] listIntInt = { new ArrayList(), 1, 2};
    Object[] listLongList = { new ArrayList(), 1L, new ArrayList() };
    Object[] intInt = {1, 2};
    Object[] longInt = {1L, 2};
    Object[] longLong = {1L, 2L};

    Introspector introspector = new Introspector(log);
    method = introspector.getMethod(
        MethodProvider.class, "lii", listIntInt);
    result = (String) method.invoke(mp, listIntInt);

    assertTrue(result.equals("lii"));

    method = introspector.getMethod(
        MethodProvider.class, "ii", intInt);
    result = (String) method.invoke(mp, intInt);

    assertTrue(result.equals("ii"));

    method = introspector.getMethod(
        MethodProvider.class, "ll", longInt);
    result = (String) method.invoke(mp, longInt);

    assertTrue(result.equals("ll"));

    /*
     * test overloading with primitives
     */

    method = introspector.getMethod(
        MethodProvider.class, "ll", longLong);
    result = (String) method.invoke(mp, longLong);

    assertTrue(result.equals("ll"));

    method = introspector.getMethod(
        MethodProvider.class, "lll", listLongList);
    result = (String) method.invoke(mp, listLongList);

    assertTrue(result.equals("lll"));

    /*
     *  test invocation with nulls
     */

    Object [] oa = {null, 0};
    method = introspector.getMethod(
        MethodProvider.class, "lll", oa );
    result = (String) method.invoke(mp, oa);

    assertTrue(result.equals("Listl"));

}
 
Example #18
Source File: IntrospectorTestCase.java    From velocity-engine with Apache License 2.0 4 votes vote down vote up
public void setUp()
{
    mp = new MethodProvider();
    log = new TestLogger();
    introspector = new Introspector(log);
}
 
Example #19
Source File: PropertyExecutor.java    From velocity-engine with Apache License 2.0 2 votes vote down vote up
/**
 * @param log
 * @param introspector
 * @param clazz
 * @param property
 * @since 1.5
 */
public PropertyExecutor(final Logger log, final Introspector introspector,
                        final Class clazz, final String property)
{
    this(log, introspector, clazz, property, false);
}
 
Example #20
Source File: BooleanPropertyExecutor.java    From velocity-engine with Apache License 2.0 2 votes vote down vote up
/**
 * @param log
 * @param introspector
 * @param clazz
 * @param property
 * @param wrapArray
 * @since 1.5
 */
public BooleanPropertyExecutor(final Logger log, final Introspector introspector,
        final Class clazz, final String property, final boolean wrapArray)
{
    super(log, introspector, clazz, property, wrapArray);
}
 
Example #21
Source File: BooleanPropertyExecutor.java    From velocity-engine with Apache License 2.0 2 votes vote down vote up
/**
 * @param log
 * @param introspector
 * @param clazz
 * @param property
 * @since 1.5
 */
public BooleanPropertyExecutor(final Logger log, final Introspector introspector,
                               final Class clazz, final String property)
{
    this(log, introspector, clazz, property, false);
}