001    /*
002     * Copyright (C) 2006-2007 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.codehaus.gmaven.plugin.execute;
018    
019    import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
020    import org.codehaus.plexus.component.configurator.ConfigurationListener;
021    import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter;
022    import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
023    import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
024    import org.codehaus.plexus.configuration.PlexusConfiguration;
025    import org.codehaus.plexus.logging.LogEnabled;
026    import org.codehaus.plexus.logging.Logger;
027    
028    /**
029     * Plexus converter for {@link Source} objects.
030     *
031     * @version $Id: SourceConverter.java 8 2009-07-16 09:15:04Z user57 $
032     * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
033     */
034    public class SourceConverter
035        extends AbstractConfigurationConverter
036        implements LogEnabled
037    {
038        private Logger log;
039    
040        public void enableLogging(final Logger logger) {
041            assert logger != null;
042    
043            this.log = logger;
044        }
045    
046        public boolean canConvert(final Class type) {
047            assert type != null;
048    
049            return Source.class.isAssignableFrom(type);
050        }
051    
052        public Object fromConfiguration(final ConverterLookup converterLookup,
053                                        final PlexusConfiguration configuration,
054                                        final Class type,
055                                        final Class baseType,
056                                        final ClassLoader classLoader,
057                                        final ExpressionEvaluator evaluator,
058                                        final ConfigurationListener listener)
059                throws ComponentConfigurationException
060        {
061            try {
062                return new Source(configuration, evaluator);
063            }
064            catch (Exception e) {
065                throw new ComponentConfigurationException(e);
066            }
067        }
068    }