1 23 24 package org.objectweb.fractal.rmi.registry; 25 26 import org.objectweb.fractal.api.Component; 27 28 import java.io.File ; 29 import java.util.HashMap ; 30 import java.util.Map ; 31 32 36 37 public class NamingServiceImpl 38 implements NamingService, NamingServiceAttributes 39 { 40 41 static final String defaultPersistenceFile = "namingServiceState.bytes"; 42 43 private boolean isPersistent = false; 44 45 private String persistenceFileName = null; 46 47 private Map bindings = new HashMap (); 48 49 53 public synchronized String [] list () { 54 return (String [])bindings.keySet().toArray(new String [bindings.size()]); 55 } 56 57 public synchronized Component lookup (final String name) { 58 return (Component)bindings.get(name); 59 } 60 61 public synchronized boolean bind (final String name, final Component comp) { 62 if (! bindings.containsKey(name)) { 63 bindings.put(name, comp); 64 return true; 65 } else { 66 return false; 67 } 68 } 69 70 public synchronized Component rebind (final String name, final Component comp) { 71 Component old = (Component)bindings.remove(name); 72 bindings.put(name, comp); 73 return old; 74 } 75 76 public synchronized Component unbind (final String name) { 77 return (Component)bindings.remove(name); 78 } 79 80 84 public boolean getPersistenceMode () { 85 return isPersistent; 86 } 87 88 public synchronized void setPersistenceMode (final boolean on) { 89 if (on) { 90 if (!isPersistent) { 91 isPersistent = true; 92 if (persistenceFileName == null) { 93 persistenceFileName = defaultPersistenceFile; 94 } 95 } 96 } 97 else if (isPersistent) { 98 isPersistent = false; 99 new File (persistenceFileName).delete(); 100 } 101 } 102 103 public String getPersistenceFileName () { 104 return persistenceFileName; 106 } 107 108 public synchronized void setPersistenceFileName (final String fileName) { 109 if (isPersistent && !fileName.equals(persistenceFileName)) { 111 new File (persistenceFileName).renameTo(new File (fileName)); 112 } 113 persistenceFileName = fileName; 114 } 115 } 116 | Popular Tags |