View Javadoc
1   package org.codehaus.plexus.component.configurator;
2   
3   import java.util.Map;
4   
5   import org.codehaus.plexus.classworlds.realm.ClassRealm;
6   import org.codehaus.plexus.component.MapOrientedComponent;
7   import org.codehaus.plexus.component.configurator.converters.composite.MapConverter;
8   import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
9   import org.codehaus.plexus.configuration.PlexusConfiguration;
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 extends AbstractComponentConfigurator {
28  
29      public void configureComponent(
30              Object component,
31              PlexusConfiguration configuration,
32              ExpressionEvaluator expressionEvaluator,
33              ClassRealm containerRealm,
34              ConfigurationListener listener)
35              throws ComponentConfigurationException {
36          if (!(component instanceof MapOrientedComponent)) {
37              throw new ComponentConfigurationException(
38                      "This configurator can only process implementations of " + MapOrientedComponent.class.getName());
39          }
40  
41          MapConverter converter = new MapConverter();
42  
43          Map context = (Map) converter.fromConfiguration(
44                  converterLookup, configuration, null, null, containerRealm, expressionEvaluator, listener);
45  
46          ((MapOrientedComponent) component).setComponentConfiguration(context);
47      }
48  }