KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > reflect > generic > GenericField


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.reflect.generic;
22
23 import com.db4o.foundation.*;
24 import com.db4o.reflect.*;
25
26 /**
27  * @exclude
28  */

29 public class GenericField implements ReflectField, DeepClone{
30
31     private final String JavaDoc _name;
32     private final GenericClass _type;
33     private final boolean _primitive;
34     private final boolean _array;
35     private final boolean _nDimensionalArray;
36
37     private int _index = -1;
38
39     public GenericField(String JavaDoc name, ReflectClass clazz, boolean primitive, boolean array, boolean nDimensionalArray) {
40         _name = name;
41         _type = (GenericClass)clazz;
42         _primitive = primitive;
43         _array = array;
44         _nDimensionalArray = nDimensionalArray;
45     }
46
47     public Object JavaDoc deepClone(Object JavaDoc obj) {
48         Reflector reflector = (Reflector)obj;
49         ReflectClass newReflectClass = null;
50         if(_type != null){
51             newReflectClass = reflector.forName(_type.getName());
52         }
53         return new GenericField(_name, newReflectClass, _primitive, _array, _nDimensionalArray);
54     }
55
56     public Object JavaDoc get(Object JavaDoc onObject) {
57         //TODO Consider: Do we need to check that onObject is an instance of the DataClass this field is a member of?
58
return ((GenericObject)onObject).get(_index);
59     }
60     
61     public String JavaDoc getName() {
62         return _name;
63     }
64
65     public ReflectClass getFieldType() {
66         if(_array){
67             return _type.arrayClass();
68         }
69         return _type;
70     }
71
72     public boolean isPublic() {
73         return true;
74     }
75     
76     public boolean isPrimitive(){
77         return _primitive;
78     }
79
80     public boolean isStatic() { //FIXME Consider static fields.
81
return false;
82     }
83
84     public boolean isTransient() {
85         return false;
86     }
87
88     public void set(Object JavaDoc onObject, Object JavaDoc value) {
89         // FIXME: Consider enabling type checking.
90
// The following will fail with arrays.
91
// if (!_type.isInstance(value)) throw new RuntimeException(); //TODO Consider: is this checking really necessary?
92
((GenericObject)onObject).set(_index,value);
93     }
94
95     public void setAccessible() {
96         // do nothing
97
}
98
99     void setIndex(int index) {
100         _index = index;
101     }
102 }
103
Popular Tags