01: // Copyright 2006 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.structure;
16:
17: import org.apache.tapestry.Binding;
18: import org.apache.tapestry.MarkupWriter;
19: import org.apache.tapestry.ioc.services.TypeCoercer;
20: import org.apache.tapestry.runtime.RenderQueue;
21:
22: /**
23: *
24: */
25: public class ExpansionPageElement implements PageElement {
26: private final Binding _binding;
27:
28: private final boolean _invariant;
29:
30: private final TypeCoercer _coercer;
31:
32: private boolean _cached;
33:
34: private String _cachedValue;
35:
36: public ExpansionPageElement(Binding binding, TypeCoercer coercer) {
37: _binding = binding;
38: _coercer = coercer;
39:
40: _invariant = _binding.isInvariant();
41: }
42:
43: public void render(MarkupWriter writer, RenderQueue queue) {
44: String value = _cached ? _cachedValue : _coercer.coerce(
45: _binding.get(), String.class);
46:
47: if (_invariant && !_cached) {
48: _cachedValue = value;
49: _cached = true;
50: }
51:
52: writer.write(value);
53: }
54:
55: @Override
56: public String toString() {
57: return String.format("Expansion[%s]", _binding.toString());
58: }
59: }
|