001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdo.query;
012:
013: import com.versant.core.metadata.FieldMetaData;
014: import com.versant.core.metadata.ClassMetaData;
015: import com.versant.core.common.Debug;
016: import com.versant.core.common.OID; //import org.apache.log4j.Category;
017:
018: import javax.jdo.spi.PersistenceCapable;
019: import java.util.ArrayList;
020: import java.math.BigDecimal;
021:
022: /**
023: */
024: public class Field implements Comparable {
025: public static final int TYPE_COLLECTION = 1;
026: public static final int TYPE_ARRAY = 2;
027: public static final int TYPE_STRING = 3;
028: public static final int TYPE_PC = 4;
029: public static final int TYPE_BOOLEAN = 5;
030: public static final int TYPE_DECIMAL = 6;
031: public static final int TYPE_CHAR = 12;
032: public static final int TYPE_MAP = 13;
033: public static final int TYPE_REF = 14;
034: public static final int TYPE_TX = 15;
035: public static final int TYPE_BOUND_VAR = 16;
036: public static final int TYPE_UNBOUND_VAR = 17;
037: public static final int TYPE_CAST = 19;
038: public static final int TYPE_OBJECT = 20;
039: // public static final int TYPE_OID=21;
040:
041: public int type;
042: public FieldMetaData fieldMetaData;
043: public ClassMetaData classMetaData;
044: public PersistenceCapable pcValue;
045: // public OID oidValue;
046: public Object value;
047: public boolean bValue;
048: public BigDecimal dValue;
049: public String sValue;
050: public char cValue;
051: public ArrayList collection;
052: public String name;
053:
054: public Field(FieldMetaData fieldMetaData) {
055: this .fieldMetaData = fieldMetaData;
056: }
057:
058: public Field(int type) {
059: this .type = type;
060: }
061:
062: public Field() {
063: }
064:
065: public String getType() {
066: switch (type) {
067: case TYPE_COLLECTION:
068: return "collection";
069: case TYPE_OBJECT:
070: return "object";
071: // case TYPE_OID:
072: // return "oid";
073: case TYPE_ARRAY:
074: return "array";
075: case TYPE_STRING:
076: return "string";
077: case TYPE_PC:
078: return "PersistenceCapable";
079: case TYPE_BOOLEAN:
080: return "boolean";
081: case TYPE_DECIMAL:
082: return "decimal";
083: case TYPE_CHAR:
084: return "char";
085: case TYPE_MAP:
086: return "map";
087: case TYPE_TX:
088: return "transactional";
089: case TYPE_REF:
090: return "reference";
091: case TYPE_UNBOUND_VAR:
092: return "unbound variable";
093: case TYPE_BOUND_VAR:
094: return "bound variable";
095: case TYPE_CAST:
096: return "cast";
097: default:
098: return null;
099: }
100: }
101:
102: public Object getValue() {
103: switch (type) {
104: case TYPE_MAP:
105: case TYPE_ARRAY:
106: case TYPE_TX:
107: case TYPE_REF:
108: case TYPE_CAST:
109: case TYPE_OBJECT:
110: return value;
111: // case TYPE_OID:
112: // return oidValue;
113: case TYPE_PC:
114: return pcValue;
115: case TYPE_BOOLEAN:
116: return new Boolean(bValue);
117: case TYPE_DECIMAL:
118: return dValue;
119: case TYPE_CHAR:
120: return new Character(cValue);
121: case TYPE_STRING:
122: return sValue;
123: case TYPE_BOUND_VAR:
124: case TYPE_COLLECTION:
125: return collection;
126: default:
127: return null;
128: }
129: }
130:
131: public String toString() {
132: StringBuffer buffer = new StringBuffer();
133: buffer.append("Type = ");
134: buffer.append(getType());
135: buffer.append(" value = ");
136: switch (type) {
137: case TYPE_MAP:
138: case TYPE_ARRAY:
139: case TYPE_TX:
140: case TYPE_REF:
141: case TYPE_CAST:
142: case TYPE_OBJECT:
143: buffer.append(value);
144: break;
145: case TYPE_PC:
146: buffer.append(pcValue);
147: // case TYPE_OID:
148: // buffer.append(oidValue);
149: case TYPE_BOOLEAN:
150: buffer.append(bValue);
151: break;
152: case TYPE_DECIMAL:
153: buffer.append(dValue);
154: break;
155: case TYPE_CHAR:
156: buffer.append(cValue);
157: break;
158: case TYPE_STRING:
159: buffer.append(sValue);
160: break;
161: case TYPE_BOUND_VAR:
162: case TYPE_COLLECTION:
163: buffer.append(collection);
164: default:
165: buffer.append(" --- ");
166: break;
167: }
168: buffer.append(" FieldMetaData = ");
169: buffer.append(fieldMetaData);
170: return buffer.toString();
171: }
172:
173: public void dump(String indent) {
174: if (Debug.DEBUG) {
175: Debug.OUT.println(indent + this .toString());
176: }
177: }
178:
179: public void clear() {
180: fieldMetaData = null;
181: collection = null;
182: classMetaData = null;
183: name = null;
184: dValue = null;
185: sValue = null;
186: pcValue = null;
187: // oidValue = null;
188: }
189:
190: public int compareTo(Object o) {
191: Comparable a = (Comparable) getValue();
192: Comparable b = null;
193: if (o instanceof Field) {
194: b = (Comparable) ((Field) o).getValue();
195: } else {
196: b = (Comparable) o;
197: }
198: if (a == null) {
199: a = "";
200: }
201: if (b == null) {
202: b = "";
203: }
204: return a.compareTo(b);
205: }
206:
207: }
|