/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 *
 */
package org.xwiki.velocity.introspection;

import java.util.Iterator;

import org.apache.velocity.util.introspection.Info;
import org.apache.velocity.util.introspection.Uberspect;
import org.apache.velocity.util.introspection.UberspectImpl;
import org.apache.velocity.util.introspection.VelMethod;
import org.apache.velocity.util.introspection.VelPropertyGet;
import org.apache.velocity.util.introspection.VelPropertySet;

/**
 * Default implementation of a {@link ChainableUberspector chainable uberspector} that forwards all
 * calls to the wrapped uberspector (when that is possible). It should be used as the base class for
 * all chainable uberspectors.
 * 
 * @version $Id: $
 * @since 1.5M1
 * @see ChainableUberspector
 */
public abstract class AbstractChainableUberspector extends UberspectImpl implements
    ChainableUberspector
{
    /** The wrapped (decorated) uberspector. */
    protected Uberspect inner;

    /**
     * {@inheritDoc}
     * <p>
     * This implementation stores the wrapped uberspector in the protected {@link #inner} member.
     * </p>
     * 
     * @see ChainableUberspector#wrap(org.apache.velocity.util.introspection.Uberspect)
     * @see #inner
     */
    public void wrap(Uberspect inner)
    {
        this.inner = inner;
    }

    /**
     * {@inheritDoc}
     * <p>
     * This implementation forwards the call to the wrapped uberspector, catching all exceptions.
     * </p>
     * 
     * @see org.apache.velocity.util.introspection.UberspectImpl#init()
     */
    @Override
    public void init()
    {
        if (inner != null) {
            try {
                inner.init();
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }

    /**
     * {@inheritDoc}
     * <p>
     * This implementation forwards the call to the wrapped uberspector.
     * </p>
     * 
     * @see org.apache.velocity.util.introspection.UberspectImpl#getIterator(java.lang.Object,
     *      org.apache.velocity.util.introspection.Info)
     */
    @SuppressWarnings("unchecked")
    @Override
    public Iterator getIterator(Object obj, Info i) throws Exception
    {
        return (inner != null) ? inner.getIterator(obj, i) : null;
    }

    /**
     * {@inheritDoc}
     * <p>
     * This implementation forwards the call to the wrapped uberspector.
     * </p>
     * 
     * @see org.apache.velocity.util.introspection.UberspectImpl#getMethod(java.lang.Object,
     *      java.lang.String, java.lang.Object[], org.apache.velocity.util.introspection.Info)
     */
    @Override
    public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i)
        throws Exception
    {
        return (inner != null) ? inner.getMethod(obj, methodName, args, i) : null;
    }

    /**
     * {@inheritDoc}
     * <p>
     * This implementation forwards the call to the wrapped uberspector.
     * </p>
     * 
     * @see org.apache.velocity.util.introspection.UberspectImpl#getPropertyGet(java.lang.Object,
     *      java.lang.String, org.apache.velocity.util.introspection.Info)
     */
    @Override
    public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception
    {
        return (inner != null) ? inner.getPropertyGet(obj, identifier, i) : null;
    }

    /**
     * {@inheritDoc}
     * <p>
     * This implementation forwards the call to the wrapped uberspector.
     * </p>
     * 
     * @see org.apache.velocity.util.introspection.UberspectImpl#getPropertySet(java.lang.Object,
     *      java.lang.String, java.lang.Object, org.apache.velocity.util.introspection.Info)
     */
    @Override
    public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i)
        throws Exception
    {
        return (inner != null) ? inner.getPropertySet(obj, identifier, arg, i) : null;
    }
}

@@ -2197,137 +2197,16 @@
 oc%7D%0A
-     * %3Cp%3E%0A     * This implementation forwards the call to the wrapped uberspector, catching all exceptions.%0A     * %3C/p%3E%0A
      * %0A
     
@@ -2193,32 +2193,32 @@
 ritDoc%7D%0A     * %0A
+
      * @see org.
@@ -2547,104 +2547,8 @@
 oc%7D%0A
-     * %3Cp%3E%0A     * This implementation forwards the call to the wrapped uberspector.%0A     * %3C/p%3E%0A
     
@@ -2942,104 +2942,8 @@
 oc%7D%0A
-     * %3Cp%3E%0A     * This implementation forwards the call to the wrapped uberspector.%0A     * %3C/p%3E%0A
     
@@ -3395,104 +3395,8 @@
 oc%7D%0A
-     * %3Cp%3E%0A     * This implementation forwards the call to the wrapped uberspector.%0A     * %3C/p%3E%0A
     
@@ -3786,32 +3786,32 @@
 %0A    %7D%0A%0A    /**%0A
+
      * %7B@inherit
@@ -3819,104 +3819,8 @@
 oc%7D%0A
-     * %3Cp%3E%0A     * This implementation forwards the call to the wrapped uberspector.%0A     * %3C/p%3E%0A
     

Improve Javadoc.