01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Core License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: DbXMLForObj.java,v 1.2 2002/06/08 00:49:38 mediumnet Exp $
08:
09: package org.ozoneDB.core.DbRemote;
10:
11: import java.io.*;
12: import org.ozoneDB.DxLib.*;
13: import org.ozoneDB.core.*;
14: import org.ozoneDB.core.xml.*;
15: import org.ozoneDB.*;
16: import org.ozoneDB.util.*;
17: import org.ozoneDB.xml.util.*;
18:
19: /**
20: * @author <a href="http://www.softwarebuero.de/">SMB</a>
21: * @version $Revision: 1.2 $Date: 2002/06/08 00:49:38 $
22: */
23: public final class DbXMLForObj extends DbCommand {
24:
25: private OzoneProxy obj;
26:
27: public DbXMLForObj() {
28: }
29:
30: public DbXMLForObj(OzoneProxy _obj) {
31: obj = _obj;
32: }
33:
34: public void perform(Transaction ta) throws Exception {
35: // env.logWriter.newEntry (this, "DbXMLForObj.perform()...", LogWriter.DEBUG);
36:
37: ObjectContainer container = ta.acquireObjectAndPin(obj
38: .remoteID(), Lock.LEVEL_READ);
39:
40: try {
41: // cache already converted XML in the container?
42: result = createChunk(container);
43: } finally {
44: container.unpin();
45: }
46: }
47:
48: public byte[] createChunk(ObjectContainer container)
49: throws Exception {
50: // because of the global locks this statement is not stricktly needed
51: synchronized (container) {
52: OzoneCompatible target = container.target();
53:
54: SAXChunkProducer chunkProducer = new SAXChunkProducer(
55: (SAXChunkProducerDelegate) null);
56: chunkProducer.startDocument();
57:
58: // check if target provides custom implementation...
59: boolean custom = target.toXML(chunkProducer);
60:
61: // ...use default mapping otherwise
62: if (!custom) {
63: Object2XML o2x = new Object2XML(chunkProducer, true);
64: o2x.toXML(target);
65: }
66:
67: chunkProducer.endDocument();
68:
69: ChunkOutputStream cos = chunkProducer.chunkStream();
70: return cos.toByteArray();
71: }
72: }
73:
74: public void writeExternal(ObjectOutput out) throws IOException {
75: out.writeObject(obj);
76: }
77:
78: public void readExternal(ObjectInput in) throws IOException,
79: ClassNotFoundException {
80: obj = (OzoneProxy) in.readObject();
81: }
82:
83: public String toString() {
84: return super.toString();
85: }
86:
87: }
|