001 // Copyright 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.services.impl;
016
017 import org.apache.hivemind.Location;
018 import org.apache.hivemind.Resource;
019 import org.apache.hivemind.util.Defense;
020 import org.apache.tapestry.IAsset;
021 import org.apache.tapestry.asset.AssetSource;
022 import org.apache.tapestry.engine.ISpecificationSource;
023 import org.apache.tapestry.services.NamespaceResources;
024 import org.apache.tapestry.spec.IComponentSpecification;
025 import org.apache.tapestry.spec.ILibrarySpecification;
026
027 /**
028 * Implementation of {@link org.apache.tapestry.services.NamespaceResources}.
029 *
030 * @author Howard M. Lewis Ship
031 */
032 public class NamespaceResourcesImpl implements NamespaceResources
033 {
034 private final ISpecificationSource _specificationSource;
035
036 private final AssetSource _assetSource;
037
038 public NamespaceResourcesImpl(ISpecificationSource source, AssetSource assetSource)
039 {
040 Defense.notNull(source, "source");
041 Defense.notNull(assetSource, "assetSource");
042
043 _specificationSource = source;
044 _assetSource = assetSource;
045 }
046
047 public ILibrarySpecification findChildLibrarySpecification(Resource parentResource,
048 String path, Location location)
049 {
050 Resource childResource = findSpecificationResource(parentResource, path, location);
051
052 return _specificationSource.getLibrarySpecification(childResource);
053
054 }
055
056 private Resource findSpecificationResource(Resource libraryResource, String path, Location location)
057 {
058 // TODO: This is where we'll play with assets and asset prefixes
059
060 IAsset childAsset = _assetSource.findAsset(libraryResource, path, null, location);
061
062 Resource childResource = childAsset.getResourceLocation();
063
064 return childResource;
065 }
066
067 public IComponentSpecification getPageSpecification(Resource resource,
068 String specificationPath, Location location)
069 {
070 Resource pageSpecificationResource = findSpecificationResource(
071 resource,
072 specificationPath,
073 location);
074
075 return _specificationSource.getPageSpecification(pageSpecificationResource);
076 }
077
078 public IComponentSpecification getComponentSpecification(Resource resource,
079 String specificationPath, Location location)
080 {
081 Resource componentSpecificationResource = findSpecificationResource(
082 resource,
083 specificationPath,
084 location);
085
086 return _specificationSource.getComponentSpecification(componentSpecificationResource);
087 }
088
089 }