KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > DbRemote > DbXMLForObj


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: DbXMLForObj.java,v 1.5 2002/12/29 11:15:56 per_nyfelt Exp $
8

9 package org.ozoneDB.core.DbRemote;
10
11 import org.ozoneDB.OzoneCompatible;
12 import org.ozoneDB.OzoneProxy;
13 import org.ozoneDB.core.*;
14 import org.ozoneDB.core.xml.Object2XML;
15 import org.ozoneDB.xml.util.*;
16
17 import java.io.*;
18
19
20 /**
21  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
22  * @version $Revision: 1.5 $Date: 2002/12/29 11:15:56 $
23  */

24 public final class DbXMLForObj extends DbCommand {
25
26     private OzoneProxy obj;
27
28
29     public DbXMLForObj() {
30     }
31
32
33     public DbXMLForObj( OzoneProxy _obj ) {
34         obj = _obj;
35     }
36
37
38     public void perform( Transaction ta ) throws Exception JavaDoc {
39         // env.logWriter.newEntry (this, "DbXMLForObj.perform()...", LogWriter.DEBUG);
40

41         ObjectContainer container = ta.acquireObject( obj.remoteID(), Lock.LEVEL_READ );
42
43         try {
44         // cache already converted XML in the container?
45
result = createChunk( container );
46         } finally {
47             container.unpin();
48         }
49     }
50
51
52     public byte[] createChunk( ObjectContainer container ) throws Exception JavaDoc {
53         // because of the global locks this statement is not stricktly needed
54
synchronized (container) {
55             OzoneCompatible target = container.target();
56
57             SAXChunkProducer chunkProducer = new SAXChunkProducer( (SAXChunkProducerDelegate)null );
58             chunkProducer.startDocument();
59
60             // check if target provides custom implementation...
61
boolean custom = target.toXML( chunkProducer );
62
63             // ...use default mapping otherwise
64
if (!custom) {
65                 Object2XML o2x = new Object2XML( chunkProducer, true );
66                 o2x.toXML( target );
67             }
68
69             chunkProducer.endDocument();
70
71             ChunkOutputStream cos = chunkProducer.chunkStream();
72             return cos.toByteArray();
73         }
74     }
75
76
77     public void writeExternal( ObjectOutput out ) throws IOException {
78         out.writeObject( obj );
79     }
80
81
82     public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException JavaDoc {
83         obj = (OzoneProxy)in.readObject();
84     }
85
86
87     public String JavaDoc toString() {
88         return super.toString();
89     }
90
91 }
92
Popular Tags