public class CMyRecord extends MyRecord implements Record { ///////////////////////////////////////////////////////////////// /** * inner class that implements the basic Record methods. */ private class Delegate extends AbstractRecord { //////////////////////////////////////////////////////////////// /** * write data to the device. * @param out DataOutputStream - stream to device. */ public void writeData (DataOutputStream out) throws IOException { // extract data from MyRecord. byte[] data = getContent (); // write it to the output stream. out.write (data, 0, memsize); } ///////////////////////////////////////////////////////////// /** * read data from the device. * @param in DataInputStream - stream from device. */ public void readData (DataInputStream in) throws IOException { // extract raw data from the stream. byte[] raw = new byte [2048]; int len = in.read (raw); // get the part we are looking for. byte[] data = new byte [len]; for (int i = 0; i < len; i++) data[i] = raw[i]; // update the MyRecord part. setContent (data); } } ///////////////////////////////////////////////////////////////// /** * constructor. */ public CMyRecord () { // create a delegate. theDelegate = new Delegate (); } //############################################################### /** * delegated methods. */ public void writeData (DataOutputStream out) throws IOException { theDelegate.writeData (out); } public void readData (DataInputStream in) throws IOException { theDelegate.readData (in); } public int getId() { return theDelegate.getId(); } public void setId (int recordId) { theDelegate.setId (recordId); } public int getIndex() { return theDelegate.getIndex(); } public void setIndex(int recIndex) { theDelegate.setIndex (recIndex); } public int getCategoryIndex() { return theDelegate.getCategoryIndex(); } public void setCategoryIndex(int categoryIndex) { theDelegate.setCategoryIndex (categoryIndex); } public boolean isModified() { return theDelegate.isModified(); } public void setIsModified(boolean isModified) { theDelegate.setIsModified (isModified); } public boolean isDeleted() { return theDelegate.isDeleted(); } public void setIsDeleted(boolean isDeleted) { theDelegate.setIsDeleted (isDeleted); } public boolean isNew() { return theDelegate.isNew(); } public void setIsNew(boolean isNew) { theDelegate.setIsNew (isNew); } public boolean isPrivate() { return theDelegate.isPrivate(); } public void setIsPrivate(boolean isPrivate) { theDelegate.setIsPrivate (isPrivate); } public boolean isArchived() { return theDelegate.isArchived(); } public void setIsArchived(boolean isArchived) { theDelegate.setIsArchived (isArchived); } ///////////////////////////////////////////////////////////////// /** * instance of the delegation class. */ private Delegate theDelegate; } |