Coverage Report - org.apache.tapestry.resolver.AbstractSpecificationResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractSpecificationResolver
0%
0/35
0%
0/6
1.333
 
 1  
 // Copyright 2004, 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.resolver;
 16  
 
 17  
 import org.apache.hivemind.Resource;
 18  
 import org.apache.tapestry.INamespace;
 19  
 import org.apache.tapestry.engine.ISpecificationSource;
 20  
 import org.apache.tapestry.spec.IComponentSpecification;
 21  
 
 22  
 /**
 23  
  * Base class for resolving a {@link org.apache.tapestry.spec.IComponentSpecification}for a
 24  
  * particular page or component, within a specified {@link org.apache.tapestry.INamespace}. In some
 25  
  * cases, a search is necessary.
 26  
  * 
 27  
  * @author Howard Lewis Ship
 28  
  * @since 3.0
 29  
  */
 30  
 
 31  0
 public class AbstractSpecificationResolver
 32  
 {
 33  
     /** Set by resolve(). */
 34  
     private INamespace _namespace;
 35  
 
 36  
     /** Set by resolve(). */
 37  
     private IComponentSpecification _specification;
 38  
 
 39  
     /** Set by container. */
 40  
     private ISpecificationSource _specificationSource;
 41  
 
 42  
     private ISpecificationResolverDelegate _delegate;
 43  
 
 44  
     private String _applicationId;
 45  
 
 46  
     private Resource _contextRoot;
 47  
 
 48  
     /** Initialized in initializeService(). */
 49  
 
 50  
     private Resource _webInfLocation;
 51  
 
 52  
     private Resource _webInfAppLocation;
 53  
 
 54  
     public void initializeService()
 55  
     {
 56  0
         _webInfLocation = _contextRoot.getRelativeResource("WEB-INF/");
 57  
 
 58  0
         _webInfAppLocation = _webInfLocation.getRelativeResource(_applicationId + "/");
 59  0
     }
 60  
 
 61  
     /**
 62  
      * Returns the {@link ISpecificationResolverDelegate}instance registered in the application 
 63  
      * or null if no such extension exists.
 64  
      */
 65  
 
 66  
     public ISpecificationResolverDelegate getDelegate()
 67  
     {
 68  0
         return _delegate;
 69  
     }
 70  
 
 71  
     /**
 72  
      * Returns the location of the servlet, within the servlet context.
 73  
      */
 74  
 
 75  
     protected Resource getContextRoot()
 76  
     {
 77  0
         return _contextRoot;
 78  
     }
 79  
 
 80  
     public void setContextRoot(Resource contextRoot)
 81  
     {
 82  0
         _contextRoot = contextRoot;
 83  0
     }
 84  
 
 85  
     /**
 86  
      * Invoked in subclasses to identify the resolved namespace.
 87  
      */
 88  
 
 89  
     protected void setNamespace(INamespace namespace)
 90  
     {
 91  0
         _namespace = namespace;
 92  0
     }
 93  
 
 94  
     /**
 95  
      * Returns the resolve namespace.
 96  
      */
 97  
 
 98  
     public INamespace getNamespace()
 99  
     {
 100  0
         return _namespace;
 101  
     }
 102  
 
 103  
     /**
 104  
      * Returns the specification source for the running application.
 105  
      */
 106  
 
 107  
     protected ISpecificationSource getSpecificationSource()
 108  
     {
 109  0
         return _specificationSource;
 110  
     }
 111  
 
 112  
     /**
 113  
      * Returns the location of /WEB-INF/, in the servlet context.
 114  
      */
 115  
 
 116  
     protected Resource getWebInfLocation()
 117  
     {
 118  0
         return _webInfLocation;
 119  
     }
 120  
 
 121  
     /**
 122  
      * Returns the location of the application-specific subdirectory, under /WEB-INF/, in the
 123  
      * servlet context.
 124  
      */
 125  
 
 126  
     protected Resource getWebInfAppLocation()
 127  
     {
 128  0
         return _webInfAppLocation;
 129  
     }
 130  
 
 131  
     /**
 132  
      * Returns the resolved specification.
 133  
      */
 134  
 
 135  
     public IComponentSpecification getSpecification()
 136  
     {
 137  0
         return _specification;
 138  
     }
 139  
 
 140  
     /**
 141  
      * Invoked in subclass to set the final specification the initial inputs are resolved to.
 142  
      */
 143  
 
 144  
     protected void setSpecification(IComponentSpecification specification)
 145  
     {
 146  0
         _specification = specification;
 147  0
     }
 148  
 
 149  
     /**
 150  
      * Clears the namespace and specification properties.
 151  
      */
 152  
 
 153  
     protected void reset()
 154  
     {
 155  0
         _namespace = null;
 156  0
         _specification = null;
 157  0
     }
 158  
 
 159  
     /** @since 4.0 */
 160  
     public void setDelegate(ISpecificationResolverDelegate delegate)
 161  
     {
 162  0
         _delegate = delegate;
 163  0
     }
 164  
 
 165  
     /** @since 4.0 */
 166  
     public void setApplicationId(String applicationId)
 167  
     {
 168  0
         _applicationId = applicationId;
 169  0
     }
 170  
 
 171  
     /** @since 4.0 */
 172  
     public void setSpecificationSource(ISpecificationSource source)
 173  
     {
 174  0
         _specificationSource = source;
 175  0
     }
 176  
 
 177  
     /** @since 4.0 */
 178  
     protected INamespace getApplicationNamespace()
 179  
     {
 180  0
         return _specificationSource.getApplicationNamespace();
 181  
     }
 182  
 
 183  
     /** @since 4.0 */
 184  
     protected INamespace getFrameworkNamespace()
 185  
     {
 186  0
         return _specificationSource.getFrameworkNamespace();
 187  
     }
 188  
 
 189  
     /**
 190  
      * @since 4.0
 191  
      */
 192  
     protected INamespace findNamespaceForId(INamespace containerNamespace, String libraryId)
 193  
     {
 194  0
         if (libraryId == null)
 195  0
             return containerNamespace;
 196  
     
 197  0
         if (libraryId.equals(INamespace.APPLICATION_NAMESPACE))
 198  0
             return getApplicationNamespace();
 199  
     
 200  0
         if (libraryId.equals(INamespace.FRAMEWORK_NAMESPACE))
 201  0
             return getFrameworkNamespace();
 202  
     
 203  0
         return containerNamespace.getChildNamespace(libraryId);
 204  
     }
 205  
 }