Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 88   Methods: 6
NCLOC: 50   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClasspathAssetFactory.java 100% 100% 100% 100%
coverage
 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   
 15    package org.apache.tapestry.asset;
 16   
 17    import java.util.Locale;
 18   
 19    import org.apache.hivemind.ApplicationRuntimeException;
 20    import org.apache.hivemind.ClassResolver;
 21    import org.apache.hivemind.Location;
 22    import org.apache.hivemind.Resource;
 23    import org.apache.hivemind.util.ClasspathResource;
 24    import org.apache.tapestry.IAsset;
 25    import org.apache.tapestry.engine.IEngineService;
 26    import org.apache.tapestry.l10n.ResourceLocalizer;
 27   
 28    /**
 29    * Creates instances of {@link org.apache.tapestry.asset.PrivateAsset}, which are the holders of
 30    * classpath: resources.
 31    *
 32    * @author Howard M. Lewis Ship
 33    * @since 4.0
 34    */
 35    public class ClasspathAssetFactory implements AssetFactory
 36    {
 37    private ClassResolver _classResolver;
 38   
 39    private IEngineService _assetService;
 40   
 41    private ResourceLocalizer _localizer;
 42   
 43  386 public IAsset createAsset(Resource baseResource, String path, Locale locale, Location location)
 44    {
 45  386 Resource asset = baseResource.getRelativeResource(path);
 46  386 Resource localized = _localizer.findLocalization(asset, locale);
 47   
 48  386 if (localized == null)
 49  1 throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, baseResource),
 50    location, null);
 51   
 52  385 return createAsset(localized, location);
 53    }
 54   
 55  6 public IAsset createAbsoluteAsset(String path, Locale locale, Location location)
 56    {
 57  6 Resource base = new ClasspathResource(_classResolver, path);
 58  6 Resource localized = _localizer.findLocalization(base, locale);
 59   
 60  6 if (localized == null)
 61  1 throw new ApplicationRuntimeException(AssetMessages.missingClasspathResource(path),
 62    location, null);
 63   
 64  5 return createAsset(localized, location);
 65    }
 66   
 67  415 public IAsset createAsset(Resource resource, Location location)
 68    {
 69  415 ClasspathResource cr = (ClasspathResource) resource;
 70   
 71  415 return new PrivateAsset(cr, _assetService, location);
 72    }
 73   
 74  42 public void setAssetService(IEngineService assetService)
 75    {
 76  42 _assetService = assetService;
 77    }
 78   
 79  42 public void setClassResolver(ClassResolver classResolver)
 80    {
 81  42 _classResolver = classResolver;
 82    }
 83   
 84  42 public void setLocalizer(ResourceLocalizer localizer)
 85    {
 86  42 _localizer = localizer;
 87    }
 88    }