KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > asset > ClasspathAssetFactory


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 JavaDoc;
18
19 import org.apache.hivemind.ApplicationRuntimeException;
20 import org.apache.hivemind.Location;
21 import org.apache.hivemind.Resource;
22 import org.apache.hivemind.util.ClasspathResource;
23 import org.apache.tapestry.IAsset;
24 import org.apache.tapestry.engine.IEngineService;
25
26 /**
27  * Creates instances of {@link org.apache.tapestry.asset.PrivateAsset}, which are the holders of
28  * classpath: resources.
29  *
30  * @author Howard M. Lewis Ship
31  * @since 4.0
32  */

33 public class ClasspathAssetFactory implements AssetFactory
34 {
35     private IEngineService _assetService;
36
37     public IAsset createAsset(Resource baseResource, String JavaDoc path, Locale JavaDoc locale, Location location)
38     {
39         Resource asset = baseResource.getRelativeResource(path);
40         Resource localized = asset.getLocalization(locale);
41
42         if (localized == null)
43             throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, baseResource),
44                     location, null);
45
46         return new PrivateAsset((ClasspathResource) localized, _assetService, location);
47     }
48
49     public IAsset createAsset(Resource resource, Location location)
50     {
51         ClasspathResource cr = (ClasspathResource) resource;
52
53         return new PrivateAsset(cr, _assetService, location);
54     }
55
56     public void setAssetService(IEngineService assetService)
57     {
58         _assetService = assetService;
59     }
60 }
Popular Tags