1 27 28 package org.objectweb.perseus.connector.ra.fos; 29 30 import org.objectweb.perseus.connector.ra.Writing; 31 import org.objectweb.perseus.fos.api.FosAccess; 32 import org.objectweb.perseus.fos.api.FosException; 33 import org.objectweb.perseus.fos.api.FosStructure; 34 35 import java.io.ObjectInputStream ; 36 import java.io.ObjectOutputStream ; 37 import javax.resource.cci.Connection ; 38 39 44 public class FosWriting implements Writing, FosStructure { 45 private static final String OBJDIR = "objdir"; 46 private String pid; 47 private String details; 48 private Connection connection; 49 private FosAccess lastUsedInFS; 50 51 protected FosWriting(int _pid, String _details) { 52 pid = Integer.toString(_pid); 53 details = _details; 54 } 55 56 public void init(Connection co) throws Exception { 57 FosAccess fa = (FosAccess) co; 58 if (fa.exist(OBJDIR, pid)) 59 fa.delete(OBJDIR, pid); 60 fa.write(OBJDIR, pid, this, null); 61 } 62 63 public void init() throws Exception { 64 init(connection); 65 } 66 67 71 public boolean passThrough(Connection co) { 72 try { 73 FosAccess fa = (FosAccess) co; 74 lastUsedInFS = null; 75 fa.write(OBJDIR, pid, this, null); 76 if (lastUsedInFS != fa) 77 return false; 78 lastUsedInFS = null; 79 fa.read(OBJDIR, pid, this, null); 80 if (lastUsedInFS != fa) 81 return false; 82 return true; 83 } catch (FosException fe) { 84 fe.printStackTrace(); 85 return false; 86 } 87 } 88 89 95 public boolean read(Connection co, boolean iswritten) 96 throws Exception { 97 FosAccess fa = (FosAccess) co; 98 return fa.exist(OBJDIR, pid) ^ iswritten; 99 } 100 101 public boolean read(boolean iswritten) 102 throws Exception { 103 return read(connection, iswritten); 104 } 105 106 109 public void write(Connection co) throws Exception { 110 FosAccess fa = (FosAccess) co; 111 if (fa.exist(OBJDIR, pid)) 112 fa.delete(OBJDIR, pid); 113 } 114 115 118 public void write() throws Exception { 119 write(connection); 120 } 121 122 public void setConnection(Connection c) throws Exception { 123 connection = c; 124 } 125 126 133 public void readFile(ObjectInputStream ois, FosAccess conn, Object ctxt) throws Exception { 134 details = ois.readUTF(); 135 lastUsedInFS = conn; 136 } 137 138 145 public void writeFile(ObjectOutputStream oos, FosAccess conn, Object ctxt) throws Exception { 146 oos.writeUTF(details); 147 lastUsedInFS = conn; 148 } 149 } | Popular Tags |