/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2008 Bull S.A.S.
 * Contact: jonas-team@ow2.org
 *
 * Application Versioning System
 * Copyright (C) 2008 France Telecom R&D
 *
 * This library 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 1any later version.
 *
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.ow2.jonas.web.tomcat6.versioning;

import org.ow2.jonas.asm.ClassAdapter;
import org.ow2.jonas.asm.ClassVisitor;
import org.ow2.jonas.asm.FieldVisitor;
import org.ow2.jonas.asm.Opcodes;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
import org.ow2.jonas.lib.util.Log;

/**
 * ASM transformation for the Tomcat Coyote Adapter.
 *
 * @author Frederic Germaneau
 * @author S. Ali Tokmen
 */
public class CoyoteAdapterTransformer extends ClassAdapter {

    /**
     * Logger.
     */
    private static Logger logger = Log.getLogger(CoyoteAdapterTransformer.class.getName());

    /**
     * Calls parent.
     *
     * @param cv  ClassVisitor used.
     */
    public CoyoteAdapterTransformer(final ClassVisitor cv) {
        super(cv);
    }

    /**
     * Changes the "connector" attribute's visibility to protected.
     *
     * @param access     Access type.
     * @param name       Name.
     * @param desc       Description.
     * @param signature  Signature.
     * @param value      Default value.
     *
     * @return Whatever the parent's visitField returns.
     */
    @Override
    public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
        logger.log(BasicLevel.DEBUG, "inside visitField for field: " + name);
        if ("connector".equals(name)) {
            logger.log(BasicLevel.DEBUG, "    Changing access for field: " + name);
            return cv.visitField(Opcodes.ACC_PROTECTED, name, desc, signature, value);
        } else {
            return cv.visitField(access, name, desc, signature, value);
        }
    }
}
