KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > query > Field


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.query;
13
14 import com.versant.core.metadata.FieldMetaData;
15 import com.versant.core.metadata.ClassMetaData;
16 import com.versant.core.common.Debug;
17 import com.versant.core.common.OID;
18 //import org.apache.log4j.Category;
19

20 import javax.jdo.spi.PersistenceCapable;
21 import java.util.ArrayList JavaDoc;
22 import java.math.BigDecimal JavaDoc;
23
24 /**
25  */

26 public class Field implements Comparable JavaDoc{
27     public static final int TYPE_COLLECTION=1;
28     public static final int TYPE_ARRAY=2;
29     public static final int TYPE_STRING=3;
30     public static final int TYPE_PC=4;
31     public static final int TYPE_BOOLEAN=5;
32     public static final int TYPE_DECIMAL=6;
33     public static final int TYPE_CHAR=12;
34     public static final int TYPE_MAP=13;
35     public static final int TYPE_REF=14;
36     public static final int TYPE_TX=15;
37     public static final int TYPE_BOUND_VAR=16;
38     public static final int TYPE_UNBOUND_VAR=17;
39     public static final int TYPE_CAST=19;
40     public static final int TYPE_OBJECT=20;
41 // public static final int TYPE_OID=21;
42

43
44     public int type;
45     public FieldMetaData fieldMetaData;
46     public ClassMetaData classMetaData;
47     public PersistenceCapable pcValue;
48 // public OID oidValue;
49
public Object JavaDoc value;
50     public boolean bValue;
51     public BigDecimal JavaDoc dValue;
52     public String JavaDoc sValue;
53     public char cValue;
54     public ArrayList JavaDoc collection;
55     public String JavaDoc name;
56
57     public Field(FieldMetaData fieldMetaData) {
58         this.fieldMetaData = fieldMetaData;
59     }
60
61     public Field(int type) {
62         this.type = type;
63     }
64
65     public Field() {
66     }
67
68     public String JavaDoc getType(){
69         switch(type){
70             case TYPE_COLLECTION:
71                 return "collection";
72             case TYPE_OBJECT:
73                 return "object";
74 // case TYPE_OID:
75
// return "oid";
76
case TYPE_ARRAY:
77                 return "array";
78             case TYPE_STRING:
79                 return "string";
80             case TYPE_PC:
81                 return "PersistenceCapable";
82             case TYPE_BOOLEAN:
83                 return "boolean";
84             case TYPE_DECIMAL:
85                 return "decimal";
86             case TYPE_CHAR:
87                 return "char";
88             case TYPE_MAP:
89                 return "map";
90             case TYPE_TX:
91                 return "transactional";
92             case TYPE_REF:
93                 return "reference";
94             case TYPE_UNBOUND_VAR:
95                 return "unbound variable";
96             case TYPE_BOUND_VAR:
97                 return "bound variable";
98             case TYPE_CAST:
99                 return "cast";
100             default:
101                 return null;
102         }
103     }
104
105     public Object JavaDoc getValue(){
106         switch(type){
107             case TYPE_MAP:
108             case TYPE_ARRAY:
109             case TYPE_TX:
110             case TYPE_REF:
111             case TYPE_CAST:
112             case TYPE_OBJECT:
113                 return value;
114 // case TYPE_OID:
115
// return oidValue;
116
case TYPE_PC:
117                 return pcValue;
118             case TYPE_BOOLEAN:
119                 return new Boolean JavaDoc(bValue);
120             case TYPE_DECIMAL:
121                 return dValue;
122             case TYPE_CHAR:
123                 return new Character JavaDoc(cValue);
124             case TYPE_STRING:
125                 return sValue;
126             case TYPE_BOUND_VAR:
127             case TYPE_COLLECTION:
128                 return collection;
129             default:
130                 return null;
131         }
132     }
133     public String JavaDoc toString(){
134         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
135         buffer.append("Type = ");
136         buffer.append(getType());
137         buffer.append(" value = ");
138         switch(type){
139             case TYPE_MAP:
140             case TYPE_ARRAY:
141             case TYPE_TX:
142             case TYPE_REF:
143             case TYPE_CAST:
144             case TYPE_OBJECT:
145                 buffer.append(value);
146                 break;
147             case TYPE_PC:
148                 buffer.append(pcValue);
149 // case TYPE_OID:
150
// buffer.append(oidValue);
151
case TYPE_BOOLEAN:
152                 buffer.append(bValue);
153                 break;
154             case TYPE_DECIMAL:
155                 buffer.append(dValue);
156                 break;
157             case TYPE_CHAR:
158                 buffer.append(cValue);
159                 break;
160             case TYPE_STRING:
161                 buffer.append(sValue);
162                 break;
163             case TYPE_BOUND_VAR:
164             case TYPE_COLLECTION:
165                 buffer.append(collection);
166             default:
167                 buffer.append(" --- ");
168                 break;
169         }
170         buffer.append(" FieldMetaData = ");
171         buffer.append(fieldMetaData);
172         return buffer.toString();
173     }
174     public void dump(String JavaDoc indent){
175         if (Debug.DEBUG) {
176             Debug.OUT.println(indent+ this.toString());
177         }
178     }
179
180     public void clear(){
181         fieldMetaData = null;
182         collection = null;
183         classMetaData = null;
184         name = null;
185         dValue = null;
186         sValue = null;
187         pcValue = null;
188 // oidValue = null;
189
}
190
191     public int compareTo(Object JavaDoc o) {
192         Comparable JavaDoc a = (Comparable JavaDoc)getValue();
193         Comparable JavaDoc b = null;
194         if(o instanceof Field){
195             b = (Comparable JavaDoc)((Field)o).getValue();
196         }else{
197             b = (Comparable JavaDoc)o;
198         }
199         if (a == null) {
200             a = "";
201         }
202         if (b == null) {
203             b = "";
204         }
205         return a.compareTo(b);
206     }
207
208
209 }
210
Popular Tags