KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > reflect > BaseProperty


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.reflect;
21
22 /**
23  * An abstract property descriptor that delegates property access to an {@link Accessor}.
24  * Used as a superclass for other implementations.
25  *
26  * @since 3.0
27  * @author Andrus Adamchik
28  */

29 public abstract class BaseProperty implements Property {
30
31     protected ClassDescriptor owner;
32     protected Accessor accessor;
33
34     // name is derived from accessor, cached here for performance
35
final String JavaDoc name;
36
37     public BaseProperty(ClassDescriptor owner, Accessor accessor) {
38
39         if (accessor == null) {
40             throw new IllegalArgumentException JavaDoc("Null accessor");
41         }
42
43         this.accessor = accessor;
44         this.owner = owner;
45         this.name = accessor.getName();
46     }
47
48     public Object JavaDoc readProperty(Object JavaDoc object) throws PropertyException {
49         return readPropertyDirectly(object);
50     }
51
52     public void writeProperty(Object JavaDoc object, Object JavaDoc oldValue, Object JavaDoc newValue)
53             throws PropertyException {
54         writePropertyDirectly(object, oldValue, newValue);
55     }
56
57     public String JavaDoc getName() {
58         return name;
59     }
60
61     public abstract boolean visit(PropertyVisitor visitor);
62
63     /**
64      * Does nothing.
65      */

66     public void injectValueHolder(Object JavaDoc object) throws PropertyException {
67         // noop
68
}
69
70     public Object JavaDoc readPropertyDirectly(Object JavaDoc object) throws PropertyException {
71         return accessor.getValue(object);
72     }
73
74     public void writePropertyDirectly(Object JavaDoc object, Object JavaDoc oldValue, Object JavaDoc newValue)
75             throws PropertyException {
76         accessor.setValue(object, newValue);
77     }
78
79     public String JavaDoc toString() {
80         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
81         buffer.append(getClass().getName()).append('@').append(
82                 System.identityHashCode(this)).append('[').append(name).append(']');
83         return buffer.toString();
84     }
85 }
86
Popular Tags