View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.configuration.internal;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import org.codehaus.plexus.classworlds.realm.ClassRealm;
25  import org.codehaus.plexus.component.configurator.BasicComponentConfigurator;
26  import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
27  import org.codehaus.plexus.component.configurator.ConfigurationListener;
28  import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter;
29  import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
30  import org.codehaus.plexus.configuration.PlexusConfiguration;
31  
32  /**
33   * A component configurator which can leverage the {@link EnhancedConfigurationConverter}
34   * and {@link EnhancedConverterLookup}.
35   */
36  @Singleton
37  @Named("enhanced")
38  public class EnhancedComponentConfigurator extends BasicComponentConfigurator {
39  
40      public EnhancedComponentConfigurator() {
41          converterLookup = new EnhancedConverterLookup();
42      }
43  
44      @Override
45      public void configureComponent(
46              final Object component,
47              final PlexusConfiguration configuration,
48              final ExpressionEvaluator evaluator,
49              final ClassRealm realm,
50              final ConfigurationListener listener)
51              throws ComponentConfigurationException {
52          try {
53              ClassRealmConverter.pushContextRealm(realm);
54  
55              new EnhancedConfigurationConverter()
56                      .processConfiguration(
57                              converterLookup,
58                              component,
59                              realm, //
60                              configuration,
61                              evaluator,
62                              listener);
63          } finally {
64              ClassRealmConverter.popContextRealm();
65          }
66      }
67  }