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.bindings;
16:
17: import java.lang.annotation.Annotation;
18:
19: import org.apache.tapestry.PropertyConduit;
20: import org.apache.tapestry.ioc.Location;
21: import org.apache.tapestry.ioc.internal.util.TapestryException;
22:
23: /**
24: * Base class for bindings created by the
25: * {@link org.apache.tapestry.internal.bindings.PropBindingFactory}. A subclass of this is created
26: * at runtime.
27: */
28: public class PropBinding extends AbstractBinding {
29: private final Object _root;
30:
31: private final PropertyConduit _conduit;
32:
33: private final String _toString;
34:
35: public PropBinding(final Object root,
36: final PropertyConduit conduit, final String toString,
37: final Location location) {
38: super (location);
39:
40: _root = root;
41: _conduit = conduit;
42: _toString = toString;
43: }
44:
45: /**
46: * The default implementation of get() will throw a TapestryException (binding is write only).
47: * The fabricated subclass <em>may</em> override this method (as well as set()).
48: */
49: public Object get() {
50: try {
51: return _conduit.get(_root);
52: } catch (Exception ex) {
53: throw new TapestryException(ex.getMessage(), getLocation(),
54: ex);
55: }
56: }
57:
58: @Override
59: public void set(Object value) {
60: try {
61: _conduit.set(_root, value);
62: } catch (Exception ex) {
63: throw new TapestryException(ex.getMessage(), getLocation(),
64: ex);
65: }
66: }
67:
68: @Override
69: public String toString() {
70: return _toString;
71: }
72:
73: /** Returns false; these properties are always dynamic. */
74: @Override
75: public boolean isInvariant() {
76: return false;
77: }
78:
79: @Override
80: public Class getBindingType() {
81: return _conduit.getPropertyType();
82: }
83:
84: @Override
85: public <T extends Annotation> T getAnnotation(
86: Class<T> annotationClass) {
87: return _conduit.getAnnotation(annotationClass);
88: }
89:
90: }
|