KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > YapTypeAbstract


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 /**
24  * @exclude
25  */

26 public abstract class YapTypeAbstract extends YapJavaClass implements YapType{
27     
28     public YapTypeAbstract(YapStream stream) {
29         super(stream);
30     }
31
32     private int i_linkLength;
33     
34     private Object JavaDoc i_compareTo;
35     
36     public abstract int compare(Object JavaDoc compare, Object JavaDoc with);
37     
38     public String JavaDoc dotNetClassName(){
39         String JavaDoc className = this.getClass().getName();
40         int pos = className.indexOf(".Net") ;
41         if(pos >=0){
42             return "System." + className.substring(pos + 4) + ", mscorlib";
43         }
44         return defaultValue().getClass().getName();
45     }
46     
47     public abstract boolean isEqual(Object JavaDoc compare, Object JavaDoc with);
48
49     void initialize(){
50         byte[] bytes = new byte[65];
51         for (int i = 0; i < bytes.length; i++) {
52             bytes[i] = 55; // TODO: Why 55? This is a '7'. Remove.
53
}
54         write(primitiveNull(), bytes, 0);
55         for (int i = 0; i < bytes.length; i++) {
56             if(bytes[i] == 55){
57                 i_linkLength = i;
58                 break;
59             }
60         }
61     }
62     
63     public int getID() {
64         return typeID();
65     }
66     
67     // This method is needed for NetSimpleTypeHandler only during
68
// initalisation and overloaded there. No abstract declaration
69
// here, so we don't have to implement the methods on .NET.
70
public String JavaDoc getName() {
71         return dotNetClassName();
72     }
73
74     public int linkLength() {
75         return i_linkLength;
76     }
77
78     protected Class JavaDoc primitiveJavaClass(){
79         return null;
80     }
81     
82     Object JavaDoc primitiveNull() {
83         return defaultValue();
84     }
85
86     public abstract Object JavaDoc read(byte[] bytes, int offset);
87     
88     Object JavaDoc read1(YapReader a_bytes) throws CorruptionException {
89         int offset = a_bytes._offset;
90         Object JavaDoc ret = read(a_bytes._buffer, a_bytes._offset);
91         a_bytes._offset = offset + linkLength();
92         return ret;
93     }
94     
95     public abstract int typeID();
96     
97     public abstract void write(Object JavaDoc obj, byte[] bytes, int offset);
98
99     public void write(Object JavaDoc a_object, YapReader a_bytes) {
100         int offset = a_bytes._offset;
101         if(a_object != null){
102             write(a_object, a_bytes._buffer, a_bytes._offset);
103         }
104         a_bytes._offset = offset + linkLength();
105     }
106
107     void prepareComparison1(Object JavaDoc obj) {
108         i_compareTo = obj;
109     }
110     
111     public Object JavaDoc current1(){
112         return i_compareTo;
113     }
114
115     boolean isEqual1(Object JavaDoc obj) {
116         return isEqual(i_compareTo, obj);
117     }
118
119     boolean isGreater1(Object JavaDoc obj) {
120         if(classReflector().isInstance(obj) && ! isEqual(i_compareTo, obj)){
121             return compare(i_compareTo, obj) > 0;
122         }
123         return false;
124     }
125
126     boolean isSmaller1(Object JavaDoc obj) {
127         if(classReflector().isInstance(obj) && ! isEqual(i_compareTo, obj)){
128             return compare(i_compareTo, obj) < 0;
129         }
130         return false;
131     }
132 }
133
Popular Tags