package deliverycube.common.atg.componentresolver.jndi;

import javax.naming.Context;
import javax.naming.NamingException;

import org.apache.log4j.Logger;

import atg.core.util.StringUtils;
import deliverycube.common.atg.componentresolver.ComponentResolver;
import deliverycube.common.atg.componentresolver.UnknownComponentException;

/**
 * Implementation of the {@link ComponentResolver} interface that uses the JNDI to resolve components.
 * 
 * This is a stateful object - the <code>componentName</code> property must be set.
 * 
 * @author Vihung Marathe
 * 
 */
public class JndiComponentResolver implements ComponentResolver {
    private static final Logger log = Logger.getLogger(JndiComponentResolver.class);

    /**
     * 
     */
    public JndiComponentResolver() {
        super();
    }

    /**
     * Uses JNDI to resolve components in any scope at invocation time
     * 
     * @throws IllegalArgumentException
     *             if no componentName has been set
     * @throws UnknownComponentException
     *             if the component cannot be resolved
     * @see deliverycube.deliverycube.common.atg.componentresolver.ComponentResolver#resolveComponent()
     */
    @Override
    public Object resolveComponent() throws UnknownComponentException {
        if (StringUtils.isEmpty(mComponentName)) throw new IllegalArgumentException("No componentName set");

        if (log.isDebugEnabled()) log.debug("componentName=" + mComponentName);
        final String jndiName = "dynamo:" + mComponentName;
        if (log.isDebugEnabled()) log.debug("jndiName=" + jndiName);

        try {
            final Context ctx = new javax.naming.InitialContext();

            final Object component = ctx.lookup(jndiName);
            if (log.isDebugEnabled()) log.debug("resolveComponent(): component=" + component);
            if (log.isDebugEnabled()) log.debug("resolveComponent(): component.class=" + component.getClass().getName());

            if (component == null) {
                throw new UnknownComponentException("Component: " + jndiName + " could not be resolved");
            }

            return component;
        } catch (final NamingException e) {
            throw new UnknownComponentException("Component: " + jndiName + " could not be resolved", e);
        }
    }

    /** Handle to the Component Name */
    private String mComponentName;

    /**
     * Accessor for the <code>componentName</code> property
     * 
     * @return the componentName
     */
    public String getComponentName() {
        return mComponentName;
    }

    /**
     * Modifier for the <code>componentName</code> property
     * 
     * @param pComponentName
     *            the componentName to set
     */
    public void setComponentName(final String pComponentName) {
        mComponentName = pComponentName;
    }

}

@@ -1272,16 +1272,105 @@
 ption %7B%0A
+        if (log.isDebugEnabled()) log.debug(%22Invoked. componentName=%22 + mComponentName);%0A
         
@@ -1475,88 +1475,8 @@
 );%0A%0A
-        if (log.isDebugEnabled()) log.debug(%22componentName=%22 + mComponentName);%0A
     
@@ -1541,37 +1541,37 @@
       if (log.is
-Debug
+Trace
 Enabled()) log.d
@@ -1569,21 +1569,21 @@
 ()) log.
-debug
+trace
 (%22jndiNa
@@ -1756,37 +1756,37 @@
       if (log.is
-Debug
+Trace
 Enabled()) log.d
@@ -1776,37 +1776,37 @@
 eEnabled()) log.
-debug
+trace
 (%22resolveCompone
@@ -1851,37 +1851,37 @@
       if (log.is
-Debug
+Trace
 Enabled()) log.d
@@ -1879,21 +1879,21 @@
 ()) log.
-debug
+trace
 (%22resolv

MODIFY jndi component resolver to clean up logging