1 /*** 2 * Redistribution and use in source and binary forms, with or without 3 * modification, are permitted provided that the following conditions are 4 * met : 5 * 6 * . Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * 9 * . Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * . The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $Id: RecordBuffer.java 377 2005-12-29 05:25:52Z mat007 $ 29 */ 30 31 package palmed.buffer; 32 33 import java.io.IOException; 34 import java.io.InputStream; 35 import java.io.OutputStream; 36 import palmed.edit.ITextBox; 37 import palmed.file.IFile; 38 import palmed.io.IRecord; 39 import palmed.io.IRecordFactory; 40 41 /*** 42 * This class provides an adapter between records and buffers. 43 * 44 * @author Mathieu Champlon 45 * @version $Revision: 377 $ $Date: 2005-12-29 14:25:52 +0900 (jeu., 29 déc. 2005) $ 46 */ 47 public final class RecordBuffer implements IRecordBuffer 48 { 49 /*** 50 * The buffer. 51 */ 52 private final IBuffer buffer_; 53 /*** 54 * The record. 55 */ 56 private final IRecord record_; 57 58 /*** 59 * Create a record buffer. 60 * 61 * @param factory the record factory 62 * @param textBox the text box 63 */ 64 public RecordBuffer( final IRecordFactory factory, final ITextBox textBox ) 65 { 66 if( factory == null ) 67 throw new IllegalArgumentException( "parameter 'factory' is null" ); 68 if( textBox == null ) 69 throw new IllegalArgumentException( "parameter 'textBox' is null" ); 70 buffer_ = new Buffer( textBox ); 71 record_ = factory.createRecord( buffer_ ); 72 } 73 74 /*** 75 * {@inheritDoc} 76 */ 77 public void open( final IFile file ) 78 { 79 buffer_.open( file ); 80 } 81 82 /*** 83 * {@inheritDoc} 84 */ 85 public boolean save() 86 { 87 return buffer_.save(); 88 } 89 90 /*** 91 * {@inheritDoc} 92 */ 93 public void save( final IFile file ) 94 { 95 buffer_.save( file ); 96 } 97 98 /*** 99 * {@inheritDoc} 100 */ 101 public boolean hasBeenModified() 102 { 103 return buffer_.hasBeenModified(); 104 } 105 106 /*** 107 * {@inheritDoc} 108 */ 109 public boolean hasFile( final IFile file ) 110 { 111 return buffer_.hasFile( file ); 112 } 113 114 /*** 115 * {@inheritDoc} 116 */ 117 public void unmarshall( final InputStream stream ) throws IOException 118 { 119 buffer_.unmarshall( stream ); 120 } 121 122 /*** 123 * {@inheritDoc} 124 */ 125 public void marshall( final OutputStream stream ) throws IOException 126 { 127 buffer_.marshall( stream ); 128 } 129 130 /*** 131 * {@inheritDoc} 132 */ 133 public void persist() 134 { 135 record_.persist(); 136 } 137 138 /*** 139 * {@inheritDoc} 140 */ 141 public void restore() 142 { 143 record_.restore(); 144 } 145 146 /*** 147 * {@inheritDoc} 148 */ 149 public void delete() 150 { 151 record_.delete(); 152 buffer_.delete(); 153 } 154 155 /*** 156 * {@inheritDoc} 157 */ 158 public void readReference( final InputStream stream ) throws IOException 159 { 160 record_.unmarshall( stream ); 161 } 162 163 /*** 164 * {@inheritDoc} 165 */ 166 public void writeReference( final OutputStream stream ) throws IOException 167 { 168 record_.marshall( stream ); 169 } 170 }