<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    There's a field introspector written by a Velocity user in the Wiki. You can configure velocity.properties to reference this. It require velocity version 1.4.

    PublicFieldUberspect.java
    -------------------------------------------------------------------------------------------------------------
    /*
    * Copyright 2003-2004 The Apache Software Foundation.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    *     http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
    package org.apache.velocity.tools.generic.introspection;
    import java.lang.reflect.Array;
    import java.lang.reflect.Field;
    import org.apache.velocity.util.introspection.Info;
    import org.apache.velocity.util.introspection.UberspectImpl;
    import org.apache.velocity.util.introspection.VelPropertyGet;
    import org.apache.velocity.util.introspection.VelPropertySet;
    /**
    * Uberspect implementation that exposes public fields.
    * Also exposes the explicit "length" field of arrays.
    *
    * <p>To use, tell Velocity to use this class for introspection
    * by adding the following to your velocity.properties:<br />
    *
    * <code>
    * runtime.introspector.uberspect = org.apache.velocity.tools.generic.introspection.PublicFieldUberspect
    * </code>
    * </p>
    *
    * @author <a href="mailto:shinobu@ieee.org">Shinobu Kawai</a>
    * @version $Id: $
    */
    public class PublicFieldUberspect extends UberspectImpl
    {
    /**
    * Default constructor.
    */
    public PublicFieldUberspect()
    {
    }
    /**
    * Property getter - returns VelPropertyGet appropos for #set($foo = $bar.woogie).
    * <br />
    * Returns a special {@link VelPropertyGet} for the <code>length</code> property of arrays.
    * Otherwise tries the regular routine.  If a getter was not found,
    * returns a {@link VelPropertyGet} that gets from public fields.
    *
    * @param obj the object
    * @param identifier the name of the property
    * @param i a bunch of information.
    * @return a valid <code>VelPropertyGet</code>, if it was found.
    * @throws Exception failed to create a valid <code>VelPropertyGet</code>.
    */
    public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i)
    throws Exception
    {
    Class clazz = obj.getClass();
    boolean isArray = clazz.isArray();
    boolean isLength = identifier.equals("length");
    if (isArray && isLength)
    {
    return new ArrayLengthGetter();
    }
    VelPropertyGet getter = super.getPropertyGet(obj, identifier, i);
    // there is no clean way to see if super succeeded
    // @see http://issues.apache.org/bugzilla/show_bug.cgi?id=31742
    try
    {
    getter.getMethodName();
    return getter;
    }
    catch (NullPointerException notFound)
    {
    }
    Field field = obj.getClass().getField(identifier);
    if (field != null)
    {
    return new PublicFieldGetter(field);
    }
    return null;
    }
    /**
    * Property setter - returns VelPropertySet appropos for #set($foo.bar = "geir").
    * <br />
    * First tries the regular routine.  If a setter was not found,
    * returns a {@link VelPropertySet} that sets to public fields.
    *
    * @param obj the object
    * @param identifier the name of the property
    * @param arg the value to set to the property
    * @param i a bunch of information.
    * @return a valid <code>VelPropertySet</code>, if it was found.
    * @throws Exception failed to create a valid <code>VelPropertySet</code>.
    */
    public VelPropertySet getPropertySet(Object obj, String identifier,
    Object arg, Info i) throws Exception
    {
    VelPropertySet setter = super.getPropertySet(obj, identifier, arg, i);
    if (setter != null)
    {
    return setter;
    }
    Field field = obj.getClass().getField(identifier);
    if (field != null)
    {
    return new PublicFieldSetter(field);
    }
    return null;
    }
    /**
    * Implementation of {@link VelPropertyGet} that gets from public fields.
    *
    * @author <a href="mailto:shinobu@ieee.org">Shinobu Kawai</a>
    * @version $Id: $
    */
    protected class PublicFieldGetter implements VelPropertyGet
    {
    /** The <code>Field</code> object representing the property. */
    private Field field = null;
    /**
    * Constructor.
    *
    * @param field The <code>Field</code> object representing the property.
    */
    public PublicFieldGetter(Field field)
    {
    this.field = field;
    }
    /**
    * Returns the value of the public field.
    *
    * @param o the object
    * @return the value
    * @throws Exception failed to get the value from the object
    */
    public Object invoke(Object o) throws Exception
    {
    return this.field.get(o);
    }
    /**
    * This class is cacheable, so it returns <code>true</code>.
    *
    * @return <code>true</code>.
    */
    public boolean isCacheable()
    {
    return true;
    }
    /**
    * Returns <code>"public field getter"</code>, since there is no method.
    *
    * @return <code>"public field getter"</code>
    */
    public String getMethodName()
    {
    return "public field getter";
    }
    }
    /**
    * Implementation of {@link VelPropertyGet} that gets length from arrays.
    *
    * @author <a href="mailto:shinobu@ieee.org">Shinobu Kawai</a>
    * @version $Id: $
    */
    protected class ArrayLengthGetter implements VelPropertyGet
    {
    /**
    * Constructor.
    */
    public ArrayLengthGetter()
    {
    }
    /**
    * Returns the length of the array.
    *
    * @param o the array
    * @return the length
    * @throws Exception failed to get the length from the array
    */
    public Object invoke(Object o) throws Exception
    {
    // Thanks to Eric Fixler for this refactor.
    return new Integer(Array.getLength(o));
    }
    /**
    * This class is cacheable, so it returns <code>true</code>.
    *
    * @return <code>true</code>.
    */
    public boolean isCacheable()
    {
    return true;
    }
    /**
    * Returns <code>"array length getter"</code>, since there is no method.
    *
    * @return <code>"array length getter"</code>
    */
    public String getMethodName()
    {
    return "array length getter";
    }
    }
    /**
    * Implementation of {@link VelPropertySet} that sets to public fields.
    *
    * @author <a href="mailto:shinobu@ieee.org">Shinobu Kawai</a>
    * @version $Id: $
    */
    protected class PublicFieldSetter implements VelPropertySet
    {
    /** The <code>Field</code> object representing the property. */
    private Field field = null;
    /**
    * Constructor.
    *
    * @param field The <code>Field</code> object representing the property.
    */
    public PublicFieldSetter(Field field)
    {
    this.field = field;
    }
    /**
    * Sets the value to the public field.
    *
    * @param o the object
    * @param value the value to set
    * @return always <code>null</code>
    * @throws Exception failed to set the value to the object
    */
    public Object invoke(Object o, Object value) throws Exception
    {
    this.field.set(o, value);
    return null;
    }
    /**
    * This class is cacheable, so it returns <code>true</code>.
    *
    * @return <code>true</code>.
    */
    public boolean isCacheable()
    {
    return true;
    }
    /**
    * Returns <code>"public field setter"</code>, since there is no method.
    *
    * @return <code>"public field setter"</code>
    */
    public String getMethodName()
    {
    return "public field setter";
    }
    }
    }
    


    See
    http://wiki.apache.org/jakarta-velocity/PublicFieldUberspect


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 久久国产精品免费| 美女羞羞免费视频网站| 国产麻豆成人传媒免费观看| 亚洲视频人成在线播放| 人人鲁免费播放视频人人香蕉| 亚洲一级黄色大片| 精品免费人成视频app| 女人18毛片a级毛片免费视频| 亚洲精品人成无码中文毛片| 91在线亚洲精品专区| 99热在线免费观看| 亚洲国产精品国自产电影| 妇女自拍偷自拍亚洲精品| 永久免费看bbb| 一级毛片不卡免费看老司机| 最近中文字幕无免费视频| 亚洲高清国产拍精品熟女| 无码不卡亚洲成?人片| 亚洲国产成+人+综合| 岛国av无码免费无禁网站| 亚洲gv猛男gv无码男同短文| 人妻无码久久一区二区三区免费| 亚洲精品视频免费| 免费一区二区三区| 久久精品国产精品亚洲| 久久精品国产大片免费观看| 亚洲最新在线视频| 国产大片91精品免费观看男同 | 99久久免费中文字幕精品| 四虎影视免费永久在线观看| 国产大片免费天天看| 亚洲精品偷拍无码不卡av| 国产精品自在自线免费观看| japanese色国产在线看免费| 日韩免费a级在线观看| 成在人线av无码免费高潮水| 亚洲高清无码在线观看| 久久久精品免费视频| 亚洲乱码无人区卡1卡2卡3| 免费精品国产日韩热久久| 曰批免费视频播放免费|