KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > ResultConverter


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: ResultConverter.java,v 1.5 2002/09/18 06:54:15 per_nyfelt Exp $
8

9 package org.ozoneDB.core;
10
11 import org.ozoneDB.*;
12 import org.ozoneDB.core.DbRemote.ProxyObjectGate;
13
14 import java.lang.reflect.*;
15
16 /**
17  * The base class for the classes that convert the parameter and results
18  * of methods invocations that go through Database or ExternalDatabase.
19  *
20  *
21  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
22  * @author <a HREF="http://www.medium.net/">Medium.net</a>
23  * @version $Revision: 1.5 $Date: 2002/09/18 06:54:15 $
24  */

25 public final class ResultConverter extends Object JavaDoc {
26
27
28     public static void updateProxyLinks( Object JavaDoc obj, OzoneInterface db ) throws Exception JavaDoc {
29         String JavaDoc name = obj != null ? obj.getClass().getName() : "(null)";
30         System.out.println( "*** Proxy test: " + name );
31
32         if (obj == null) {
33         //do nothing
34
} else if (obj instanceof OzoneProxy) {
35             ((OzoneProxy)obj).link = db;
36             System.out.println( " *** link changed *** " + db );
37         } else {
38             Class JavaDoc cl = obj.getClass();
39             int mdf = cl.getModifiers();
40             if (Modifier.isTransient( mdf ) || Modifier.isStatic( mdf ) || Modifier.isFinal( mdf )) {
41             //do nothing
42
} else if (cl.isPrimitive()) {
43             //do nothing
44
} else if (cl.isArray()) {
45                 int len = Array.getLength( obj );
46                 for (int j = 0; j < len; j++) {
47                     Object JavaDoc member = Array.get( obj, j );
48                     updateProxyLinks( member, db );
49                 }
50             } else {
51                 Field[] fields = cl.getFields();
52                 for (int i = 0; i < fields.length; i++) {
53                     // System.out.println (fields[i].toString());
54
Object JavaDoc member = fields[i].get( obj );
55                     updateProxyLinks( member, db );
56                 }
57             }
58         }
59     }
60
61     /**
62         Substitute OzoneCompatible by a corresponding proxy. Do this recursive
63         for all members.
64     */

65     public static Object JavaDoc substituteOzoneCompatibles(Object JavaDoc obj) /*throws Exception*/ {
66         return substituteOzoneCompatibles(obj,null);
67     }
68
69     /**
70         Substitute OzoneCompatible by a corresponding proxy. Do this recursive
71         for all members.
72
73         @param proxyObjectGate
74             the client ProxyObjectGate whose objectsReferencesByClient should be filled with all OzoneProxy-Objects
75             found herein or null, if no database client's ProxyObjectGate objectsReferencesByClient should be updated.
76      */

77     public static Object JavaDoc substituteOzoneCompatibles(Object JavaDoc obj,ProxyObjectGate proxyObjectGate) /*throws Exception*/ {
78         // String name = obj != null ? obj.getClass().getName() : "(null)";
79
// System.out.println ("***OzoneCompatible test:" + name);
80

81         //FIXME: should be recursive
82
// if (obj != null && obj instanceof OzoneCompatible) {
83
if (obj instanceof OzoneCompatible) {
84             // System.out.println ("*** substitute ***");
85
OzoneProxy proxy = ((OzoneCompatible)obj).container().ozoneProxy();
86
87             if (proxyObjectGate!=null) {
88                 proxyObjectGate.addObjectReferencedByClient(proxy);
89             }
90
91             return proxy;
92         // return (((OzoneCompatible)obj).objID()!=null) ? ((OzoneCompatible)obj).container().ozoneProxy() : obj;
93
}
94
95         if (proxyObjectGate!=null) { // If the object is not OzoneCompatible, it may be OzoneProxy, which should also be registered at the client.
96
if (obj instanceof OzoneProxy) {
97                 proxyObjectGate.addObjectReferencedByClient((OzoneProxy) obj);
98             }
99         }
100         return obj;
101     }
102 }
103
Popular Tags