1 16 package com.buchuki.ensmer.object; 17 18 import java.io.Serializable ; 19 import javax.media.j3d.BranchGroup; 20 import javax.swing.event.*; 21 import com.buchuki.annotations.*; 22 import com.buchuki.ensmer.EnsmerManager; 23 import com.buchuki.ensmer.builtin.Configurator; 24 import java.util.*; 25 26 27 42 public abstract class Backend { 43 44 48 public Backend() { 49 changeEvent = new ChangeEvent(this); 50 this.id = id; 51 } 52 53 58 public void addChangeListener(ChangeListener l) { 59 listenerList.add(ChangeListener.class, l); 60 } 61 62 67 public void removeChangeListener(ChangeListener l) { 68 listenerList.remove(ChangeListener.class, l); 69 } 70 71 78 public abstract Serializable getSerializable(); 79 80 85 public Long getId() { 86 return id; 87 } 88 89 96 public void setConfigProperty(String key, String value) { 97 Configurator conf = EnsmerManager.instance().getConfigManager().getConfigurator(getId()); 98 conf.setProperty(key, value); 99 } 100 101 106 public String getConfigProperty(String key) { 107 Configurator conf = EnsmerManager.instance().getConfigManager().getConfigurator(getId()); 108 return conf.getProperty(key); 109 } 110 111 118 public String getConfigProperty(String key, String defaultVal) { 119 String prop = getConfigProperty(key); 120 return prop == null ? defaultVal : prop; 121 } 122 123 130 public Properties getConfigProperties() { 131 Properties props = new Properties(); 132 Configurator conf = EnsmerManager.instance().getConfigManager().getConfigurator(getId()); 133 List<String > names = conf.getPropertyNames(); 134 for (String name : names) { 135 props.setProperty(name, conf.getProperty(name)); 136 } 137 return props; 138 } 139 140 153 public static BranchGroup getRepresentation() { 154 return null; 155 } 156 157 158 169 @CallOnce 170 @Optimize("Method should not be public") 171 public void setId(Long id) { 172 if (this.id != null) { 173 throw new IllegalStateException ("Identifier has already been set"); 174 } 175 this.id = id; 176 } 177 178 181 protected void fireChangeEvent() { 182 Object [] listeners = listenerList.getListenerList(); 183 for (int i = listeners.length - 2; i >= 0; i -= 2) { 184 if (listeners[i] == ChangeListener.class) { 185 ((ChangeListener) listeners[i + 1]).stateChanged(changeEvent); 186 } 187 } 188 } 189 190 193 private EventListenerList listenerList = new EventListenerList(); 194 195 199 private ChangeEvent changeEvent; 200 201 204 private Long id; 205 206 } 207 208 | Popular Tags |