KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > resolver > AbstractSpecificationResolver


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.Tapestry;
20 import org.apache.tapestry.engine.ISpecificationSource;
21 import org.apache.tapestry.spec.IComponentSpecification;
22
23 /**
24  * Base class for resolving a {@link org.apache.tapestry.spec.IComponentSpecification}for a
25  * particular page or component, within a specified {@link org.apache.tapestry.INamespace}. In some
26  * cases, a search is necessary.
27  *
28  * @author Howard Lewis Ship
29  * @since 3.0
30  */

31
32 public class AbstractSpecificationResolver
33 {
34     /** Set by resolve() */
35     private INamespace _namespace;
36
37     /** Set by resolve() */
38     private IComponentSpecification _specification;
39
40     /** Set by container */
41     private ISpecificationSource _specificationSource;
42
43     private ISpecificationResolverDelegate _delegate;
44
45     private String JavaDoc _applicationId;
46
47     private Resource _contextRoot;
48
49     /** Initialized in initializeService() */
50
51     private Resource _webInfLocation;
52
53     private Resource _webInfAppLocation;
54
55     public void initializeService()
56     {
57         _webInfLocation = _contextRoot.getRelativeResource("WEB-INF/");
58
59         _webInfAppLocation = _webInfLocation.getRelativeResource(_applicationId + "/");
60     }
61
62     /**
63      * Returns the {@link ISpecificationResolverDelegate}instance registered in the application
64      * specification as extension {@link Tapestry#SPECIFICATION_RESOLVER_DELEGATE_EXTENSION_NAME},
65      * or null if no such extension exists.
66      */

67
68     public ISpecificationResolverDelegate getDelegate()
69     {
70         return _delegate;
71     }
72
73     /**
74      * Returns the location of the servlet, within the servlet context.
75      */

76
77     protected Resource getContextRoot()
78     {
79         return _contextRoot;
80     }
81
82     public void setContextRoot(Resource contextRoot)
83     {
84         _contextRoot = contextRoot;
85     }
86
87     /**
88      * Invoked in subclasses to identify the resolved namespace.
89      */

90
91     protected void setNamespace(INamespace namespace)
92     {
93         _namespace = namespace;
94     }
95
96     /**
97      * Returns the resolve namespace.
98      */

99
100     public INamespace getNamespace()
101     {
102         return _namespace;
103     }
104
105     /**
106      * Returns the specification source for the running application.
107      */

108
109     protected ISpecificationSource getSpecificationSource()
110     {
111         return _specificationSource;
112     }
113
114     /**
115      * Returns the location of /WEB-INF/, in the servlet context.
116      */

117
118     protected Resource getWebInfLocation()
119     {
120         return _webInfLocation;
121     }
122
123     /**
124      * Returns the location of the application-specific subdirectory, under /WEB-INF/, in the
125      * servlet context.
126      */

127
128     protected Resource getWebInfAppLocation()
129     {
130         return _webInfAppLocation;
131     }
132
133     /**
134      * Returns the resolved specification.
135      */

136
137     public IComponentSpecification getSpecification()
138     {
139         return _specification;
140     }
141
142     /**
143      * Invoked in subclass to set the final specification the initial inputs are resolved to.
144      */

145
146     protected void setSpecification(IComponentSpecification specification)
147     {
148         _specification = specification;
149     }
150
151     /**
152      * Clears the namespace and specification properties.
153      */

154
155     protected void reset()
156     {
157         _namespace = null;
158         _specification = null;
159     }
160
161     /** @since 4.0 */
162     public void setDelegate(ISpecificationResolverDelegate delegate)
163     {
164         _delegate = delegate;
165     }
166
167     /** @since 4.0 */
168     public void setApplicationId(String JavaDoc applicationId)
169     {
170         _applicationId = applicationId;
171     }
172
173     /** @since 4.0 */
174     public void setSpecificationSource(ISpecificationSource source)
175     {
176         _specificationSource = source;
177     }
178
179 }
Popular Tags