1 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 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 { 39 41 ObjectContainer container = ta.acquireObject( obj.remoteID(), Lock.LEVEL_READ ); 42 43 try { 44 result = createChunk( container ); 46 } finally { 47 container.unpin(); 48 } 49 } 50 51 52 public byte[] createChunk( ObjectContainer container ) throws Exception { 53 synchronized (container) { 55 OzoneCompatible target = container.target(); 56 57 SAXChunkProducer chunkProducer = new SAXChunkProducer( (SAXChunkProducerDelegate)null ); 58 chunkProducer.startDocument(); 59 60 boolean custom = target.toXML( chunkProducer ); 62 63 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 { 83 obj = (OzoneProxy)in.readObject(); 84 } 85 86 87 public String toString() { 88 return super.toString(); 89 } 90 91 } 92 | Popular Tags |