1 package org.apache.axis2.storage.impl; 2 3 import java.io.File ; 4 import java.io.FileNotFoundException ; 5 import java.io.FileOutputStream ; 6 import java.io.IOException ; 7 import java.util.HashMap ; 8 9 26 public class AxisFileStorage extends AbstractStorage{ 27 28 private File file; 29 private FileOutputStream fos; 30 private HashMap map; 31 32 public AxisFileStorage() { 33 map = new HashMap (); 34 } 35 36 public AxisFileStorage(File file) { 37 this(); 38 this.setFile(file); 39 } 40 41 public File getFile() { 42 return file; 43 } 44 45 public void setFile(File file) { 46 try { 47 this.file = file; 48 this.fos = new FileOutputStream (file); 49 } catch (FileNotFoundException e) { 50 throw new UnsupportedOperationException ("No such file!"); 51 } 52 } 53 54 public Object put(Object value) { 55 56 try { 57 String key = getUniqueKey(); 58 map.put(key,value); 59 60 updateFileState(); 61 62 return key; 63 } catch (IOException e) { 64 throw new UnsupportedOperationException (e.getMessage()); 65 } catch (Exception e) { 66 throw new UnsupportedOperationException (e.getMessage()); 67 } 68 69 } 70 71 public Object get(Object key) { 72 return map.get(key); 73 } 74 75 public Object remove(Object key) { 76 try { 77 Object objToRemove = map.remove(key); 78 79 updateFileState(); 80 81 return objToRemove; 82 } catch (IOException e) { 83 throw new UnsupportedOperationException (" file writing failed!"); 84 } 85 } 86 87 private void updateFileState() throws IOException { 88 } 92 93 public boolean clean() { 94 try { 95 map.clear(); 96 updateFileState(); 97 return true; 98 } catch (Exception e) { 99 return false; 100 } 101 } 102 103 104 } 105 | Popular Tags |