Coverage Report - org.apache.tapestry.enhance.AutowireWorker
 
Classes in this File Line Coverage Branch Coverage Complexity
AutowireWorker
0%
0/21
0%
0/10
3
 
 1  
 // Copyright 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // 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
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 package org.apache.tapestry.enhance;
 15  
 
 16  
 import org.apache.commons.logging.Log;
 17  
 import org.apache.hivemind.Location;
 18  
 import org.apache.hivemind.internal.Module;
 19  
 import org.apache.tapestry.spec.IComponentSpecification;
 20  
 
 21  
 import java.util.Iterator;
 22  
 import java.util.List;
 23  
 
 24  
 /**
 25  
  * An enhancement worker which automatically injects HiveMind services
 26  
  * into pages/components if exactly one service point exists which is
 27  
  * compatible with the read-only property's type.
 28  
  * 
 29  
  */
 30  
 public class AutowireWorker implements EnhancementWorker
 31  
 {
 32  
     private final Log _log;
 33  
 
 34  
     private final Module _module;
 35  
 
 36  
     public AutowireWorker( Module module, Log log)
 37  0
     {
 38  0
         _module = module;
 39  0
         _log = log;
 40  0
     }
 41  
 
 42  
     public void performEnhancement( EnhancementOperation op, IComponentSpecification spec )
 43  
     {
 44  0
         final List propertyNames = op.findUnclaimedAbstractProperties();
 45  
 
 46  0
         for( Iterator i = propertyNames.iterator(); i.hasNext(); ) {
 47  
             
 48  0
             String propertyName = ( String ) i.next();
 49  
             
 50  0
             Class propertyType = op.getPropertyType( propertyName );
 51  0
             if( propertyType == null )
 52  0
                 propertyType = Object.class;
 53  
             
 54  0
             if (!op.canClaimAsReadOnlyProperty(propertyName))
 55  0
                 continue;
 56  
 
 57  0
             if( _module.containsService( propertyType )) {
 58  
                 
 59  0
                 final Object serviceProxy = _module.getService( propertyType );
 60  0
                 final Location location = spec.getLocation();
 61  
                 
 62  0
                 _log.debug( EnhanceMessages.autowiring( propertyName, spec, serviceProxy ) );
 63  
                 
 64  0
                 final String fieldName = op.addInjectedField( "_$" + propertyName, propertyType, serviceProxy );
 65  
                 
 66  0
                 EnhanceUtils.createSimpleAccessor( op, fieldName, propertyName, propertyType, location );
 67  0
                 op.claimReadonlyProperty( propertyName );
 68  
             }
 69  
 
 70  0
         }
 71  0
     }
 72  
 }