Coverage Report - org.codehaus.plexus.metadata.ComponentDescriptorExtractorSupport
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentDescriptorExtractorSupport
0 %
0/16
0 %
0/18
4
 
 1  
 /*
 2  
  * Copyright (C) 2007 the original author or authors.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 5  
  * in compliance with the License. You may obtain a copy of the License at
 6  
  * 
 7  
  * http://www.apache.org/licenses/LICENSE-2.0
 8  
  * 
 9  
  * Unless required by applicable law or agreed to in writing, software distributed under the License
 10  
  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 11  
  * or implied. See the License for the specific language governing permissions and limitations under
 12  
  * the License.
 13  
  */
 14  
 
 15  
 package org.codehaus.plexus.metadata;
 16  
 
 17  
 import java.util.HashMap;
 18  
 import java.util.Map;
 19  
 
 20  
 import org.codehaus.plexus.component.repository.ComponentDescriptor;
 21  
 
 22  
 /**
 23  
  * Support for {@link ComponentDescriptorExtractor} implementations.
 24  
  * 
 25  
  * @version $Id$
 26  
  */
 27  0
 public abstract class ComponentDescriptorExtractorSupport
 28  
     implements ComponentDescriptorExtractor
 29  
 {
 30  
     protected Map<String, ComponentDescriptor<?>> getDefaultsByRole( final ComponentDescriptor<?>[] roleDefaults )
 31  
     {
 32  0
         Map<String, ComponentDescriptor<?>> defaultsByRole = new HashMap<String, ComponentDescriptor<?>>();
 33  
 
 34  0
         if ( roleDefaults != null )
 35  
         {
 36  0
             for (ComponentDescriptor<?> roleDefault : roleDefaults) {
 37  0
                 String role = roleDefault.getRole();
 38  
 
 39  0
                 if (role == null) {
 40  0
                     throw new IllegalArgumentException("Invalid role defaults; found null role in: " + roleDefault);
 41  
                 }
 42  
 
 43  0
                 defaultsByRole.put(role, roleDefault);
 44  
             }
 45  
         }
 46  
 
 47  0
         return defaultsByRole;
 48  
     }
 49  
 
 50  
     protected void applyDefaults( ComponentDescriptor<?> descriptor, Map<String, ComponentDescriptor<?>> defaultsByRole )
 51  
     {
 52  0
         assert descriptor != null;
 53  0
         assert defaultsByRole != null;
 54  
 
 55  0
         if ( defaultsByRole.containsKey( descriptor.getRole() ) )
 56  
         {
 57  0
             ComponentDescriptor<?> defaults = defaultsByRole.get( descriptor.getRole() );
 58  
 
 59  0
             if ( descriptor.getInstantiationStrategy() == null )
 60  
             {
 61  0
                 descriptor.setInstantiationStrategy( defaults.getInstantiationStrategy() );
 62  
             }
 63  
         }
 64  0
     }
 65  
 }