1 package org.myoodb.core; 25 26 import java.io.*; 27 28 import org.myoodb.util.*; 29 30 public final class Properties extends java.util.Properties 31 { 32 protected Observable m_observable; 33 34 public Properties() 35 { 36 m_observable = new Observable(); 37 } 38 39 public Properties(Properties defaults) 40 { 41 super(defaults); 42 43 m_observable = new Observable(); 44 } 45 46 public void addObserver(java.util.Observer observer) 47 { 48 m_observable.addObserver(observer); 49 } 50 51 public void removeObserver(java.util.Observer observer) 52 { 53 m_observable.deleteObserver(observer); 54 } 55 56 public void notifyObservers() 57 { 58 m_observable.notifyObservers(this); 59 } 60 61 public boolean hasChanged() 62 { 63 return m_observable.hasChanged(); 64 } 65 66 public void setProperty(String key, Object val) 67 { 68 m_observable.setChanged(); 69 try 70 { 71 ByteArrayOutputStream buf = new ByteArrayOutputStream(1024); 72 ObjectOutputStream out = new ObjectOutputStream(buf); 73 out.writeObject(val); 74 out.close(); 75 76 MimeBase64 mimeBase64 = new MimeBase64(); 77 mimeBase64.translate(buf.toByteArray()); 78 79 super.setProperty(key, new String (mimeBase64.getCharArray())); 80 } 81 catch (Exception e) 82 { 83 throw new org.myoodb.exception.InternalException("Caught during set property: " + e, e); 84 } 85 } 86 87 public Object getProperty(String key, Object defaultVar) 88 { 89 try 90 { 91 String result = super.getProperty(key, (String )defaultVar); 92 if (result != null) 93 { 94 MimeBase64 mimeBase64 = new MimeBase64(); 95 mimeBase64.translate(result.toCharArray()); 96 97 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(mimeBase64.getByteArray())); 98 return in.readObject(); 99 } 100 else 101 { 102 return null; 103 } 104 } 105 catch (Exception e) 106 { 107 throw new org.myoodb.exception.InternalException("Caught during get property: " + e, e); 108 } 109 } 110 111 public void setLongProperty(String key, long val) 112 { 113 setProperty(key, String.valueOf(val)); 114 } 115 116 public long getLongProperty(String key, long defaultVar) 117 { 118 String result = getProperty(key, String.valueOf(defaultVar)); 119 return Long.valueOf(result).longValue(); 120 } 121 } 122 123 class Observable extends java.util.Observable 124 { 125 public Observable() 126 { 127 } 128 129 public void setChanged() 130 { 131 super.setChanged(); 132 } 133 } 134 | Popular Tags |