KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > QField


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;
22
23 import com.db4o.foundation.*;
24 import com.db4o.reflect.*;
25 import com.db4o.types.*;
26
27 /**
28  * @exclude
29  */

30 public class QField implements Visitor4, Unversioned{
31     
32     transient Transaction i_trans;
33     public String JavaDoc i_name;
34     transient YapField i_yapField;
35     public int i_yapClassID;
36     public int i_index;
37     
38     public QField(){
39         // C/S only
40
}
41     
42     QField(Transaction a_trans, String JavaDoc name, YapField a_yapField, int a_yapClassID, int a_index){
43         i_trans = a_trans;
44         i_name = name;
45         i_yapField = a_yapField;
46         i_yapClassID = a_yapClassID;
47         i_index = a_index;
48         if(i_yapField != null){
49             if(! i_yapField.alive()){
50                 i_yapField = null;
51             }
52         }
53     }
54     
55     boolean canHold(ReflectClass claxx){
56         return i_yapField == null || i_yapField.canHold(claxx);
57     }
58     
59     Object JavaDoc coerce(Object JavaDoc a_object){
60         ReflectClass claxx = null;
61         Reflector reflector = i_trans.reflector();
62         if(a_object != null){
63             if(a_object instanceof ReflectClass){
64                 claxx = (ReflectClass)a_object;
65             }else{
66                 claxx = reflector.forObject(a_object);
67             }
68         }else{
69             if(Deploy.csharp){
70                 return a_object;
71             }
72         }
73         if(i_yapField == null){
74             return a_object;
75         }
76         return i_yapField.coerce(claxx, a_object);
77     }
78     
79     
80     YapClass getYapClass(){
81         if(i_yapField != null){
82             return i_yapField.getFieldYapClass(i_trans.stream());
83         }
84         return null;
85     }
86     
87     YapField getYapField(YapClass yc){
88         if(i_yapField != null){
89             return i_yapField;
90         }
91         YapField yf = yc.getYapField(i_name);
92         if(yf != null){
93             yf.alive();
94         }
95         return yf;
96     }
97     
98     public YapField getYapField() {
99         return i_yapField;
100     }
101     
102     boolean isArray(){
103         return i_yapField != null && i_yapField.getHandler() instanceof YapArray;
104     }
105     
106     boolean isClass(){
107         return i_yapField == null || i_yapField.getHandler().getTypeID() == YapConst.TYPE_CLASS;
108     }
109     
110     boolean isSimple(){
111         return i_yapField != null && i_yapField.getHandler().getTypeID() == YapConst.TYPE_SIMPLE;
112     }
113     
114     YapComparable prepareComparison(Object JavaDoc obj){
115         if(i_yapField != null){
116             return i_yapField.prepareComparison(obj);
117         }
118         if(obj == null){
119             return Null.INSTANCE;
120         }
121         YapClass yc = i_trans.stream().produceYapClass(i_trans.reflector().forObject(obj));
122         YapField yf = yc.getYapField(i_name);
123         if(yf != null){
124             return yf.prepareComparison(obj);
125         }
126         return null;
127     }
128     
129     void unmarshall(Transaction a_trans){
130         if(i_yapClassID != 0){
131             YapClass yc = a_trans.stream().getYapClass(i_yapClassID);
132             i_yapField = yc.i_fields[i_index];
133         }
134     }
135     
136     public void visit(Object JavaDoc obj) {
137         ((QCandidate) obj).useField(this);
138     }
139 }
140
141
Popular Tags