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.Binding;
20: import org.apache.tapestry.ioc.BaseLocatable;
21: import org.apache.tapestry.ioc.Location;
22: import org.apache.tapestry.ioc.internal.util.TapestryException;
23:
24: /**
25: * Abstract base class for bindings. Assumes that the binding is read only and invariant. Subclasses
26: * must provide an implementation of {@link Binding#get()}.
27: */
28: public abstract class AbstractBinding extends BaseLocatable implements
29: Binding {
30: public AbstractBinding() {
31: this (null);
32: }
33:
34: public AbstractBinding(Location location) {
35: super (location);
36: }
37:
38: /**
39: * @throws TapestryException
40: * always
41: */
42: public void set(Object value) {
43: throw new TapestryException(BindingsMessages
44: .bindingIsReadOnly(this ), this , null);
45: }
46:
47: /**
48: * Returns true. Subclasses that do not supply a fixed, read-only value should override this
49: * method to return false.
50: */
51: public boolean isInvariant() {
52: return true;
53: }
54:
55: /**
56: * Returns the actual class, by invoking {@link Binding#get()}. Subclasses may override this
57: * method to work more efficiently (say, when the binding type is known statically).
58: */
59: public Class getBindingType() {
60: return get().getClass();
61: }
62:
63: /**
64: * Always returns null. Bindings that provide access to a method or field will override this
65: * method to return the appropriate annotation.
66: */
67: public <T extends Annotation> T getAnnotation(
68: Class<T> annotationClass) {
69: return null;
70: }
71:
72: }
|