01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.internal.services;
16:
17: import org.apache.tapestry.Asset;
18: import org.apache.tapestry.ValidationDecorator;
19: import org.apache.tapestry.internal.DefaultValidationDecorator;
20: import org.apache.tapestry.ioc.Messages;
21: import org.apache.tapestry.ioc.services.ThreadLocale;
22: import org.apache.tapestry.services.Environment;
23: import org.apache.tapestry.services.PageRenderCommand;
24: import org.apache.tapestry.services.ValidationMessagesSource;
25:
26: /**
27: * Pushes a {@link DefaultValidationDecorator} instance into the Environment's
28: * {@link ValidationDecorator} service stack.
29: */
30: public class DefaultValidationDelegateCommand implements
31: PageRenderCommand {
32: private final ThreadLocale _threadLocale;
33:
34: private final ValidationMessagesSource _messagesSource;
35:
36: private final Asset _iconAsset;
37:
38: public DefaultValidationDelegateCommand(ThreadLocale threadLocale,
39: ValidationMessagesSource messagesSource, Asset iconAsset) {
40: _threadLocale = threadLocale;
41: _messagesSource = messagesSource;
42: _iconAsset = iconAsset;
43: }
44:
45: public void cleanup(Environment environment) {
46: environment.pop(ValidationDecorator.class);
47: }
48:
49: public void setup(Environment environment) {
50: Messages messages = _messagesSource
51: .getValidationMessages(_threadLocale.getLocale());
52:
53: ValidationDecorator decorator = new DefaultValidationDecorator(
54: environment, messages, _iconAsset);
55:
56: environment.push(ValidationDecorator.class, decorator);
57: }
58:
59: }
|