View Javadoc
1   package org.codehaus.plexus.component.configurator;
2   
3   import org.codehaus.plexus.classworlds.realm.ClassRealm;
4   import org.codehaus.plexus.component.MapOrientedComponent;
5   import org.codehaus.plexus.component.configurator.converters.composite.MapConverter;
6   import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
7   import org.codehaus.plexus.configuration.PlexusConfiguration;
8   
9   import java.util.Map;
10  
11  /*
12   * Copyright 2001-2005 The Apache Software Foundation.
13   *
14   * Licensed under the Apache License, Version 2.0 (the "License");
15   * you may not use this file except in compliance with the License.
16   * You may obtain a copy of the License at
17   *
18   *      http://www.apache.org/licenses/LICENSE-2.0
19   *
20   * Unless required by applicable law or agreed to in writing, software
21   * distributed under the License is distributed on an "AS IS" BASIS,
22   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23   * See the License for the specific language governing permissions and
24   * limitations under the License.
25   */
26  
27  public class MapOrientedComponentConfigurator
28      extends AbstractComponentConfigurator
29  {
30  
31      public void configureComponent( Object component, PlexusConfiguration configuration,
32                                      ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm,
33                                      ConfigurationListener listener )
34          throws ComponentConfigurationException
35      {
36          if ( !( component instanceof MapOrientedComponent ) )
37          {
38              throw new ComponentConfigurationException(
39                  "This configurator can only process implementations of " + MapOrientedComponent.class.getName() );
40          }
41  
42          MapConverter converter = new MapConverter();
43  
44          Map context = (Map) converter.fromConfiguration( converterLookup, configuration, null, null,
45                                                           containerRealm, expressionEvaluator,
46                                                           listener );
47  
48          ( (MapOrientedComponent) component ).setComponentConfiguration( context );
49      }
50  
51  }